List of usage examples for com.intellij.openapi.actionSystem CommonShortcuts ESCAPE
ShortcutSet ESCAPE
To view the source code for com.intellij.openapi.actionSystem CommonShortcuts ESCAPE.
Click Source Link
From source file:com.intellij.codeInsight.intention.impl.QuickEditHandler.java
License:Apache License
QuickEditHandler(Project project, PsiFile injectedFile, final PsiFile origFile, Editor editor, QuickEditAction action) {// w ww.ja v a 2 s . c o m myProject = project; myEditor = editor; myAction = action; myOrigDocument = editor.getDocument(); final Place shreds = InjectedLanguageUtil.getShreds(injectedFile); final FileType fileType = injectedFile.getFileType(); final Language language = injectedFile.getLanguage(); final PsiFileFactory factory = PsiFileFactory.getInstance(project); final String text = InjectedLanguageManager.getInstance(project).getUnescapedText(injectedFile); final String newFileName = StringUtil.notNullize(language.getDisplayName(), "Injected") + " Fragment " + "(" + origFile.getName() + ":" + shreds.get(0).getHost().getTextRange().getStartOffset() + ")" + "." + fileType.getDefaultExtension(); myNewFile = factory.createFileFromText(newFileName, language, text, true, true); myNewVirtualFile = (LightVirtualFile) myNewFile.getVirtualFile(); assert myNewVirtualFile != null; // suppress possible errors as in injected mode myNewFile.putUserData(InjectedLanguageUtil.FRANKENSTEIN_INJECTION, injectedFile.getUserData(InjectedLanguageUtil.FRANKENSTEIN_INJECTION)); final SmartPointerManager smartPointerManager = SmartPointerManager.getInstance(project); myNewFile.putUserData(FileContextUtil.INJECTED_IN_ELEMENT, smartPointerManager.createSmartPsiElementPointer(origFile)); myNewDocument = PsiDocumentManager.getInstance(project).getDocument(myNewFile); assert myNewDocument != null; EditorActionManager.getInstance().setReadonlyFragmentModificationHandler(myNewDocument, new MyQuietHandler()); myOrigCreationStamp = myOrigDocument.getModificationStamp(); // store creation stamp for UNDO tracking myOrigDocument.addDocumentListener(this, this); myNewDocument.addDocumentListener(this, this); EditorFactory editorFactory = ObjectUtils.assertNotNull(EditorFactory.getInstance()); // not FileEditorManager listener because of RegExp checker and alike editorFactory.addEditorFactoryListener(new EditorFactoryAdapter() { int myEditorCount; @Override public void editorCreated(@NotNull EditorFactoryEvent event) { if (event.getEditor().getDocument() != myNewDocument) return; myEditorCount++; final EditorActionHandler editorEscape = EditorActionManager.getInstance() .getActionHandler(IdeActions.ACTION_EDITOR_ESCAPE); new AnAction() { @Override public void update(AnActionEvent e) { Editor editor = PlatformDataKeys.EDITOR.getData(e.getDataContext()); e.getPresentation().setEnabled(editor != null && LookupManager.getActiveLookup(editor) == null && TemplateManager.getInstance(myProject).getActiveTemplate(editor) == null && (editorEscape == null || !editorEscape.isEnabled(editor, e.getDataContext()))); } @Override public void actionPerformed(AnActionEvent e) { closeEditor(); } }.registerCustomShortcutSet(CommonShortcuts.ESCAPE, event.getEditor().getContentComponent()); } @Override public void editorReleased(@NotNull EditorFactoryEvent event) { if (event.getEditor().getDocument() != myNewDocument) return; if (--myEditorCount > 0) return; Disposer.dispose(QuickEditHandler.this); } }, this); if ("JAVA".equals(shreds.get(0).getHost().getLanguage().getID())) { myAltFullRange = myOrigDocument.createRangeMarker(shreds.get(0).getHostRangeMarker().getStartOffset(), shreds.get(shreds.size() - 1).getHostRangeMarker().getEndOffset()); myAltFullRange.setGreedyToLeft(true); myAltFullRange.setGreedyToRight(true); initGuardedBlocks(shreds); myInjectedFile = null; } else { initMarkers(shreds); myAltFullRange = null; myInjectedFile = injectedFile; } }
From source file:com.intellij.ui.SearchTextField.java
License:Apache License
public SearchTextField(boolean historyEnabled) { super(new BorderLayout()); myModel = new MyModel(); myTextField = new TextFieldWithProcessing() { @Override/* w w w . j a v a2 s . c o m*/ public void processKeyEvent(final KeyEvent e) { if (preprocessEventForTextField(e)) return; super.processKeyEvent(e); } @Override public void setBackground(final Color bg) { super.setBackground(bg); if (!hasIconsOutsideOfTextField()) { if (myClearFieldLabel != null) { myClearFieldLabel.setBackground(bg); } } if (myToggleHistoryLabel != null) { myToggleHistoryLabel.setBackground(bg); } } }; myTextField.setColumns(15); myTextField.addFocusListener(new FocusAdapter() { @Override public void focusLost(FocusEvent e) { onFocusLost(); super.focusLost(e); } @Override public void focusGained(FocusEvent e) { onFocusGained(); super.focusGained(e); } }); add(myTextField, BorderLayout.CENTER); myTextField.addKeyListener(new KeyAdapter() { @Override public void keyPressed(KeyEvent e) { if (e.getKeyCode() == KeyEvent.VK_DOWN) { if (isSearchControlUISupported() && myNativeSearchPopup != null) { myNativeSearchPopup.show(myTextField, 5, myTextField.getHeight()); } else if (myPopup == null || !myPopup.isVisible()) { showPopup(); } } } }); if (isSearchControlUISupported() || UIUtil.isUnderBuildInLaF()) { myTextField.putClientProperty("JTextField.variant", "search"); } if (isSearchControlUISupported()) { if (historyEnabled) { myNativeSearchPopup = new JBPopupMenu(); myNoItems = new JBMenuItem("No recent searches"); myNoItems.setEnabled(false); updateMenu(); myTextField.putClientProperty("JTextField.Search.FindPopup", myNativeSearchPopup); } } else { myToggleHistoryLabel = new JLabel(AllIcons.Actions.Search); myToggleHistoryLabel.setOpaque(true); myToggleHistoryLabel.addMouseListener(new MouseAdapter() { @Override public void mousePressed(MouseEvent e) { togglePopup(); } }); if (historyEnabled) { add(myToggleHistoryLabel, BorderLayout.WEST); } myClearFieldLabel = new JLabel( UIUtil.isUnderDarcula() ? AllIcons.Actions.Clean : AllIcons.Actions.CleanLight); myClearFieldLabel.setOpaque(true); add(myClearFieldLabel, BorderLayout.EAST); myClearFieldLabel.addMouseListener(new MouseAdapter() { @Override public void mousePressed(MouseEvent e) { myTextField.setText(""); onFieldCleared(); } }); if (!hasIconsOutsideOfTextField()) { final Border originalBorder; if (SystemInfo.isMac) { originalBorder = BorderFactory.createLoweredBevelBorder(); } else { originalBorder = myTextField.getBorder(); } myToggleHistoryLabel.setBackground(myTextField.getBackground()); myClearFieldLabel.setBackground(myTextField.getBackground()); setBorder(new CompoundBorder(IdeBorderFactory.createEmptyBorder(2, 0, 2, 0), originalBorder)); myTextField.setOpaque(true); myTextField.setBorder(IdeBorderFactory.createEmptyBorder(0, 5, 0, 5)); } else { setBorder(IdeBorderFactory.createEmptyBorder(2, 0, 2, 0)); } } if (ApplicationManager.getApplication() != null) { //tests final ActionManager actionManager = ActionManager.getInstance(); if (actionManager != null) { final AnAction clearTextAction = actionManager.getAction(IdeActions.ACTION_CLEAR_TEXT); if (clearTextAction.getShortcutSet().getShortcuts().length == 0) { clearTextAction.registerCustomShortcutSet(CommonShortcuts.ESCAPE, this); } } } }
From source file:com.intellij.uiDesigner.designSurface.GuiEditor.java
License:Apache License
/** * @param file file to be edited/*from w w w . jav a 2 s. c om*/ * @throws java.lang.IllegalArgumentException if the <code>file</code> * is <code>null</code> or <code>file</code> is not valid PsiFile */ public GuiEditor(@NotNull UIFormEditor editor, @NotNull Project project, @NotNull Module module, @NotNull VirtualFile file) { myEditor = editor; LOG.assertTrue(file.isValid()); myProject = project; myModule = module; myFile = file; myCutCopyPasteSupport = new CutCopyPasteSupport(this); setLayout(new BorderLayout()); myContentSplitter.setDividerWidth(0); myContentSplitter.setDividerMouseZoneSize(Registry.intValue("ide.splitter.mouseZone")); add(myContentSplitter, BorderLayout.CENTER); myValidCard = new JPanel(new BorderLayout()); myInvalidCard = createInvalidCard(); myCardPanel.add(myValidCard, CARD_VALID); myCardPanel.add(myInvalidCard, CARD_INVALID); JPanel contentPanel = new JPanel(new LightFillLayout()); JLabel toolbar = new JLabel(); toolbar.setVisible(false); contentPanel.add(toolbar); contentPanel.add(myCardPanel); myContentSplitter.setInnerComponent(contentPanel); myListenerList = new EventListenerList(); myDecorationLayer = new PassiveDecorationLayer(this); myDragLayer = new DragLayer(this); myLayeredPane = new MyLayeredPane(); myInplaceEditingLayer = new InplaceEditingLayer(this); myLayeredPane.add(myInplaceEditingLayer, LAYER_INPLACE_EDITING); myActiveDecorationLayer = new ActiveDecorationLayer(this); myLayeredPane.add(myActiveDecorationLayer, LAYER_ACTIVE_DECORATION); myGlassLayer = new GlassLayer(this); myLayeredPane.add(myGlassLayer, LAYER_GLASS); myLayeredPane.add(myDecorationLayer, LAYER_PASSIVE_DECORATION); myLayeredPane.add(myDragLayer, LAYER_DND); myGlassLayer.addFocusListener(new FocusListener() { @Override public void focusGained(FocusEvent e) { myDecorationLayer.repaint(); //fireSelectedComponentChanged(); // EA-36478 } @Override public void focusLost(FocusEvent e) { myDecorationLayer.repaint(); } }); // Ctrl+W / Ctrl+Shift+W support mySelectionState = new SelectionState(this); // DeleteProvider myDeleteProvider = new MyDeleteProvider(); // We need to synchronize GUI editor with the document final Alarm alarm = new Alarm(); myDocumentListener = new DocumentAdapter() { @Override public void documentChanged(final DocumentEvent e) { if (!myInsideChange) { UndoManager undoManager = UndoManager.getInstance(getProject()); alarm.cancelAllRequests(); alarm.addRequest( new MySynchronizeRequest( undoManager.isUndoInProgress() || undoManager.isRedoInProgress()), 100/*any arbitrary delay*/, ModalityState.stateForComponent(GuiEditor.this)); } } }; // Prepare document myDocument = FileDocumentManager.getInstance().getDocument(file); myDocument.addDocumentListener(myDocumentListener); // Read form from file readFromFile(false); JPanel panel = new JPanel(new GridBagLayout()); panel.setBackground(GridCaptionPanel.getGutterColor()); myHorzCaptionPanel = new GridCaptionPanel(this, false); myVertCaptionPanel = new GridCaptionPanel(this, true); GridBagConstraints gbc = new GridBagConstraints(); gbc.gridx = 0; gbc.gridy = 1; gbc.weightx = 0.0; gbc.weighty = 0.0; gbc.fill = GridBagConstraints.BOTH; panel.add(myVertCaptionPanel, gbc); gbc.gridx = 1; gbc.gridy = 0; panel.add(myHorzCaptionPanel, gbc); gbc.gridx = 1; gbc.gridy = 1; gbc.weightx = 1.0; gbc.weighty = 1.0; myScrollPane = ScrollPaneFactory.createScrollPane(myLayeredPane); myScrollPane.setBackground(new JBColor(new NotNullProducer<Color>() { @NotNull @Override public Color produce() { return EditorColorsManager.getInstance().getGlobalScheme().getDefaultBackground(); } })); panel.add(myScrollPane, gbc); myHorzCaptionPanel.attachToScrollPane(myScrollPane); myVertCaptionPanel.attachToScrollPane(myScrollPane); myValidCard.add(panel, BorderLayout.CENTER); final CancelCurrentOperationAction cancelCurrentOperationAction = new CancelCurrentOperationAction(); cancelCurrentOperationAction.registerCustomShortcutSet(CommonShortcuts.ESCAPE, this); myProcessor = new MainProcessor(this); // PSI listener to restart error highlighter myPsiTreeChangeListener = new MyPsiTreeChangeListener(); PsiManager.getInstance(getProject()).addPsiTreeChangeListener(myPsiTreeChangeListener); myQuickFixManager = new QuickFixManagerImpl(this, myGlassLayer, myScrollPane.getViewport()); myDropTargetListener = new DesignDropTargetListener(this); if (!ApplicationManager.getApplication().isHeadlessEnvironment()) { new DropTarget(getGlassLayer(), DnDConstants.ACTION_COPY_OR_MOVE, myDropTargetListener); } myActiveDecorationLayer.installSelectionWatcher(); ActionManager.getInstance().getAction("GuiDesigner.IncreaseIndent").registerCustomShortcutSet( new CustomShortcutSet(KeyStroke.getKeyStroke(KeyEvent.VK_TAB, 0)), myGlassLayer); ActionManager.getInstance().getAction("GuiDesigner.DecreaseIndent").registerCustomShortcutSet( new CustomShortcutSet(KeyStroke.getKeyStroke(KeyEvent.VK_TAB, KeyEvent.SHIFT_MASK)), myGlassLayer); UIUtil.invokeLaterIfNeeded(new Runnable() { @Override public void run() { DesignerToolWindowManager.getInstance(myProject).bind(GuiEditor.this); PaletteToolWindowManager.getInstance(myProject).bind(GuiEditor.this); } }); }
From source file:com.intellij.uiDesigner.propertyInspector.editors.BindingEditor.java
License:Apache License
public BindingEditor(final Project project) { myCbx.setEditable(true);//from w w w . ja va2s . c o m final JComponent editorComponent = (JComponent) myCbx.getEditor().getEditorComponent(); editorComponent.setBorder(null); myCbx.addActionListener(new ActionListener() { @Override public void actionPerformed(final ActionEvent e) { fireValueCommitted(true, false); } }); new AnAction() { @Override public void actionPerformed(final AnActionEvent e) { if (!myCbx.isPopupVisible()) { fireEditingCancelled(); SwingUtilities.invokeLater(new Runnable() { @Override public void run() { DesignerToolWindowManager .getInstance( DesignerToolWindowManager.getInstance(project).getActiveFormEditor()) .getPropertyInspector().requestFocus(); } }); } } }.registerCustomShortcutSet(CommonShortcuts.ESCAPE, myCbx); }
From source file:com.intellij.uiDesigner.propertyInspector.editors.string.StringEditor.java
License:Apache License
public StringEditor(Project project, final IntroStringProperty property) { myProject = project;/* www.j a v a 2 s . c o m*/ myProperty = property; myTfWithButton = new TextFieldWithBrowseButton(new MyActionListener()); myTfWithButton.getTextField().setBorder(null); final JTextField textField = myTfWithButton.getTextField(); textField.addActionListener(new ActionListener() { public void actionPerformed(final ActionEvent e) { fireValueCommitted(false, false); } }); textField.getDocument().addDocumentListener(new DocumentAdapter() { protected void textChanged(final DocumentEvent e) { preferredSizeChanged(); myTextFieldModified = true; } }); final MyCancelEditingAction cancelEditingAction = new MyCancelEditingAction(); cancelEditingAction.registerCustomShortcutSet(CommonShortcuts.ESCAPE, myTfWithButton); }
From source file:ru.list.search.AssistantSearchEverywhereAction.java
License:Apache License
private void initSearchActions(JBPopup balloon, MySearchTextField searchTextField) { final JTextField editor = searchTextField.getTextEditor(); new DumbAwareAction() { @Override// w w w . j av a 2 s .c o m public void actionPerformed(AnActionEvent e) { jumpNextGroup(true); } }.registerCustomShortcutSet(CustomShortcutSet.fromString("TAB"), editor, balloon); new DumbAwareAction() { @Override public void actionPerformed(AnActionEvent e) { jumpNextGroup(false); } }.registerCustomShortcutSet(CustomShortcutSet.fromString("shift TAB"), editor, balloon); final AnAction escape = ActionManager.getInstance().getAction("EditorEscape"); new DumbAwareAction() { @Override public void actionPerformed(AnActionEvent e) { if (myBalloon != null && myBalloon.isVisible()) { myBalloon.cancel(); } if (myPopup != null && myPopup.isVisible()) { myPopup.cancel(); } } }.registerCustomShortcutSet(escape == null ? CommonShortcuts.ESCAPE : escape.getShortcutSet(), editor, balloon); new DumbAwareAction() { @Override public void actionPerformed(AnActionEvent e) { final int index = myList.getSelectedIndex(); if (index != -1) { doNavigate(index, WindowIndex.MAIN); } } }.registerCustomShortcutSet(CustomShortcutSet.fromString("ENTER", "shift ENTER"), editor, balloon); new DumbAwareAction() { @Override public void actionPerformed(AnActionEvent e) { final PropertiesComponent storage = PropertiesComponent.getInstance(e.getProject()); final String[] values = storage.getValues(SE_HISTORY_KEY); if (values != null) { if (values.length > myHistoryIndex) { final List<String> data = StringUtil.split(values[myHistoryIndex], "\t"); myHistoryItem = new HistoryItem(data.get(0), data.get(1), data.get(2)); myHistoryIndex++; editor.setText(myHistoryItem.pattern); editor.setCaretPosition(myHistoryItem.pattern.length()); editor.moveCaretPosition(0); } } } @Override public void update(AnActionEvent e) { e.getPresentation().setEnabled(editor.getCaretPosition() == 0); } }.registerCustomShortcutSet(CustomShortcutSet.fromString("LEFT"), editor, balloon); CustomShortcutSet assistantShortcutSet = new CustomShortcutSet( KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, InputEvent.ALT_DOWN_MASK)); new DumbAwareAction() { @Override public void actionPerformed(AnActionEvent e) { final int index = myList.getSelectedIndex(); if (index != -1) { doNavigate(index, WindowIndex.ASSISTANT); } } }.registerCustomShortcutSet(assistantShortcutSet, editor, balloon); new DumbAwareAction() { @Override public void actionPerformed(AnActionEvent e) { final PropertiesComponent storage = PropertiesComponent.getInstance(e.getProject()); final String[] values = storage.getValues(SE_HISTORY_KEY); if (values != null) { if (values.length > myHistoryIndex) { final List<String> data = StringUtil.split(values[myHistoryIndex], "\t"); myHistoryItem = new HistoryItem(data.get(0), data.get(1), data.get(2)); myHistoryIndex++; editor.setText(myHistoryItem.pattern); editor.setCaretPosition(myHistoryItem.pattern.length()); editor.moveCaretPosition(0); } } } @Override public void update(AnActionEvent e) { e.getPresentation().setEnabled(editor.getCaretPosition() == 0); } }.registerCustomShortcutSet(CustomShortcutSet.fromString("LEFT"), editor, balloon); }