Merge lp:~tapaal-contributor/tapaal/seperate-save-paths-1855266 into lp:tapaal

Proposed by Peter Haahr Taankvist
Status: Merged
Approved by: Jiri Srba
Approved revision: 1035
Merged at revision: 1037
Proposed branch: lp:~tapaal-contributor/tapaal/seperate-save-paths-1855266
Merge into: lp:tapaal
Diff against target: 222 lines (+40/-23)
4 files modified
src/pipe/gui/GuiFrame.java (+4/-4)
src/pipe/gui/widgets/filebrowser/FileBrowser.java (+4/-6)
src/pipe/gui/widgets/filebrowser/NativeFileBrowser.java (+14/-6)
src/pipe/gui/widgets/filebrowser/NativeFileBrowserFallback.java (+18/-7)
To merge this branch: bzr merge lp:~tapaal-contributor/tapaal/seperate-save-paths-1855266
Reviewer Review Type Date Requested Status
Jiri Srba Approve
Peter Haahr Taankvist (community) Needs Resubmitting
Kenneth Yrke Jørgensen Approve
Review via email: mp+378117@code.launchpad.net

Commit message

Use static save paths in filebrowser, such that they are kept across instances.

To post a comment you must log in.
Revision history for this message
Jiri Srba (srba) wrote :

Remove debugging information please.

Otherwise it seems to work just fine.

review: Needs Fixing
Revision history for this message
Kenneth Yrke Jørgensen (yrke) :
review: Approve
1035. By Peter Taankvist <email address hidden>

Removed debugging line

Revision history for this message
Peter Haahr Taankvist (ptaank) wrote :

Removed debugging line

review: Needs Resubmitting
Revision history for this message
Jiri Srba (srba) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/pipe/gui/GuiFrame.java'
2--- src/pipe/gui/GuiFrame.java 2019-11-29 17:35:45 +0000
3+++ src/pipe/gui/GuiFrame.java 2020-02-03 17:41:11 +0000
4@@ -1632,13 +1632,13 @@
5 saveNet(index, modelFile);
6 result = true;
7 } else { // save as
8- String path;
9+ String path = null;
10 if (modelFile != null) {
11 path = modelFile.getParent();
12- } else {
13- path = appTab.getTitleAt(index);
14 }
15- String filename = FileBrowser.constructor("Timed-Arc Petri Net", "tapn", path).saveFile(path);
16+
17+ String suggestedName = appTab.getTitleAt(index);
18+ String filename = FileBrowser.constructor("Timed-Arc Petri Net", "tapn", path).saveFile(suggestedName);
19 if (filename != null) {
20 modelFile = new File(filename);
21 saveNet(index, modelFile);
22
23=== modified file 'src/pipe/gui/widgets/filebrowser/FileBrowser.java'
24--- src/pipe/gui/widgets/filebrowser/FileBrowser.java 2018-08-11 09:28:11 +0000
25+++ src/pipe/gui/widgets/filebrowser/FileBrowser.java 2020-02-03 17:41:11 +0000
26@@ -11,7 +11,8 @@
27 //Default value null makes the open dialog open default folder, For Windows, My Documents, For *nix ~ , etc
28 //XXX 2018-05-23 moved from CreateGUI, refactor with regards to usage with lastPath local var in this class
29 public static String userPath = null;
30- String lastPath = null;
31+ static String lastSavePath = null;
32+ static String lastOpenPath = null;
33
34 public static FileBrowser constructor(String filetype, final String ext) {
35 return constructor(filetype, ext, null);
36@@ -24,16 +25,13 @@
37
38 if(JavaUtil.getJREMajorVersion() >= 7){
39 FileBrowser newObject = new NativeFileBrowser(filetype, ext, optionalExt, path);
40- if(path != null) {
41- newObject.lastPath = path;
42- }
43
44 return newObject;
45 }else{
46 FileBrowser newObject = new NativeFileBrowserFallback(filetype, ext, optionalExt, path);
47- if(path != null) {
48+ /*if(path != null) {
49 newObject.lastPath = path;
50- }
51+ }*/
52 return newObject;
53 }
54
55
56=== modified file 'src/pipe/gui/widgets/filebrowser/NativeFileBrowser.java'
57--- src/pipe/gui/widgets/filebrowser/NativeFileBrowser.java 2018-08-02 10:02:01 +0000
58+++ src/pipe/gui/widgets/filebrowser/NativeFileBrowser.java 2020-02-03 17:41:11 +0000
59@@ -14,20 +14,22 @@
60 class NativeFileBrowser extends FileBrowser {
61 private FileDialog fc;
62 private String ext;
63+ private String specifiedPath;
64 NativeFileBrowser(String filetype, final String ext, String path) {
65 this(filetype, ext, "", path);
66 }
67
68 NativeFileBrowser(String filetype, final String ext, final String optionalExt, String path) {
69 fc = new FileDialog(CreateGui.getAppGui(), filetype);
70-
71+ this.specifiedPath = path;
72+
73 if (filetype == null) {
74 filetype = "file";
75 }
76- if(path == null) path = lastPath;
77+ //if(path == null) path = lastPath;
78
79 this.ext = ext;
80- fc.setDirectory(path);
81+ //fc.setDirectory(path);
82
83 // Setup filter if extension specified
84 if(!ext.equals("")){
85@@ -52,29 +54,35 @@
86
87
88 public File openFile() {
89+ if(specifiedPath == null) specifiedPath = lastOpenPath;
90+ fc.setDirectory(specifiedPath);
91 fc.setFile(ext.equals("")? "":"*."+ext);
92 fc.setMode(FileDialog.LOAD);
93 fc.setMultipleMode(false);
94 fc.setVisible(true);
95 String selectedFile = fc.getFile();
96 String selectedDir = fc.getDirectory();
97- lastPath = selectedDir;
98+ lastOpenPath = selectedDir;
99 File file = selectedFile == null? null:new File(selectedDir + selectedFile);
100 return file;
101 }
102
103 public File[] openFiles() {
104+ if(specifiedPath == null) specifiedPath = lastOpenPath;
105+ fc.setDirectory(specifiedPath);
106 fc.setFile(ext.equals("")? "":"*."+ext);
107 fc.setMultipleMode(true);
108 fc.setMode(FileDialog.LOAD);
109 fc.setVisible(true);
110 File[] selectedFiles = fc.getFiles();
111 String selectedDir = fc.getDirectory();
112- lastPath = selectedDir;
113+ lastOpenPath = selectedDir;
114 return selectedFiles;
115 }
116
117 public String saveFile(String suggestedName) {
118+ if(specifiedPath == null) specifiedPath = lastSavePath;
119+ fc.setDirectory(specifiedPath);
120 fc.setFile(suggestedName + (suggestedName.endsWith("."+ext)? "":"."+ext));
121 fc.setMode(FileDialog.SAVE);
122 fc.setVisible(true);
123@@ -90,7 +98,7 @@
124 }
125
126 String file = fc.getFile() == null? null: fc.getDirectory() + fc.getFile();
127- lastPath = fc.getDirectory();
128+ lastSavePath = fc.getDirectory();
129
130 if(file == null){
131 return file;
132
133=== modified file 'src/pipe/gui/widgets/filebrowser/NativeFileBrowserFallback.java'
134--- src/pipe/gui/widgets/filebrowser/NativeFileBrowserFallback.java 2018-08-02 10:02:01 +0000
135+++ src/pipe/gui/widgets/filebrowser/NativeFileBrowserFallback.java 2020-02-03 17:41:11 +0000
136@@ -4,6 +4,7 @@
137 import java.io.File;
138 import java.io.FilenameFilter;
139 import java.io.IOException;
140+import java.nio.file.Path;
141 import java.util.regex.Matcher;
142 import java.util.regex.Pattern;
143
144@@ -16,6 +17,7 @@
145 class NativeFileBrowserFallback extends FileBrowser {
146 private FileDialog fc;
147 private String ext;
148+ private String specifiedPath;
149 private JFileChooser fileChooser;
150 /**
151 This show native open/save dialogs for all type of dialogs except multifile open,
152@@ -26,14 +28,15 @@
153 }
154 NativeFileBrowserFallback(String filetype, final String ext, final String optionalExt, String path) {
155 fc = new FileDialog(CreateGui.getAppGui(), filetype);
156-
157+
158+ specifiedPath = path;
159 if (filetype == null) {
160 filetype = "file";
161 }
162- if(path == null) path = lastPath;
163+ //if(path == null) path = lastPath;
164
165 this.ext = ext;
166- fc.setDirectory(path);
167+ //fc.setDirectory(path);
168
169 /* Setup JFileChooser for multi file selection */
170 fileChooser = new JFileChooser();
171@@ -71,39 +74,47 @@
172 }
173
174 public File openFile() {
175+ if(specifiedPath == null) specifiedPath = lastOpenPath;
176+ fc.setDirectory(specifiedPath);
177 fc.setFile(ext.equals("")? "":"*."+ext);
178 fc.setMode(FileDialog.LOAD);
179 fc.setVisible(true);
180 String selectedFile = fc.getFile();
181 String selectedDir = fc.getDirectory();
182- lastPath = selectedDir;
183+ lastOpenPath = selectedDir;
184 File file = selectedFile == null? null:new File(selectedDir + selectedFile);
185 return file;
186 }
187
188 public File[] openFiles() {
189- if (lastPath != null) {
190+ if(specifiedPath == null) specifiedPath = lastOpenPath;
191+ if(new File(specifiedPath).exists()) fileChooser.setCurrentDirectory(new File(specifiedPath));
192+ /*if (lastPath != null) {
193 File path = new File(lastPath);
194 if (path.exists()) {
195 fileChooser.setCurrentDirectory(path);
196 }
197- }
198+ }*/
199 File[] filesArray = new File[0];
200 int result = fileChooser.showOpenDialog(null);
201 if (result == JFileChooser.APPROVE_OPTION) {
202 filesArray = fileChooser.getSelectedFiles();
203 }
204+ //They should all come from the same directory so we just take one
205+ lastOpenPath = filesArray[0].getAbsolutePath();
206 return filesArray;
207 }
208
209
210 public String saveFile(String suggestedName) {
211+ if(specifiedPath == null) specifiedPath = lastSavePath;
212+ fc.setDirectory(specifiedPath);
213 fc.setFile(suggestedName + (suggestedName.endsWith("."+ext)? "":"."+ext));
214 fc.setMode(FileDialog.SAVE);
215 fc.setVisible(true);
216
217 String file = fc.getFile() == null? null: fc.getDirectory() + fc.getFile();
218- lastPath = fc.getDirectory();
219+ lastSavePath = fc.getDirectory();
220
221 if(file == null){
222 return file;

Subscribers

People subscribed via source and target branches