Merge lp:~tapaal-contributor/tapaal/save-file-browser-location-3.9 into lp:tapaal/3.9

Proposed by Lena Ernstsen
Status: Merged
Approved by: Jiri Srba
Approved revision: 1173
Merged at revision: 1173
Proposed branch: lp:~tapaal-contributor/tapaal/save-file-browser-location-3.9
Merge into: lp:tapaal/3.9
Diff against target: 180 lines (+34/-16)
3 files modified
src/net/tapaal/Preferences.java (+14/-0)
src/pipe/gui/widgets/filebrowser/NativeFileBrowser.java (+10/-8)
src/pipe/gui/widgets/filebrowser/NativeFileBrowserFallback.java (+10/-8)
To merge this branch: bzr merge lp:~tapaal-contributor/tapaal/save-file-browser-location-3.9
Reviewer Review Type Date Requested Status
Jiri Srba Approve
Review via email: mp+427687@code.launchpad.net

This proposal supersedes a proposal from 2022-08-01.

Commit message

Stores the location of the file browser

To post a comment you must log in.
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
=== modified file 'src/net/tapaal/Preferences.java'
--- src/net/tapaal/Preferences.java 2016-11-14 09:58:40 +0000
+++ src/net/tapaal/Preferences.java 2022-08-01 13:40:11 +0000
@@ -329,4 +329,18 @@
329329
330 return object;330 return object;
331 }331 }
332
333 public void setFileBrowserLocation(String location) {
334 final String key = "file.location";
335
336 if (location == null || location.equals("")){
337 pref.remove(key);
338 } else {
339 pref.put(key, location);
340 }
341 }
342
343 public String getFileBrowserLocation() {
344 return pref.get("file.location", null);
345 }
332}346}
333347
=== modified file 'src/pipe/gui/widgets/filebrowser/NativeFileBrowser.java'
--- src/pipe/gui/widgets/filebrowser/NativeFileBrowser.java 2020-11-27 12:35:35 +0000
+++ src/pipe/gui/widgets/filebrowser/NativeFileBrowser.java 2022-08-01 13:40:11 +0000
@@ -8,6 +8,8 @@
8import java.util.regex.Pattern;8import java.util.regex.Pattern;
99
10import javax.swing.*;10import javax.swing.*;
11
12import net.tapaal.Preferences;
11import pipe.gui.CreateGui;13import pipe.gui.CreateGui;
1214
13class NativeFileBrowser extends FileBrowser {15class NativeFileBrowser extends FileBrowser {
@@ -56,7 +58,7 @@
56 58
5759
58 public File openFile() {60 public File openFile() {
59 if(specifiedPath == null) specifiedPath = lastOpenPath;61 if(specifiedPath == null) specifiedPath = Preferences.getInstance().getFileBrowserLocation();
60 fc.setDirectory(specifiedPath);62 fc.setDirectory(specifiedPath);
61 //This is needed for Windows63 //This is needed for Windows
62 if(optionalExt.equals("")) fc.setFile(ext.equals("")? "":("*."+ext));64 if(optionalExt.equals("")) fc.setFile(ext.equals("")? "":("*."+ext));
@@ -66,13 +68,13 @@
66 fc.setVisible(true);68 fc.setVisible(true);
67 String selectedFile = fc.getFile();69 String selectedFile = fc.getFile();
68 String selectedDir = fc.getDirectory();70 String selectedDir = fc.getDirectory();
69 lastOpenPath = selectedDir;71 Preferences.getInstance().setFileBrowserLocation(selectedDir);
70 File file = selectedFile == null? null:new File(selectedDir + selectedFile);72 File file = selectedFile == null? null:new File(selectedDir + selectedFile);
71 return file;73 return file;
72 }74 }
73 75
74 public File[] openFiles() {76 public File[] openFiles() {
75 if(specifiedPath == null) specifiedPath = lastOpenPath;77 if(specifiedPath == null) specifiedPath = Preferences.getInstance().getFileBrowserLocation();;
76 fc.setDirectory(specifiedPath);78 fc.setDirectory(specifiedPath);
77 //This is needed for Windows79 //This is needed for Windows
78 if(optionalExt.equals("")) fc.setFile(ext.equals("")? "":("*."+ext));80 if(optionalExt.equals("")) fc.setFile(ext.equals("")? "":("*."+ext));
@@ -81,12 +83,12 @@
81 fc.setMode(FileDialog.LOAD);83 fc.setMode(FileDialog.LOAD);
82 fc.setVisible(true);84 fc.setVisible(true);
83 File[] selectedFiles = fc.getFiles();85 File[] selectedFiles = fc.getFiles();
84 lastOpenPath = fc.getDirectory();86 Preferences.getInstance().setFileBrowserLocation(fc.getDirectory());
85 return selectedFiles;87 return selectedFiles;
86 }88 }
8789
88 public String saveFile(String suggestedName) {90 public String saveFile(String suggestedName) {
89 if(specifiedPath == null) specifiedPath = lastSavePath;91 if(specifiedPath == null) specifiedPath = Preferences.getInstance().getFileBrowserLocation();
90 fc.setDirectory(specifiedPath);92 fc.setDirectory(specifiedPath);
91 fc.setFile(suggestedName + (suggestedName.endsWith("."+ext)? "":"."+ext));93 fc.setFile(suggestedName + (suggestedName.endsWith("."+ext)? "":"."+ext));
92 fc.setMode(FileDialog.SAVE);94 fc.setMode(FileDialog.SAVE);
@@ -103,7 +105,7 @@
103 }105 }
104106
105 String file = fc.getFile() == null? null: fc.getDirectory() + fc.getFile();107 String file = fc.getFile() == null? null: fc.getDirectory() + fc.getFile();
106 lastSavePath = fc.getDirectory();108 Preferences.getInstance().setFileBrowserLocation(fc.getDirectory());
107 109
108 if(file == null){110 if(file == null){
109 return file;111 return file;
@@ -150,14 +152,14 @@
150 //So we make a JFileChooser in which we can control it152 //So we make a JFileChooser in which we can control it
151 if(System.getProperty("os.name").startsWith("Windows")) {153 if(System.getProperty("os.name").startsWith("Windows")) {
152 File selectedDir = null;154 File selectedDir = null;
153 if (specifiedPath == null) specifiedPath = lastSavePath;155 if (specifiedPath == null) specifiedPath = Preferences.getInstance().getFileBrowserLocation();;
154 JFileChooser c = new JFileChooser(specifiedPath);156 JFileChooser c = new JFileChooser(specifiedPath);
155 c.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);157 c.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
156 c.setDialogTitle("Choose target directory for export");158 c.setDialogTitle("Choose target directory for export");
157 int rVal = c.showSaveDialog(c);159 int rVal = c.showSaveDialog(c);
158 if (rVal == JFileChooser.APPROVE_OPTION) {160 if (rVal == JFileChooser.APPROVE_OPTION) {
159 selectedDir = c.getSelectedFile();161 selectedDir = c.getSelectedFile();
160 lastSavePath = selectedDir.getPath();162 Preferences.getInstance().setFileBrowserLocation(selectedDir.getPath());
161 }163 }
162164
163 return selectedDir;165 return selectedDir;
164166
=== modified file 'src/pipe/gui/widgets/filebrowser/NativeFileBrowserFallback.java'
--- src/pipe/gui/widgets/filebrowser/NativeFileBrowserFallback.java 2020-05-05 18:17:52 +0000
+++ src/pipe/gui/widgets/filebrowser/NativeFileBrowserFallback.java 2022-08-01 13:40:11 +0000
@@ -10,6 +10,8 @@
10import javax.swing.JFileChooser;10import javax.swing.JFileChooser;
11import javax.swing.JOptionPane;11import javax.swing.JOptionPane;
12import javax.swing.filechooser.FileNameExtensionFilter;12import javax.swing.filechooser.FileNameExtensionFilter;
13
14import net.tapaal.Preferences;
13import pipe.gui.CreateGui;15import pipe.gui.CreateGui;
1416
15class NativeFileBrowserFallback extends FileBrowser {17class NativeFileBrowserFallback extends FileBrowser {
@@ -75,7 +77,7 @@
75 }77 }
7678
77 public File openFile() {79 public File openFile() {
78 if(specifiedPath == null) specifiedPath = lastOpenPath;80 if(specifiedPath == null) specifiedPath = Preferences.getInstance().getFileBrowserLocation();;
79 fc.setDirectory(specifiedPath);81 fc.setDirectory(specifiedPath);
80 //This is needed for windows82 //This is needed for windows
81 if(optionalExt.equals("")) fc.setFile(ext.equals("")? "":("*."+ext));83 if(optionalExt.equals("")) fc.setFile(ext.equals("")? "":("*."+ext));
@@ -84,13 +86,13 @@
84 fc.setVisible(true);86 fc.setVisible(true);
85 String selectedFile = fc.getFile();87 String selectedFile = fc.getFile();
86 String selectedDir = fc.getDirectory();88 String selectedDir = fc.getDirectory();
87 lastOpenPath = selectedDir;89 Preferences.getInstance().setFileBrowserLocation(selectedDir);
88 File file = selectedFile == null? null:new File(selectedDir + selectedFile);90 File file = selectedFile == null? null:new File(selectedDir + selectedFile);
89 return file;91 return file;
90 }92 }
9193
92 public File[] openFiles() {94 public File[] openFiles() {
93 if(specifiedPath == null) specifiedPath = lastOpenPath;95 if(specifiedPath == null) specifiedPath = Preferences.getInstance().getFileBrowserLocation();;
94 if(new File(specifiedPath).exists()) fileChooser.setCurrentDirectory(new File(specifiedPath));96 if(new File(specifiedPath).exists()) fileChooser.setCurrentDirectory(new File(specifiedPath));
95 /*if (lastPath != null) {97 /*if (lastPath != null) {
96 File path = new File(lastPath);98 File path = new File(lastPath);
@@ -104,20 +106,20 @@
104 filesArray = fileChooser.getSelectedFiles();106 filesArray = fileChooser.getSelectedFiles();
105 }107 }
106 //They should all come from the same directory so we just take one108 //They should all come from the same directory so we just take one
107 lastOpenPath = filesArray[0].getAbsolutePath();109 Preferences.getInstance().setFileBrowserLocation(filesArray[0].getAbsolutePath());
108 return filesArray;110 return filesArray;
109 }111 }
110112
111113
112 public String saveFile(String suggestedName) {114 public String saveFile(String suggestedName) {
113 if(specifiedPath == null) specifiedPath = lastSavePath;115 if(specifiedPath == null) specifiedPath = Preferences.getInstance().getFileBrowserLocation();;
114 fc.setDirectory(specifiedPath);116 fc.setDirectory(specifiedPath);
115 fc.setFile(suggestedName + (suggestedName.endsWith("."+ext)? "":"."+ext));117 fc.setFile(suggestedName + (suggestedName.endsWith("."+ext)? "":"."+ext));
116 fc.setMode(FileDialog.SAVE);118 fc.setMode(FileDialog.SAVE);
117 fc.setVisible(true);119 fc.setVisible(true);
118120
119 String file = fc.getFile() == null? null: fc.getDirectory() + fc.getFile();121 String file = fc.getFile() == null? null: fc.getDirectory() + fc.getFile();
120 lastSavePath = fc.getDirectory();122 Preferences.getInstance().setFileBrowserLocation(fc.getDirectory());
121123
122 if(file == null){124 if(file == null){
123 return file;125 return file;
@@ -163,14 +165,14 @@
163 //So we make a JFileChooser in which we can control it165 //So we make a JFileChooser in which we can control it
164 if(System.getProperty("os.name").startsWith("Windows")) {166 if(System.getProperty("os.name").startsWith("Windows")) {
165 File selectedDir = null;167 File selectedDir = null;
166 if (specifiedPath == null) specifiedPath = lastSavePath;168 if (specifiedPath == null) specifiedPath = Preferences.getInstance().getFileBrowserLocation();;
167 JFileChooser c = new JFileChooser(specifiedPath);169 JFileChooser c = new JFileChooser(specifiedPath);
168 c.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);170 c.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
169 c.setDialogTitle("Choose target directory for export");171 c.setDialogTitle("Choose target directory for export");
170 int rVal = c.showSaveDialog(c);172 int rVal = c.showSaveDialog(c);
171 if (rVal == JFileChooser.APPROVE_OPTION) {173 if (rVal == JFileChooser.APPROVE_OPTION) {
172 selectedDir = c.getSelectedFile();174 selectedDir = c.getSelectedFile();
173 lastSavePath = selectedDir.getPath();175 Preferences.getInstance().setFileBrowserLocation(selectedDir.getPath());
174 }176 }
175177
176 return selectedDir;178 return selectedDir;

Subscribers

People subscribed via source and target branches