mirror of
https://github.com/chylex/IntelliJ-IdeaVim.git
synced 2025-05-25 00:34:09 +02:00
Added confirm dialog use
This commit is contained in:
parent
e4386f52f7
commit
8d3e737320
@ -23,10 +23,11 @@ import com.intellij.openapi.actionSystem.DataContext;
|
|||||||
import com.intellij.openapi.diagnostic.Logger;
|
import com.intellij.openapi.diagnostic.Logger;
|
||||||
import com.intellij.openapi.editor.Editor;
|
import com.intellij.openapi.editor.Editor;
|
||||||
import com.intellij.openapi.util.TextRange;
|
import com.intellij.openapi.util.TextRange;
|
||||||
import com.maddyhome.idea.vim.helper.EditorHelper;
|
|
||||||
import java.nio.CharBuffer;
|
import java.nio.CharBuffer;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
import javax.swing.JOptionPane;
|
||||||
|
import javax.swing.JButton;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@ -100,6 +101,7 @@ public class SearchGroup extends AbstractActionGroup
|
|||||||
int lastMatch = -1;
|
int lastMatch = -1;
|
||||||
boolean found = true;
|
boolean found = true;
|
||||||
int lastLine = -1;
|
int lastLine = -1;
|
||||||
|
boolean checkConfirm = true;
|
||||||
while (found)
|
while (found)
|
||||||
{
|
{
|
||||||
char[] chars = editor.getDocument().getChars();
|
char[] chars = editor.getDocument().getChars();
|
||||||
@ -120,9 +122,42 @@ public class SearchGroup extends AbstractActionGroup
|
|||||||
int line = editor.offsetToLogicalPosition(start + spos).line;
|
int line = editor.offsetToLogicalPosition(start + spos).line;
|
||||||
if ((flags & GLOBAL) != 0 || line != lastLine)
|
if ((flags & GLOBAL) != 0 || line != lastLine)
|
||||||
{
|
{
|
||||||
lastLine = line;
|
boolean doReplace = true;
|
||||||
editor.getDocument().replaceString(start + spos, start + epos, match);
|
if ((flags & CONFIRM) != 0 && checkConfirm)
|
||||||
lastMatch = start + spos;
|
{
|
||||||
|
editor.getSelectionModel().setSelection(start + spos, start + epos);
|
||||||
|
int choice = JOptionPane.showOptionDialog(null, "Replace with " + match + " ?", "Confirm Replace",
|
||||||
|
JOptionPane.DEFAULT_OPTION, JOptionPane.QUESTION_MESSAGE, null, getConfirmButtons(), null);
|
||||||
|
editor.getSelectionModel().removeSelection();
|
||||||
|
switch (choice)
|
||||||
|
{
|
||||||
|
case 0: // Yes
|
||||||
|
doReplace = true;
|
||||||
|
break;
|
||||||
|
case 1: // No
|
||||||
|
doReplace = false;
|
||||||
|
break;
|
||||||
|
case 2: // All
|
||||||
|
checkConfirm = false;
|
||||||
|
break;
|
||||||
|
case JOptionPane.CLOSED_OPTION:
|
||||||
|
case 3: // Quit
|
||||||
|
found = false;
|
||||||
|
doReplace = false;
|
||||||
|
break;
|
||||||
|
case 4: // Last
|
||||||
|
found = false;
|
||||||
|
doReplace = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (doReplace)
|
||||||
|
{
|
||||||
|
lastLine = line;
|
||||||
|
editor.getDocument().replaceString(start + spos, start + epos, match);
|
||||||
|
lastMatch = start + spos;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int diff = match.length() - (epos - spos);
|
int diff = match.length() - (epos - spos);
|
||||||
@ -178,10 +213,37 @@ public class SearchGroup extends AbstractActionGroup
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Object[] getConfirmButtons()
|
||||||
|
{
|
||||||
|
if (confirmBtns == null)
|
||||||
|
{
|
||||||
|
// TODO - need buttons with mnemonics
|
||||||
|
/*
|
||||||
|
confirmBtns = new JButton[] {
|
||||||
|
new JButton("Yes"),
|
||||||
|
new JButton("No"),
|
||||||
|
new JButton("All"),
|
||||||
|
new JButton("Quit"),
|
||||||
|
new JButton("Last")
|
||||||
|
};
|
||||||
|
|
||||||
|
confirmBtns[0].setMnemonic('Y');
|
||||||
|
confirmBtns[1].setMnemonic('N');
|
||||||
|
confirmBtns[2].setMnemonic('A');
|
||||||
|
confirmBtns[3].setMnemonic('Q');
|
||||||
|
confirmBtns[4].setMnemonic('L');
|
||||||
|
*/
|
||||||
|
confirmBtns = new String[] { "Yes", "No", "All", "Quit", "Last" };
|
||||||
|
}
|
||||||
|
|
||||||
|
return confirmBtns;
|
||||||
|
}
|
||||||
|
|
||||||
private Pattern lastSearch;
|
private Pattern lastSearch;
|
||||||
private Pattern lastPattern;
|
private Pattern lastPattern;
|
||||||
private String lastReplace;
|
private String lastReplace;
|
||||||
private int lastFlags;
|
private int lastFlags;
|
||||||
|
private Object[] confirmBtns;
|
||||||
|
|
||||||
private static Logger logger = Logger.getInstance(SearchGroup.class.getName());
|
private static Logger logger = Logger.getInstance(SearchGroup.class.getName());
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user