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
1=== modified file 'src/net/tapaal/Preferences.java'
2--- src/net/tapaal/Preferences.java 2016-11-14 09:58:40 +0000
3+++ src/net/tapaal/Preferences.java 2022-08-01 13:40:11 +0000
4@@ -329,4 +329,18 @@
5
6 return object;
7 }
8+
9+ public void setFileBrowserLocation(String location) {
10+ final String key = "file.location";
11+
12+ if (location == null || location.equals("")){
13+ pref.remove(key);
14+ } else {
15+ pref.put(key, location);
16+ }
17+ }
18+
19+ public String getFileBrowserLocation() {
20+ return pref.get("file.location", null);
21+ }
22 }
23
24=== modified file 'src/pipe/gui/widgets/filebrowser/NativeFileBrowser.java'
25--- src/pipe/gui/widgets/filebrowser/NativeFileBrowser.java 2020-11-27 12:35:35 +0000
26+++ src/pipe/gui/widgets/filebrowser/NativeFileBrowser.java 2022-08-01 13:40:11 +0000
27@@ -8,6 +8,8 @@
28 import java.util.regex.Pattern;
29
30 import javax.swing.*;
31+
32+import net.tapaal.Preferences;
33 import pipe.gui.CreateGui;
34
35 class NativeFileBrowser extends FileBrowser {
36@@ -56,7 +58,7 @@
37
38
39 public File openFile() {
40- if(specifiedPath == null) specifiedPath = lastOpenPath;
41+ if(specifiedPath == null) specifiedPath = Preferences.getInstance().getFileBrowserLocation();
42 fc.setDirectory(specifiedPath);
43 //This is needed for Windows
44 if(optionalExt.equals("")) fc.setFile(ext.equals("")? "":("*."+ext));
45@@ -66,13 +68,13 @@
46 fc.setVisible(true);
47 String selectedFile = fc.getFile();
48 String selectedDir = fc.getDirectory();
49- lastOpenPath = selectedDir;
50+ Preferences.getInstance().setFileBrowserLocation(selectedDir);
51 File file = selectedFile == null? null:new File(selectedDir + selectedFile);
52 return file;
53 }
54
55 public File[] openFiles() {
56- if(specifiedPath == null) specifiedPath = lastOpenPath;
57+ if(specifiedPath == null) specifiedPath = Preferences.getInstance().getFileBrowserLocation();;
58 fc.setDirectory(specifiedPath);
59 //This is needed for Windows
60 if(optionalExt.equals("")) fc.setFile(ext.equals("")? "":("*."+ext));
61@@ -81,12 +83,12 @@
62 fc.setMode(FileDialog.LOAD);
63 fc.setVisible(true);
64 File[] selectedFiles = fc.getFiles();
65- lastOpenPath = fc.getDirectory();
66+ Preferences.getInstance().setFileBrowserLocation(fc.getDirectory());
67 return selectedFiles;
68 }
69
70 public String saveFile(String suggestedName) {
71- if(specifiedPath == null) specifiedPath = lastSavePath;
72+ if(specifiedPath == null) specifiedPath = Preferences.getInstance().getFileBrowserLocation();
73 fc.setDirectory(specifiedPath);
74 fc.setFile(suggestedName + (suggestedName.endsWith("."+ext)? "":"."+ext));
75 fc.setMode(FileDialog.SAVE);
76@@ -103,7 +105,7 @@
77 }
78
79 String file = fc.getFile() == null? null: fc.getDirectory() + fc.getFile();
80- lastSavePath = fc.getDirectory();
81+ Preferences.getInstance().setFileBrowserLocation(fc.getDirectory());
82
83 if(file == null){
84 return file;
85@@ -150,14 +152,14 @@
86 //So we make a JFileChooser in which we can control it
87 if(System.getProperty("os.name").startsWith("Windows")) {
88 File selectedDir = null;
89- if (specifiedPath == null) specifiedPath = lastSavePath;
90+ if (specifiedPath == null) specifiedPath = Preferences.getInstance().getFileBrowserLocation();;
91 JFileChooser c = new JFileChooser(specifiedPath);
92 c.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
93 c.setDialogTitle("Choose target directory for export");
94 int rVal = c.showSaveDialog(c);
95 if (rVal == JFileChooser.APPROVE_OPTION) {
96 selectedDir = c.getSelectedFile();
97- lastSavePath = selectedDir.getPath();
98+ Preferences.getInstance().setFileBrowserLocation(selectedDir.getPath());
99 }
100
101 return selectedDir;
102
103=== modified file 'src/pipe/gui/widgets/filebrowser/NativeFileBrowserFallback.java'
104--- src/pipe/gui/widgets/filebrowser/NativeFileBrowserFallback.java 2020-05-05 18:17:52 +0000
105+++ src/pipe/gui/widgets/filebrowser/NativeFileBrowserFallback.java 2022-08-01 13:40:11 +0000
106@@ -10,6 +10,8 @@
107 import javax.swing.JFileChooser;
108 import javax.swing.JOptionPane;
109 import javax.swing.filechooser.FileNameExtensionFilter;
110+
111+import net.tapaal.Preferences;
112 import pipe.gui.CreateGui;
113
114 class NativeFileBrowserFallback extends FileBrowser {
115@@ -75,7 +77,7 @@
116 }
117
118 public File openFile() {
119- if(specifiedPath == null) specifiedPath = lastOpenPath;
120+ if(specifiedPath == null) specifiedPath = Preferences.getInstance().getFileBrowserLocation();;
121 fc.setDirectory(specifiedPath);
122 //This is needed for windows
123 if(optionalExt.equals("")) fc.setFile(ext.equals("")? "":("*."+ext));
124@@ -84,13 +86,13 @@
125 fc.setVisible(true);
126 String selectedFile = fc.getFile();
127 String selectedDir = fc.getDirectory();
128- lastOpenPath = selectedDir;
129+ Preferences.getInstance().setFileBrowserLocation(selectedDir);
130 File file = selectedFile == null? null:new File(selectedDir + selectedFile);
131 return file;
132 }
133
134 public File[] openFiles() {
135- if(specifiedPath == null) specifiedPath = lastOpenPath;
136+ if(specifiedPath == null) specifiedPath = Preferences.getInstance().getFileBrowserLocation();;
137 if(new File(specifiedPath).exists()) fileChooser.setCurrentDirectory(new File(specifiedPath));
138 /*if (lastPath != null) {
139 File path = new File(lastPath);
140@@ -104,20 +106,20 @@
141 filesArray = fileChooser.getSelectedFiles();
142 }
143 //They should all come from the same directory so we just take one
144- lastOpenPath = filesArray[0].getAbsolutePath();
145+ Preferences.getInstance().setFileBrowserLocation(filesArray[0].getAbsolutePath());
146 return filesArray;
147 }
148
149
150 public String saveFile(String suggestedName) {
151- if(specifiedPath == null) specifiedPath = lastSavePath;
152+ if(specifiedPath == null) specifiedPath = Preferences.getInstance().getFileBrowserLocation();;
153 fc.setDirectory(specifiedPath);
154 fc.setFile(suggestedName + (suggestedName.endsWith("."+ext)? "":"."+ext));
155 fc.setMode(FileDialog.SAVE);
156 fc.setVisible(true);
157
158 String file = fc.getFile() == null? null: fc.getDirectory() + fc.getFile();
159- lastSavePath = fc.getDirectory();
160+ Preferences.getInstance().setFileBrowserLocation(fc.getDirectory());
161
162 if(file == null){
163 return file;
164@@ -163,14 +165,14 @@
165 //So we make a JFileChooser in which we can control it
166 if(System.getProperty("os.name").startsWith("Windows")) {
167 File selectedDir = null;
168- if (specifiedPath == null) specifiedPath = lastSavePath;
169+ if (specifiedPath == null) specifiedPath = Preferences.getInstance().getFileBrowserLocation();;
170 JFileChooser c = new JFileChooser(specifiedPath);
171 c.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
172 c.setDialogTitle("Choose target directory for export");
173 int rVal = c.showSaveDialog(c);
174 if (rVal == JFileChooser.APPROVE_OPTION) {
175 selectedDir = c.getSelectedFile();
176- lastSavePath = selectedDir.getPath();
177+ Preferences.getInstance().setFileBrowserLocation(selectedDir.getPath());
178 }
179
180 return selectedDir;

Subscribers

People subscribed via source and target branches