Bug 7842 fixed: There was not the filepath in the title bar 84/1684/2
Calixte DENIZET [Tue, 24 Aug 2010 20:48:28 +0000 (22:48 +0200)]
Change-Id: I619d041f3db578f5d9b1b1161044206bdebd33e9

scilab/CHANGES_5.3.X
scilab/modules/scinotes/src/java/org/scilab/modules/scinotes/SciNotes.java
scilab/modules/scinotes/src/java/org/scilab/modules/scinotes/ScilabEditorPane.java
scilab/modules/scinotes/src/java/org/scilab/modules/scinotes/actions/SplitAction.java
scilab/modules/scinotes/tests/nonreg_tests/bug_7842.tst [new file with mode: 0644]

index e6a8012..2526272 100644 (file)
@@ -81,6 +81,8 @@ the Code Navigator.
 
 * bug 7830 fixed - There was a problem when opening a file at a line number.
 
+* bug 7842 fixed - There was not the filepath in the title bar.
+
 Editvar/Browsevar:
 ==================
 
index 5c60491..afc0cdb 100644 (file)
@@ -122,7 +122,6 @@ public class SciNotes extends SwingScilabTab implements Tab {
     private static final String ALL_SCX_FILES = "*.sc*";
     private static final String ALL_SCILAB = "all";
     private static final String ALL_FILES = "*.*";
-    private static final String TIRET = " - ";
     private static final String DOT = ".";
 
     private static final String DEFAULTACTIONPATH = "org.scilab.modules.scinotes.actions";
@@ -178,9 +177,6 @@ public class SciNotes extends SwingScilabTab implements Tab {
                 public void stateChanged(ChangeEvent e) {
                     String path = new String("");
                     if (getTextPane() != null) {
-                        if (getTextPane().getName() != null) {
-                            path  =  " (" + getTextPane().getName() + ")";
-                        }
                         updateUI();
                         getTextPane().updateInfosWhenFocused();
 
@@ -189,7 +185,7 @@ public class SciNotes extends SwingScilabTab implements Tab {
 
                         // Update End Of Line  menu
                         EndOfLineAction.updateEolMenu((ScilabDocument) getTextPane().getDocument());
-                        setTitle(tabPane.getTitleAt(tabPane.getSelectedIndex()) + path + TIRET + SciNotesMessages.SCILAB_EDITOR);
+                        setTitle(getTextPane().getTitle());
                     }
                 }
             });
@@ -685,14 +681,22 @@ public class SciNotes extends SwingScilabTab implements Tab {
         ScilabDocument styledDocument = (ScilabDocument) textPaneAt.getDocument();
         styledDocument.setContentModified(false);
 
-        getTabPane().setTitleAt(getTabPane().getSelectedIndex() , newSavedFile.getName());
-        setTitle(newSavedFile.getPath() + TIRET + SciNotesMessages.SCILAB_EDITOR);
-
         // Get current file path for Execute file into Scilab
         fileFullPath = newSavedFile.getAbsolutePath();
         getTextPane().setLastModified(newSavedFile.lastModified());
 
+        if (textPaneAt.getName() == null) {
+            String name = getTabPane().getTitleAt(getTabPane().getSelectedIndex());
+            String index = name.substring(name.length() - 1, name.length());
+            tabList.remove(Integer.valueOf(index));
+            closedTabList.add(Integer.valueOf(index));
+        }
+
         textPaneAt.setName(fileToSave);
+        getTabPane().setTitleAt(getTabPane().getSelectedIndex() , newSavedFile.getName());
+
+        setTitle(textPaneAt.getTitle());
+
         return true;
     }
 
@@ -721,13 +725,14 @@ public class SciNotes extends SwingScilabTab implements Tab {
         styledDocument.setContentModified(false);
 
         getTabPane().setTitleAt(getTabPane().getSelectedIndex() , newSavedFile.getName());
-        setTitle(newSavedFile.getPath() + TIRET + SciNotesMessages.SCILAB_EDITOR);
 
         // Get current file path for Execute file into Scilab
         fileFullPath = newSavedFile.getAbsolutePath();
         getTextPane().setLastModified(newSavedFile.lastModified());
 
         textPaneAt.setName(fileToSave);
+        setTitle(textPaneAt.getTitle());
+
         return true;
     }
 
@@ -874,12 +879,20 @@ public class SciNotes extends SwingScilabTab implements Tab {
             return false;
         }
 
+        if (getTextPane().getName() == null) {
+            String name = getTabPane().getTitleAt(getTabPane().getSelectedIndex());
+            String index = name.substring(name.length() - 1, name.length());
+            tabList.remove(Integer.valueOf(index));
+            closedTabList.add(Integer.valueOf(index));
+        }
+
         ConfigManager.saveLastOpenedDirectory(f.getPath());
         ConfigSciNotesManager.saveToRecentOpenedFiles(f.getPath());
         ConfigSciNotesManager.renameOpenFilesItem(f.getPath(), this, getTextPane());
         getTextPane().setName(f.getPath());
         getTabPane().setTitleAt(getTabPane().getSelectedIndex(), f.getName());
-        setTitle(f.getPath() + TIRET + SciNotesMessages.SCILAB_EDITOR);
+        setTitle(getTextPane().getTitle());
+
         RecentFileAction.updateRecentOpenedFilesMenu(this);
 
         NavigatorWindow.updateNavigator(styledDocument);
@@ -917,7 +930,6 @@ public class SciNotes extends SwingScilabTab implements Tab {
         tabPane.setSelectedIndex(ind);
         setContentPane(tabPane);
         initInputMap(sep);
-        setTitle(title + TIRET + SciNotesMessages.SCILAB_EDITOR);
         updateTabTitle();
         getInfoBar().setText(sep.getInfoBarText());
         repaint();
@@ -1048,16 +1060,19 @@ public class SciNotes extends SwingScilabTab implements Tab {
     public ScilabEditorPane addEmptyTab() {
         ScilabEditorPane sep;
         if (closedTabList.size() > 0) {
-            Object obj = Collections.min(closedTabList);
-            closedTabList.remove(Integer.valueOf(obj.toString()));
-            sep = addTab(SciNotesMessages.UNTITLED + obj.toString());
-            sep.setShortName(SciNotesMessages.UNTITLED + obj.toString());
+            Integer n = (Integer) Collections.min(closedTabList);
+            closedTabList.remove(n);
+            sep = addTab(SciNotesMessages.UNTITLED + n);
+            sep.setShortName(SciNotesMessages.UNTITLED + n);
+            sep.setTitle(SciNotesMessages.UNTITLED + n);
         } else {
             numberOfUntitled++;
             tabList.add(Integer.valueOf(numberOfUntitled));
             sep = addTab(SciNotesMessages.UNTITLED + numberOfUntitled);
             sep.setShortName(SciNotesMessages.UNTITLED + numberOfUntitled);
+            sep.setTitle(SciNotesMessages.UNTITLED + numberOfUntitled);
         }
+        setTitle(sep.getTitle());
 
         return sep;
     }
@@ -1585,6 +1600,7 @@ public class SciNotes extends SwingScilabTab implements Tab {
 
             theTextPane.setName(f.getAbsolutePath());
             getTabPane().setTitleAt(getTabPane().getSelectedIndex() , f.getName());
+            setTitle(theTextPane.getTitle());
             styleDocument.setContentModified(false);
             styleDocument.enableUndoManager();
 
@@ -1649,7 +1665,7 @@ public class SciNotes extends SwingScilabTab implements Tab {
             ConfigSciNotesManager.saveToOpenFiles(editor.getTextPane().getName(), editor, editor.getTextPane());
             theTextPane.setName(f.getPath());
             getTabPane().setTitleAt(getTabPane().getSelectedIndex() , f.getName());
-            setTitle(f.getPath() + TIRET + SciNotesMessages.SCILAB_EDITOR);
+            setTitle(theTextPane.getTitle());
             RecentFileAction.updateRecentOpenedFilesMenu(this);
 
             styleDocument.setContentModified(false);
index 86a58e1..1cc7c23 100644 (file)
@@ -61,11 +61,12 @@ public class ScilabEditorPane extends JEditorPane implements Highlighter.Highlig
                                                              MouseMotionListener, Cloneable,
                                                              KeyListener {
 
-    private static ScilabEditorPane focused;
-
+    private static final String TIRET = " - ";
     private static final Cursor HANDCURSOR = Cursor.getPredefinedCursor(Cursor.HAND_CURSOR);
     private static final Cursor TEXTCURSOR = Cursor.getPredefinedCursor(Cursor.TEXT_CURSOR);
 
+    private static ScilabEditorPane focused;
+
     private Color highlightColor;
     private Color highlightContourColor;
     private boolean highlightEnable;
@@ -81,6 +82,7 @@ public class ScilabEditorPane extends JEditorPane implements Highlighter.Highlig
     private boolean readonly;
     private String infoBar = "";
     private String shortName = "";
+    private String title = "";
 
     private long lastModified;
 
@@ -270,11 +272,27 @@ public class ScilabEditorPane extends JEditorPane implements Highlighter.Highlig
     public void setName(String name) {
         super.setName(name);
         if (name != null) {
-            this.shortName = new File(name).getName();
+            File f = new File(name);
+            this.shortName = f.getName();
+            title =  shortName + " (" + f.getAbsolutePath() + ")" + TIRET + SciNotesMessages.SCILAB_EDITOR;
         }
     }
 
     /**
+     * @param title the title
+     */
+    public void setTitle(String title) {
+        this.title = title + TIRET + SciNotesMessages.SCILAB_EDITOR;
+    }
+
+    /**
+     * @return the title
+     */
+    public String getTitle() {
+        return title;
+    }
+
+    /**
      * @param name the short name
      */
     public void setShortName(String name) {
@@ -384,6 +402,7 @@ public class ScilabEditorPane extends JEditorPane implements Highlighter.Highlig
         pane.suppressCom = suppressCom;
         pane.setName(getName());
         pane.setShortName(getShortName());
+        pane.setTitle(getTitle());
         pane.setEditable(isEditable());
     }
 
index 13f6657..37f02fa 100644 (file)
  */
 package org.scilab.modules.scinotes.actions;
 
+import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeListener;
 import java.awt.event.ActionEvent;
 import java.awt.event.ActionListener;
 import java.util.StringTokenizer;
 
 import javax.swing.ButtonGroup;
+import javax.swing.JComponent;
 import javax.swing.JMenu;
 import javax.swing.JRadioButtonMenuItem;
+import javax.swing.JSplitPane;
 import javax.swing.KeyStroke;
 
 import org.scilab.modules.gui.menu.Menu;
@@ -69,7 +73,7 @@ public final class SplitAction extends DefaultAction {
      * @param key KeyStroke
      * @return createMenu
      */
-    public static Menu createMenu(String label, SciNotes editor, KeyStroke key) {
+    public static Menu createMenu(String label, final SciNotes editor, KeyStroke key) {
         StringTokenizer tokens = new StringTokenizer(label, ";");
         String labelSplitView = tokens.nextToken();
         String labelOff = tokens.nextToken();
@@ -82,7 +86,7 @@ public final class SplitAction extends DefaultAction {
 
         ButtonGroup group = new ButtonGroup();
         JRadioButtonMenuItem radio;
-        JRadioButtonMenuItem[] arr = new JRadioButtonMenuItem[3];
+        final JRadioButtonMenuItem[] arr = new JRadioButtonMenuItem[3];
         String[] labels = new String[]{labelOff, labelH, labelV};
 
         for (int i = 0; i < 3; i++) {
@@ -94,6 +98,22 @@ public final class SplitAction extends DefaultAction {
 
         arr[0].setSelected(true);
 
+        ((JMenu) menu.getAsSimpleMenu()).addPropertyChangeListener(new PropertyChangeListener() {
+                public void propertyChange(PropertyChangeEvent e) {
+                    JComponent c = editor.getTextPane().getParentComponent();
+                    int state = 0;
+                    if (c instanceof JSplitPane) {
+                        JSplitPane split = (JSplitPane) c;
+                        if (split.getOrientation() == JSplitPane.HORIZONTAL_SPLIT) {
+                            state = 1;
+                        } else {
+                            state = 2;
+                        }
+                    }
+                    arr[state].setSelected(true);
+                }
+            });
+
         return menu;
     }
 
diff --git a/scilab/modules/scinotes/tests/nonreg_tests/bug_7842.tst b/scilab/modules/scinotes/tests/nonreg_tests/bug_7842.tst
new file mode 100644 (file)
index 0000000..dd5d0d0
--- /dev/null
@@ -0,0 +1,21 @@
+// =============================================================================
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) 2010 - Calixte DENIZET
+//
+//  This file is distributed under the same license as the Scilab package.
+// =============================================================================
+
+// <-- INTERACTIVE TEST -->
+// <-- TEST WITH SCINOTES -->
+//
+// <-- Non-regression test for bug 7842 -->
+//
+// <-- Bugzilla URL -->
+// http://bugzilla.scilab.org/show_bug.cgi?id=7842
+//
+// <-- Short Description -->
+// There was not the filepath in the title bar.
+
+scinotes("SCI/modules/graphics/demos/2d_3d_plots/plotyyy.dem.sce");
+
+// the window's title must be the full path of plotyyy.dem.sce