Merge lp:~tapaal-contributor/tapaal/only-dirs-batch-export-1870887 into lp:tapaal

Proposed by Peter Haahr Taankvist
Status: Merged
Approved by: Jiri Srba
Approved revision: 1054
Merged at revision: 1052
Proposed branch: lp:~tapaal-contributor/tapaal/only-dirs-batch-export-1870887
Merge into: lp:tapaal
Diff against target: 174 lines (+73/-13)
4 files modified
src/pipe/gui/ExportBatchDialog.java (+7/-5)
src/pipe/gui/widgets/filebrowser/FileBrowser.java (+3/-2)
src/pipe/gui/widgets/filebrowser/NativeFileBrowser.java (+33/-5)
src/pipe/gui/widgets/filebrowser/NativeFileBrowserFallback.java (+30/-1)
To merge this branch: bzr merge lp:~tapaal-contributor/tapaal/only-dirs-batch-export-1870887
Reviewer Review Type Date Requested Status
Jiri Srba Approve
Peter Haahr Taankvist (community) Needs Resubmitting
Kenneth Yrke Jørgensen code Needs Fixing
Review via email: mp+383302@code.launchpad.net

Commit message

Make specific function for choosing directories only. New behaviour for windows and old one for Ubuntu.

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

The issues is not fixed for Mac, it is still possible to select a file and it will ask whether it should be overwritten.

Please, remove also the debugging information.

review: Needs Fixing
Revision history for this message
Kenneth Yrke Jørgensen (yrke) :
review: Needs Fixing (code)
Revision history for this message
Kenneth Yrke Jørgensen (yrke) wrote :

Please also add a comment about why its needed to handle Windows different form other architecture, would be nice if we could linkt something describing the differences in behavior.

1053. By Peter Haahr Taankvist

Added property that should make filedialog directories only for mac

1054. By Peter Haahr Taankvist

Add the new function to NativeFileBrowserFallback

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

Added a property which should make the filedialog directories only for mac.

Also added some comments describing the need for different behaviour.

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

On Mac the behaviour is better now: it says "Select folder ..." in the dialog but it still allows to select a file - if done so, it will ask only once if it should be rewritten and not twice. If this cannot be fixed any better, it is acceptable.

Has it been tested on Linux?

In the code for mac, the string
apple.awt.fileDialogForDirectories
is set to value "false" after the change. It would be safer to change it to the
previously set value.

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

Is it the TAPAAL dialog or your system dialog? If it is the TAPAAL dialog we may be able to suppress it. On Linux files are not shown when saving it seems.

The default value for apple.awt.fileDialogForDirectories is false. When it is false you should be able to choose both files and directories, but when true only directories.

We can also try the same solution for Mac as we used for Windows, but I seem to remember that you did not like the look of JFileChooser on Mac.

Revision history for this message
Jiri Srba (srba) wrote :

In 3.6 I get both the system dialog followed by the TAPAAL dialog.
After the fix in the branch I get only the system dialog. The dialog looks
different - it asks to select only directory and in fact files are grayed out,
but they can be still selected and then I get the system warning. It is only
the directory that appears in the path after the selection, so not a big deal
if this cannot be fixed further, I think it is acceptable.

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

I cannot come up with anything better. Should i prepare a branch for 3.6?

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

Yes, if it works as it should on Linux and Windows (I didn't test it) the I think we can merge it to trunk now. Please, prepare also 3.6 branch for the merge.

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

Kenneth, I am gonna merge. The code issues where fixed.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/pipe/gui/ExportBatchDialog.java'
2--- src/pipe/gui/ExportBatchDialog.java 2020-04-18 16:08:44 +0000
3+++ src/pipe/gui/ExportBatchDialog.java 2020-05-05 18:18:57 +0000
4@@ -237,7 +237,9 @@
5 JButton destinationPathSelector = new JButton("Select destination folder");
6 destinationPathSelector.addActionListener(e -> {
7 selectDestinationPath();
8- destinationPathField.setText(destinationFile.getParent());
9+ if(destinationFile != null) {
10+ destinationPathField.setText(lastExportPath);
11+ }
12 enableButtons();
13 });
14 chooserPanel.add(destinationPathSelector, gbc);
15@@ -450,10 +452,10 @@
16 }
17
18 private void selectDestinationPath() {
19- String chosenFile = FileBrowser.constructor("Select an export folder", ".", lastExportPath).saveFile("Export");
20+ File chosenFile = FileBrowser.constructor("Select an export folder", ".", lastExportPath).saveFileToDir();
21 if(chosenFile != null) {
22- destinationFile = new File(chosenFile);
23- lastExportPath = chosenFile;
24+ destinationFile = chosenFile;
25+ lastExportPath = destinationFile.getAbsolutePath();
26 }
27 else return;
28 }
29@@ -463,7 +465,7 @@
30 initProgressBar();
31
32 if(destinationFile != null && destinationFile.exists()) {
33- String destPath = destinationFile.isFile() ? destinationFile.getParent() : destinationFile.getAbsolutePath();
34+ String destPath = destinationFile.isDirectory() ? destinationFile.getAbsolutePath(): destinationFile.getParent();
35 lastExportPath = destPath;
36 progressBarThread.start();
37 for(File file : files) {
38
39=== modified file 'src/pipe/gui/widgets/filebrowser/FileBrowser.java'
40--- src/pipe/gui/widgets/filebrowser/FileBrowser.java 2020-04-18 15:39:19 +0000
41+++ src/pipe/gui/widgets/filebrowser/FileBrowser.java 2020-05-05 18:18:57 +0000
42@@ -11,8 +11,8 @@
43 //Default value null makes the open dialog open default folder, For Windows, My Documents, For *nix ~ , etc
44 //XXX 2018-05-23 moved from CreateGUI, refactor with regards to usage with lastPath local var in this class
45 public static String userPath = null;
46- static String lastSavePath = null;
47- static String lastOpenPath = null;
48+ static String lastSavePath = ".";
49+ static String lastOpenPath = ".";
50
51 public static FileBrowser constructor(String filetype, final String ext) {
52 return constructor(filetype, ext, null);
53@@ -48,5 +48,6 @@
54 }
55
56 public abstract String saveFile(String suggestedName);
57+ public abstract File saveFileToDir();
58
59 }
60
61=== modified file 'src/pipe/gui/widgets/filebrowser/NativeFileBrowser.java'
62--- src/pipe/gui/widgets/filebrowser/NativeFileBrowser.java 2020-04-18 15:39:19 +0000
63+++ src/pipe/gui/widgets/filebrowser/NativeFileBrowser.java 2020-05-05 18:18:57 +0000
64@@ -7,8 +7,7 @@
65 import java.util.regex.Matcher;
66 import java.util.regex.Pattern;
67
68-import javax.swing.JOptionPane;
69-
70+import javax.swing.*;
71 import pipe.gui.CreateGui;
72
73 class NativeFileBrowser extends FileBrowser {
74@@ -23,7 +22,7 @@
75 NativeFileBrowser(String filetype, final String ext, final String optionalExt, String path) {
76 fc = new FileDialog(CreateGui.getAppGui(), filetype);
77 this.specifiedPath = path;
78-
79+
80 if (filetype == null) {
81 filetype = "file";
82 }
83@@ -85,7 +84,7 @@
84 lastOpenPath = fc.getDirectory();
85 return selectedFiles;
86 }
87-
88+
89 public String saveFile(String suggestedName) {
90 if(specifiedPath == null) specifiedPath = lastSavePath;
91 fc.setDirectory(specifiedPath);
92@@ -146,5 +145,34 @@
93
94 return file;
95 }
96-
97+ public File saveFileToDir(){
98+ //In Windows the native FileDialog only works with files
99+ //So we make a JFileChooser in which we can control it
100+ if(System.getProperty("os.name").startsWith("Windows")) {
101+ File selectedDir = null;
102+ if (specifiedPath == null) specifiedPath = lastSavePath;
103+ JFileChooser c = new JFileChooser(specifiedPath);
104+ c.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
105+ c.setDialogTitle("Choose target directory for export");
106+ int rVal = c.showSaveDialog(c);
107+ if (rVal == JFileChooser.APPROVE_OPTION) {
108+ selectedDir = c.getSelectedFile();
109+ lastSavePath = selectedDir.getPath();
110+ }
111+
112+ return selectedDir;
113+ } else{
114+ //For Mac we can set Directories only
115+ //For linux a save dialog only shows directories
116+ System.setProperty("apple.awt.fileDialogForDirectories", "true");
117+ String selection = saveFile("Choose Directory");
118+ System.setProperty("apple.awt.fileDialogForDirectories", "false");
119+ if(selection != null) {
120+ return new File(fc.getDirectory());
121+ } else{
122+ return null;
123+ }
124+ }
125+
126+ }
127 }
128
129=== modified file 'src/pipe/gui/widgets/filebrowser/NativeFileBrowserFallback.java'
130--- src/pipe/gui/widgets/filebrowser/NativeFileBrowserFallback.java 2020-04-18 14:41:05 +0000
131+++ src/pipe/gui/widgets/filebrowser/NativeFileBrowserFallback.java 2020-05-05 18:18:57 +0000
132@@ -10,7 +10,6 @@
133 import javax.swing.JFileChooser;
134 import javax.swing.JOptionPane;
135 import javax.swing.filechooser.FileNameExtensionFilter;
136-
137 import pipe.gui.CreateGui;
138
139 class NativeFileBrowserFallback extends FileBrowser {
140@@ -159,4 +158,34 @@
141 }
142 return file;
143 }
144+ public File saveFileToDir(){
145+ //In Windows the native FileDialog only works with files
146+ //So we make a JFileChooser in which we can control it
147+ if(System.getProperty("os.name").startsWith("Windows")) {
148+ File selectedDir = null;
149+ if (specifiedPath == null) specifiedPath = lastSavePath;
150+ JFileChooser c = new JFileChooser(specifiedPath);
151+ c.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
152+ c.setDialogTitle("Choose target directory for export");
153+ int rVal = c.showSaveDialog(c);
154+ if (rVal == JFileChooser.APPROVE_OPTION) {
155+ selectedDir = c.getSelectedFile();
156+ lastSavePath = selectedDir.getPath();
157+ }
158+
159+ return selectedDir;
160+ } else{
161+ //For Mac we can set Directories only
162+ //For linux a save dialog only shows directories
163+ System.setProperty("apple.awt.fileDialogForDirectories", "true");
164+ String selection = saveFile("Choose Directory");
165+ System.setProperty("apple.awt.fileDialogForDirectories", "false");
166+ if(selection != null) {
167+ return new File(fc.getDirectory());
168+ } else{
169+ return null;
170+ }
171+ }
172+
173+ }
174 }

Subscribers

People subscribed via source and target branches