Bug 12830 fixed: In SciNotes, it was not possible to replace from the caret position 91/12291/2
Calixte DENIZET [Mon, 19 Aug 2013 09:43:05 +0000 (11:43 +0200)]
Change-Id: If5be4862dca8ac15c7a4f95b560f448af79ddac2

scilab/CHANGES_5.5.X
scilab/modules/scinotes/src/java/org/scilab/modules/scinotes/actions/FindAction.java
scilab/modules/scinotes/src/java/org/scilab/modules/scinotes/utils/SciNotesMessages.java

index 21019f1..ac94f4b 100644 (file)
@@ -565,6 +565,8 @@ Bug fixes
 
 * Bug #12823 fixed - In help generation (toolbox) links were not correctly handled.
 
+* Bug #12830 fixed - In SciNotes, it was not possible to replace from the caret position.
+
 * Bug #12833 fixed - In SciNotes, there was no autoscroll when searching a pattern.
 
 * Bug #12836 fixed - There was an error in strcmpi documentation.
index 4c41ff4..d1c5c93 100644 (file)
@@ -126,6 +126,7 @@ public final class FindAction extends DefaultAction implements WindowFocusListen
     private JPanel panelScope;
     private SwingScilabTextBox statusBar;
     private JRadioButton radioAll;
+    private JRadioButton radioFromCaret;
     private JRadioButton radioBackward;
     private JRadioButton radioForward;
     private JRadioButton radioSelection;
@@ -308,6 +309,7 @@ public final class FindAction extends DefaultAction implements WindowFocusListen
         radioBackward = new JRadioButton();
         panelScope = new JPanel();
         radioAll = new JRadioButton();
+        radioFromCaret = new JRadioButton();
         radioSelection = new JRadioButton();
         panelOptions = new JPanel();
         checkCase = new JCheckBox();
@@ -352,7 +354,7 @@ public final class FindAction extends DefaultAction implements WindowFocusListen
         buttonGroup1.add(radioBackward);
         radioBackward.setText(SciNotesMessages.BACKWARD);
 
-        panelDirection.setLayout(new GridLayout(2, 1, GAP, GAP));
+        panelDirection.setLayout(new GridLayout(3, 1, GAP, GAP));
         panelDirection.add(radioForward);
         panelDirection.add(radioBackward);
 
@@ -362,11 +364,15 @@ public final class FindAction extends DefaultAction implements WindowFocusListen
         buttonGroup2.add(radioAll);
         radioAll.setText(SciNotesMessages.SELECT_ALL);
 
+        buttonGroup2.add(radioFromCaret);
+        radioFromCaret.setText(SciNotesMessages.SELECT_FROM_CARET);
+
         buttonGroup2.add(radioSelection);
         radioSelection.setText(SciNotesMessages.SELECTED_LINES);
 
-        panelScope.setLayout(new GridLayout(2, 1, GAP, GAP));
+        panelScope.setLayout(new GridLayout(3, 1, GAP, GAP));
         panelScope.add(radioAll);
+        panelScope.add(radioFromCaret);
         panelScope.add(radioSelection);
 
         JPanel panelDirectionScope = new JPanel();
@@ -510,6 +516,15 @@ public final class FindAction extends DefaultAction implements WindowFocusListen
             }
         });
 
+        radioFromCaret.addActionListener(new ActionListener() {
+            @Override
+            public void actionPerformed(ActionEvent e) {
+                removeAllHighlights();
+                previousRegexp = "";
+                updateFindReplaceButtonStatus();
+            }
+        });
+
         radioBackward.addActionListener(new ActionListener() {
             @Override
             public void actionPerformed(ActionEvent e) {
@@ -584,6 +599,17 @@ public final class FindAction extends DefaultAction implements WindowFocusListen
                     try {
                         text = doc.getText(startSelectedLines, endSelectedLines - startSelectedLines);
                     } catch (BadLocationException ex) { }
+                } else if (radioFromCaret.isSelected()) {
+                    if (radioForward.isSelected()) {
+                        start = currentCaretPos;
+                        end = doc.getLength();
+                    } else {
+                        start = 0;
+                        end = currentCaretPos;
+                    }
+                    try {
+                        text = doc.getText(start, end - start);
+                    } catch (BadLocationException ex) { }
                 } else {
                     text = doc.getText();
                 }
index 66eee7c..3d1c816 100644 (file)
@@ -153,6 +153,7 @@ public class SciNotesMessages {
     public static final String SCOPE = Messages.gettext("Scope");
     public static final String ALL = Messages.gettext("All");
     public static final String SELECTED_LINES = Messages.gettext("Selected lines");
+    public static final String SELECT_FROM_CARET = Messages.gettext("Select from caret");
     public static final String OPTIONS = Messages.gettext("Options");
     public static final String CASE_SENSITIVE = Messages.gettext("Case sensitive");
     public static final String CIRCULAR_SEARCH = Messages.gettext("Circular search");