File Browser: add an entry in the main menu 57/4657/3
Calixte DENIZET [Mon, 1 Aug 2011 14:33:34 +0000 (16:33 +0200)]
Change-Id: I3d79d944eebefcc288946e4728ab7cb4cee573e4

scilab/modules/gui/etc/main_menubar.xml
scilab/modules/ui_data/Makefile.am
scilab/modules/ui_data/Makefile.in
scilab/modules/ui_data/sci_gateway/cpp/sci_filebrowser.cpp
scilab/modules/ui_data/src/c/ui_data.vcxproj
scilab/modules/ui_data/src/java/org/scilab/modules/ui_data/filebrowser/ScilabFileBrowserHistory.java
scilab/modules/ui_data/src/java/org/scilab/modules/ui_data/filebrowser/SwingScilabTreeTable.java

index f95777d..c2bf1f4 100644 (file)
         <submenu label="&amp;Command History">
             <callback instruction='org.scilab.modules.history_browser.CommandHistory.setVisible' type="3"/>
         </submenu>
+        <submenu label="&amp;File Browser">
+            <callback instruction='filebrowser()' type="0"/>
+        </submenu>
     </menu>
 
     <!-- Help menu -->
index ccea264..02a1b5d 100644 (file)
@@ -69,7 +69,8 @@ libsciui_data_la_CPPFLAGS = $(JAVA_JNI_INCLUDE) \
                        -I$(top_srcdir)/modules/jvm/includes/ \
                        -I$(top_srcdir)/modules/output_stream/includes \
                        -I$(top_srcdir)/modules/localization/includes \
-                       -I$(top_srcdir)/modules/api_scilab/includes
+                       -I$(top_srcdir)/modules/api_scilab/includes \
+                       -I$(top_srcdir)/modules/fileio/includes
 
 # Without the ui_data module 
 libsciui_data_disable_la_CFLAGS = -Iincludes/ \
index ed63a0a..bcfcd87 100644 (file)
@@ -550,7 +550,8 @@ libsciui_data_la_CPPFLAGS = $(JAVA_JNI_INCLUDE) \
                        -I$(top_srcdir)/modules/jvm/includes/ \
                        -I$(top_srcdir)/modules/output_stream/includes \
                        -I$(top_srcdir)/modules/localization/includes \
-                       -I$(top_srcdir)/modules/api_scilab/includes
+                       -I$(top_srcdir)/modules/api_scilab/includes \
+                       -I$(top_srcdir)/modules/fileio/includes
 
 
 # Without the ui_data module 
index 082d010..abb0c76 100644 (file)
@@ -17,6 +17,7 @@ extern "C"
 #include "gw_ui_data.h"
 #include "getScilabJavaVM.h"
 #include "stack-c.h"
+#include "scicurdir.h"
 }
 
 using namespace org_scilab_modules_ui_data;
@@ -24,11 +25,20 @@ using namespace org_scilab_modules_ui_data;
 /*--------------------------------------------------------------------------*/
 int sci_filebrowser(char *fname, unsigned long fname_len)
 {
+    char * cwd = NULL;
+    int err = 0;
+
     CheckRhs(0, 0);
     CheckLhs(0, 1);
 
     FileBrowser::openFileBrowser(getScilabJavaVM());
 
+    cwd = scigetcwd(&err);
+    if (cwd)
+    {
+        FileBrowser::setBaseDir(getScilabJavaVM(), cwd);
+    }
+
     LhsVar(1) = 0;
     PutLhsVar();
 
index 18a04a5..508b37f 100644 (file)
       <Project>{43c5bab1-1dca-4743-a183-77e0d42fe7d0}</Project>
       <ReferenceOutputAssembly>false</ReferenceOutputAssembly>
     </ProjectReference>
+    <ProjectReference Include="..\..\..\fileio\fileio.vcxproj">
+      <Project>{4fc72d4a-80ee-4b1a-8724-0201c1a35621}</Project>
+    </ProjectReference>
     <ProjectReference Include="..\..\..\jvm\libjvm.vcxproj">
       <Project>{8ba2dda8-bd04-4d4d-8ee6-6caa955f7470}</Project>
       <ReferenceOutputAssembly>false</ReferenceOutputAssembly>
index ae19989..a305c60 100644 (file)
@@ -15,7 +15,7 @@ package org.scilab.modules.ui_data.filebrowser;
 import java.awt.Rectangle;
 import java.awt.event.MouseAdapter;
 import java.awt.event.MouseEvent;
-
+import java.io.File;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Timer;
@@ -28,6 +28,7 @@ import javax.swing.JMenuItem;
 import javax.swing.JPopupMenu;
 import javax.swing.SwingUtilities;
 
+import org.scilab.modules.action_binding.InterpreterManagement;
 import org.scilab.modules.gui.bridge.pushbutton.SwingScilabPushButton;
 import org.scilab.modules.gui.events.callback.CallBack;
 import org.scilab.modules.gui.pushbutton.PushButton;
@@ -145,6 +146,7 @@ public class ScilabFileBrowserHistory {
                 item.addActionListener(new CallBack(null) {
                         public void callBack() {
                             ScilabFileBrowserHistory.this.stt.setBaseDir(history.get(j), false);
+                            chDir(history.get(j));
                             setPositionInHistory(j);
                         }
                     });
@@ -157,6 +159,7 @@ public class ScilabFileBrowserHistory {
                 item.addActionListener(new CallBack(null) {
                         public void callBack() {
                             ScilabFileBrowserHistory.this.stt.setBaseDir(history.get(j), false);
+                            chDir(history.get(j));
                             setPositionInHistory(j);
                         }
                     });
@@ -175,6 +178,13 @@ public class ScilabFileBrowserHistory {
         popup.show(button, 0, button.getBounds(null).height);
     }
 
+    private static final void chDir(String path) {
+        File f = new File(path);
+        if (f.exists() && f.isDirectory() && f.canRead()) {
+            InterpreterManagement.requestScilabExec("chdir('" + path + "')");
+        }
+    }
+
     /**
      * Add a path in the history
      * @param path the path to add
index 6a0a2db..f721578 100644 (file)
@@ -52,7 +52,6 @@ import javax.swing.table.TableCellRenderer;
 import javax.swing.table.TableColumn;
 import javax.swing.tree.TreePath;
 
-import org.scilab.modules.action_binding.InterpreterManagement;
 import org.scilab.modules.gui.events.callback.CallBack;
 import org.scilab.modules.gui.pushbutton.PushButton;
 import org.scilab.modules.ui_data.filebrowser.actions.ChangeCWDAction;
@@ -303,15 +302,15 @@ public class SwingScilabTreeTable extends JTable {
     public void setBaseDir(String baseDir, boolean addInHistory) {
         ScilabFileBrowserModel model = (ScilabFileBrowserModel) tree.getModel();
         combobox.setBaseDir(baseDir);
-        File f = new File(baseDir);
-        if (!baseDir.equals(model.getBaseDir()) && f.exists() && f.isDirectory() && f.canRead()) {
-            tree.setModel(null);
-            if (addInHistory) {
-                history.addPathInHistory(baseDir);
-            } else {
-                InterpreterManagement.requestScilabExec("chdir('" + baseDir + "')");
+        if (model != null) {
+            File f = new File(baseDir);
+            if (!baseDir.equals(model.getBaseDir()) && f.exists() && f.isDirectory() && f.canRead()) {
+                tree.setModel(null);
+                if (addInHistory) {
+                    history.addPathInHistory(baseDir);
+                }
+                model.setBaseDir(baseDir, this);
             }
-            model.setBaseDir(baseDir, this);
         }
     }
 
@@ -344,6 +343,9 @@ public class SwingScilabTreeTable extends JTable {
         tree.collapsePath(path);
         ((JScrollPane) SwingUtilities.getAncestorOfClass(JScrollPane.class, this)).getVerticalScrollBar().setValue(0);
         tree.expandPath(path);
+       if (getRowCount() >= 1) {
+           repaint(tree.getRowBounds(1));
+       }
         editingRow = 0;
     }