Skip to content

Commit

Permalink
[Image Export] Save last folder (not file) and ensure folder path exi…
Browse files Browse the repository at this point in the history
…sts when saving
  • Loading branch information
Phillipus committed Jun 17, 2019
1 parent 2ef5c14 commit 57c5232
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public void setErrorMessage(String message) {
};

private static final String PREFS_LAST_PROVIDER = "ExportImageLastProvider"; //$NON-NLS-1$
private static final String PREFS_LAST_FILE = "ExportImageLastFile"; //$NON-NLS-1$
private static final String PREFS_LAST_FOLDER = "ExportImageLastFolder"; //$NON-NLS-1$

public ExportAsImagePage(IFigure figure, String name) {
super("ExportAsImagePage"); //$NON-NLS-1$
Expand Down Expand Up @@ -130,20 +130,14 @@ public void createControl(Composite parent) {
fFileTextField = new Text(exportGroup, SWT.BORDER | SWT.SINGLE);
fFileTextField.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

// Get last file name used so we can re-use the path
String lastFileName = Preferences.STORE.getString(PREFS_LAST_FILE);
if(StringUtils.isSet(lastFileName)) {
// Use our name
File file = new File(lastFileName);
File path = file.getParentFile();
if(path != null) {
lastFileName = new File(path, fName).getPath();
}

fFileTextField.setText(lastFileName);
// Get last folder
String lastFolder = Preferences.STORE.getString(PREFS_LAST_FOLDER);
if(StringUtils.isSet(lastFolder)) {
File file = new File(lastFolder);
fFileTextField.setText(new File(file, fName).getAbsolutePath());
}
else {
fFileTextField.setText(new File(System.getProperty("user.home"), fName).getPath()); //$NON-NLS-1$
fFileTextField.setText(new File(System.getProperty("user.home"), fName).getAbsolutePath()); //$NON-NLS-1$
}

// Single text control so strip CRLFs
Expand Down Expand Up @@ -353,7 +347,12 @@ public void setErrorMessage(String message) {
}

void storePreferences() {
Preferences.STORE.setValue(PREFS_LAST_FILE, getFileName());
// Store current folder
File parentFile = new File(getFileName()).getAbsoluteFile().getParentFile(); // Make sure to use absolute file
if(parentFile != null) {
Preferences.STORE.setValue(PREFS_LAST_FOLDER, parentFile.getAbsolutePath());
}

if(fSelectedProvider != null) {
Preferences.STORE.setValue(PREFS_LAST_PROVIDER, fSelectedProvider.getID());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,18 @@ public boolean performFinish() {
if(file.exists()) {
boolean result = MessageDialog.openQuestion(Display.getCurrent().getActiveShell(),
Messages.ExportAsImageWizard_3,
NLS.bind(Messages.ExportAsImageWizard_4, file));
NLS.bind(Messages.ExportAsImageWizard_4, file.getAbsolutePath()));
if(!result) {
return false;
}
}

// Make sure parent folder exists
File parent = file.getParentFile();
if(parent != null) {
parent.mkdirs();
}

BusyIndicator.showWhile(Display.getCurrent(), new Runnable() {
@Override
public void run() {
Expand Down

0 comments on commit 57c5232

Please sign in to comment.