tmf: Bug 452415: Remember last location for Open Trace
authorMarc-Andre Laperle <marc-andre.laperle@ericsson.com>
Thu, 11 Jun 2015 21:44:05 +0000 (17:44 -0400)
committerMarc-Andre Laperle <marc-andre.laperle@ericsson.com>
Fri, 12 Jun 2015 22:52:02 +0000 (18:52 -0400)
Change-Id: Iffe079c1d292705c624701853c7374b602463ff1
Signed-off-by: Marc-Andre Laperle <marc-andre.laperle@ericsson.com>
Reviewed-on: https://git.eclipse.org/r/50106
Reviewed-by: Hudson CI
Reviewed-by: Alexandre Montplaisir <alexmonthy@voxpopuli.im>
Tested-by: Alexandre Montplaisir <alexmonthy@voxpopuli.im>
org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/internal/tmf/ui/ITmfUIPreferences.java
org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/internal/tmf/ui/commands/OpenFileHandler.java

index bb81bf0af387dad451789f2be6bc084437a51e78..739118474864f340c6fc6f683a3498dafd0167a9 100644 (file)
@@ -22,4 +22,9 @@ public interface ITmfUIPreferences {
      * Preference for aligning the views based on the time axis
      */
     String PREF_ALIGN_VIEWS = "PREF_ALIGN_VIEWS"; //$NON-NLS-1$
+
+    /**
+     * Preference (not user visible) for saving the last location used when using "Open Trace"
+     */
+    String PREF_SAVED_OPEN_FILE_LOCATION = "PREF_LAST_OPEN_FILE_LOCATION"; //$NON-NLS-1$
 }
index ee1d56893b619cb64651cf62d7a8b69e72ea6791..eb94b9a0ae7f6e1effec9f6789a278a31a5dec4e 100644 (file)
 
 package org.eclipse.tracecompass.internal.tmf.ui.commands;
 
+import java.io.File;
+
 import org.eclipse.core.commands.AbstractHandler;
 import org.eclipse.core.commands.ExecutionEvent;
 import org.eclipse.core.resources.IProject;
 import org.eclipse.core.runtime.CoreException;
 import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.core.runtime.preferences.IEclipsePreferences;
+import org.eclipse.core.runtime.preferences.InstanceScope;
 import org.eclipse.jface.viewers.ISelection;
 import org.eclipse.jface.viewers.IStructuredSelection;
 import org.eclipse.swt.widgets.FileDialog;
 import org.eclipse.swt.widgets.Shell;
 import org.eclipse.tracecompass.internal.tmf.ui.Activator;
+import org.eclipse.tracecompass.internal.tmf.ui.ITmfUIPreferences;
 import org.eclipse.tracecompass.tmf.core.TmfCommonConstants;
 import org.eclipse.tracecompass.tmf.ui.project.model.TmfOpenTraceHelper;
 import org.eclipse.tracecompass.tmf.ui.project.model.TmfProjectElement;
@@ -49,6 +54,14 @@ public class OpenFileHandler extends AbstractHandler {
         final Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
         FileDialog fd = new FileDialog(shell);
         fd.setText(Messages.OpenFileHandler_SelectTraceFile);
+        IEclipsePreferences defaultPreferences = InstanceScope.INSTANCE.getNode(Activator.PLUGIN_ID);
+        String lastLocation = defaultPreferences.get(ITmfUIPreferences.PREF_SAVED_OPEN_FILE_LOCATION, null);
+        if (lastLocation != null && !lastLocation.isEmpty()) {
+            File parentFile = new File(lastLocation).getParentFile();
+            if (parentFile != null && parentFile.exists()) {
+                fd.setFilterPath(parentFile.toString());
+            }
+        }
         String filePath = fd.open();
         if (filePath == null) {
             return null;
@@ -74,6 +87,8 @@ public class OpenFileHandler extends AbstractHandler {
         } catch (CoreException e) {
             Activator.getDefault().logError(e.getMessage(), e);
         }
+
+        InstanceScope.INSTANCE.getNode(Activator.PLUGIN_ID).put(ITmfUIPreferences.PREF_SAVED_OPEN_FILE_LOCATION, filePath);
         return null;
     }
 }
This page took 0.028996 seconds and 5 git commands to generate.