5151 */
5252public class SelectImageAction implements IExternalJavaAction {
5353
54+ private static final String LAST_BROWSED_DIRECTORY = "roboconf.last.browsed.directory" ;
5455 private static final String [] EXTENSIONS = {
5556 "*.jpg;*.jpeg;*.gif;*.svg;*.png" ,
5657 "*.jpg" , "*.jpeg" , "*.gif" , "*.png" , "*.svg"
@@ -82,10 +83,14 @@ public boolean canExecute( Collection<? extends EObject> selections ) {
8283 @ Override
8384 public void execute ( Collection <? extends EObject > selections , Map <String ,Object > parameters ) {
8485
86+ // Get the last browsed directory
87+ String lastDir = RoboconfModelerPlugin .getDefault ().getPreferenceStore ().getString ( LAST_BROWSED_DIRECTORY );
88+
8589 // Open a selection dialog
8690 FileDialog dialog = new FileDialog ( new Shell (), SWT .OPEN );
8791 dialog .setFilterExtensions ( EXTENSIONS );
8892 dialog .setFilterNames ( NAMES );
93+ dialog .setFilterPath ( lastDir );
8994 String result = dialog .open ();
9095
9196 // If a file was selected, import it in the project
@@ -96,6 +101,12 @@ public void execute( Collection<? extends EObject> selections, Map<String,Object
96101 if ( ! imgFolder .exists ())
97102 imgFolder .create ( true , true , new NullProgressMonitor ());
98103
104+ // Update the preferences
105+ File selectedFile = new File ( result );
106+ RoboconfModelerPlugin .getDefault ().getPreferenceStore ().setValue (
107+ LAST_BROWSED_DIRECTORY ,
108+ selectedFile .getParentFile ().getAbsolutePath ());
109+
99110 // We can only select a component or a facet, and a component inherits from a facet.
100111 int index = result .lastIndexOf ( '.' );
101112 String ext = result .substring ( index );
@@ -106,7 +117,7 @@ public void execute( Collection<? extends EObject> selections, Map<String,Object
106117 EclipseUtils .deleteImageOf ( imgFolder , name );
107118
108119 // Copy the content then.
109- Utils .copyStream ( new File ( result ) , targetFile .getLocation ().toFile ());
120+ Utils .copyStream ( selectedFile , targetFile .getLocation ().toFile ());
110121
111122 // Refresh the images directory.
112123 imgFolder .refreshLocal ( IResource .DEPTH_ONE , new NullProgressMonitor ());
0 commit comments