Scinotes: show a messagebox when an external modif has been made on the current file 72/10572/3
Calixte DENIZET [Fri, 22 Feb 2013 10:26:16 +0000 (11:26 +0100)]
Change-Id: I6ad2e0c841ac2f637caca9541a2e05e1e2d55738

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/utils/SaveFile.java
scilab/modules/scinotes/src/java/org/scilab/modules/scinotes/utils/SciNotesMessages.java

index a632aec..4608d92 100644 (file)
@@ -178,11 +178,11 @@ public class SciNotes extends SwingScilabTab {
         ConfigSciNotesManager.createUserCopy();
         ScilabTabFactory.getInstance().addTabFactory(SciNotesTabFactory.getInstance());
         Scilab.registerInitialHook(new Runnable() {
-                @Override
-                public void run() {
-                    updateSciNotes();
-                }
-            });
+            @Override
+            public void run() {
+                updateSciNotes();
+            }
+        });
 
         Document doc = ScilabXMLUtilities.readDocument(System.getenv("SCI") + "/modules/console/etc/Actions-Configuration.xml");
         actionToName = XConfiguration.get(doc, "name", String.class, "action", String.class, XPATH_SCINOTES_ACTION);
@@ -206,23 +206,23 @@ public class SciNotes extends SwingScilabTab {
         contentPane = new SciNotesContents(this);
         tabPane = contentPane.getScilabTabbedPane();
         tabPane.addChangeListener(new ChangeListener() {
-                @Override
-                public void stateChanged(ChangeEvent e) {
-                    if (getTextPane() != null) {
-                        // updateUI();
-                        getTextPane().updateInfosWhenFocused();
-                        getTextPane().requestFocus();
-                        getTextPane().highlightWords(IncrementalSearchAction.getWord(SciNotes.this), IncrementalSearchAction.getExact(SciNotes.this));
-
-                        // Update encoding menu
-                        EncodingAction.updateEncodingMenu((ScilabDocument) getTextPane().getDocument());
-
-                        // Update End Of Line menu
-                        EndOfLineAction.updateEolMenu((ScilabDocument) getTextPane().getDocument());
-                        setTitle(getTextPane().getTitle());
-                    }
+            @Override
+            public void stateChanged(ChangeEvent e) {
+                if (getTextPane() != null) {
+                    // updateUI();
+                    getTextPane().updateInfosWhenFocused();
+                    getTextPane().requestFocus();
+                    getTextPane().highlightWords(IncrementalSearchAction.getWord(SciNotes.this), IncrementalSearchAction.getExact(SciNotes.this));
+
+                    // Update encoding menu
+                    EncodingAction.updateEncodingMenu((ScilabDocument) getTextPane().getDocument());
+
+                    // Update End Of Line menu
+                    EndOfLineAction.updateEolMenu((ScilabDocument) getTextPane().getDocument());
+                    setTitle(getTextPane().getTitle());
                 }
-            });
+            }
+        });
         this.setContentPane(contentPane);
     }
 
@@ -440,15 +440,15 @@ public class SciNotes extends SwingScilabTab {
         try {
             SwingUtilities.invokeAndWait(new Runnable() {
 
-                    @Override
-                    public void run() {
-                        launchSciNotes();
-                        // Open an empty file if no tabs were opened at launch.
-                        if (editor.getTabPane().getTabCount() == 0) {
-                            editor.openFile(null, 0, null);
-                        }
+                @Override
+                public void run() {
+                    launchSciNotes();
+                    // Open an empty file if no tabs were opened at launch.
+                    if (editor.getTabPane().getTabCount() == 0) {
+                        editor.openFile(null, 0, null);
                     }
-                });
+                }
+            });
         } catch (InterruptedException e) {
             Logger.getLogger(SciNotes.class.getName()).severe(e.toString());
             throw new RuntimeException(e);
@@ -472,12 +472,12 @@ public class SciNotes extends SwingScilabTab {
         try {
             SwingUtilities.invokeAndWait(new Runnable() {
 
-                    @Override
-                    public void run() {
-                        launchSciNotes();
-                        editor.openFile(filePath, 0, null);
-                    }
-                });
+                @Override
+                public void run() {
+                    launchSciNotes();
+                    editor.openFile(filePath, 0, null);
+                }
+            });
         } catch (InterruptedException e) {
             Logger.getLogger(SciNotes.class.getName()).severe(e.toString());
             throw new RuntimeException(e);
@@ -503,12 +503,12 @@ public class SciNotes extends SwingScilabTab {
         try {
             SwingUtilities.invokeAndWait(new Runnable() {
 
-                    @Override
-                    public void run() {
-                        launchSciNotes();
-                        editor.openFile(filePath, lineNumber, functionName);
-                    }
-                });
+                @Override
+                public void run() {
+                    launchSciNotes();
+                    editor.openFile(filePath, lineNumber, functionName);
+                }
+            });
         } catch (InterruptedException e) {
             Logger.getLogger(SciNotes.class.getName()).severe(e.toString());
             throw new RuntimeException(e);
@@ -549,16 +549,16 @@ public class SciNotes extends SwingScilabTab {
         try {
             SwingUtilities.invokeAndWait(new Runnable() {
 
-                    @Override
-                    public void run() {
-                        launchSciNotes();
-                        if (options != null && options.length != 0) {
-                            editor.openFile(filePath, 0, options[0]);
-                        } else {
-                            editor.openFile(filePath, 0, "");
-                        }
+                @Override
+                public void run() {
+                    launchSciNotes();
+                    if (options != null && options.length != 0) {
+                        editor.openFile(filePath, 0, options[0]);
+                    } else {
+                        editor.openFile(filePath, 0, "");
                     }
-                });
+                }
+            });
         } catch (InterruptedException e) {
             Logger.getLogger(SciNotes.class.getName()).severe(e.toString());
             throw new RuntimeException(e);
@@ -664,11 +664,11 @@ public class SciNotes extends SwingScilabTab {
             try {
                 SwingUtilities.invokeAndWait(new Runnable() {
 
-                        @Override
-                        public void run() {
-                            restorePreviousSession();
-                        }
-                    });
+                    @Override
+                    public void run() {
+                        restorePreviousSession();
+                    }
+                });
             } catch (InterruptedException e) {
                 Logger.getLogger(SciNotes.class.getName()).severe(e.toString());
                 throw new RuntimeException(e);
@@ -697,30 +697,30 @@ public class SciNotes extends SwingScilabTab {
         }
 
         SwingUtilities.invokeLater(new Runnable() {
-                @Override
-                public void run() {
-                    RestoreOpenedFilesAction.displayDialog((JFrame) SwingUtilities.getAncestorOfClass(JFrame.class, SciNotes.this), getUUID().toString());
-                    List<File> list = RestoreOpenedFilesAction.getSelectedFiles();
-
-                    if (list != null && list.size() != 0) {
-                        for (File f : list) {
-                            openFile(f.getPath(), 0, null);
-                        }
-                    } else {
-                        if (getTabPane().getTabCount() == 0 || getTextPane(0).getName() == null) {
-                            openFile(null, 0, null);
-                        }
+            @Override
+            public void run() {
+                RestoreOpenedFilesAction.displayDialog((JFrame) SwingUtilities.getAncestorOfClass(JFrame.class, SciNotes.this), getUUID().toString());
+                List<File> list = RestoreOpenedFilesAction.getSelectedFiles();
+
+                if (list != null && list.size() != 0) {
+                    for (File f : list) {
+                        openFile(f.getPath(), 0, null);
                     }
-
-                    setWindowIcon("accessories-text-editor");
-
-                    if (navigator != null) {
-                        navigator.updateTree();
+                } else {
+                    if (getTabPane().getTabCount() == 0 || getTextPane(0).getName() == null) {
+                        openFile(null, 0, null);
                     }
+                }
+
+                setWindowIcon("accessories-text-editor");
 
-                    WindowsConfigurationManager.restorationFinished(SciNotes.this);
+                if (navigator != null) {
+                    navigator.updateTree();
                 }
-            });
+
+                WindowsConfigurationManager.restorationFinished(SciNotes.this);
+            }
+        });
     }
 
     /**
@@ -1065,22 +1065,22 @@ public class SciNotes extends SwingScilabTab {
         if (!force) {
             AnswerOption answer;
             if (scilabClose) {
-                answer = ScilabModalDialog.show(this, getTabPane().getScilabTitleAt(indexTab) + SciNotesMessages.MODIFIED, SciNotesMessages.SCILAB_EDITOR,
+                answer = ScilabModalDialog.show(this, String.format(SciNotesMessages.MODIFIED, textPaneAt.getShortName()), SciNotesMessages.SCILAB_EDITOR,
                                                 IconType.QUESTION_ICON, ButtonType.YES_NO);
             } else {
-                answer = ScilabModalDialog.show(this, getTabPane().getScilabTitleAt(indexTab) + SciNotesMessages.MODIFIED, SciNotesMessages.SCILAB_EDITOR,
+                answer = ScilabModalDialog.show(this, String.format(SciNotesMessages.MODIFIED, textPaneAt.getShortName()), SciNotesMessages.SCILAB_EDITOR,
                                                 IconType.QUESTION_ICON, ButtonType.YES_NO_CANCEL);
             }
 
             switch (answer) {
-            case YES_OPTION: // Yes, continue
-                break;
-            case NO_OPTION:// No, exit and returns true
-                return true;
-            case CANCEL_OPTION: // Cancel, exit and return false
-                return false;
-            default:
-                break;
+                case YES_OPTION: // Yes, continue
+                    break;
+                case NO_OPTION:// No, exit and returns true
+                    return true;
+                case CANCEL_OPTION: // Cancel, exit and return false
+                    return false;
+                default:
+                    break;
             }
         }
 
@@ -1281,7 +1281,7 @@ public class SciNotes extends SwingScilabTab {
             String fileName = f.getName();
             if (fileName.lastIndexOf(DOT) != -1) {
                 if (fileName.substring(fileName.lastIndexOf(DOT), fileName.length()).length() >= 2
-                    && fileName.substring(fileName.lastIndexOf(DOT), fileName.length()).length() <= 4) {
+                        && fileName.substring(fileName.lastIndexOf(DOT), fileName.length()).length() <= 4) {
                     hasNoExtension = false;
                 }
             }
@@ -1773,22 +1773,22 @@ public class SciNotes extends SwingScilabTab {
                     messageBox.displayAndWait(); // Waits for a user action
 
                     switch (messageBox.getSelectedButton()) {
-                    case 1: // Reload
-                        if ((i == 0) && (getTabPane().getTabCount() == 1)) {
-                            for (int j = 0; j < tabPane.getChangeListeners().length; j++) {
-                                tabPane.removeChangeListener(tabPane.getChangeListeners()[j]);
+                        case 1: // Reload
+                            if ((i == 0) && (getTabPane().getTabCount() == 1)) {
+                                for (int j = 0; j < tabPane.getChangeListeners().length; j++) {
+                                    tabPane.removeChangeListener(tabPane.getChangeListeners()[j]);
+                                }
                             }
-                        }
-                        tabPane.remove(i);
-                        f = new File(textPaneAt.getName());
-                        index = i;
-                        break;
-                    case 2: // Overwrite 2
-                        overwrite(i);
-                        alreadyOpened = true;
-                        break;
-                    default: // Ignore
-                        alreadyOpened = true;
+                            tabPane.remove(i);
+                            f = new File(textPaneAt.getName());
+                            index = i;
+                            break;
+                        case 2: // Overwrite 2
+                            overwrite(i);
+                            alreadyOpened = true;
+                            break;
+                        default: // Ignore
+                            alreadyOpened = true;
                     }
                 } else {
                     alreadyOpened = true;
@@ -2320,7 +2320,7 @@ public class SciNotes extends SwingScilabTab {
         ScilabEditorPane theTextPane = addEmptyTab();
         ScilabDocument styleDocument = null;
         int choice = JOptionPane.showConfirmDialog(SciNotes.this, String.format(SciNotesMessages.FILE_DOESNT_EXIST, f.getName()), SCINOTES,
-                                                   JOptionPane.YES_NO_OPTION);
+                     JOptionPane.YES_NO_OPTION);
         if (choice == 0) { // OK
             styleDocument = (ScilabDocument) theTextPane.getDocument();
             styleDocument.disableUndoManager();
@@ -2415,16 +2415,16 @@ public class SciNotes extends SwingScilabTab {
         try {
             SwingUtilities.invokeAndWait(new Runnable() {
 
-                    @Override
-                    public void run() {
-                        SciNotes[] arr = scinotesList.toArray(new SciNotes[0]);
-                        for (int i = 0; i < arr.length; i++) {
-                            arr[i].setProtectOpenFileList(true);
-                            ExitAction.doExit(arr[i]);
-                        }
-                        scinotesList.clear();
+                @Override
+                public void run() {
+                    SciNotes[] arr = scinotesList.toArray(new SciNotes[0]);
+                    for (int i = 0; i < arr.length; i++) {
+                        arr[i].setProtectOpenFileList(true);
+                        ExitAction.doExit(arr[i]);
                     }
-                });
+                    scinotesList.clear();
+                }
+            });
         } catch (InterruptedException e) {
             Logger.getLogger(SciNotes.class.getName()).severe(e.toString());
         } catch (InvocationTargetException e) {
@@ -2544,21 +2544,21 @@ public class SciNotes extends SwingScilabTab {
     public static boolean executeAction(String fileName, final String[] actionsName) throws IOException {
         final boolean[] hasAction = new boolean[] { false };
         ActionOnDocument action = new ActionOnDocument() {
-                public void actionOn(ScilabDocument doc) throws IOException {
-                    for (String act : actionsName) {
-                        if (act.equalsIgnoreCase("indent")) {
-                            hasAction[0] = true;
-                            org.scilab.modules.scinotes.actions.IndentAction.getActionOnDocument().actionOn(doc);
-                        } else if (act.equalsIgnoreCase("trailing")) {
-                            hasAction[0] = true;
-                            org.scilab.modules.scinotes.actions.RemoveTrailingWhiteAction.getActionOnDocument().actionOn(doc);
-                        } else if (act.equalsIgnoreCase("quote")) {
-                            hasAction[0] = true;
-                            org.scilab.modules.scinotes.actions.DoubleQuoteStringAction.getActionOnDocument().actionOn(doc);
-                        }
+            public void actionOn(ScilabDocument doc) throws IOException {
+                for (String act : actionsName) {
+                    if (act.equalsIgnoreCase("indent")) {
+                        hasAction[0] = true;
+                        org.scilab.modules.scinotes.actions.IndentAction.getActionOnDocument().actionOn(doc);
+                    } else if (act.equalsIgnoreCase("trailing")) {
+                        hasAction[0] = true;
+                        org.scilab.modules.scinotes.actions.RemoveTrailingWhiteAction.getActionOnDocument().actionOn(doc);
+                    } else if (act.equalsIgnoreCase("quote")) {
+                        hasAction[0] = true;
+                        org.scilab.modules.scinotes.actions.DoubleQuoteStringAction.getActionOnDocument().actionOn(doc);
                     }
                 }
-            };
+            }
+        };
 
         executeAction(fileName, action);
 
index 2cda36e..367a85e 100644 (file)
@@ -60,6 +60,12 @@ import javax.swing.text.View;
 import org.scilab.modules.commons.OS;
 import org.scilab.modules.commons.gui.ScilabCaret;
 import org.scilab.modules.console.utils.ScilabLaTeXViewer;
+import org.scilab.modules.gui.messagebox.MessageBox;
+import org.scilab.modules.gui.messagebox.ScilabMessageBox;
+import org.scilab.modules.gui.messagebox.ScilabModalDialog;
+import org.scilab.modules.gui.messagebox.ScilabModalDialog.AnswerOption;
+import org.scilab.modules.gui.messagebox.ScilabModalDialog.ButtonType;
+import org.scilab.modules.gui.messagebox.ScilabModalDialog.IconType;
 import org.scilab.modules.gui.utils.WebBrowser;
 import org.scilab.modules.scinotes.actions.CopyAsHTMLAction;
 import org.scilab.modules.scinotes.actions.OpenSourceFileOnKeywordAction;
@@ -73,9 +79,9 @@ import org.scilab.modules.scinotes.utils.SciNotesMessages;
  *
  */
 public class ScilabEditorPane extends JEditorPane implements Highlighter.HighlightPainter,
-                                                  CaretListener, MouseListener,
-                                                  MouseMotionListener, Cloneable,
-                                                  KeyListener {
+    CaretListener, MouseListener,
+    MouseMotionListener, Cloneable,
+    KeyListener {
 
     private static final long serialVersionUID = 4322071415211939097L;
 
@@ -109,6 +115,7 @@ public class ScilabEditorPane extends JEditorPane implements Highlighter.Highlig
     private Point mousePoint;
 
     private long lastModified;
+    private long lastExternalModification;
 
     /* matchLR matches Left to Right ... */
     private MatchingBlockManager matchLR;
@@ -164,32 +171,32 @@ public class ScilabEditorPane extends JEditorPane implements Highlighter.Highlig
         enableMatchingOpeners(SciNotesOptions.getSciNotesDisplay().highlightBrackets);
         setFocusable(true);
         addFocusListener(new FocusListener() {
-                public void focusGained(FocusEvent e) {
-                    updateInfosWhenFocused();
-                    if (ScilabEditorPane.this.editor != null) {
-                        NavigatorWindow nav = ScilabEditorPane.this.editor.getNavigator();
-                        if (nav != null) {
-                            nav.update((ScilabDocument) getDocument());
-                        }
+            public void focusGained(FocusEvent e) {
+                updateInfosWhenFocused();
+                if (ScilabEditorPane.this.editor != null) {
+                    NavigatorWindow nav = ScilabEditorPane.this.editor.getNavigator();
+                    if (nav != null) {
+                        nav.update((ScilabDocument) getDocument());
                     }
                 }
+            }
 
-                public void focusLost(FocusEvent e) {
-                    ((ScilabDocument) getDocument()).setFocused(false);
-                }
-            });
+            public void focusLost(FocusEvent e) {
+                ((ScilabDocument) getDocument()).setFocused(false);
+            }
+        });
 
         addKeywordListener(new KeywordAdapter.MouseOverAdapter() {
-                public void caughtKeyword(KeywordEvent e) {
-                    if (ScilabLexerConstants.isClickable(e.getType())) {
-                        if (ctrlHit) {
-                            setCursor(HANDCURSOR);
-                            hand = true;
-                            try {
-                                String url = ((ScilabDocument) getDocument()).getText(e.getStart(), e.getLength());
-                                if (ScilabLexerConstants.isClickable(e.getType())) {
-                                    String text;
-                                    switch (e.getType()) {
+            public void caughtKeyword(KeywordEvent e) {
+                if (ScilabLexerConstants.isClickable(e.getType())) {
+                    if (ctrlHit) {
+                        setCursor(HANDCURSOR);
+                        hand = true;
+                        try {
+                            String url = ((ScilabDocument) getDocument()).getText(e.getStart(), e.getLength());
+                            if (ScilabLexerConstants.isClickable(e.getType())) {
+                                String text;
+                                switch (e.getType()) {
                                     case ScilabLexerConstants.URL :
                                         text = SciNotesMessages.OPENURL;
                                         break;
@@ -204,77 +211,77 @@ public class ScilabEditorPane extends JEditorPane implements Highlighter.Highlig
                                         break;
                                     default :
                                         text = null;
-                                    }
+                                }
 
-                                    if (text != null && ScilabEditorPane.this.editor != null) {
-                                        ScilabEditorPane.this.editor.getInfoBar().setText(text + url);
-                                        infoBarChanged = true;
-                                    }
+                                if (text != null && ScilabEditorPane.this.editor != null) {
+                                    ScilabEditorPane.this.editor.getInfoBar().setText(text + url);
+                                    infoBarChanged = true;
                                 }
-                            } catch (BadLocationException ex) { }
-                        } else if (ScilabEditorPane.this.editor != null) {
-                            ScilabEditorPane.this.editor.getInfoBar().setText(SciNotesMessages.CLICKABLE_URL);
-                            infoBarChanged = true;
-                            if (hand) {
-                                setCursor(TEXTCURSOR);
-                                hand = false;
                             }
-                        }
-                    } else {
+                        } catch (BadLocationException ex) { }
+                    } else if (ScilabEditorPane.this.editor != null) {
+                        ScilabEditorPane.this.editor.getInfoBar().setText(SciNotesMessages.CLICKABLE_URL);
+                        infoBarChanged = true;
                         if (hand) {
                             setCursor(TEXTCURSOR);
                             hand = false;
                         }
-                        if (infoBarChanged && ScilabEditorPane.this.editor != null) {
-                            ScilabEditorPane.this.editor.getInfoBar().setText(infoBar);
-                            infoBarChanged = false;
-                        }
-                        if (ScilabLexerConstants.isLaTeX(e.getType())) {
-                            try {
-                                int start = e.getStart();
-                                int end = start + e.getLength();
-                                String exp = ((ScilabDocument) getDocument()).getText(start, e.getLength());
-                                int height = edComponent.getScrollPane().getHeight() + edComponent.getScrollPane().getVerticalScrollBar().getValue();
-                                ScilabLaTeXViewer.displayExpression(ScilabEditorPane.this, height, exp, start, end);
-                            } catch (BadLocationException ex) { }
-                        } else {
-                            ScilabLaTeXViewer.removeLaTeXViewer(ScilabEditorPane.this);
-                        }
                     }
-                }
-            });
-
-        addKeywordListener(new KeywordAdapter.MouseClickedAdapter() {
-                public void caughtKeyword(KeywordEvent e) {
-                    if (ctrlHit && ScilabLexerConstants.isClickable(e.getType())) {
+                } else {
+                    if (hand) {
+                        setCursor(TEXTCURSOR);
+                        hand = false;
+                    }
+                    if (infoBarChanged && ScilabEditorPane.this.editor != null) {
+                        ScilabEditorPane.this.editor.getInfoBar().setText(infoBar);
+                        infoBarChanged = false;
+                    }
+                    if (ScilabLexerConstants.isLaTeX(e.getType())) {
                         try {
-                            hand = false;
-                            ctrlHit = false;
-                            infoBarChanged = false;
-                            setCursor(TEXTCURSOR);
-                            if (ScilabEditorPane.this.editor != null) {
-                                ScilabEditorPane.this.editor.getInfoBar().setText(infoBar);
-                            }
-                            String url = ((ScilabDocument) getDocument()).getText(e.getStart(), e.getLength());
-                            if (ScilabLexerConstants.URL == e.getType() || ScilabLexerConstants.MAIL == e.getType()) {
-                                WebBrowser.openUrl(url);
-                            } else if (ScilabLexerConstants.isOpenable(e.getType())) {
-                                OpenSourceFileOnKeywordAction.openSource(ScilabEditorPane.this, url);
-                            }
+                            int start = e.getStart();
+                            int end = start + e.getLength();
+                            String exp = ((ScilabDocument) getDocument()).getText(start, e.getLength());
+                            int height = edComponent.getScrollPane().getHeight() + edComponent.getScrollPane().getVerticalScrollBar().getValue();
+                            ScilabLaTeXViewer.displayExpression(ScilabEditorPane.this, height, exp, start, end);
                         } catch (BadLocationException ex) { }
+                    } else {
+                        ScilabLaTeXViewer.removeLaTeXViewer(ScilabEditorPane.this);
                     }
                 }
-            });
+            }
+        });
+
+        addKeywordListener(new KeywordAdapter.MouseClickedAdapter() {
+            public void caughtKeyword(KeywordEvent e) {
+                if (ctrlHit && ScilabLexerConstants.isClickable(e.getType())) {
+                    try {
+                        hand = false;
+                        ctrlHit = false;
+                        infoBarChanged = false;
+                        setCursor(TEXTCURSOR);
+                        if (ScilabEditorPane.this.editor != null) {
+                            ScilabEditorPane.this.editor.getInfoBar().setText(infoBar);
+                        }
+                        String url = ((ScilabDocument) getDocument()).getText(e.getStart(), e.getLength());
+                        if (ScilabLexerConstants.URL == e.getType() || ScilabLexerConstants.MAIL == e.getType()) {
+                            WebBrowser.openUrl(url);
+                        } else if (ScilabLexerConstants.isOpenable(e.getType())) {
+                            OpenSourceFileOnKeywordAction.openSource(ScilabEditorPane.this, url);
+                        }
+                    } catch (BadLocationException ex) { }
+                }
+            }
+        });
 
         getScrollPane().addMouseWheelListener(new MouseWheelListener() {
-                public void mouseWheelMoved(MouseWheelEvent e) {
-                    if ((OS.get() == OS.MAC && e.isMetaDown()) || e.isControlDown()) {
-                        int n = e.getWheelRotation();
-                        SciNotes.updateFontSize(n);
-                        e.consume();
-                    }
+            public void mouseWheelMoved(MouseWheelEvent e) {
+                if ((OS.get() == OS.MAC && e.isMetaDown()) || e.isControlDown()) {
+                    int n = e.getWheelRotation();
+                    SciNotes.updateFontSize(n);
+                    e.consume();
                 }
-            });
+            }
+        });
 
         addKeyListener(this);
         setTransferHandler(new CopyAsHTMLAction.HTMLTransferHandler());
@@ -410,8 +417,8 @@ public class ScilabEditorPane extends JEditorPane implements Highlighter.Highlig
     public void keyPressed(KeyEvent e) {
         // Workaround for bug 7238
         if (e.getKeyLocation() == KeyEvent.KEY_LOCATION_NUMPAD
-            && e.getKeyCode() == KeyEvent.VK_DELETE
-            && e.getKeyChar() != KeyEvent.VK_DELETE) {
+                && e.getKeyCode() == KeyEvent.VK_DELETE
+                && e.getKeyChar() != KeyEvent.VK_DELETE) {
             e.setKeyCode(KeyEvent.VK_DECIMAL);
             ctrlHit = false;
         } else if (mousePoint != null && e.getKeyCode() == KeyEvent.VK_CONTROL) {
@@ -516,11 +523,11 @@ public class ScilabEditorPane extends JEditorPane implements Highlighter.Highlig
      */
     public void init(final int pos) {
         SwingUtilities.invokeLater(new Runnable() {
-                public void run() {
-                    requestFocus();
-                    setCaretPosition(pos);
-                }
-            });
+            public void run() {
+                requestFocus();
+                setCaretPosition(pos);
+            }
+        });
     }
 
     /**
@@ -544,8 +551,13 @@ public class ScilabEditorPane extends JEditorPane implements Highlighter.Highlig
         doc.getUndoManager().enableUndoRedoButtons();
 
         if (editor != null) {
-            if (checkExternalModif()) {
+            if (checkExternalModif() && lastExternalModification < getLastModification()) {
                 editor.getInfoBar().setText(SciNotesMessages.EXTERNAL_MODIFICATION_INFO);
+                if (ScilabModalDialog.show(editor, String.format(SciNotesMessages.ASK_TO_RELOAD, getShortName()), SciNotesMessages.RELOAD, IconType.QUESTION_ICON, ButtonType.YES_NO) == AnswerOption.YES_OPTION) {
+                    editor.reload(getEditor().getTabPane().indexOfComponent(getEditorComponent()));
+                    editor.getTextPane().updateInfosWhenFocused();
+                }
+                lastExternalModification = getLastModification();
             } else {
                 editor.getInfoBar().setText(getInfoBarText());
             }
@@ -569,6 +581,22 @@ public class ScilabEditorPane extends JEditorPane implements Highlighter.Highlig
     }
 
     /**
+     * Get last modification on file
+     * @return the lastModified value
+     */
+    public long getLastModification() {
+        String path = getName();
+        if (path != null) {
+            File f = new File(path);
+            if (f != null && f.exists()) {
+                return f.lastModified();
+            }
+        }
+
+        return -1;
+    }
+
+    /**
      * @return the String which must be displayed in the infobar
      */
     public String getInfoBarText() {
@@ -765,28 +793,28 @@ public class ScilabEditorPane extends JEditorPane implements Highlighter.Highlig
      */
     public void scrollTextToPos(final int pos, final boolean setCaret, final boolean centered) {
         SwingUtilities.invokeLater(new Runnable() {
-                public void run() {
-                    try {
-                        if (setCaret) {
-                            setCaretPosition(pos);
+            public void run() {
+                try {
+                    if (setCaret) {
+                        setCaretPosition(pos);
+                    }
+                    JScrollBar scrollbar = edComponent.getScrollPane().getVerticalScrollBar();
+                    Rectangle rect = modelToView(pos);
+                    if (centered) {
+                        int value = scrollbar.getValue();
+                        int h = scrollbar.getHeight();
+                        if (rect.y < value || rect.y > value + h) {
+                            scrollbar.setValue(Math.max(0, rect.y - h / 2));
                         }
-                        JScrollBar scrollbar = edComponent.getScrollPane().getVerticalScrollBar();
-                        Rectangle rect = modelToView(pos);
-                        if (centered) {
-                            int value = scrollbar.getValue();
-                            int h = scrollbar.getHeight();
-                            if (rect.y < value || rect.y > value + h) {
-                                scrollbar.setValue(Math.max(0, rect.y - h / 2));
-                            }
-                        } else {
-                            if (rect.y > scrollbar.getMaximum()) {
-                                scrollbar.setMaximum(rect.y);
-                            }
-                            scrollbar.setValue(rect.y);
+                    } else {
+                        if (rect.y > scrollbar.getMaximum()) {
+                            scrollbar.setMaximum(rect.y);
                         }
-                    } catch (BadLocationException e) { }
-                }
-            });
+                        scrollbar.setValue(rect.y);
+                    }
+                } catch (BadLocationException e) { }
+            }
+        });
     }
 
     /**
@@ -810,20 +838,20 @@ public class ScilabEditorPane extends JEditorPane implements Highlighter.Highlig
         if (lineNumber >= 1 && lineNumber <= root.getElementCount()) {
             final int pos = root.getElement(lineNumber - 1).getStartOffset();
             SwingUtilities.invokeLater(new Runnable() {
-                    public void run() {
-                        scrollTextToPos(pos, setCaret, centered);
-                        if (highlight) {
-                            saveHighlightContourColor = highlightContourColor;
-                            highlightContourColor = null;
-                            saveHighlightColor = highlightColor;
-                            highlightColor = Color.YELLOW;
-                            saveHighlightEnable = highlightEnable;
-                            hasBeenSaved = true;
-                            enableHighlightedLine(false);
-                            enableHighlightedLine(true);
-                        }
+                public void run() {
+                    scrollTextToPos(pos, setCaret, centered);
+                    if (highlight) {
+                        saveHighlightContourColor = highlightContourColor;
+                        highlightContourColor = null;
+                        saveHighlightColor = highlightColor;
+                        highlightColor = Color.YELLOW;
+                        saveHighlightEnable = highlightEnable;
+                        hasBeenSaved = true;
+                        enableHighlightedLine(false);
+                        enableHighlightedLine(true);
                     }
-                });
+                }
+            });
         }
     }
 
@@ -1447,17 +1475,17 @@ public class ScilabEditorPane extends JEditorPane implements Highlighter.Highlig
             final Caret caret = new SciNotesCaret(this);
             setCaretColor(getCaretColor());
             SwingUtilities.invokeLater(new Runnable() {
-                    public void run() {
-                        int blinkRate = 500;
-                        Object o = UIManager.get("TextComponent.caretBlinkRate");
-                        if ((o != null) && (o instanceof Integer)) {
-                            Integer rate = (Integer) o;
-                            blinkRate = rate.intValue();
-                        }
-                        caret.setBlinkRate(blinkRate);
-                        caret.setVisible(true);
+                public void run() {
+                    int blinkRate = 500;
+                    Object o = UIManager.get("TextComponent.caretBlinkRate");
+                    if ((o != null) && (o instanceof Integer)) {
+                        Integer rate = (Integer) o;
+                        blinkRate = rate.intValue();
                     }
-                });
+                    caret.setBlinkRate(blinkRate);
+                    caret.setVisible(true);
+                }
+            });
             super.setCaret(caret);
         } else {
             super.setCaret(c);
index 5c5c0a3..06eec67 100644 (file)
@@ -47,8 +47,6 @@ public final class SaveFile {
      */
     private SaveFile() { }
 
-
-
     /**
      * save text in JEditorPane
      * @param textPane JEditorPane
index 60e2a1c..6482786 100644 (file)
@@ -32,6 +32,7 @@ public class SciNotesMessages {
 
     public static final String INVALID_FILE = Messages.gettext("File not found: %s");
     public static final String IO_EXCEPTION = Messages.gettext("I/O error: %s");
+    public static final String ASK_TO_RELOAD = Messages.gettext("The file %s has been modified by an other program. Reload it ?");
 
     /** FILE MENU */
     public static final String FILE = Messages.gettext("File");
@@ -167,11 +168,11 @@ public class SciNotesMessages {
     public static final String BEGIN_OF_DOCUMENT = Messages.gettext("You have reached the beginning of the document");
     public static final String STRING_NOT_FOUND = Messages.gettext("String %s not found");
 
-    public static final String FILE_DOESNT_EXIST = Messages.gettext("The file %s does not exist\nDo you want to create it?");
+    public static final String FILE_DOESNT_EXIST = Messages.gettext("The file %s does not exist. Do you want to create it?");
     public static final String CLOSE_TAB_TIP = Messages.gettext("close this tab");
     public static final String THIS_FILE = Messages.gettext("This file");
-    public static final String MODIFIED = Messages.gettext(" has been modified since last save\nsave it?");
-    public static final String EXTERNAL_MODIFICATION = Messages.gettext("The file %s has been modified by another program !\n Overwrite it ?");
+    public static final String MODIFIED = Messages.gettext("%s has been modified since last save. Save it?");
+    public static final String EXTERNAL_MODIFICATION = Messages.gettext("The file %s has been modified by another program ! Overwrite it ?");
     public static final String EXTERNAL_MODIFICATION_INFO = Messages.gettext("Warning: the file has been modified by another program !");
     public static final String RELOAD = Messages.gettext("Reload");
     public static final String OVERWRITE = Messages.gettext("Overwrite");