@Nullable @Override public final ShortcutSet getShortcut(@NotNull DataContext context) { SearchSession search = SearchSession.KEY.getData(context); boolean singleLine = search != null && !search.getFindModel().isMultiline(); return Utils.shortcutSetOf( singleLine ? ContainerUtil.concat(getDefaultShortcuts(), getSingleLineShortcuts()) : getDefaultShortcuts()); }
public void showHistory(final boolean byClickingToolbarButton, JTextComponent textField) { FeatureUsageTracker.getInstance().triggerFeatureUsed("find.recent.search"); FindSettings settings = FindSettings.getInstance(); String[] recent = textField == mySearchTextComponent ? settings.getRecentFindStrings() : settings.getRecentReplaceStrings(); final boolean toShowAd = textField == mySearchTextComponent && textField.getText().isEmpty() && FindManager.getInstance(myProject).getPreviousFindModel() != null; Utils.showCompletionPopup( byClickingToolbarButton ? mySearchActionsToolbar1 : null, new JBList((Object[]) ArrayUtil.reverseArray(recent)), "Recent " + (textField == mySearchTextComponent ? "Searches" : "Replaces"), textField, toShowAd ? RestorePreviousSettingsAction.getAd() : null); }
private boolean updateTextComponent(final boolean search) { JTextComponent oldComponent = search ? mySearchTextComponent : myReplaceTextComponent; Color oldBackground = oldComponent != null ? oldComponent.getBackground() : null; Wrapper wrapper = search ? mySearchFieldWrapper : myReplaceFieldWrapper; boolean multiline = myFindModel.isMultiline(); if (multiline && oldComponent instanceof JTextArea) return false; if (!multiline && oldComponent instanceof JTextField) return false; final JTextComponent textComponent; if (multiline) { textComponent = new JTextArea(); ((JTextArea) textComponent).setColumns(25); ((JTextArea) textComponent).setRows(2); wrapper.setContent( new SearchWrapper(textComponent, new ShowHistoryAction(textComponent, this))); } else { SearchTextField searchTextField = new SearchTextField(true); searchTextField.setOpaque(false); textComponent = searchTextField.getTextEditor(); searchTextField.getTextEditor().setColumns(25); if (UIUtil.isUnderGTKLookAndFeel()) { textComponent.setOpaque(false); } setupHistoryToSearchField( searchTextField, search ? FindSettings.getInstance().getRecentFindStrings() : FindSettings.getInstance().getRecentReplaceStrings()); textComponent.registerKeyboardAction( new ActionListener() { @Override public void actionPerformed(final ActionEvent e) { final String text = textComponent.getText(); myFindModel.setMultiline(true); ApplicationManager.getApplication() .invokeLater( new Runnable() { @Override public void run() { if (search) { mySearchTextComponent.setText(text + "\n"); } else { myReplaceTextComponent.setText(text + "\n"); } } }); } }, KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, InputEvent.ALT_DOWN_MASK), JComponent.WHEN_FOCUSED); wrapper.setContent(searchTextField); } if (search) { mySearchTextComponent = textComponent; } else { myReplaceTextComponent = textComponent; } UIUtil.addUndoRedoActions(textComponent); Utils.setSmallerFont(textComponent); textComponent.putClientProperty("AuxEditorComponent", Boolean.TRUE); if (oldBackground != null) { textComponent.setBackground(oldBackground); } textComponent.addFocusListener( new FocusListener() { @Override public void focusGained(final FocusEvent e) { textComponent.repaint(); } @Override public void focusLost(final FocusEvent e) { textComponent.repaint(); } }); new CloseOnESCAction(this, textComponent); return true; }
private void initReplaceToolBars() { DefaultActionGroup actionGroup1 = new DefaultActionGroup("replace bar 1", false); myReplaceActionsToolbar1 = (ActionToolbarImpl) ActionManager.getInstance() .createActionToolbar(ActionPlaces.EDITOR_TOOLBAR, actionGroup1, true); myReplaceActionsToolbar1.setForceMinimumSize(true); final JButton myReplaceButton = new JButton("Replace"); myReplaceButton.setFocusable(false); myReplaceButton.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent actionEvent) { replaceCurrent(); } }); final JButton myReplaceAllButton = new JButton("Replace all"); myReplaceAllButton.setFocusable(false); myReplaceAllButton.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent actionEvent) { myLivePreviewController.performReplaceAll(); } }); final JButton myExcludeButton = new JButton(""); myExcludeButton.setFocusable(false); myExcludeButton.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent actionEvent) { myLivePreviewController.exclude(); moveCursor(SearchResults.Direction.DOWN); } }); if (!UISettings.getInstance().DISABLE_MNEMONICS_IN_CONTROLS) { myReplaceButton.setMnemonic('p'); myReplaceAllButton.setMnemonic('a'); myExcludeButton.setMnemonic('l'); } actionGroup1.addAction( new DefaultCustomComponentAction(myReplaceButton) { @Override public void update(AnActionEvent e) { myReplaceButton.setEnabled(canReplaceCurrent()); } }); actionGroup1.addAction( new DefaultCustomComponentAction(myReplaceAllButton) { @Override public void update(AnActionEvent e) { myReplaceAllButton.setEnabled(mySearchResults != null && mySearchResults.hasMatches()); } }); actionGroup1.addAction( new DefaultCustomComponentAction(myExcludeButton) { @Override public void update(AnActionEvent e) { FindResult cursor = mySearchResults != null ? mySearchResults.getCursor() : null; myExcludeButton.setEnabled(cursor != null); myExcludeButton.setText( cursor != null && mySearchResults.isExcluded(cursor) ? "Include" : "Exclude"); } }); myReplaceActionsToolbar1.setLayoutPolicy(ActionToolbar.AUTO_LAYOUT_POLICY); myReplaceActionsToolbar1.setBorder(null); myReplaceActionsToolbar1.setOpaque(false); DefaultActionGroup actionGroup2 = new DefaultActionGroup("replace bar 2", false); myReplaceActionsToolbar2 = (ActionToolbarImpl) ActionManager.getInstance() .createActionToolbar(ActionPlaces.EDITOR_TOOLBAR, actionGroup2, true); actionGroup2.addAction(new TogglePreserveCaseAction(this)); actionGroup2.addAction(new ToggleSelectionOnlyAction(this)); myReplaceActionsToolbar2.setLayoutPolicy(ActionToolbar.AUTO_LAYOUT_POLICY); myReplaceActionsToolbar2.setBorder(null); myReplaceActionsToolbar2.setOpaque(false); Utils.setSmallerFontForChildren(myReplaceActionsToolbar1); Utils.setSmallerFontForChildren(myReplaceActionsToolbar2); }
private void initSearchToolbars() { DefaultActionGroup actionGroup1 = new DefaultActionGroup("search bar 1", false); mySearchActionsToolbar1 = (ActionToolbarImpl) ActionManager.getInstance() .createActionToolbar(ActionPlaces.EDITOR_TOOLBAR, actionGroup1, true); mySearchActionsToolbar1.setForceMinimumSize(true); mySearchActionsToolbar1.setReservePlaceAutoPopupIcon(false); mySearchActionsToolbar1.setSecondaryButtonPopupStateModifier( new ActionToolbarImpl.PopupStateModifier() { @Override public int getModifiedPopupState() { return ActionButtonComponent.PUSHED; } @Override public boolean willModify() { return myFindModel.getSearchContext() != FindModel.SearchContext.ANY; } }); mySearchActionsToolbar1.setSecondaryActionsTooltip( "More Options(" + ShowMoreOptions.SHORT_CUT + ")"); actionGroup1.add(new PrevOccurrenceAction(this, mySearchFieldWrapper)); actionGroup1.add(new NextOccurrenceAction(this, mySearchFieldWrapper)); actionGroup1.add(new FindAllAction(this)); actionGroup1.addSeparator(); actionGroup1.add(new AddOccurrenceAction(this)); actionGroup1.add(new RemoveOccurrenceAction(this)); actionGroup1.add(new SelectAllAction(this)); // actionGroup1.addSeparator(); // actionGroup1.add(new ToggleMultiline(this));//todo get rid of it! actionGroup1.addSeparator(); actionGroup1.addAction(new ToggleInCommentsAction(this)).setAsSecondary(true); actionGroup1.addAction(new ToggleInLiteralsOnlyAction(this)).setAsSecondary(true); actionGroup1.addAction(new ToggleExceptCommentsAction(this)).setAsSecondary(true); actionGroup1.addAction(new ToggleExceptLiteralsAction(this)).setAsSecondary(true); actionGroup1.addAction(new ToggleExceptCommentsAndLiteralsAction(this)).setAsSecondary(true); DefaultActionGroup actionGroup2 = new DefaultActionGroup("search bar 2", false); mySearchActionsToolbar2 = (ActionToolbarImpl) ActionManager.getInstance() .createActionToolbar(ActionPlaces.EDITOR_TOOLBAR, actionGroup2, true); actionGroup2.add(new ToggleMatchCase(this)); actionGroup2.add(new ToggleRegex(this)); actionGroup2.add(new ToggleWholeWordsOnlyAction(this)); myMatchInfoLabel = new JLabel() { @Override public Font getFont() { Font font = super.getFont(); return font != null ? font.deriveFont(Font.BOLD) : null; } }; myMatchInfoLabel.setBorder(JBUI.Borders.empty(2, 20, 0, 20)); myClickToHighlightLabel = new LinkLabel<Object>( "Click to highlight", null, new LinkListener<Object>() { @Override public void linkSelected(LinkLabel aSource, Object aLinkData) { setMatchesLimit(Integer.MAX_VALUE); updateResults(true); } }); myClickToHighlightLabel.setVisible(false); mySearchActionsToolbar2 = (ActionToolbarImpl) ActionManager.getInstance() .createActionToolbar(ActionPlaces.EDITOR_TOOLBAR, actionGroup2, true); actionGroup2.add(new DefaultCustomComponentAction(myMatchInfoLabel)); actionGroup2.add(new DefaultCustomComponentAction(myClickToHighlightLabel)); mySearchActionsToolbar1.setLayoutPolicy(ActionToolbar.AUTO_LAYOUT_POLICY); mySearchActionsToolbar2.setLayoutPolicy(ActionToolbar.AUTO_LAYOUT_POLICY); mySearchActionsToolbar1.setBorder(null); mySearchActionsToolbar2.setBorder(null); mySearchActionsToolbar1.setOpaque(false); mySearchActionsToolbar2.setOpaque(false); new ShowMoreOptions(mySearchActionsToolbar1, mySearchFieldWrapper); Utils.setSmallerFontForChildren(mySearchActionsToolbar1); Utils.setSmallerFontForChildren(mySearchActionsToolbar2); }