preselect initial text in "Run Rails generator" action

This commit is contained in:
Dmitry Jemerov
2010-06-24 16:44:31 +04:00
committed by Dennis Ushakov
parent abe169eb27
commit a3d62623aa
2 changed files with 15 additions and 0 deletions
@@ -78,6 +78,7 @@ public abstract class ChooseByNameBase{
protected final Project myProject;
protected final ChooseByNameModel myModel;
protected final String myInitialText;
private boolean myPreselectInitialText;
private final Reference<PsiElement> myContext;
protected Component myPreviouslyFocusedComponent;
@@ -147,6 +148,14 @@ public abstract class ChooseByNameBase{
myContext = new WeakReference<PsiElement>(context);
}
public boolean isPreselectInitialText() {
return myPreselectInitialText;
}
public void setPreselectInitialText(boolean preselectInitialText) {
myPreselectInitialText = preselectInitialText;
}
/**
* Set tool area. The method may be called only before invoke.
* @param toolArea a tool area component
@@ -321,6 +330,9 @@ public abstract class ChooseByNameBase{
myFuture = new ArrayList<Pair<String, Integer>>();
myTextField = new MyTextField();
myTextField.setText(myInitialText);
if (myPreselectInitialText) {
myTextField.select(0, myInitialText.length());
}
final ActionMap actionMap = new ActionMap();
actionMap.setParent(myTextField.getActionMap());
@@ -40,6 +40,9 @@ public class ChooseByNamePopup extends ChooseByNameBase implements ChooseByNameP
private ChooseByNamePopup(final Project project, final ChooseByNameModel model, final ChooseByNamePopup oldPopup,
final PsiElement context, @Nullable final String predefinedText) {
super(project, model, oldPopup != null ? oldPopup.getEnteredText() : predefinedText, context);
if (oldPopup == null && predefinedText != null) {
setPreselectInitialText(true);
}
if (oldPopup != null) { //inherit old focus owner
myOldFocusOwner = oldPopup.myPreviouslyFocusedComponent;
}