use of com.intellij.ui.speedSearch.SpeedSearchSupply in project intellij-community by JetBrains.
the class DeleteAction method update.
@Override
public void update(AnActionEvent e) {
Presentation presentation = e.getPresentation();
if (ActionPlaces.PROJECT_VIEW_POPUP.equals(e.getPlace()) || ActionPlaces.COMMANDER_POPUP.equals(e.getPlace())) {
presentation.setText(IdeBundle.message("action.delete.ellipsis"));
} else {
presentation.setText(IdeBundle.message("action.delete"));
}
if (e.getProject() == null) {
presentation.setEnabled(false);
return;
}
DataContext dataContext = e.getDataContext();
DeleteProvider provider = getDeleteProvider(dataContext);
if (e.getInputEvent() instanceof KeyEvent) {
KeyEvent keyEvent = (KeyEvent) e.getInputEvent();
Object component = PlatformDataKeys.CONTEXT_COMPONENT.getData(dataContext);
// Do not override text deletion
if (component instanceof JTextComponent)
provider = null;
if (keyEvent.getKeyCode() == KeyEvent.VK_BACK_SPACE) {
// Do not override text deletion in speed search
if (component instanceof JComponent) {
SpeedSearchSupply searchSupply = SpeedSearchSupply.getSupply((JComponent) component);
if (searchSupply != null)
provider = null;
}
String activeSpeedSearchFilter = SpeedSearchSupply.SPEED_SEARCH_CURRENT_QUERY.getData(dataContext);
if (!StringUtil.isEmpty(activeSpeedSearchFilter)) {
provider = null;
}
}
}
if (provider instanceof TitledHandler) {
presentation.setText(((TitledHandler) provider).getActionTitle());
}
boolean canDelete = provider != null && provider.canDeleteElement(dataContext);
if (ActionPlaces.isPopupPlace(e.getPlace())) {
presentation.setVisible(canDelete);
} else {
presentation.setEnabled(canDelete);
}
}
use of com.intellij.ui.speedSearch.SpeedSearchSupply in project intellij-community by JetBrains.
the class InjectionsSettingsUI method createActions.
private void createActions(ToolbarDecorator decorator) {
final Consumer<BaseInjection> consumer = injection -> addInjection(injection);
final Factory<BaseInjection> producer = (NullableFactory<BaseInjection>) () -> {
final InjInfo info = getSelectedInjection();
return info == null ? null : info.injection;
};
for (LanguageInjectionSupport support : InjectorUtils.getActiveInjectionSupports()) {
ContainerUtil.addAll(myAddActions, support.createAddActions(myProject, consumer));
final AnAction action = support.createEditAction(myProject, producer);
myEditActions.put(support.getId(), action == null ? AbstractLanguageInjectionSupport.createDefaultEditAction(myProject, producer) : action);
mySupports.put(support.getId(), support);
}
Collections.sort(myAddActions, (o1, o2) -> Comparing.compare(o1.getTemplatePresentation().getText(), o2.getTemplatePresentation().getText()));
decorator.disableUpDownActions();
decorator.setAddActionUpdater(new AnActionButtonUpdater() {
@Override
public boolean isEnabled(AnActionEvent e) {
return !myAddActions.isEmpty();
}
});
decorator.setAddAction(new AnActionButtonRunnable() {
@Override
public void run(AnActionButton button) {
performAdd(button);
}
});
decorator.setRemoveActionUpdater(new AnActionButtonUpdater() {
@Override
public boolean isEnabled(AnActionEvent e) {
boolean enabled = false;
for (InjInfo info : getSelectedInjections()) {
if (!info.bundled) {
enabled = true;
break;
}
}
return enabled;
}
});
decorator.setRemoveAction(new AnActionButtonRunnable() {
@Override
public void run(AnActionButton button) {
performRemove();
}
});
decorator.setEditActionUpdater(new AnActionButtonUpdater() {
@Override
public boolean isEnabled(AnActionEvent e) {
AnAction edit = getEditAction();
if (edit != null)
edit.update(e);
return edit != null && edit.getTemplatePresentation().isEnabled();
}
});
decorator.setEditAction(new AnActionButtonRunnable() {
@Override
public void run(AnActionButton button) {
performEditAction();
}
});
decorator.addExtraAction(new DumbAwareActionButton("Duplicate", "Duplicate", PlatformIcons.COPY_ICON) {
@Override
public boolean isEnabled() {
return getEditAction() != null;
}
@Override
public void actionPerformed(@NotNull AnActionEvent e) {
final InjInfo injection = getSelectedInjection();
if (injection != null) {
addInjection(injection.injection.copy());
//performEditAction(e);
}
}
});
decorator.addExtraAction(new DumbAwareActionButton("Enable Selected Injections", "Enable Selected Injections", PlatformIcons.SELECT_ALL_ICON) {
@Override
public void actionPerformed(@NotNull final AnActionEvent e) {
performSelectedInjectionsEnabled(true);
}
});
decorator.addExtraAction(new DumbAwareActionButton("Disable Selected Injections", "Disable Selected Injections", PlatformIcons.UNSELECT_ALL_ICON) {
@Override
public void actionPerformed(@NotNull final AnActionEvent e) {
performSelectedInjectionsEnabled(false);
}
});
new DumbAwareAction("Toggle") {
@Override
public void update(@NotNull AnActionEvent e) {
SpeedSearchSupply supply = SpeedSearchSupply.getSupply(myInjectionsTable);
e.getPresentation().setEnabled(supply == null || !supply.isPopupActive());
}
@Override
public void actionPerformed(@NotNull final AnActionEvent e) {
performToggleAction();
}
}.registerCustomShortcutSet(new CustomShortcutSet(KeyStroke.getKeyStroke(KeyEvent.VK_SPACE, 0)), myInjectionsTable);
if (myInfos.length > 1) {
AnActionButton shareAction = new DumbAwareActionButton("Move to IDE Scope", null, PlatformIcons.IMPORT_ICON) {
{
addCustomUpdater(new AnActionButtonUpdater() {
@Override
public boolean isEnabled(AnActionEvent e) {
CfgInfo cfg = getTargetCfgInfo(getSelectedInjections());
e.getPresentation().setText(cfg == getDefaultCfgInfo() ? "Move to IDE Scope" : "Move to Project Scope");
return cfg != null;
}
});
}
@Override
public void actionPerformed(@NotNull final AnActionEvent e) {
final List<InjInfo> injections = getSelectedInjections();
final CfgInfo cfg = getTargetCfgInfo(injections);
if (cfg == null)
return;
for (InjInfo info : injections) {
if (info.cfgInfo == cfg)
continue;
if (info.bundled)
continue;
info.cfgInfo.injectionInfos.remove(info);
cfg.addInjection(info.injection);
}
final int[] selectedRows = myInjectionsTable.getSelectedRows();
myInjectionsTable.getListTableModel().setItems(getInjInfoList(myInfos));
TableUtil.selectRows(myInjectionsTable, selectedRows);
}
@Nullable
private CfgInfo getTargetCfgInfo(final List<InjInfo> injections) {
CfgInfo cfg = null;
for (InjInfo info : injections) {
if (info.bundled) {
continue;
}
if (cfg == null)
cfg = info.cfgInfo;
else if (cfg != info.cfgInfo)
return info.cfgInfo;
}
if (cfg == null)
return null;
for (CfgInfo info : myInfos) {
if (info != cfg)
return info;
}
throw new AssertionError();
}
};
shareAction.setShortcut(new CustomShortcutSet(KeyStroke.getKeyStroke(KeyEvent.VK_SPACE, InputEvent.SHIFT_DOWN_MASK)));
decorator.addExtraAction(shareAction);
}
decorator.addExtraAction(new DumbAwareActionButton("Import", "Import", AllIcons.Actions.Install) {
@Override
public void actionPerformed(@NotNull final AnActionEvent e) {
doImportAction(e.getDataContext());
updateCountLabel();
}
});
decorator.addExtraAction(new DumbAwareActionButton("Export", "Export", AllIcons.Actions.Export) {
@Override
public void actionPerformed(@NotNull final AnActionEvent e) {
final List<BaseInjection> injections = getInjectionList(getSelectedInjections());
final VirtualFileWrapper wrapper = FileChooserFactory.getInstance().createSaveFileDialog(new FileSaverDescriptor("Export Selected Injections to File...", "", "xml"), myProject).save(null, null);
if (wrapper == null)
return;
final Configuration configuration = new Configuration();
configuration.setInjections(injections);
try {
JdomKt.write(configuration.getState(), wrapper.getFile().toPath());
} catch (IOException ex) {
final String msg = ex.getLocalizedMessage();
Messages.showErrorDialog(myProject, msg != null && msg.length() > 0 ? msg : ex.toString(), "Export Failed");
}
}
@Override
public boolean isEnabled() {
return !getSelectedInjections().isEmpty();
}
});
}
use of com.intellij.ui.speedSearch.SpeedSearchSupply in project intellij-community by JetBrains.
the class GotoActionBase method getInitialText.
protected static Pair<String, Integer> getInitialText(boolean useEditorSelection, AnActionEvent e) {
final String predefined = e.getData(PlatformDataKeys.PREDEFINED_TEXT);
if (!StringUtil.isEmpty(predefined)) {
return Pair.create(predefined, 0);
}
if (useEditorSelection) {
String selectedText = getInitialTextForNavigation(e.getData(CommonDataKeys.EDITOR));
if (selectedText != null)
return new Pair<>(selectedText, 0);
}
final String query = e.getData(SpeedSearchSupply.SPEED_SEARCH_CURRENT_QUERY);
if (!StringUtil.isEmpty(query)) {
return Pair.create(query, 0);
}
final Component focusOwner = IdeFocusManager.getInstance(getEventProject(e)).getFocusOwner();
if (focusOwner instanceof JComponent) {
final SpeedSearchSupply supply = SpeedSearchSupply.getSupply((JComponent) focusOwner);
if (supply != null) {
return Pair.create(supply.getEnteredPrefix(), 0);
}
}
if (myInAction != null) {
final Pair<String, Integer> lastString = ourLastStrings.get(myInAction);
if (lastString != null) {
return lastString;
}
}
return Pair.create("", 0);
}
use of com.intellij.ui.speedSearch.SpeedSearchSupply in project intellij-community by JetBrains.
the class FileStructureDialog method addCheckbox.
private void addCheckbox(final JPanel panel, final TreeAction action) {
String text = action instanceof FileStructureFilter ? ((FileStructureFilter) action).getCheckBoxText() : action instanceof FileStructureNodeProvider ? ((FileStructureNodeProvider) action).getCheckBoxText() : null;
if (text == null)
return;
Shortcut[] shortcuts = FileStructurePopup.extractShortcutFor(action);
final JCheckBox chkFilter = new JCheckBox();
chkFilter.addActionListener(new ActionListener() {
@Override
public void actionPerformed(final ActionEvent e) {
ProjectListBuilder builder = (ProjectListBuilder) myCommanderPanel.getBuilder();
PsiElement currentParent = null;
if (builder != null) {
final AbstractTreeNode parentNode = builder.getParentNode();
final Object value = parentNode.getValue();
if (value instanceof StructureViewTreeElement) {
final Object elementValue = ((StructureViewTreeElement) value).getValue();
if (elementValue instanceof PsiElement) {
currentParent = (PsiElement) elementValue;
}
}
}
final boolean state = chkFilter.isSelected();
myTreeActionsOwner.setActionIncluded(action, action instanceof FileStructureFilter ? !state : state);
myTreeStructure.rebuildTree();
if (builder != null) {
if (currentParent != null) {
boolean oldNarrowDown = myShouldNarrowDown;
myShouldNarrowDown = false;
try {
builder.enterElement(currentParent, PsiUtilCore.getVirtualFile(currentParent));
} finally {
myShouldNarrowDown = oldNarrowDown;
}
}
builder.updateList(true);
}
if (SpeedSearchBase.hasActiveSpeedSearch(myCommanderPanel.getList())) {
final SpeedSearchSupply supply = SpeedSearchSupply.getSupply(myCommanderPanel.getList());
if (supply != null && supply.isPopupActive())
supply.refreshSelection();
}
}
});
chkFilter.setFocusable(false);
if (shortcuts.length > 0) {
text += " (" + KeymapUtil.getShortcutText(shortcuts[0]) + ")";
new AnAction() {
@Override
public void actionPerformed(final AnActionEvent e) {
chkFilter.doClick();
}
}.registerCustomShortcutSet(new CustomShortcutSet(shortcuts), myCommanderPanel);
}
chkFilter.setText(text);
panel.add(chkFilter);
//,new GridBagConstraints(0, GridBagConstraints.RELATIVE, 1, 1, 0, 0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 5, 0, 5), 0, 0));
}
use of com.intellij.ui.speedSearch.SpeedSearchSupply in project intellij-community by JetBrains.
the class ContentChooser method createCenterPanel.
@Override
protected JComponent createCenterPanel() {
final int selectionMode = myAllowMultipleSelections ? ListSelectionModel.MULTIPLE_INTERVAL_SELECTION : ListSelectionModel.SINGLE_SELECTION;
myList.setSelectionMode(selectionMode);
if (myUseIdeaEditor) {
EditorColorsScheme scheme = EditorColorsManager.getInstance().getGlobalScheme();
myList.setFont(scheme.getFont(EditorFontType.PLAIN));
Color fg = ObjectUtils.chooseNotNull(scheme.getDefaultForeground(), new JBColor(UIUtil::getListForeground));
Color bg = ObjectUtils.chooseNotNull(scheme.getDefaultBackground(), new JBColor(UIUtil::getListBackground));
myList.setForeground(fg);
myList.setBackground(bg);
}
new DoubleClickListener() {
@Override
protected boolean onDoubleClick(MouseEvent e) {
close(OK_EXIT_CODE);
return true;
}
}.installOn(myList);
MyListCellRenderer renderer = new MyListCellRenderer();
myList.setCellRenderer(renderer);
myList.addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent e) {
if (e.getKeyCode() == KeyEvent.VK_DELETE) {
int newSelectionIndex = -1;
for (Object o : myList.getSelectedValuesList()) {
int i = ((Item) o).index;
removeContentAt(myAllContents.get(i));
if (newSelectionIndex < 0) {
newSelectionIndex = i;
}
}
rebuildListContent();
if (myAllContents.isEmpty()) {
close(CANCEL_EXIT_CODE);
return;
}
newSelectionIndex = Math.min(newSelectionIndex, myAllContents.size() - 1);
myList.setSelectedIndex(newSelectionIndex);
} else if (e.getKeyCode() == KeyEvent.VK_ENTER) {
doOKAction();
} else {
SpeedSearchSupply supply = SpeedSearchSupply.getSupply(myList);
if (supply != null && supply.isPopupActive())
return;
char aChar = e.getKeyChar();
if (aChar >= '0' && aChar <= '9') {
int idx = aChar == '0' ? 9 : aChar - '1';
if (idx < myAllContents.size()) {
myList.setSelectedIndex(idx);
e.consume();
doOKAction();
}
}
}
}
});
mySplitter.setFirstComponent(ListWithFilter.wrap(myList, ScrollPaneFactory.createScrollPane(myList), o -> o.getShortText(renderer.previewChars)));
mySplitter.setSecondComponent(new JPanel());
mySplitter.getFirstComponent().addComponentListener(new ComponentAdapter() {
@Override
public void componentResized(ComponentEvent e) {
FontMetrics metrics = myList.getFontMetrics(myList.getFont());
int charWidth = metrics.charWidth('m');
renderer.previewChars = myList.getParent().getParent().getWidth() / charWidth + 10;
}
});
rebuildListContent();
ScrollingUtil.installActions(myList);
ScrollingUtil.ensureSelectionExists(myList);
updateViewerForSelection();
myList.addListSelectionListener(new ListSelectionListener() {
@Override
public void valueChanged(ListSelectionEvent e) {
if (myUpdateAlarm.isDisposed())
return;
myUpdateAlarm.cancelAllRequests();
myUpdateAlarm.addRequest(() -> updateViewerForSelection(), 100);
}
});
mySplitter.setPreferredSize(JBUI.size(500, 500));
SplitterProportionsData d = new SplitterProportionsDataImpl();
d.externalizeToDimensionService(getClass().getName());
d.restoreSplitterProportions(mySplitter);
return mySplitter;
}
Aggregations