use of com.intellij.openapi.wm.IdeFocusManager in project intellij-community by JetBrains.
the class EmmetAbbreviationBalloon method show.
public void show(@NotNull final CustomTemplateCallback customTemplateCallback) {
if (ApplicationManager.getApplication().isUnitTestMode()) {
if (ourTestingAbbreviation == null) {
throw new RuntimeException("Testing abbreviation is not set. See EmmetAbbreviationBalloon#setTestingAbbreviation");
}
myCallback.onEnter(ourTestingAbbreviation);
return;
}
final TextFieldWithStoredHistory field = new TextFieldWithStoredHistory(myAbbreviationsHistoryKey);
final Dimension fieldPreferredSize = field.getPreferredSize();
field.setPreferredSize(new Dimension(Math.max(220, fieldPreferredSize.width), fieldPreferredSize.height));
field.setHistorySize(10);
final JBPopupFactory popupFactory = JBPopupFactory.getInstance();
final BalloonImpl balloon = (BalloonImpl) popupFactory.createDialogBalloonBuilder(field, myTitle).setCloseButtonEnabled(false).setBlockClicksThroughBalloon(true).setAnimationCycle(0).setHideOnKeyOutside(true).setHideOnClickOutside(true).createBalloon();
final DocumentAdapter documentListener = new DocumentAdapter() {
@Override
protected void textChanged(DocumentEvent e) {
if (!isValid(customTemplateCallback)) {
balloon.hide();
return;
}
validateTemplateKey(field, balloon, field.getText(), customTemplateCallback);
}
};
field.addDocumentListener(documentListener);
final KeyAdapter keyListener = new KeyAdapter() {
@Override
public void keyPressed(@NotNull KeyEvent e) {
if (!field.isPopupVisible()) {
if (!isValid(customTemplateCallback)) {
balloon.hide();
return;
}
switch(e.getKeyCode()) {
case KeyEvent.VK_ENTER:
final String abbreviation = field.getText();
if (validateTemplateKey(field, balloon, abbreviation, customTemplateCallback)) {
myCallback.onEnter(abbreviation);
PropertiesComponent.getInstance().setValue(myLastAbbreviationKey, abbreviation);
field.addCurrentTextToHistory();
balloon.hide();
}
break;
case KeyEvent.VK_ESCAPE:
balloon.hide(false);
break;
}
}
}
};
field.addKeyboardListener(keyListener);
balloon.addListener(new JBPopupListener.Adapter() {
@Override
public void beforeShown(LightweightWindowEvent event) {
field.setText(PropertiesComponent.getInstance().getValue(myLastAbbreviationKey, ""));
}
@Override
public void onClosed(LightweightWindowEvent event) {
field.removeKeyListener(keyListener);
field.removeDocumentListener(documentListener);
super.onClosed(event);
}
});
balloon.show(popupFactory.guessBestPopupLocation(customTemplateCallback.getEditor()), Balloon.Position.below);
final IdeFocusManager focusManager = IdeFocusManager.getInstance(customTemplateCallback.getProject());
focusManager.doWhenFocusSettlesDown(() -> {
focusManager.requestFocus(field, true);
field.selectText();
});
}
use of com.intellij.openapi.wm.IdeFocusManager in project intellij-community by JetBrains.
the class AbstractWizard method requestFocusTo.
private static void requestFocusTo(final JComponent component) {
UiNotifyConnector.doWhenFirstShown(component, () -> {
final IdeFocusManager focusManager = IdeFocusManager.findInstanceByComponent(component);
focusManager.requestFocus(component, false);
});
}
use of com.intellij.openapi.wm.IdeFocusManager in project intellij-community by JetBrains.
the class EditableSchemesCombo method cancelEdit.
public void cancelEdit() {
mySchemesPanel.clearInfo();
myLayout.first(myRootPanel);
final IdeFocusManager focusManager = IdeFocusManager.getGlobalInstance();
focusManager.doWhenFocusSettlesDown(() -> IdeFocusManager.getGlobalInstance().requestFocus(myRootPanel, true));
}
use of com.intellij.openapi.wm.IdeFocusManager in project intellij-community by JetBrains.
the class EditableSchemesCombo method startEdit.
public void startEdit() {
T scheme = getSelectedScheme();
if (scheme != null) {
showHint();
myNameEditorField.setText(scheme.getName());
myLayout.last(myRootPanel);
final IdeFocusManager focusManager = IdeFocusManager.getGlobalInstance();
focusManager.doWhenFocusSettlesDown(() -> focusManager.requestFocus(myNameEditorField, true));
}
}
use of com.intellij.openapi.wm.IdeFocusManager in project intellij-community by JetBrains.
the class WrapReturnValueDialog method toggleRadioEnablement.
private void toggleRadioEnablement() {
UIUtil.setEnabled(myExistingClassPanel, useExistingClassButton.isSelected(), true);
UIUtil.setEnabled(myNewClassPanel, createNewClassButton.isSelected(), true);
UIUtil.setEnabled(myCreateInnerPanel, myCreateInnerClassButton.isSelected(), true);
final IdeFocusManager focusManager = IdeFocusManager.getInstance(myProject);
if (useExistingClassButton.isSelected()) {
focusManager.requestFocus(existingClassField, true);
} else if (myCreateInnerClassButton.isSelected()) {
focusManager.requestFocus(myInnerClassNameTextField, true);
} else {
focusManager.requestFocus(classNameField, true);
}
validateButtons();
}
Aggregations