summaryrefslogtreecommitdiff
path: root/platform/lang-api/src/com/intellij/find/FindModel.java
diff options
context:
space:
mode:
Diffstat (limited to 'platform/lang-api/src/com/intellij/find/FindModel.java')
-rw-r--r--platform/lang-api/src/com/intellij/find/FindModel.java107
1 files changed, 79 insertions, 28 deletions
diff --git a/platform/lang-api/src/com/intellij/find/FindModel.java b/platform/lang-api/src/com/intellij/find/FindModel.java
index a09070c1ed24..5dafc2db8acf 100644
--- a/platform/lang-api/src/com/intellij/find/FindModel.java
+++ b/platform/lang-api/src/com/intellij/find/FindModel.java
@@ -19,6 +19,7 @@ import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.util.UserDataHolderBase;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.psi.search.SearchScope;
+import com.intellij.util.PatternUtil;
import com.intellij.util.containers.ContainerUtil;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
@@ -72,8 +73,7 @@ public class FindModel extends UserDataHolderBase implements Cloneable {
private boolean isSearchHighlighters = false;
private boolean isReplaceState = false;
private boolean isWholeWordsOnly = false;
- private boolean isInCommentsOnly;
- private boolean isInStringLiteralsOnly;
+ private SearchContext searchContext = SearchContext.ANY;
private boolean isFromCursor = true;
private boolean isForward = true;
private boolean isGlobal = true;
@@ -96,6 +96,7 @@ public class FindModel extends UserDataHolderBase implements Cloneable {
private SearchScope customScope;
private boolean isCustomScope = false;
private boolean isMultiline = false;
+ private boolean mySearchInProjectFiles;
public boolean isMultiline() {
return isMultiline;
@@ -170,8 +171,7 @@ public class FindModel extends UserDataHolderBase implements Cloneable {
isCustomScope = model.isCustomScope;
isFindAll = model.isFindAll;
- isInCommentsOnly = model.isInCommentsOnly;
- isInStringLiteralsOnly = model.isInStringLiteralsOnly;
+ searchContext = model.searchContext;
isMultiline = model.isMultiline;
}
@@ -190,8 +190,8 @@ public class FindModel extends UserDataHolderBase implements Cloneable {
if (isForward != findModel.isForward) return false;
if (isFromCursor != findModel.isFromCursor) return false;
if (isGlobal != findModel.isGlobal) return false;
- if (isInCommentsOnly != findModel.isInCommentsOnly) return false;
- if (isInStringLiteralsOnly != findModel.isInStringLiteralsOnly) return false;
+ if (searchContext != findModel.searchContext) return false;
+
if (isMultiline != findModel.isMultiline) return false;
if (isMultipleFiles != findModel.isMultipleFiles) return false;
if (isOpenInNewTabEnabled != findModel.isOpenInNewTabEnabled) return false;
@@ -215,6 +215,7 @@ public class FindModel extends UserDataHolderBase implements Cloneable {
if (myStringToReplace != null ? !myStringToReplace.equals(findModel.myStringToReplace) : findModel.myStringToReplace != null) {
return false;
}
+ if (mySearchInProjectFiles != findModel.mySearchInProjectFiles) return false;
return true;
}
@@ -227,8 +228,7 @@ public class FindModel extends UserDataHolderBase implements Cloneable {
result = 31 * result + (isSearchHighlighters ? 1 : 0);
result = 31 * result + (isReplaceState ? 1 : 0);
result = 31 * result + (isWholeWordsOnly ? 1 : 0);
- result = 31 * result + (isInCommentsOnly ? 1 : 0);
- result = 31 * result + (isInStringLiteralsOnly ? 1 : 0);
+ result = 31 * result + (searchContext.ordinal());
result = 31 * result + (isFromCursor ? 1 : 0);
result = 31 * result + (isForward ? 1 : 0);
result = 31 * result + (isGlobal ? 1 : 0);
@@ -252,6 +252,7 @@ public class FindModel extends UserDataHolderBase implements Cloneable {
result = 31 * result + (isCustomScope ? 1 : 0);
result = 31 * result + (isMultiline ? 1 : 0);
result = 31 * result + (isPreserveCase ? 1 : 0);
+ result = 31 * result + (mySearchInProjectFiles ? 1 : 0);
result = 31 * result + (myPattern != null ? myPattern.hashCode() : 0);
return result;
}
@@ -274,7 +275,7 @@ public class FindModel extends UserDataHolderBase implements Cloneable {
public void setStringToFind(@NotNull String s) {
boolean changed = !StringUtil.equals(s, myStringToFind);
myStringToFind = s;
- myPattern = NO_PATTERN;
+ myPattern = PatternUtil.NOTHING;
if (changed) {
notifyObservers();
}
@@ -409,7 +410,7 @@ public class FindModel extends UserDataHolderBase implements Cloneable {
boolean changed = val != isCaseSensitive;
isCaseSensitive = val;
if (changed) {
- myPattern = NO_PATTERN;
+ myPattern = PatternUtil.NOTHING;
notifyObservers();
}
}
@@ -658,8 +659,8 @@ public class FindModel extends UserDataHolderBase implements Cloneable {
}
@Override
- public Object clone() {
- return super.clone();
+ public FindModel clone() {
+ return (FindModel)super.clone();
}
@@ -670,8 +671,7 @@ public class FindModel extends UserDataHolderBase implements Cloneable {
buffer.append("myStringToReplace =").append(myStringToReplace).append("\n");
buffer.append("isReplaceState =").append(isReplaceState).append("\n");
buffer.append("isWholeWordsOnly =").append(isWholeWordsOnly).append("\n");
- buffer.append("isInStringLiterals =").append(isInStringLiteralsOnly).append("\n");
- buffer.append("isInComments =").append(isInCommentsOnly).append("\n");
+ buffer.append("searchContext =").append(searchContext).append("\n");
buffer.append("isFromCursor =").append(isFromCursor).append("\n");
buffer.append("isForward =").append(isForward).append("\n");
buffer.append("isGlobal =").append(isGlobal).append("\n");
@@ -689,6 +689,7 @@ public class FindModel extends UserDataHolderBase implements Cloneable {
buffer.append("fileFilter =").append(fileFilter).append("\n");
buffer.append("moduleName =").append(moduleName).append("\n");
buffer.append("customScopeName =").append(customScopeName).append("\n");
+ buffer.append("searchInProjectFiles =").append(mySearchInProjectFiles).append("\n");
return buffer.toString();
}
@@ -849,45 +850,95 @@ public class FindModel extends UserDataHolderBase implements Cloneable {
}
}
+ public enum SearchContext {
+ ANY, IN_STRING_LITERALS, IN_COMMENTS, EXCEPT_STRING_LITERALS, EXCEPT_COMMENTS, EXCEPT_COMMENTS_AND_STRING_LITERALS
+ }
+
public boolean isInStringLiteralsOnly() {
- return isInStringLiteralsOnly;
+ return searchContext == SearchContext.IN_STRING_LITERALS;
+ }
+
+ public boolean isExceptComments() {
+ return searchContext == SearchContext.EXCEPT_COMMENTS;
+ }
+
+ public boolean isExceptStringLiterals() {
+ return searchContext == SearchContext.EXCEPT_STRING_LITERALS;
+ }
+
+ public boolean isInCommentsOnly() {
+ return searchContext == SearchContext.IN_COMMENTS;
+ }
+
+ public boolean isExceptCommentsAndStringLiterals() {
+ return searchContext == SearchContext.EXCEPT_COMMENTS_AND_STRING_LITERALS;
+ }
+
+ @Deprecated
+ public void setInCommentsOnly(boolean inCommentsOnly) {
+ doApplyContextChange(inCommentsOnly, SearchContext.IN_COMMENTS);
}
+ @Deprecated
public void setInStringLiteralsOnly(boolean inStringLiteralsOnly) {
- boolean changed = isInStringLiteralsOnly != inStringLiteralsOnly;
- isInStringLiteralsOnly = inStringLiteralsOnly;
+ doApplyContextChange(inStringLiteralsOnly, SearchContext.IN_STRING_LITERALS);
+ }
+
+ private void doApplyContextChange(boolean newOptionValue, SearchContext option) {
+ boolean changed = false;
+ if (newOptionValue) {
+ changed = searchContext != option;
+ searchContext = option;
+ } else if (searchContext == option) { // do not reset unrelated value
+ changed = true;
+ searchContext = SearchContext.ANY;
+ }
+
if (changed) {
notifyObservers();
}
}
- public boolean isInCommentsOnly() {
- return isInCommentsOnly;
+ public @NotNull SearchContext getSearchContext() {
+ return searchContext;
}
- public void setInCommentsOnly(boolean inCommentsOnly) {
- boolean changed = isInCommentsOnly != inCommentsOnly;
- isInCommentsOnly = inCommentsOnly;
+ public void setSearchContext(@NotNull SearchContext _searchContext) {
+ doSetContext(_searchContext);
+ }
+
+ private void doSetContext(SearchContext newSearchContext) {
+ boolean changed = newSearchContext != searchContext;
+ searchContext = newSearchContext;
+ if (changed) {
+ notifyObservers();
+ }
+ }
+
+ public boolean isSearchInProjectFiles() {
+ return mySearchInProjectFiles;
+ }
+
+ public void setSearchInProjectFiles(boolean searchInProjectFiles) {
+ boolean changed = mySearchInProjectFiles != searchInProjectFiles;
+ mySearchInProjectFiles = searchInProjectFiles;
if (changed) {
notifyObservers();
}
}
- private static final Pattern NO_PATTERN = Pattern.compile("");
- private Pattern myPattern = NO_PATTERN;
+ private Pattern myPattern = PatternUtil.NOTHING;
public Pattern compileRegExp() {
String toFind = getStringToFind();
Pattern pattern = myPattern;
- if (pattern == NO_PATTERN) {
+ if (pattern == PatternUtil.NOTHING) {
try {
myPattern = pattern = Pattern.compile(toFind, isCaseSensitive() ? Pattern.MULTILINE : Pattern.MULTILINE | Pattern.CASE_INSENSITIVE);
}
catch (PatternSyntaxException e) {
- LOG.error("Regexp:'" + toFind + "'", e);
- myPattern = null;
- return null;
+ myPattern = pattern = null;
}
}