Skip to content

Commit ecc3f7a

Browse files
committed
Merge branch 'master' of git.labs.intellij.net:idea/community
2 parents d0214ed + 6963550 commit ecc3f7a

File tree

34 files changed

+1116
-197
lines changed

34 files changed

+1116
-197
lines changed

build/conf/mac/Contents/MacOS/idea

100644100755
-13.2 KB
Binary file not shown.

platform/lang-impl/src/com/intellij/find/impl/FindDialog.java

Lines changed: 147 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
import com.intellij.util.ArrayUtil;
5858
import com.intellij.util.Consumer;
5959
import org.jetbrains.annotations.NonNls;
60+
import org.jetbrains.annotations.Nullable;
6061

6162
import javax.swing.*;
6263
import javax.swing.text.BadLocationException;
@@ -106,10 +107,14 @@ class FindDialog extends DialogWrapper {
106107
private JRadioButton myRbCustomScope;
107108
private ScopeChooserCombo myScopeCombo;
108109

110+
private LivePreviewController myLivePreviewController;
111+
112+
109113
public FindDialog(Project project, FindModel model, Runnable myOkHandler){
110114
super(project, true);
111115
myProject = project;
112116
myModel = model;
117+
113118
this.myOkHandler = myOkHandler;
114119

115120
if (myModel.isReplaceState()){
@@ -133,6 +138,7 @@ public FindDialog(Project project, FindModel model, Runnable myOkHandler){
133138
setOKButtonIcon(IconLoader.getIcon("/actions/find.png"));
134139
init();
135140
initByModel();
141+
myLivePreviewController = new LivePreviewController(this, new LivePreview(myProject), getContentPane());
136142
}
137143

138144
@Override
@@ -141,6 +147,9 @@ protected void dispose() {
141147
e.getKey().removeDocumentListener(e.getValue());
142148
}
143149
myComboBoxListeners.clear();
150+
if (myLivePreviewController != null) {
151+
myLivePreviewController.cleanUp();
152+
}
144153
super.dispose();
145154
}
146155

@@ -274,6 +283,22 @@ private void handleComboBoxValueChanged(final ComboBox comboBox) {
274283
validateFindButton();
275284
}
276285

286+
public FindModel getModel() {
287+
return myModel;
288+
}
289+
290+
@Nullable
291+
public FindModel getCurrentModel() {
292+
FindModel validateModel = (FindModel)myModel.clone();
293+
applyTo(validateModel, false);
294+
295+
296+
if (getValidationInfo(validateModel) == null) {
297+
return validateModel;
298+
}
299+
return null;
300+
}
301+
277302
private static int getCaretPosition(JComboBox comboBox) {
278303
Component editorComponent = comboBox.getEditor().getEditorComponent();
279304
if (editorComponent instanceof JTextField){
@@ -293,7 +318,6 @@ private static void setCaretPosition(JComboBox comboBox, int position) {
293318

294319
private void validateFindButton() {
295320
final String toFind = getStringToFind();
296-
297321
if (toFind == null || toFind.length() == 0){
298322
setOKStatus(false);
299323
return;
@@ -416,76 +440,130 @@ public void doOKAction() {
416440

417441
private void doOKAction(boolean findAll) {
418442
FindModel validateModel = (FindModel)myModel.clone();
419-
applyTo(validateModel);
420-
validateModel.setFindAll(findAll);
421-
if (validateModel.getDirectoryName() != null) {
422-
PsiDirectory directory = FindInProjectUtil.getPsiDirectory(validateModel, myProject);
423-
if (directory == null) {
443+
applyTo(validateModel, findAll);
444+
445+
ValidationInfo validationInfo = getValidationInfo(validateModel);
446+
447+
if (validationInfo == null) {
448+
449+
myModel.copyFrom(validateModel);
450+
updateFindSettings();
451+
452+
super.doOKAction();
453+
myOkHandler.run();
454+
} else {
455+
String message = validationInfo.message;
456+
if (message != null) {
424457
Messages.showMessageDialog(
425458
myProject,
426-
FindBundle.message("find.directory.not.found.error", validateModel.getDirectoryName()),
459+
message,
427460
CommonBundle.getErrorTitle(),
428461
Messages.getErrorIcon()
429462
);
430-
return;
463+
}
464+
}
465+
}
466+
467+
private void updateFindSettings() {
468+
FindSettings findSettings = FindSettings.getInstance();
469+
findSettings.setCaseSensitive(myModel.isCaseSensitive());
470+
if (myModel.isReplaceState()) {
471+
findSettings.setPreserveCase(myModel.isPreserveCase());
472+
}
473+
474+
findSettings.setWholeWordsOnly(myModel.isWholeWordsOnly());
475+
findSettings.setInStringLiteralsOnly(myModel.isInStringLiteralsOnly());
476+
findSettings.setInCommentsOnly(myModel.isInCommentsOnly());
477+
478+
findSettings.setRegularExpressions(myModel.isRegularExpressions());
479+
if (!myModel.isMultipleFiles()){
480+
findSettings.setForward(myModel.isForward());
481+
findSettings.setFromCursor(myModel.isFromCursor());
482+
483+
findSettings.setGlobal(myModel.isGlobal());
484+
} else{
485+
String directoryName = myModel.getDirectoryName();
486+
if (directoryName != null && !directoryName.isEmpty()) {
487+
findSettings.setWithSubdirectories(myModel.isWithSubdirectories());
488+
}
489+
else if (myRbModule.isSelected()) {
490+
}
491+
else if (myRbCustomScope.isSelected()) {
492+
SearchScope selectedScope = myScopeCombo.getSelectedScope();
493+
String customScopeName = selectedScope == null ? null : selectedScope.getDisplayName();
494+
findSettings.setCustomScope(customScopeName);
495+
}
496+
}
497+
498+
if (myCbToSkipResultsWhenOneUsage != null){
499+
findSettings.setSkipResultsWithOneUsage(
500+
isSkipResultsWhenOneUsage()
501+
);
502+
}
503+
504+
findSettings.setFileMask(myModel.getFileFilter());
505+
}
506+
507+
@Override
508+
protected boolean postponeValidation() {
509+
return true;
510+
}
511+
512+
private ValidationInfo getValidationInfo(FindModel model) {
513+
if (myRbDirectory != null && myRbDirectory.isEnabled() && myRbDirectory.isSelected()) {
514+
PsiDirectory directory = FindInProjectUtil.getPsiDirectory(model, myProject);
515+
if (directory == null) {
516+
return new ValidationInfo(FindBundle.message("find.directory.not.found.error", getDirectory()), myDirectoryComboBox);
431517
}
432518
}
433519

434-
if (validateModel.isRegularExpressions()) {
435-
String toFind = validateModel.getStringToFind();
520+
String toFind = (String)myInputComboBox.getSelectedItem();
521+
if (toFind != null && toFind.isEmpty()) {
522+
return new ValidationInfo("String to find is empty", myInputComboBox);
523+
}
524+
525+
if (myCbRegularExpressions != null && myCbRegularExpressions.isEnabled()) {
436526
try {
437-
Pattern pattern = Pattern.compile(toFind, validateModel.isCaseSensitive() ? Pattern.MULTILINE : Pattern.MULTILINE | Pattern.CASE_INSENSITIVE);
527+
boolean isCaseSensitive = myCbCaseSensitive != null && myCbCaseSensitive.isEnabled();
528+
Pattern pattern =
529+
Pattern.compile(toFind, isCaseSensitive ? Pattern.MULTILINE : Pattern.MULTILINE | Pattern.CASE_INSENSITIVE);
438530
if (pattern.matcher("").matches() && !toFind.endsWith("$") && !toFind.startsWith("^")) {
439-
throw new PatternSyntaxException(FindBundle.message("find.empty.match.regular.expression.error"),toFind, -1);
531+
return new ValidationInfo(FindBundle.message("find.empty.match.regular.expression.error"), myInputComboBox);
440532
}
441533
}
442-
catch(PatternSyntaxException e){
443-
Messages.showMessageDialog(
444-
myProject,
445-
FindBundle.message("find.invalid.regular.expression.error", toFind, e.getDescription()),
446-
CommonBundle.getErrorTitle(),
447-
Messages.getErrorIcon()
448-
);
449-
return;
534+
catch (PatternSyntaxException e) {
535+
return new ValidationInfo(FindBundle.message("find.invalid.regular.expression.error", toFind, e.getDescription()), myInputComboBox);
450536
}
451537
}
452538

453-
validateModel.setFileFilter( null );
454-
FindSettings.getInstance().setFileMask(null);
455-
456-
if (useFileFilter!=null && useFileFilter.isSelected() &&
457-
myFileFilter.getSelectedItem()!=null
458-
) {
459-
final String mask = (String)myFileFilter.getSelectedItem();
539+
final String mask = myFileFilter == null ? null : (String)myFileFilter.getSelectedItem();
460540

461-
if (mask.length() > 0) {
541+
if (mask != null) {
542+
if (mask.length() == 0) {
543+
return new ValidationInfo(FindBundle.message("find.filter.empty.file.mask.error"), myFileFilter);
544+
}
545+
else {
462546
try {
463547
FindInProjectUtil.createFileMaskRegExp(mask); // verify that the regexp compiles
464-
validateModel.setFileFilter(mask);
465-
FindSettings.getInstance().setFileMask(mask);
466548
}
467549
catch (PatternSyntaxException ex) {
468-
Messages.showMessageDialog(myProject, FindBundle.message("find.filter.invalid.file.mask.error", myFileFilter.getSelectedItem()),
469-
CommonBundle.getErrorTitle(), Messages.getErrorIcon());
470-
return;
550+
return new ValidationInfo(FindBundle.message("find.filter.invalid.file.mask.error", mask), myFileFilter);
471551
}
472552
}
473-
else {
474-
Messages.showMessageDialog(myProject, FindBundle.message("find.filter.empty.file.mask.error"), CommonBundle.getErrorTitle(),
475-
Messages.getErrorIcon());
476-
return;
477-
}
478553
}
554+
return null;
555+
}
479556

480-
if (myCbToSkipResultsWhenOneUsage != null){
481-
FindSettings.getInstance().setSkipResultsWithOneUsage(
482-
isSkipResultsWhenOneUsage()
483-
);
484-
}
557+
@Override
558+
protected ValidationInfo doValidate() {
559+
FindModel validateModel = (FindModel)myModel.clone();
560+
applyTo(validateModel, false);
561+
562+
ValidationInfo result = getValidationInfo(validateModel);
563+
564+
setOKStatus(result == null);
485565

486-
myModel.copyFrom(validateModel);
487-
super.doOKAction();
488-
myOkHandler.run();
566+
return result;
489567
}
490568

491569
public void doHelpAction() {
@@ -768,7 +846,7 @@ public void actionPerformed(ActionEvent e) {
768846
public void consume(final VirtualFile[] files) {
769847
if (files.length != 0) {
770848
myDirectoryComboBox.setSelectedItem(files[0].getPresentableUrl());
771-
validateFindButton();
849+
//validateFindButton();
772850
}
773851
}
774852
});
@@ -845,10 +923,12 @@ private JPanel createOriginPanel() {
845923
}
846924

847925
private String getStringToFind() {
848-
return (String)myInputComboBox.getEditor().getItem();
926+
String string = (String)myInputComboBox.getEditor().getItem();
927+
return string == null ? "" : string;
849928
}
850929
private String getStringToReplace() {
851-
return (String)myReplaceComboBox.getEditor().getItem();
930+
String item = (String)myReplaceComboBox.getEditor().getItem();
931+
return item == null ? "" : item;
852932
}
853933

854934
private String getDirectory() {
@@ -886,27 +966,26 @@ private void setDirectories(ArrayList strings, String directoryName) {
886966
}
887967
}
888968

889-
private void applyTo(FindModel model) {
890-
FindSettings findSettings = FindSettings.getInstance();
969+
970+
971+
private void applyTo(FindModel model, boolean findAll) {
972+
891973
model.setCaseSensitive(myCbCaseSensitive.isSelected());
892-
findSettings.setCaseSensitive(myCbCaseSensitive.isSelected());
893974

894975
if (model.isReplaceState()) {
895976
model.setPreserveCase(myCbPreserveCase.isSelected());
896-
findSettings.setPreserveCase(myCbPreserveCase.isSelected());
897977
}
898978

899979
model.setWholeWordsOnly(myCbWholeWordsOnly.isSelected());
900-
findSettings.setWholeWordsOnly(myCbWholeWordsOnly.isSelected());
901980
model.setInStringLiteralsOnly(myCbInStringLiteralsOnly.isSelected());
902-
findSettings.setInStringLiteralsOnly(myCbInStringLiteralsOnly.isSelected());
903981

904982
model.setInCommentsOnly(myCbInCommentsOnly.isSelected());
905-
findSettings.setInCommentsOnly(myCbInCommentsOnly.isSelected());
906983

907984
model.setRegularExpressions(myCbRegularExpressions.isSelected());
908-
findSettings.setRegularExpressions(myCbRegularExpressions.isSelected());
909-
model.setStringToFind(getStringToFind());
985+
String stringToFind = getStringToFind();
986+
if (stringToFind.length() > 0) {
987+
model.setStringToFind(stringToFind);
988+
}
910989

911990
if (model.isReplaceState()){
912991
model.setPromptOnReplace(true);
@@ -920,11 +999,8 @@ private void applyTo(FindModel model) {
920999

9211000
if (!model.isMultipleFiles()){
9221001
model.setForward(myRbForward.isSelected());
923-
findSettings.setForward(myRbForward.isSelected());
9241002
model.setFromCursor(myRbFromCursor.isSelected());
925-
findSettings.setFromCursor(myRbFromCursor.isSelected());
9261003
model.setGlobal(myRbGlobal.isSelected());
927-
findSettings.setGlobal(myRbGlobal.isSelected());
9281004
}
9291005
else{
9301006
if (myCbToOpenInNewTab != null){
@@ -942,7 +1018,6 @@ private void applyTo(FindModel model) {
9421018
String directory = getDirectory();
9431019
model.setDirectoryName(directory == null ? "" : directory);
9441020
model.setWithSubdirectories(myCbWithSubdirectories.isSelected());
945-
findSettings.setWithSubdirectories(myCbWithSubdirectories.isSelected());
9461021
}
9471022
else if (myRbModule.isSelected()) {
9481023
model.setModuleName((String)myModuleComboBox.getSelectedItem());
@@ -953,9 +1028,17 @@ else if (myRbCustomScope.isSelected()) {
9531028
model.setCustomScopeName(customScopeName);
9541029
model.setCustomScope(selectedScope == null ? null : selectedScope);
9551030
model.setCustomScope(true);
956-
findSettings.setCustomScope(customScopeName);
9571031
}
9581032
}
1033+
1034+
model.setFindAll(findAll);
1035+
1036+
String mask = null;
1037+
if (useFileFilter!=null && useFileFilter.isSelected()) {
1038+
mask = (String)myFileFilter.getSelectedItem();
1039+
}
1040+
model.setFileFilter(mask);
1041+
9591042
}
9601043

9611044

@@ -1061,7 +1144,7 @@ else if (myModel.getModuleName() != null) {
10611144
setStringsToComboBox(FindSettings.getInstance().getRecentReplaceStrings(), myReplaceComboBox, myModel.getStringToReplace());
10621145
}
10631146
updateControls();
1064-
validateFindButton();
1147+
10651148
}
10661149
}
10671150

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package com.intellij.find.impl;
2+
3+
import com.intellij.openapi.util.TextRange;
4+
5+
import java.util.ArrayList;
6+
import java.util.Collection;
7+
8+
public class LiveOccurrence {
9+
private TextRange myPrimaryRange;
10+
private Collection<TextRange> mySecondaryRanges = new ArrayList<TextRange>();
11+
12+
public TextRange getPrimaryRange() {
13+
return myPrimaryRange;
14+
}
15+
16+
public Collection<TextRange> getSecondaryRanges() {
17+
return mySecondaryRanges;
18+
}
19+
20+
public void setPrimaryRange(TextRange primaryRange) {
21+
this.myPrimaryRange = primaryRange;
22+
}
23+
24+
public void setSecondaryRanges(Collection<TextRange> secondaryRanges) {
25+
this.mySecondaryRanges = secondaryRanges;
26+
}
27+
}

0 commit comments

Comments
 (0)