diff --git a/api.search/apichanges.xml b/api.search/apichanges.xml --- a/api.search/apichanges.xml +++ b/api.search/apichanges.xml @@ -105,6 +105,27 @@ + + + Added ReplacePattern and replace history to SearchHistory class + + + + + +

+ Search History has two new methods: addReplace() and getReplacePatterns(). + It has one more property name ADD_TO_REPLACE for firing changes in replacepatternlist. + Replace implementation is identical to Search history with Search Patterns.. +

+

+ New ReplacePattern has two variables - replaceExpression and preserveCase. It is a wrap class for replace expression. +

+
+ + +
+ Added method SearchResultsDisplayer.closed() diff --git a/api.search/manifest.mf b/api.search/manifest.mf --- a/api.search/manifest.mf +++ b/api.search/manifest.mf @@ -1,5 +1,5 @@ Manifest-Version: 1.0 OpenIDE-Module: org.netbeans.api.search OpenIDE-Module-Localizing-Bundle: org/netbeans/api/search/Bundle.properties -OpenIDE-Module-Specification-Version: 1.7 +OpenIDE-Module-Specification-Version: 1.8 diff --git a/api.search/src/org/netbeans/api/search/SearchPattern.java b/api.search/src/org/netbeans/api/search/ReplacePattern.java copy from api.search/src/org/netbeans/api/search/SearchPattern.java copy to api.search/src/org/netbeans/api/search/ReplacePattern.java --- a/api.search/src/org/netbeans/api/search/SearchPattern.java +++ b/api.search/src/org/netbeans/api/search/ReplacePattern.java @@ -44,189 +44,99 @@ package org.netbeans.api.search; /** - * Pattern describes the search conditions - * - * @author Martin Roskanin + * Pattern describes the replace conditions + * @since 1.8 */ -public final class SearchPattern { +public final class ReplacePattern { - /** - * SearchExpression - a text to search - */ - private String searchExpression; - /** - * if true, only whole words were searched - */ - private boolean wholeWords; - /** - * if true, case sensitive search was preformed - */ - private boolean matchCase; - /** - * if true, regular expression search was performed - */ - private boolean regExp; - - /** - * Creates a new instance of SearchPattern - * - * @param searchExpression a searched text - * @param wholeWords if true, only whole words were searched - * @param matchCase if true, case sensitive search was preformed - * @param regExp if true, regular expression search was performed - */ - private SearchPattern(String searchExpression, boolean wholeWords, - boolean matchCase, boolean regExp) { - this.searchExpression = searchExpression; - this.wholeWords = wholeWords; - this.matchCase = matchCase; - this.regExp = regExp; + private String replaceExpression; + private boolean preserveCase; + + private ReplacePattern(String replaceExpression, boolean preserveCase) { + this.replaceExpression = replaceExpression; + this.preserveCase = preserveCase; } /** - * Creates a new SearchPattern in accordance with given parameters + * Creates a new ReplacePattern in accordance with given parameters * * @param searchExpression non-null String of a searched text * @param wholeWords if true, only whole words were searched - * @param matchCase if true, case sensitive search was preformed - * @param regExp if true, regular expression search was performed - * @return a new SearchPattern in accordance with given parameters */ - public static SearchPattern create(String searchExpression, boolean wholeWords, - boolean matchCase, boolean regExp) { - return new SearchPattern(searchExpression, wholeWords, matchCase, regExp); + public static ReplacePattern create(String replaceExpression, boolean preserveCase) { + return new ReplacePattern(replaceExpression, preserveCase); + } + + public String getReplaceExpression() { + return replaceExpression; } - /** - * @return searchExpression - */ - public String getSearchExpression() { - return searchExpression; + public boolean isPreserveCase() { + return preserveCase; } - - /** - * @return true if the wholeWords parameter was used during search - * performing - */ - public boolean isWholeWords() { - return wholeWords; - } - - /** - * @return true if the matchCase parameter was used during search performing - */ - public boolean isMatchCase() { - return matchCase; - } - - /** - * @return true if the regExp parameter was used during search performing - */ - public boolean isRegExp() { - return regExp; - } - + @Override public boolean equals(Object obj) { - if (!(obj instanceof SearchPattern)) { + if (!(obj instanceof ReplacePattern)) { return false; } - SearchPattern sp = (SearchPattern) obj; - return (this.searchExpression.equals(sp.getSearchExpression()) - && this.wholeWords == sp.isWholeWords() - && this.matchCase == sp.isMatchCase() - && this.regExp == sp.isRegExp()); + ReplacePattern sp = (ReplacePattern) obj; + return (this.replaceExpression.equals(sp.getReplaceExpression()) + && this.preserveCase == sp.isPreserveCase()); } @Override public int hashCode() { int result = 17; - result = 37 * result + (this.wholeWords ? 1 : 0); - result = 37 * result + (this.matchCase ? 1 : 0); - result = 37 * result + (this.regExp ? 1 : 0); - result = 37 * result + this.searchExpression.hashCode(); + result = 37 * result + (this.preserveCase ? 1 : 0); + result = 37 * result + this.replaceExpression.hashCode(); return result; } /** - * Create new instance with "search expression" set to passed value, and + * Create new instance with "replace expression" set to passed value, and * other values copied from this instance. * */ - public SearchPattern changeSearchExpression(String expression) { - if ((expression == null && this.searchExpression == null) + public ReplacePattern changeReplaceExpression(String expression) { + if ((expression == null && this.replaceExpression == null) || (expression != null - && expression.equals(this.searchExpression))) { + && expression.equals(this.replaceExpression))) { return this; } else { - return SearchPattern.create(expression, wholeWords, - matchCase, regExp); + return ReplacePattern.create(expression, preserveCase); } } /** - * Create new instance with "whole words" set to passed value, and other + * Create new instance with "preserve case" set to passed value, and other * values copied from this instance. * */ - public SearchPattern changeWholeWords(boolean wholeWords) { - if (this.wholeWords == wholeWords) { + public ReplacePattern changePreserveCase(boolean preserveCase) { + if (this.preserveCase == preserveCase) { return this; } else { - return SearchPattern.create(searchExpression, wholeWords, - matchCase, regExp); - } - } - - /** - * Create new instance with "match case" set to passed value, and other - * values copied from this instance. - * - */ - public SearchPattern changeMatchCase(boolean matchCase) { - if (this.matchCase == matchCase) { - return this; - } else { - return SearchPattern.create(searchExpression, wholeWords, - matchCase, regExp); - } - } - - /** - * Create new instance with "regular expression" set to passed value, and - * other values copied from this instance. - * - */ - public SearchPattern changeRegExp(boolean regExp) { - if (this.regExp == regExp) { - return this; - } else { - return SearchPattern.create(searchExpression, wholeWords, - matchCase, regExp); + return ReplacePattern.create(replaceExpression, preserveCase); } } String toCanonicalString() { - char m = isMatchCase() ? 'M' : 'm'; - char r = isRegExp() ? 'R' : 'r'; - char w = isWholeWords() ? 'W' : 'w'; - return "" + m + r + w + "-" + getSearchExpression(); + char p = isPreserveCase()? 'P' : 'p'; + return "" + p + "-" + getReplaceExpression(); //NOI18N } - static SearchPattern parseSearchPattern(String canonicalString) { - //format mrw-findwhat + static ReplacePattern parsePattern(String canonicalString) { + //format p-replaceWith if (canonicalString == null - || Character.toUpperCase(canonicalString.charAt(0)) != 'M' - || Character.toUpperCase(canonicalString.charAt(1)) != 'R' - || Character.toUpperCase(canonicalString.charAt(2)) != 'W' - || canonicalString.charAt(3) != '-') { + || Character.toUpperCase(canonicalString.charAt(0)) != 'P' + || canonicalString.charAt(1) != '-') { return null; } - boolean matchCase = Character.isUpperCase(canonicalString.charAt(0)); - boolean regExp = Character.isUpperCase(canonicalString.charAt(1)); - boolean wholeWords = Character.isUpperCase(canonicalString.charAt(2)); - String findWhat = canonicalString.substring(4); - return new SearchPattern(findWhat, wholeWords, matchCase, regExp); + + boolean preserveCase = Character.isUpperCase(canonicalString.charAt(0)); + String replaceWith = canonicalString.substring(2); + return new ReplacePattern(replaceWith, preserveCase); } } diff --git a/api.search/src/org/netbeans/api/search/SearchHistory.java b/api.search/src/org/netbeans/api/search/SearchHistory.java --- a/api.search/src/org/netbeans/api/search/SearchHistory.java +++ b/api.search/src/org/netbeans/api/search/SearchHistory.java @@ -79,11 +79,13 @@ private static final int MAX_SEARCH_PATTERNS_ITEMS = 10; /** Limit for stored pattern length */ - private static final int MAX_PATTERN_LENGHT = 16384; // 16 kB + private static final int MAX_PATTERN_LENGTH = 16384; // 16 kB /** Shareable SearchPattern history. It is a List of SearchPatterns */ private List searchPatternsList = new ArrayList(MAX_SEARCH_PATTERNS_ITEMS); + + private List replacePatternsList = new ArrayList(MAX_SEARCH_PATTERNS_ITEMS); /** Singleton instance */ private static SearchHistory INSTANCE = null; @@ -103,12 +105,21 @@ * newValue - added pattern */ public final static String ADD_TO_HISTORY = "add-to-history"; //NOI18N + + /** Property name for adding replace pattern that was not in history + * Firing: + * oldValue - null + * newValue - added pattern + * @since 1.8 + */ + public final static String ADD_TO_REPLACE = "add-to-replace"; //NOI18N /** Preferences node for storing history info */ private static Preferences prefs; /** Name of preferences node where we persist history */ private static final String PREFS_NODE = "SearchHistory"; //NOI18N private static final String PROP_SEARCH_PATTERN_PREFIX = "search_"; //NOI18N + private static final String PROP_REPLACE_PATTERN_PREFIX = "replace_"; //NOI18N /** Creates a new instance of SearchHistory */ private SearchHistory() { @@ -129,9 +140,17 @@ */ private void load () { for(int i=0; i < MAX_SEARCH_PATTERNS_ITEMS; i++){ - SearchPattern pattern = SearchPattern.parseSearchPattern(prefs.get(PROP_SEARCH_PATTERN_PREFIX + i, null)); - if (pattern != null) + SearchPattern pattern = SearchPattern.parsePattern(prefs.get(PROP_SEARCH_PATTERN_PREFIX + i, null)); + if (pattern != null) { searchPatternsList.add(pattern); + } + } + + for(int i=0; i < MAX_SEARCH_PATTERNS_ITEMS; i++){ + ReplacePattern pattern = ReplacePattern.parsePattern(prefs.get(PROP_REPLACE_PATTERN_PREFIX + i, null)); + if (pattern != null) { + replacePatternsList.add(pattern); + } } } @@ -185,13 +204,20 @@ return Collections.unmodifiableList(searchPatternsList); } + /** @return unmodifiable List of ReplacePatterns + * @since 1.8 + */ + public synchronized List getReplacePatterns(){ + return Collections.unmodifiableList(replacePatternsList); + } + /** Adds SearchPattern to SearchHistory * @param pattern the SearchPattern to add */ public synchronized void add(SearchPattern pattern) { if (pattern == null || pattern.getSearchExpression() == null || pattern.getSearchExpression().length() == 0 || (searchPatternsList.size() > 0 && pattern.equals(searchPatternsList.get(0)) - || pattern.getSearchExpression().length() > MAX_PATTERN_LENGHT)) { + || pattern.getSearchExpression().length() > MAX_PATTERN_LENGTH)) { return; } @@ -215,6 +241,37 @@ } } + /** Adds ReplacePattern to ReplaceHistory + * @param pattern the ReplacePattern to add + * @since 1.8 + */ + public synchronized void addReplace(ReplacePattern pattern) { + if (pattern == null || pattern.getReplaceExpression() == null || pattern.getReplaceExpression().length() == 0 + || (replacePatternsList.size() > 0 && pattern.equals(replacePatternsList.get(0)) + || pattern.getReplaceExpression().length() > MAX_PATTERN_LENGTH)) { + return; + } + + for (int i = 0; i < replacePatternsList.size(); i++) { + if (pattern.getReplaceExpression().equals(replacePatternsList.get(i).getReplaceExpression())) { + replacePatternsList.remove(i); + break; + } + } + + if (replacePatternsList.size() == MAX_SEARCH_PATTERNS_ITEMS){ + replacePatternsList.remove(MAX_SEARCH_PATTERNS_ITEMS-1); + } + replacePatternsList.add(0, pattern); + + for(int i=0;i < replacePatternsList.size();i++){ + prefs.put(PROP_REPLACE_PATTERN_PREFIX + i, replacePatternsList.get(i).toCanonicalString()); + } + if (pcs != null) { + pcs.firePropertyChange(ADD_TO_REPLACE, null, pattern); + } + } + /** * Store last used file name pattern. * diff --git a/api.search/src/org/netbeans/api/search/SearchPattern.java b/api.search/src/org/netbeans/api/search/SearchPattern.java --- a/api.search/src/org/netbeans/api/search/SearchPattern.java +++ b/api.search/src/org/netbeans/api/search/SearchPattern.java @@ -210,10 +210,10 @@ char m = isMatchCase() ? 'M' : 'm'; char r = isRegExp() ? 'R' : 'r'; char w = isWholeWords() ? 'W' : 'w'; - return "" + m + r + w + "-" + getSearchExpression(); + return "" + m + r + w + "-" + getSearchExpression(); //NOI18N } - static SearchPattern parseSearchPattern(String canonicalString) { + static SearchPattern parsePattern(String canonicalString) { //format mrw-findwhat if (canonicalString == null || Character.toUpperCase(canonicalString.charAt(0)) != 'M' diff --git a/o.openidex.util/test/unit/src/org/openidex/search/SearchPatternTest.java b/api.search/test/unit/src/org/netbeans/api/search/ReplacePatternTest.java rename from o.openidex.util/test/unit/src/org/openidex/search/SearchPatternTest.java rename to api.search/test/unit/src/org/netbeans/api/search/ReplacePatternTest.java --- a/o.openidex.util/test/unit/src/org/openidex/search/SearchPatternTest.java +++ b/api.search/test/unit/src/org/netbeans/api/search/ReplacePatternTest.java @@ -39,34 +39,35 @@ * * Portions Copyrighted 2012 Sun Microsystems, Inc. */ -package org.openidex.search; +package org.netbeans.api.search; -import org.junit.AfterClass; import org.junit.Test; import static org.junit.Assert.*; -import org.junit.BeforeClass; -/** - * - * @author mito - */ -public class SearchPatternTest { + +public class ReplacePatternTest { @Test public void testManuallyParse() throws Exception { - String canString= "MrW-Test"; - SearchPattern sp = SearchPattern.parseSearchPattern(canString); - assertTrue(sp.isMatchCase()); - assertFalse(sp.isRegExp()); - assertTrue(sp.isWholeWords()); - assertEquals("Test", sp.getSearchExpression()); + String canString= "P-Test"; + ReplacePattern rp = ReplacePattern.parsePattern(canString); + assertTrue(rp.isPreserveCase()); + assertEquals("Test", rp.getReplaceExpression()); + + canString= "p--Test2"; + rp = ReplacePattern.parsePattern(canString); + assertFalse(rp.isPreserveCase()); + assertEquals("-Test2", rp.getReplaceExpression()); } @Test public void testManuallyCanString() throws Exception { - SearchPattern sp = SearchPattern.create("ta", true, false, true); - String canString = sp.toCanonicalString(); + ReplacePattern rp = ReplacePattern.create("ta", true); + String canString = rp.toCanonicalString(); + assertEquals("P-ta", canString); - assertEquals("mRW-ta", canString); + rp = ReplacePattern.create("pa", false); + canString = rp.toCanonicalString(); + assertEquals("p-pa", canString); } } diff --git a/api.search/test/unit/src/org/netbeans/api/search/provider/impl/SearchHistoryTest.java b/api.search/test/unit/src/org/netbeans/api/search/SearchHistoryTest.java rename from api.search/test/unit/src/org/netbeans/api/search/provider/impl/SearchHistoryTest.java rename to api.search/test/unit/src/org/netbeans/api/search/SearchHistoryTest.java --- a/api.search/test/unit/src/org/netbeans/api/search/provider/impl/SearchHistoryTest.java +++ b/api.search/test/unit/src/org/netbeans/api/search/SearchHistoryTest.java @@ -42,7 +42,7 @@ * made subject to such option by the copyright holder. */ -package org.netbeans.api.search.provider.impl; +package org.netbeans.api.search; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; diff --git a/o.openidex.util/test/unit/src/org/openidex/search/SearchPatternTest.java b/api.search/test/unit/src/org/netbeans/api/search/SearchPatternTest.java copy from o.openidex.util/test/unit/src/org/openidex/search/SearchPatternTest.java copy to api.search/test/unit/src/org/netbeans/api/search/SearchPatternTest.java --- a/o.openidex.util/test/unit/src/org/openidex/search/SearchPatternTest.java +++ b/api.search/test/unit/src/org/netbeans/api/search/SearchPatternTest.java @@ -39,23 +39,17 @@ * * Portions Copyrighted 2012 Sun Microsystems, Inc. */ -package org.openidex.search; +package org.netbeans.api.search; -import org.junit.AfterClass; import org.junit.Test; import static org.junit.Assert.*; -import org.junit.BeforeClass; -/** - * - * @author mito - */ public class SearchPatternTest { @Test public void testManuallyParse() throws Exception { String canString= "MrW-Test"; - SearchPattern sp = SearchPattern.parseSearchPattern(canString); + SearchPattern sp = SearchPattern.parsePattern(canString); assertTrue(sp.isMatchCase()); assertFalse(sp.isRegExp()); assertTrue(sp.isWholeWords()); diff --git a/editor.lib2/manifest.mf b/editor.lib2/manifest.mf --- a/editor.lib2/manifest.mf +++ b/editor.lib2/manifest.mf @@ -1,6 +1,6 @@ Manifest-Version: 1.0 OpenIDE-Module: org.netbeans.modules.editor.lib2/1 -OpenIDE-Module-Implementation-Version: 39 +OpenIDE-Module-Implementation-Version: 40 OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/editor/lib2/Bundle.properties OpenIDE-Module-Layer: org/netbeans/modules/editor/lib2/resources/layer.xml OpenIDE-Module-Needs: org.netbeans.modules.editor.actions diff --git a/editor.lib2/src/org/netbeans/modules/editor/lib2/search/EditorFindSupport.java b/editor.lib2/src/org/netbeans/modules/editor/lib2/search/EditorFindSupport.java --- a/editor.lib2/src/org/netbeans/modules/editor/lib2/search/EditorFindSupport.java +++ b/editor.lib2/src/org/netbeans/modules/editor/lib2/search/EditorFindSupport.java @@ -137,8 +137,10 @@ /** It's public only to keep backwards compatibility of the FindSupport class. */ public static final String FIND_HISTORY_PROP = "find-history-prop"; //NOI18N + public static final String REPLACE_HISTORY_PROP = "replace-history-prop"; //NOI18N /** It's public only to keep backwards compatibility of the FindSupport class. */ public static final String FIND_HISTORY_CHANGED_PROP = "find-history-changed-prop"; //NOI18N + public static final String REPLACE_HISTORY_CHANGED_PROP = "replace-history-changed-prop"; //NOI18N /** * Default message 'importance' for messages from find and replace actions. @@ -162,6 +164,7 @@ private SPW lastSelected; private List historyList = new ArrayList(); + private List replaceList = new ArrayList(); private EditorFindSupport() { } @@ -917,12 +920,23 @@ // firePropertyChange(FIND_HISTORY_CHANGED_PROP,null,null); } + public void setReplaceHistory(List rpList){ + this.replaceList = new ArrayList(rpList); + } + public List getHistory(){ if (historyList.isEmpty()) firePropertyChange(FIND_HISTORY_CHANGED_PROP,null,null); return historyList; } + public List getReplaceHistory(){ + if (replaceList.isEmpty()) { + firePropertyChange(REPLACE_HISTORY_CHANGED_PROP,null,null); + } + return replaceList; + } + public void setLastSelected(SPW spw){ this.lastSelected = spw; Map props = getFindProperties(); @@ -942,6 +956,13 @@ firePropertyChange(FIND_HISTORY_PROP, null, spw); } + public void addToReplaceHistory(RP rp) { + if (rp == null) { + return; + } + firePropertyChange(REPLACE_HISTORY_PROP, null, rp); + } + public final static class SPW{ private String searchExpression; private boolean wholeWords; @@ -1010,4 +1031,41 @@ return sb.toString(); } } // End of SPW class + + public final static class RP { + + private String replaceExpression; + private boolean preserveCase; + + public RP(String replaceExpression, boolean preserveCase) { + this.replaceExpression = replaceExpression; + this.preserveCase = preserveCase; + } + + public String getReplaceExpression() { + return replaceExpression; + } + + public boolean isPreserveCase() { + return preserveCase; + } + + @Override + public boolean equals(Object obj) { + if (!(obj instanceof RP)) { + return false; + } + RP sp = (RP) obj; + return (this.replaceExpression.equals(sp.getReplaceExpression()) + && this.preserveCase == sp.isPreserveCase()); + } + + @Override + public int hashCode() { + int result = 17; + result = 37 * result + (this.preserveCase ? 1 : 0); + result = 37 * result + this.replaceExpression.hashCode(); + return result; + } + } } diff --git a/editor.search/nbproject/project.properties b/editor.search/nbproject/project.properties --- a/editor.search/nbproject/project.properties +++ b/editor.search/nbproject/project.properties @@ -1,3 +1,3 @@ javac.source=1.6 javac.compilerargs=-Xlint -Xlint:-serial -spec.version.base=1.9.0 +spec.version.base=1.10.0 diff --git a/editor.search/nbproject/project.xml b/editor.search/nbproject/project.xml --- a/editor.search/nbproject/project.xml +++ b/editor.search/nbproject/project.xml @@ -6,6 +6,14 @@ org.netbeans.modules.editor.search + org.netbeans.api.search + + + + 1.8 + + + org.netbeans.modules.editor diff --git a/editor.search/src/org/netbeans/modules/editor/search/ReplaceBar.java b/editor.search/src/org/netbeans/modules/editor/search/ReplaceBar.java --- a/editor.search/src/org/netbeans/modules/editor/search/ReplaceBar.java +++ b/editor.search/src/org/netbeans/modules/editor/search/ReplaceBar.java @@ -276,6 +276,7 @@ } void updateReplaceComboBoxHistory(String incrementalSearchText) { + EditorFindSupport.getInstance().addToReplaceHistory(new EditorFindSupport.RP(incrementalSearchText, preserveCaseCheckBox.isSelected())); // Add the text to the top of the list for (int i = replaceComboBox.getItemCount() - 1; i >= 0; i--) { String item = (String) replaceComboBox.getItemAt(i); @@ -357,9 +358,18 @@ public void gainFocus() { if (!isVisible()) { changeSearchBarToBePartOfReplaceBar(); - setVisible(true); SearchComboBoxEditor.changeToOneLineEditorPane((JEditorPane) replaceTextField); addEnterKeystrokeReplaceTo(replaceTextField); + String lastReplace = replaceTextField.getText(); + MutableComboBoxModel comboBoxModelIncSearch = ((MutableComboBoxModel) replaceComboBox.getModel()); + for (int i = comboBoxModelIncSearch.getSize() - 1; i >= 0; i--) { + comboBoxModelIncSearch.removeElementAt(i); + } + for (EditorFindSupport.RP rp : EditorFindSupport.getInstance().getReplaceHistory()) { + comboBoxModelIncSearch.addElement(rp.getReplaceExpression()); + } + replaceTextField.setText(lastReplace); + setVisible(true); } searchBar.gainFocus(); searchBar.getIncSearchTextField().requestFocusInWindow(); diff --git a/editor.search/src/org/netbeans/modules/editor/search/SearchBar.java b/editor.search/src/org/netbeans/modules/editor/search/SearchBar.java --- a/editor.search/src/org/netbeans/modules/editor/search/SearchBar.java +++ b/editor.search/src/org/netbeans/modules/editor/search/SearchBar.java @@ -44,6 +44,7 @@ import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; import java.lang.ref.WeakReference; +import java.util.ArrayList; import java.util.Arrays; import java.util.LinkedList; import java.util.List; @@ -64,6 +65,9 @@ import org.netbeans.api.editor.mimelookup.MimeLookup; import org.netbeans.api.editor.mimelookup.MimePath; import org.netbeans.api.editor.settings.SimpleValueNames; +import org.netbeans.api.search.ReplacePattern; +import org.netbeans.api.search.SearchHistory; +import org.netbeans.api.search.SearchPattern; import org.netbeans.editor.BaseDocument; import org.netbeans.editor.BaseKit; import org.netbeans.editor.MultiKeymap; @@ -140,6 +144,7 @@ @SuppressWarnings("unchecked") private SearchBar() { + loadSearchHistory(); addEscapeKeystrokeFocusBackTo(this); setLayout(new BoxLayout(this, BoxLayout.LINE_AXIS)); setFocusCycleRoot(true); @@ -236,6 +241,86 @@ setVisible(false); usageLogging(); } + + private static class SearchHistoryUtility { + + public static List convertFromSearchHistoryToEditorFindSupport(List searchPatterns) { + List history = new ArrayList(); + for (int i = 0; i < searchPatterns.size(); i++) { + SearchPattern sptr = searchPatterns.get(i); + EditorFindSupport.SPW spwrap = new EditorFindSupport.SPW(sptr.getSearchExpression(), + sptr.isWholeWords(), sptr.isMatchCase(), sptr.isRegExp()); + history.add(spwrap); + } + return history; + } + + public static List convertFromReplaceHistoryToEditorFindSupport(List replacePatterns) { + List history = new ArrayList(); + for (int i = 0; i < replacePatterns.size(); i++) { + ReplacePattern rp = replacePatterns.get(i); + EditorFindSupport.RP spwrap = new EditorFindSupport.RP(rp.getReplaceExpression(), rp.isPreserveCase()); + history.add(spwrap); + } + return history; + } + } + private static PropertyChangeListener searchSelectedPatternListener; + private static PropertyChangeListener editorHistoryChangeListener; + + private static void loadSearchHistory() { + searchSelectedPatternListener = new PropertyChangeListener() { + @Override + public void propertyChange(PropertyChangeEvent evt) { + if (evt == null) { + return; + } + if (SearchHistory.ADD_TO_HISTORY.equals(evt.getPropertyName())) { + EditorFindSupport.getInstance().setHistory( + SearchHistoryUtility.convertFromSearchHistoryToEditorFindSupport(SearchHistory.getDefault().getSearchPatterns())); + } + + if (SearchHistory.ADD_TO_REPLACE.equals(evt.getPropertyName())) { + EditorFindSupport.getInstance().setReplaceHistory( + SearchHistoryUtility.convertFromReplaceHistoryToEditorFindSupport(SearchHistory.getDefault().getReplacePatterns())); + } + } + }; + + editorHistoryChangeListener = new PropertyChangeListener() { + @Override + public void propertyChange(PropertyChangeEvent evt) { + if (evt == null) { + return; + } + if (EditorFindSupport.FIND_HISTORY_PROP.equals(evt.getPropertyName())) { + EditorFindSupport.SPW spw = (EditorFindSupport.SPW) evt.getNewValue(); + if (spw == null || spw.getSearchExpression() == null || "".equals(spw.getSearchExpression())) { //NOI18N + return; + } + SearchPattern sp = SearchPattern.create(spw.getSearchExpression(), + spw.isWholeWords(), spw.isMatchCase(), spw.isRegExp()); + SearchHistory.getDefault().add(sp); + } else if (EditorFindSupport.FIND_HISTORY_CHANGED_PROP.equals(evt.getPropertyName())) { + EditorFindSupport.getInstance().setHistory( + SearchHistoryUtility.convertFromSearchHistoryToEditorFindSupport(SearchHistory.getDefault().getSearchPatterns())); + } else if (EditorFindSupport.REPLACE_HISTORY_PROP.equals(evt.getPropertyName())) { + EditorFindSupport.RP rp = (EditorFindSupport.RP) evt.getNewValue(); + if (rp == null || rp.getReplaceExpression() == null || "".equals(rp.getReplaceExpression())) { //NOI18N + return; + } + ReplacePattern replacePattern = ReplacePattern.create(rp.getReplaceExpression(), rp.isPreserveCase()); + SearchHistory.getDefault().addReplace(replacePattern); + } else if (EditorFindSupport.REPLACE_HISTORY_CHANGED_PROP.equals(evt.getPropertyName())) { + EditorFindSupport.getInstance().setReplaceHistory( + SearchHistoryUtility.convertFromReplaceHistoryToEditorFindSupport(SearchHistory.getDefault().getReplacePatterns())); + } + } + }; + + SearchHistory.getDefault().addPropertyChangeListener(searchSelectedPatternListener); + EditorFindSupport.getInstance().addPropertyChangeListener(editorHistoryChangeListener); + } private static void usageLogging() { Logger logger = Logger.getLogger("org.netbeans.ui.metrics.editor"); // NOI18N diff --git a/editor.search/src/org/netbeans/modules/editor/search/completion/SearchCompletion.java b/editor.search/src/org/netbeans/modules/editor/search/completion/SearchCompletion.java --- a/editor.search/src/org/netbeans/modules/editor/search/completion/SearchCompletion.java +++ b/editor.search/src/org/netbeans/modules/editor/search/completion/SearchCompletion.java @@ -48,6 +48,7 @@ import javax.swing.text.JTextComponent; import org.netbeans.api.editor.mimelookup.MimeRegistration; import org.netbeans.modules.editor.lib2.search.EditorFindSupport; +import org.netbeans.modules.editor.lib2.search.EditorFindSupport.RP; import org.netbeans.modules.editor.lib2.search.EditorFindSupport.SPW; import org.netbeans.modules.editor.search.SearchBar; import org.netbeans.modules.editor.search.SearchNbEditorKit; @@ -109,6 +110,13 @@ results.add(searchCompletionItem); } } + for (RP rp : EditorFindSupport.getInstance().getReplaceHistory()) { + String s = rp.getReplaceExpression().trim(); + if (s.toLowerCase().startsWith(queryText) && s.length() != queryText.length()) { + SearchCompletionItem searchCompletionItem = new SearchCompletionItem(s); + results.add(searchCompletionItem); + } + } } if (resultSet != null) { // resultSet can be null only in tests! resultSet.addAllItems(results); diff --git a/editor/nbproject/project.properties b/editor/nbproject/project.properties --- a/editor/nbproject/project.properties +++ b/editor/nbproject/project.properties @@ -42,7 +42,7 @@ javac.compilerargs=-Xlint:unchecked javac.source=1.6 -spec.version.base=1.69.0 +spec.version.base=1.70.0 is.autoload=true javadoc.arch=${basedir}/arch.xml diff --git a/editor/nbproject/project.xml b/editor/nbproject/project.xml --- a/editor/nbproject/project.xml +++ b/editor/nbproject/project.xml @@ -59,14 +59,6 @@ - org.netbeans.api.search - - - - 1.0 - - - org.netbeans.modules.editor.fold diff --git a/editor/src/org/netbeans/modules/editor/EditorModule.java b/editor/src/org/netbeans/modules/editor/EditorModule.java --- a/editor/src/org/netbeans/modules/editor/EditorModule.java +++ b/editor/src/org/netbeans/modules/editor/EditorModule.java @@ -50,11 +50,9 @@ import java.io.IOException; import java.lang.reflect.Field; import java.lang.reflect.Method; -import java.util.ArrayList; import java.util.HashSet; import java.util.Hashtable; import java.util.Iterator; -import java.util.List; import java.util.Map; import java.util.concurrent.atomic.AtomicBoolean; import java.util.logging.Level; @@ -69,8 +67,6 @@ import javax.swing.text.rtf.RTFEditorKit; import org.netbeans.api.editor.mimelookup.MimeLookup; import org.netbeans.api.editor.mimelookup.MimePath; -import org.netbeans.api.search.SearchHistory; -import org.netbeans.api.search.SearchPattern; import org.netbeans.editor.AnnotationType; import org.netbeans.editor.AnnotationTypes; import org.netbeans.editor.BaseDocument; @@ -81,7 +77,6 @@ import org.netbeans.modules.editor.lib.EditorPackageAccessor; import org.netbeans.modules.editor.lib2.actions.EditorRegistryWatcher; import org.netbeans.modules.editor.lib2.document.ReadWriteUtils; -import org.netbeans.modules.editor.lib2.search.EditorFindSupport; import org.netbeans.modules.editor.options.AnnotationTypesFolder; import org.openide.cookies.EditorCookie; import org.openide.filesystems.FileObject; @@ -113,20 +108,6 @@ private static final boolean debug = Boolean.getBoolean("netbeans.debug.editor.kits"); - private static class SearchHistoryUtility { - public static List convertFromSearchHistoryToEditorFindSupport(List searchPatterns) { - List history = new ArrayList(); - for (int i = 0; i < searchPatterns.size(); i++) { - SearchPattern sptr = searchPatterns.get(i); - EditorFindSupport.SPW spwrap = new EditorFindSupport.SPW(sptr.getSearchExpression(), - sptr.isWholeWords(), sptr.isMatchCase(), sptr.isRegExp()); - history.add(spwrap); - } - return history; - } - } - private PropertyChangeListener searchSelectedPatternListener; - private PropertyChangeListener editorHistoryChangeListener; private PropertyChangeListener topComponentRegistryListener; /** Module installed again. */ @@ -228,43 +209,7 @@ // ------------------------------------------------------------ - searchSelectedPatternListener = new PropertyChangeListener(){ - - @Override - public void propertyChange(PropertyChangeEvent evt){ - if (evt == null) - return; - if (SearchHistory.ADD_TO_HISTORY.equals(evt.getPropertyName())){ - EditorFindSupport.getInstance().setHistory( - SearchHistoryUtility.convertFromSearchHistoryToEditorFindSupport(SearchHistory.getDefault().getSearchPatterns())); - } - } - }; - editorHistoryChangeListener = new PropertyChangeListener() { - - @Override - public void propertyChange(PropertyChangeEvent evt) { - if (evt == null) { - return; - } - if (EditorFindSupport.FIND_HISTORY_PROP.equals(evt.getPropertyName())) { - EditorFindSupport.SPW spw = (EditorFindSupport.SPW) evt.getNewValue(); - if (spw == null || spw.getSearchExpression() == null || "".equals(spw.getSearchExpression())) { //NOI18N - return; - } - SearchPattern sp = SearchPattern.create(spw.getSearchExpression(), - spw.isWholeWords(), spw.isMatchCase(), spw.isRegExp()); - SearchHistory.getDefault().add(sp); - } else if (EditorFindSupport.FIND_HISTORY_CHANGED_PROP.equals(evt.getPropertyName())) { - EditorFindSupport.getInstance().setHistory( - SearchHistoryUtility.convertFromSearchHistoryToEditorFindSupport(SearchHistory.getDefault().getSearchPatterns())); - } - } - }; - - SearchHistory.getDefault().addPropertyChangeListener(searchSelectedPatternListener); - EditorFindSupport.getInstance().addPropertyChangeListener(editorHistoryChangeListener); if (topComponentRegistryListener == null) { topComponentRegistryListener = new PropertyChangeListener() { @Override