Fixed Bug 1953 - Import File Browse Doesn't remember last directory
authorEugene Ostroukhov <eugeneo@symbian.org>
Wed, 24 Feb 2010 10:32:25 -0800
changeset 190 13a34213b146
parent 189 ccfbeb9e8e29
child 191 61c04b3eb3e7
Fixed Bug 1953 - Import File Browse Doesn't remember last directory
org.symbian.tools.wrttools/plugin.xml
org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/core/WrtIdeCorePreferences.java
org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/wizards/WgzImportWizard.java
org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/wizards/WgzImportWizardPage.java
--- a/org.symbian.tools.wrttools/plugin.xml	Wed Feb 24 09:04:14 2010 -0800
+++ b/org.symbian.tools.wrttools/plugin.xml	Wed Feb 24 10:32:25 2010 -0800
@@ -55,6 +55,9 @@
  <extension
     point="org.eclipse.core.runtime.preferences">
     <initializer class="org.symbian.tools.wrttools.core.deploy.PreferenceInitializer"/>
+    <initializer
+          class="org.symbian.tools.wrttools.core.WrtIdeCorePreferences">
+    </initializer>
  </extension>
  <extension
        point="org.eclipse.ui.preferencePages">
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/core/WrtIdeCorePreferences.java	Wed Feb 24 10:32:25 2010 -0800
@@ -0,0 +1,14 @@
+package org.symbian.tools.wrttools.core;
+
+import org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer;
+import org.symbian.tools.wrttools.Activator;
+
+public class WrtIdeCorePreferences extends AbstractPreferenceInitializer {
+    public static final String WGZ_IMPORT_PATH = "wgz.import.path";
+
+    @Override
+    public void initializeDefaultPreferences() {
+        Activator.getDefault().getPreferenceStore().setDefault(WGZ_IMPORT_PATH, System.getProperty("user.home"));
+    }
+
+}
--- a/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/wizards/WgzImportWizard.java	Wed Feb 24 09:04:14 2010 -0800
+++ b/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/wizards/WgzImportWizard.java	Wed Feb 24 10:32:25 2010 -0800
@@ -1,5 +1,6 @@
 package org.symbian.tools.wrttools.wizards;
 
+import java.io.File;
 import java.io.IOException;
 import java.lang.reflect.InvocationTargetException;
 import java.net.URI;
@@ -22,6 +23,7 @@
 import org.eclipse.ui.IWorkbench;
 import org.eclipse.ui.statushandlers.StatusManager;
 import org.symbian.tools.wrttools.Activator;
+import org.symbian.tools.wrttools.core.WrtIdeCorePreferences;
 import org.symbian.tools.wrttools.util.ProjectUtils;
 
 public class WgzImportWizard extends Wizard implements IImportWizard {
@@ -87,6 +89,8 @@
 				}
 			});
 			if (holder[0] != null) {
+                Activator.getDefault().getPreferenceStore().setValue(WrtIdeCorePreferences.WGZ_IMPORT_PATH,
+                        new File(archiveName).getParentFile().getAbsolutePath());
 				ProjectUtils.focusOn(holder[0]);
 			}
 		} catch (InvocationTargetException e) {
@@ -100,7 +104,7 @@
 	public void init(IWorkbench workbench, IStructuredSelection selection) {
 		file = null;
 		if (selection instanceof IStructuredSelection && !selection.isEmpty()) {
-			Object element = ((IStructuredSelection) selection)
+			Object element = (selection)
 					.getFirstElement();
 			if (element instanceof IAdaptable) {
 				IResource resource = (IResource) ((IAdaptable) element)
--- a/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/wizards/WgzImportWizardPage.java	Wed Feb 24 09:04:14 2010 -0800
+++ b/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/wizards/WgzImportWizardPage.java	Wed Feb 24 10:32:25 2010 -0800
@@ -38,10 +38,30 @@
 import org.eclipse.ui.internal.ide.IIDEHelpContextIds;
 import org.eclipse.ui.internal.ide.dialogs.ProjectContentsLocationArea;
 import org.eclipse.ui.internal.ide.dialogs.ProjectContentsLocationArea.IErrorMessageReporter;
+import org.symbian.tools.wrttools.Activator;
+import org.symbian.tools.wrttools.core.WrtIdeCorePreferences;
 
 @SuppressWarnings("restriction")
 public class WgzImportWizardPage extends WizardPage {
+	// constants
+	private static final int SIZING_TEXT_FIELD_WIDTH = 250;
+
 	private final IFile file;
+	// initial value stores
+	private String initialProjectFieldValue;
+	private ProjectContentsLocationArea locationArea;
+	private final Listener nameModifyListener = new Listener() {
+		public void handleEvent(Event e) {
+			setLocationForSelection();
+			boolean valid = validatePage();
+			setPageComplete(valid);
+
+		}
+	};
+	// widgets
+    private Text projectNameField;
+	private Text wgzName;
+	private WorkingSetGroup workingSetGroup;
 
 	protected WgzImportWizardPage(IFile file) {
 		super("ImportWgz");
@@ -51,6 +71,22 @@
 		setPageComplete(false);
 	}
 
+	protected void browse() {
+		FileDialog fileDialog = new FileDialog(getShell(), SWT.OPEN);
+		String path = wgzName.getText();
+        path = path.trim().length() > 0 ? path.trim() : Activator.getDefault().getPreferenceStore().getString(
+                WrtIdeCorePreferences.WGZ_IMPORT_PATH);
+        fileDialog.setFilterPath(path);
+		fileDialog.setFilterExtensions(new String[] {"*.wgz", "*.*"} );
+		fileDialog.setFilterNames(new String[] {"WRT Archive (wgz)", "All Files"} );
+		String res = fileDialog.open();
+		if (res != null) {
+			updateWgzName(path.trim(), res);
+			wgzName.setText(res);
+			setPageComplete(validatePage());
+		}
+	}
+
 	public void createControl(Composite parent) {
 		Composite composite = new Composite(parent, SWT.NULL);
 
@@ -86,83 +122,6 @@
 		setControl(composite);
 	}
 
-	// initial value stores
-	private String initialProjectFieldValue;
-
-	// widgets
-	Text projectNameField;
-
-	private Listener nameModifyListener = new Listener() {
-		public void handleEvent(Event e) {
-			setLocationForSelection();
-			boolean valid = validatePage();
-			setPageComplete(valid);
-
-		}
-	};
-
-	private ProjectContentsLocationArea locationArea;
-	private WorkingSetGroup workingSetGroup;
-
-	// constants
-	private static final int SIZING_TEXT_FIELD_WIDTH = 250;
-
-	private Text wgzName;
-
-	/**
-	 * Create a working set group for this page. This method can only be called
-	 * once.
-	 * 
-	 * @param composite
-	 *            the composite in which to create the group
-	 * @param selection
-	 *            the current workbench selection
-	 * @param supportedWorkingSetTypes
-	 *            an array of working set type IDs that will restrict what types
-	 *            of working sets can be chosen in this group
-	 * @return the created group. If this method has been called previously the
-	 *         original group will be returned.
-	 * @since 3.4
-	 */
-	public WorkingSetGroup createWorkingSetGroup(Composite composite,
-			IStructuredSelection selection, String[] supportedWorkingSetTypes) {
-		if (workingSetGroup != null)
-			return workingSetGroup;
-		workingSetGroup = new WorkingSetGroup(composite, selection,
-				supportedWorkingSetTypes);
-		return workingSetGroup;
-	}
-
-	/**
-	 * Get an error reporter for the receiver.
-	 * 
-	 * @return IErrorMessageReporter
-	 */
-	private IErrorMessageReporter getErrorReporter() {
-		return new IErrorMessageReporter() {
-			/*
-			 * (non-Javadoc)
-			 * 
-			 * @see
-			 * org.eclipse.ui.internal.ide.dialogs.ProjectContentsLocationArea
-			 * .IErrorMessageReporter#reportError(java.lang.String)
-			 */
-			public void reportError(String errorMessage, boolean infoOnly) {
-				if (infoOnly) {
-					setMessage(errorMessage, IStatus.INFO);
-					setErrorMessage(null);
-				} else
-					setErrorMessage(errorMessage);
-				boolean valid = errorMessage == null;
-				if (valid) {
-					valid = validatePage();
-				}
-
-				setPageComplete(valid);
-			}
-		};
-	}
-
 	/**
 	 * Creates the project name specification controls.
 	 * 
@@ -234,26 +193,64 @@
 		projectNameField.addListener(SWT.Modify, nameModifyListener);
 	}
 
-	protected void browse() {
-		FileDialog fileDialog = new FileDialog(getShell(), SWT.OPEN);
-		fileDialog.setFilterPath(wgzName.getText());
-		fileDialog.setFilterExtensions(new String[] {"*.wgz", "*.*"} );
-		fileDialog.setFilterNames(new String[] {"WRT Archive (wgz)", "All Files"} );
-		String res = fileDialog.open();
-		if (res != null) {
-			updateWgzName(wgzName.getText().trim(), res);
-			wgzName.setText(res);
-			setPageComplete(validatePage());
-		}
+	/**
+	 * Create a working set group for this page. This method can only be called
+	 * once.
+	 * 
+	 * @param composite
+	 *            the composite in which to create the group
+	 * @param selection
+	 *            the current workbench selection
+	 * @param supportedWorkingSetTypes
+	 *            an array of working set type IDs that will restrict what types
+	 *            of working sets can be chosen in this group
+	 * @return the created group. If this method has been called previously the
+	 *         original group will be returned.
+	 * @since 3.4
+	 */
+	public WorkingSetGroup createWorkingSetGroup(Composite composite,
+			IStructuredSelection selection, String[] supportedWorkingSetTypes) {
+		if (workingSetGroup != null) {
+            return workingSetGroup;
+        }
+		workingSetGroup = new WorkingSetGroup(composite, selection,
+				supportedWorkingSetTypes);
+		return workingSetGroup;
+	}
+
+	public String getArchiveFile() {
+		return wgzName.getText().trim();
 	}
 
-	private void updateWgzName(String oldValue, String newValue) {
-		String project = projectNameField.getText().trim();
-		if (project.length() == 0 || project.equals(new Path(oldValue).removeFileExtension().lastSegment())) {
-			String projectName = new Path(newValue).removeFileExtension().lastSegment();
-			projectNameField.setText(projectName);
-			locationArea.updateProjectName(projectName);
-		}
+	/**
+	 * Get an error reporter for the receiver.
+	 * 
+	 * @return IErrorMessageReporter
+	 */
+	private IErrorMessageReporter getErrorReporter() {
+		return new IErrorMessageReporter() {
+			/*
+			 * (non-Javadoc)
+			 * 
+			 * @see
+			 * org.eclipse.ui.internal.ide.dialogs.ProjectContentsLocationArea
+			 * .IErrorMessageReporter#reportError(java.lang.String)
+			 */
+			public void reportError(String errorMessage, boolean infoOnly) {
+				if (infoOnly) {
+					setMessage(errorMessage, IStatus.INFO);
+					setErrorMessage(null);
+				} else {
+                    setErrorMessage(errorMessage);
+                }
+				boolean valid = errorMessage == null;
+				if (valid) {
+					valid = validatePage();
+				}
+
+				setPageComplete(valid);
+			}
+		};
 	}
 
 	/**
@@ -324,6 +321,18 @@
 	}
 
 	/**
+	 * Return the selected working sets, if any. If this page is not configured
+	 * to interact with working sets this will be an empty array.
+	 * 
+	 * @return the selected working sets
+	 * @since 3.4
+	 */
+	public IWorkingSet[] getSelectedWorkingSets() {
+		return workingSetGroup == null ? new IWorkingSet[0] : workingSetGroup
+				.getSelectedWorkingSets();
+	}
+
+	/**
 	 * Sets the initial project name that this page will use when created. The
 	 * name is ignored if the createControl(Composite) method has already been
 	 * called. Leading and trailing spaces in the name are ignored. Providing
@@ -355,6 +364,24 @@
 		locationArea.updateProjectName(getProjectNameFieldValue());
 	}
 
+	private void updateWgzName(String oldValue, String newValue) {
+		String project = projectNameField.getText().trim();
+		if (project.length() == 0 || project.equals(new Path(oldValue).removeFileExtension().lastSegment())) {
+			String projectName = new Path(newValue).removeFileExtension().lastSegment();
+			projectNameField.setText(projectName);
+			locationArea.updateProjectName(projectName);
+		}
+	}
+
+	/**
+	 * Returns the useDefaults.
+	 * 
+	 * @return boolean
+	 */
+	public boolean useDefaults() {
+		return locationArea.isDefault();
+	}
+
 	/**
 	 * Returns whether this page's controls currently all contain valid values.
 	 * 
@@ -414,29 +441,4 @@
 		return true;
 	}
 
-	/**
-	 * Returns the useDefaults.
-	 * 
-	 * @return boolean
-	 */
-	public boolean useDefaults() {
-		return locationArea.isDefault();
-	}
-
-	/**
-	 * Return the selected working sets, if any. If this page is not configured
-	 * to interact with working sets this will be an empty array.
-	 * 
-	 * @return the selected working sets
-	 * @since 3.4
-	 */
-	public IWorkingSet[] getSelectedWorkingSets() {
-		return workingSetGroup == null ? new IWorkingSet[0] : workingSetGroup
-				.getSelectedWorkingSets();
-	}
-
-	public String getArchiveFile() {
-		return wgzName.getText().trim();
-	}
-
 }