use of com.intellij.openapi.options.ex.Settings in project intellij-community by JetBrains.
the class MavenKeymapExtension method createGroup.
@Override
public KeymapGroup createGroup(Condition<AnAction> condition, final Project project) {
KeymapGroup result = KeymapGroupFactory.getInstance().createGroup(TasksBundle.message("maven.tasks.action.group.name"), MavenIcons.MavenLogo);
if (project == null)
return result;
Comparator<MavenProject> projectComparator = (o1, o2) -> o1.getDisplayName().compareToIgnoreCase(o2.getDisplayName());
Map<MavenProject, Set<Pair<String, String>>> projectToActionsMapping = new TreeMap<>(projectComparator);
ActionManager actionManager = ActionManager.getInstance();
//noinspection TestOnlyProblems
for (String eachId : actionManager.getActionIds(getActionPrefix(project, null))) {
AnAction eachAction = actionManager.getAction(eachId);
if (!(eachAction instanceof MavenGoalAction))
continue;
if (condition != null && !condition.value(actionManager.getActionOrStub(eachId)))
continue;
MavenGoalAction mavenAction = (MavenGoalAction) eachAction;
MavenProject mavenProject = mavenAction.getMavenProject();
Set<Pair<String, String>> actions = projectToActionsMapping.get(mavenProject);
if (actions == null) {
final List<String> projectGoals = collectGoals(mavenProject);
actions = new TreeSet<>((o1, o2) -> {
String goal1 = o1.getFirst();
String goal2 = o2.getFirst();
int index1 = projectGoals.indexOf(goal1);
int index2 = projectGoals.indexOf(goal2);
if (index1 == index2)
return goal1.compareToIgnoreCase(goal2);
return (index1 < index2 ? -1 : 1);
});
projectToActionsMapping.put(mavenProject, actions);
}
actions.add(Pair.create(mavenAction.getGoal(), eachId));
}
for (Map.Entry<MavenProject, Set<Pair<String, String>>> each : projectToActionsMapping.entrySet()) {
Set<Pair<String, String>> goalsToActionIds = each.getValue();
for (Pair<String, String> eachGoalToActionId : goalsToActionIds) {
result.addActionId(eachGoalToActionId.getSecond());
}
}
Icon icon = SystemInfoRt.isMac ? AllIcons.ToolbarDecorator.Mac.Add : AllIcons.ToolbarDecorator.Add;
((Group) result).addHyperlink(new Hyperlink(icon, "Choose a phase/goal to assign a shortcut") {
@Override
public void onClick(MouseEvent e) {
SelectMavenGoalDialog dialog = new SelectMavenGoalDialog(project);
if (dialog.showAndGet() && dialog.getResult() != null) {
MavenProjectsStructure.GoalNode goalNode = dialog.getResult();
String goal = goalNode.getGoal();
String actionId = MavenShortcutsManager.getInstance(project).getActionId(goalNode.getProjectPath(), goal);
getOrRegisterAction(goalNode.getMavenProject(), actionId, goal);
ApplicationManager.getApplication().getMessageBus().syncPublisher(KeymapListener.CHANGE_TOPIC).processCurrentKeymapChanged();
Settings allSettings = Settings.KEY.getData(DataManager.getInstance().getDataContext(e.getComponent()));
KeymapPanel keymapPanel = allSettings != null ? allSettings.find(KeymapPanel.class) : null;
if (keymapPanel != null) {
// clear actions filter
keymapPanel.showOption("");
keymapPanel.selectAction(actionId);
}
}
}
});
return result;
}
use of com.intellij.openapi.options.ex.Settings in project intellij-community by JetBrains.
the class SeverityEditorDialog method editColorsAndFonts.
private void editColorsAndFonts() {
final String toConfigure = getSelectedType().getSeverity(null).myName;
if (myCloseDialogWhenSettingsShown) {
doOKAction();
}
myOptionsList.clearSelection();
final DataContext dataContext = DataManager.getInstance().getDataContext(myPanel);
Settings settings = Settings.KEY.getData(dataContext);
if (settings != null) {
ColorAndFontOptions colorAndFontOptions = settings.find(ColorAndFontOptions.class);
assert colorAndFontOptions != null;
final SearchableConfigurable javaPage = colorAndFontOptions.findSubConfigurable(InspectionColorSettingsPage.class);
LOG.assertTrue(javaPage != null);
settings.select(javaPage).doWhenDone(() -> {
final Runnable runnable = javaPage.enableSearch(toConfigure);
if (runnable != null) {
SwingUtilities.invokeLater(runnable);
}
});
} else {
ColorAndFontOptions colorAndFontOptions = new ColorAndFontOptions();
final Configurable[] configurables = colorAndFontOptions.buildConfigurables();
try {
final SearchableConfigurable javaPage = colorAndFontOptions.findSubConfigurable(InspectionColorSettingsPage.class);
LOG.assertTrue(javaPage != null);
ShowSettingsUtil.getInstance().editConfigurable(CommonDataKeys.PROJECT.getData(dataContext), javaPage);
} finally {
for (Configurable configurable : configurables) {
configurable.disposeUIResources();
}
colorAndFontOptions.disposeUIResources();
}
}
}
use of com.intellij.openapi.options.ex.Settings in project intellij-community by JetBrains.
the class ExternalSystemKeymapExtension method createGroup.
public KeymapGroup createGroup(Condition<AnAction> condition, final Project project) {
KeymapGroup result = KeymapGroupFactory.getInstance().createGroup(ExternalSystemBundle.message("external.system.keymap.group"), ExternalSystemIcons.TaskGroup);
AnAction[] externalSystemActions = ActionsTreeUtil.getActions("ExternalSystem.Actions");
for (AnAction action : externalSystemActions) {
ActionsTreeUtil.addAction(result, action, condition);
}
if (project == null)
return result;
MultiMap<ProjectSystemId, String> projectToActionsMapping = MultiMap.create();
for (ExternalSystemManager<?, ?, ?, ?, ?> manager : ExternalSystemApiUtil.getAllManagers()) {
projectToActionsMapping.putValues(manager.getSystemId(), ContainerUtil.<String>emptyList());
}
ActionManager actionManager = ActionManager.getInstance();
if (actionManager != null) {
for (String eachId : actionManager.getActionIds(getActionPrefix(project, null))) {
AnAction eachAction = actionManager.getAction(eachId);
if (!(eachAction instanceof MyExternalSystemAction))
continue;
if (condition != null && !condition.value(actionManager.getActionOrStub(eachId)))
continue;
MyExternalSystemAction taskAction = (MyExternalSystemAction) eachAction;
projectToActionsMapping.putValue(taskAction.getSystemId(), eachId);
}
}
Map<ProjectSystemId, KeymapGroup> keymapGroupMap = ContainerUtil.newHashMap();
for (ProjectSystemId systemId : projectToActionsMapping.keySet()) {
if (!keymapGroupMap.containsKey(systemId)) {
final Icon projectIcon = ExternalSystemUiUtil.getUiAware(systemId).getProjectIcon();
KeymapGroup group = KeymapGroupFactory.getInstance().createGroup(systemId.getReadableName(), projectIcon);
keymapGroupMap.put(systemId, group);
}
}
for (Map.Entry<ProjectSystemId, Collection<String>> each : projectToActionsMapping.entrySet()) {
Collection<String> tasks = each.getValue();
final ProjectSystemId systemId = each.getKey();
final KeymapGroup systemGroup = keymapGroupMap.get(systemId);
if (systemGroup == null)
continue;
for (String actionId : tasks) {
systemGroup.addActionId(actionId);
}
if (systemGroup instanceof Group) {
Icon icon = SystemInfoRt.isMac ? AllIcons.ToolbarDecorator.Mac.Add : AllIcons.ToolbarDecorator.Add;
((Group) systemGroup).addHyperlink(new Hyperlink(icon, "Choose a task to assign a shortcut") {
@Override
public void onClick(MouseEvent e) {
SelectExternalTaskDialog dialog = new SelectExternalTaskDialog(systemId, project);
if (dialog.showAndGet() && dialog.getResult() != null) {
TaskData taskData = dialog.getResult().second;
String ownerModuleName = dialog.getResult().first;
ExternalSystemTaskAction externalSystemAction = (ExternalSystemTaskAction) getOrRegisterAction(project, ownerModuleName, taskData);
ApplicationManager.getApplication().getMessageBus().syncPublisher(KeymapListener.CHANGE_TOPIC).processCurrentKeymapChanged();
Settings allSettings = Settings.KEY.getData(DataManager.getInstance().getDataContext(e.getComponent()));
KeymapPanel keymapPanel = allSettings != null ? allSettings.find(KeymapPanel.class) : null;
if (keymapPanel != null) {
// clear actions filter
keymapPanel.showOption("");
keymapPanel.selectAction(externalSystemAction.myId);
}
}
}
});
}
}
for (KeymapGroup keymapGroup : keymapGroupMap.values()) {
if (isGroupFiltered(condition, keymapGroup)) {
result.addGroup(keymapGroup);
}
}
for (ActionsProvider extension : ActionsProvider.EP_NAME.getExtensions()) {
KeymapGroup keymapGroup = extension.createGroup(condition, project);
if (isGroupFiltered(condition, keymapGroup)) {
result.addGroup(keymapGroup);
}
}
return result;
}
use of com.intellij.openapi.options.ex.Settings in project intellij-community by JetBrains.
the class JumpToColorsAndFontsAction method actionPerformed.
@Override
public void actionPerformed(AnActionEvent e) {
// todo handle ColorKey's as well
Project project = e.getData(CommonDataKeys.PROJECT);
Editor editor = e.getData(CommonDataKeys.EDITOR);
if (project == null || editor == null)
return;
Map<TextAttributesKey, Pair<ColorSettingsPage, AttributesDescriptor>> keyMap = ContainerUtil.newHashMap();
Processor<RangeHighlighterEx> processor = r -> {
Object tt = r.getErrorStripeTooltip();
TextAttributesKey key = tt instanceof HighlightInfo ? ObjectUtils.chooseNotNull(((HighlightInfo) tt).forcedTextAttributesKey, ((HighlightInfo) tt).type.getAttributesKey()) : null;
Pair<ColorSettingsPage, AttributesDescriptor> p = key == null ? null : ColorSettingsPages.getInstance().getAttributeDescriptor(key);
if (p != null)
keyMap.put(key, p);
return true;
};
JBIterable<Editor> editors = editor instanceof EditorWindow ? JBIterable.of(editor, ((EditorWindow) editor).getDelegate()) : JBIterable.of(editor);
for (Editor ed : editors) {
TextRange selection = EditorUtil.getSelectionInAnyMode(ed);
MarkupModel forDocument = DocumentMarkupModel.forDocument(ed.getDocument(), project, false);
if (forDocument != null) {
((MarkupModelEx) forDocument).processRangeHighlightersOverlappingWith(selection.getStartOffset(), selection.getEndOffset(), processor);
}
((MarkupModelEx) ed.getMarkupModel()).processRangeHighlightersOverlappingWith(selection.getStartOffset(), selection.getEndOffset(), processor);
EditorHighlighter highlighter = ed instanceof EditorEx ? ((EditorEx) ed).getHighlighter() : null;
SyntaxHighlighter syntaxHighlighter = highlighter instanceof LexerEditorHighlighter ? ((LexerEditorHighlighter) highlighter).getSyntaxHighlighter() : null;
if (syntaxHighlighter != null) {
HighlighterIterator iterator = highlighter.createIterator(selection.getStartOffset());
while (!iterator.atEnd()) {
for (TextAttributesKey key : syntaxHighlighter.getTokenHighlights(iterator.getTokenType())) {
Pair<ColorSettingsPage, AttributesDescriptor> p = key == null ? null : ColorSettingsPages.getInstance().getAttributeDescriptor(key);
if (p != null)
keyMap.put(key, p);
}
if (iterator.getEnd() >= selection.getEndOffset())
break;
iterator.advance();
}
}
}
if (keyMap.isEmpty()) {
HintManager.getInstance().showErrorHint(editor, "No text attributes found");
} else if (keyMap.size() == 1) {
Pair<ColorSettingsPage, AttributesDescriptor> p = keyMap.values().iterator().next();
if (!openSettingsAndSelectKey(project, p.first, p.second)) {
HintManager.getInstance().showErrorHint(editor, "No appropriate settings page found");
}
} else {
ArrayList<Pair<ColorSettingsPage, AttributesDescriptor>> attrs = ContainerUtil.newArrayList(keyMap.values());
Collections.sort(attrs, (o1, o2) -> StringUtil.naturalCompare(o1.first.getDisplayName() + o1.second.getDisplayName(), o2.first.getDisplayName() + o2.second.getDisplayName()));
EditorColorsScheme colorsScheme = editor.getColorsScheme();
JBList<Pair<ColorSettingsPage, AttributesDescriptor>> list = new JBList<>(attrs);
list.setCellRenderer(new ColoredListCellRenderer<Pair<ColorSettingsPage, AttributesDescriptor>>() {
@Override
protected void customizeCellRenderer(@NotNull JList<? extends Pair<ColorSettingsPage, AttributesDescriptor>> list, Pair<ColorSettingsPage, AttributesDescriptor> value, int index, boolean selected, boolean hasFocus) {
TextAttributes ta = colorsScheme.getAttributes(value.second.getKey());
Color fg = ObjectUtils.chooseNotNull(ta.getForegroundColor(), colorsScheme.getDefaultForeground());
Color bg = ObjectUtils.chooseNotNull(ta.getBackgroundColor(), colorsScheme.getDefaultBackground());
SimpleTextAttributes sa = fromTextAttributes(ta);
SimpleTextAttributes saOpaque = sa.derive(STYLE_OPAQUE | sa.getStyle(), fg, bg, null);
SimpleTextAttributes saSelected = REGULAR_ATTRIBUTES.derive(sa.getStyle(), null, null, null);
SimpleTextAttributes saCur = REGULAR_ATTRIBUTES;
List<String> split = StringUtil.split(value.first.getDisplayName() + "//" + value.second.getDisplayName(), "//");
for (int i = 0, len = split.size(); i < len; i++) {
boolean last = i == len - 1;
saCur = !last ? REGULAR_ATTRIBUTES : selected ? saSelected : saOpaque;
if (last)
append(" ", saCur);
append(split.get(i), saCur);
if (last)
append(" ", saCur);
else
append(" > ", GRAYED_ATTRIBUTES);
}
Color stripeColor = ta.getErrorStripeColor();
boolean addStripe = stripeColor != null && stripeColor != saCur.getBgColor();
boolean addBoxed = ta.getEffectType() == EffectType.BOXED && ta.getEffectColor() != null;
if (addBoxed) {
append("▢" + (addStripe ? "" : " "), saCur.derive(-1, ta.getEffectColor(), null, null));
}
if (addStripe) {
append(" ", saCur.derive(STYLE_OPAQUE, null, stripeColor, null));
}
}
});
JBPopupFactory.getInstance().createListPopupBuilder(list).setTitle(StringUtil.notNullize(e.getPresentation().getText())).setMovable(false).setResizable(false).setRequestFocus(true).setItemChoosenCallback(() -> {
Pair<ColorSettingsPage, AttributesDescriptor> p = list.getSelectedValue();
if (p != null && !openSettingsAndSelectKey(project, p.first, p.second)) {
HintManager.getInstance().showErrorHint(editor, "No appropriate settings page found");
}
}).createPopup().showInBestPositionFor(editor);
}
}
use of com.intellij.openapi.options.ex.Settings in project intellij-community by JetBrains.
the class JumpToColorsAndFontsAction method openSettingsAndSelectKey.
private static boolean openSettingsAndSelectKey(@NotNull Project project, @NotNull ColorSettingsPage page, @NotNull AttributesDescriptor descriptor) {
SettingsDialog dialog = (SettingsDialog) ShowSettingsUtilImpl.getDialog(project, ShowSettingsUtilImpl.getConfigurableGroups(project, true), null);
Settings settings = Settings.KEY.getData(dialog);
ColorAndFontOptions configurable0 = settings == null ? null : settings.find(ColorAndFontOptions.class);
SearchableConfigurable configurable = configurable0 == null ? null : configurable0.findSubConfigurable(page.getDisplayName());
if (configurable == null)
return false;
Runnable runnable = configurable.enableSearch(descriptor.getDisplayName());
ActionCallback callback = settings.select(configurable);
if (runnable != null)
callback.doWhenDone(runnable);
dialog.show();
return true;
}
Aggregations