~yrke/tapaal/slimImageIcons-2

« back to all changes in this revision

Viewing changes to src/pipe/gui/widgets/filebrowser/NativeFileBrowserFallback.java

merged in lp:~tapaal-contributor/tapaal/seperate-save-paths-1855266 fixing load/save paths 

Show diffs side-by-side

added added

removed removed

Lines of Context:
4
4
import java.io.File;
5
5
import java.io.FilenameFilter;
6
6
import java.io.IOException;
 
7
import java.nio.file.Path;
7
8
import java.util.regex.Matcher;
8
9
import java.util.regex.Pattern;
9
10
 
16
17
class NativeFileBrowserFallback extends FileBrowser {
17
18
        private FileDialog fc;
18
19
        private String ext;
 
20
        private String specifiedPath;
19
21
        private JFileChooser fileChooser;
20
22
        /**
21
23
                This show native open/save dialogs for all type of dialogs except multifile open,
26
28
        }
27
29
        NativeFileBrowserFallback(String filetype, final String ext, final String optionalExt, String path) {
28
30
                fc = new FileDialog(CreateGui.getAppGui(), filetype);
29
 
 
 
31
                
 
32
                specifiedPath = path;
30
33
                if (filetype == null) {
31
34
                        filetype = "file";
32
35
                }
33
 
                if(path == null) path = lastPath;
 
36
                //if(path == null) path = lastPath;
34
37
 
35
38
                this.ext = ext;
36
 
                fc.setDirectory(path);
 
39
                //fc.setDirectory(path);
37
40
 
38
41
                /* Setup JFileChooser for multi file selection */
39
42
                fileChooser = new JFileChooser();
71
74
        }
72
75
 
73
76
        public File openFile() {
 
77
                if(specifiedPath == null) specifiedPath = lastOpenPath;
 
78
                fc.setDirectory(specifiedPath);
74
79
                fc.setFile(ext.equals("")? "":"*."+ext);
75
80
                fc.setMode(FileDialog.LOAD);
76
81
                fc.setVisible(true);
77
82
                String selectedFile = fc.getFile();
78
83
                String selectedDir = fc.getDirectory();
79
 
                lastPath = selectedDir;
 
84
                lastOpenPath = selectedDir;
80
85
                File file = selectedFile == null? null:new File(selectedDir + selectedFile);
81
86
                return file;
82
87
        }
83
88
 
84
89
        public File[] openFiles() {
85
 
                if (lastPath != null) {
 
90
                if(specifiedPath == null) specifiedPath = lastOpenPath;
 
91
                if(new File(specifiedPath).exists()) fileChooser.setCurrentDirectory(new File(specifiedPath));
 
92
                /*if (lastPath != null) {
86
93
                        File path = new File(lastPath);
87
94
                        if (path.exists()) {
88
95
                                fileChooser.setCurrentDirectory(path);
89
96
                        }
90
 
                }
 
97
                }*/
91
98
                File[] filesArray = new File[0];
92
99
                int result = fileChooser.showOpenDialog(null);
93
100
                if (result == JFileChooser.APPROVE_OPTION) {
94
101
                        filesArray = fileChooser.getSelectedFiles();
95
102
                }
 
103
                //They should all come from the same directory so we just take one
 
104
                lastOpenPath = filesArray[0].getAbsolutePath();
96
105
                return filesArray;
97
106
        }
98
107
 
99
108
 
100
109
        public String saveFile(String suggestedName) {
 
110
                if(specifiedPath == null) specifiedPath = lastSavePath;
 
111
                fc.setDirectory(specifiedPath);
101
112
                fc.setFile(suggestedName + (suggestedName.endsWith("."+ext)? "":"."+ext));
102
113
                fc.setMode(FileDialog.SAVE);
103
114
                fc.setVisible(true);
104
115
 
105
116
                String file = fc.getFile() == null? null: fc.getDirectory() + fc.getFile();
106
 
                lastPath = fc.getDirectory();
 
117
                lastSavePath = fc.getDirectory();
107
118
 
108
119
                if(file == null){
109
120
                        return file;