private void reset(@NotNull Keymap keymap, @NotNull QuickList[] allQuickLists, String filter, @Nullable KeyboardShortcut shortcut) { myKeymap = keymap; final PathsKeeper pathsKeeper = new PathsKeeper(); pathsKeeper.storePaths(); myRoot.removeAllChildren(); ActionManager actionManager = ActionManager.getInstance(); Project project = CommonDataKeys.PROJECT.getData(DataManager.getInstance().getDataContext(myComponent)); Group mainGroup = ActionsTreeUtil.createMainGroup(project, keymap, allQuickLists, filter, true, ActionsTreeUtil.isActionFiltered(actionManager, keymap, shortcut, filter, true)); if ((filter != null && filter.length() > 0 || shortcut != null) && mainGroup.initIds().isEmpty()){ mainGroup = ActionsTreeUtil.createMainGroup(project, keymap, allQuickLists, filter, false, ActionsTreeUtil.isActionFiltered(actionManager, keymap, shortcut, filter, false)); } myRoot = ActionsTreeUtil.createNode(mainGroup); myMainGroup = mainGroup; MyModel model = (MyModel)myTree.getModel(); model.setRoot(myRoot); model.nodeStructureChanged(myRoot); pathsKeeper.restorePaths(); }
public Object getValueAt(Object value, int column) { if (!(value instanceof DefaultMutableTreeNode)) { return "???"; } if (column == 0) { return value; } else if (column == 1) { Object userObject = ((DefaultMutableTreeNode)value).getUserObject(); if (userObject instanceof QuickList) { userObject = ((QuickList)userObject).getActionId(); } return userObject instanceof String ? KeymapUtil.getShortcutsText(myKeymap.getShortcuts((String)userObject)) : ""; } else { return "???"; } }
@Nullable private String getPath(DefaultMutableTreeNode node) { final Object userObject = node.getUserObject(); if (userObject instanceof String) { String actionId = (String)userObject; final TreeNode parent = node.getParent(); if (parent instanceof DefaultMutableTreeNode) { final Object object = ((DefaultMutableTreeNode)parent).getUserObject(); if (object instanceof Group) { return ((Group)object).getActionQualifiedPath(actionId); } } return myMainGroup.getActionQualifiedPath(actionId); } if (userObject instanceof Group) { return ((Group)userObject).getQualifiedPath(); } if (userObject instanceof QuickList) { return ((QuickList)userObject).getName(); } return null; }
public void setItem(@Nullable QuickList item) { apply(); this.item = item; if (item == null) { return; } myName.setText(item.getName()); myName.setEnabled(QuickListsManager.getInstance().getSchemeManager().isMetadataEditable(item)); myDescription.setText(item.getDescription()); actionsModel.removeAll(); for (String id : item.getActionIds()) { includeActionId(id); } }
public void addAll(Group group) { for (Object o : group.getChildren()) { if (o instanceof String) { addActionId((String)o); } else if (o instanceof QuickList) { addQuickList((QuickList)o); } else if (o instanceof Group) { addGroup((Group)o); } else if (o instanceof Separator) { addSeparator(); } } }
@Override public void quickListRenamed(final QuickList oldQuickList, final QuickList newQuickList) { for (Keymap keymap : myEditor.getModel().getItems()) { String actionId = oldQuickList.getActionId(); Shortcut[] shortcuts = keymap.getShortcuts(actionId); if (shortcuts.length != 0) { String newActionId = newQuickList.getActionId(); for (Shortcut shortcut : shortcuts) { keymap.removeShortcut(actionId, shortcut); keymap.addShortcut(newActionId, shortcut); } } } myQuickListsModified = true; }
private static Group createQuickListsGroup(final Condition<AnAction> filtered, final String filter, final boolean forceFiltering, final QuickList[] quickLists) { Arrays.sort(quickLists, new Comparator<QuickList>() { public int compare(QuickList l1, QuickList l2) { return l1.getActionId().compareTo(l2.getActionId()); } }); Group group = new Group(KeyMapBundle.message("quick.lists.group.title"), null, null); for (QuickList quickList : quickLists) { if (filtered != null && filtered.value(ActionManagerEx.getInstanceEx().getAction(quickList.getActionId()))) { group.addQuickList(quickList); } else if (SearchUtil.isComponentHighlighted(quickList.getName(), filter, forceFiltering, null)) { group.addQuickList(quickList); } else if (filtered == null && StringUtil.isEmpty(filter)) { group.addQuickList(quickList); } } return group; }
public ChooseActionsDialog(Component parent, Keymap keymap, QuickList[] quicklists) { super(parent, true); myKeymap = keymap; myQuicklists = quicklists; myActionsTree = new ActionsTree(); myActionsTree.reset(keymap, quicklists); myActionsTree.getTree().getSelectionModel().setSelectionMode(TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION); new DoubleClickListener() { @Override protected boolean onDoubleClick(MouseEvent e) { doOKAction(); return true; } }.installOn(myActionsTree.getTree()); myTreeExpansionMonitor = TreeExpansionMonitor.install(myActionsTree.getTree()); setTitle("Add Actions to Quick List"); init(); }
public String[] getTreeSelectedActionIds() { TreePath[] paths = myActionsTree.getTree().getSelectionPaths(); if (paths == null) return ArrayUtil.EMPTY_STRING_ARRAY; ArrayList<String> actions = new ArrayList<String>(); for (TreePath path : paths) { Object node = path.getLastPathComponent(); if (node instanceof DefaultMutableTreeNode) { DefaultMutableTreeNode defNode = (DefaultMutableTreeNode)node; Object userObject = defNode.getUserObject(); if (userObject instanceof String) { actions.add((String)userObject); } else if (userObject instanceof QuickList) { actions.add(((QuickList)userObject).getActionId()); } } } return ArrayUtil.toStringArray(actions); }
@Override public void apply(@NotNull List<QuickList> settings) throws ConfigurationException { itemPanel.apply(); editor.ensureNonEmptyNames("Quick list should have non empty name"); editor.processModifiedItems(new PairProcessor<QuickList, QuickList>() { @Override public boolean process(QuickList newItem, QuickList oldItem) { if (!oldItem.getName().equals(newItem.getName())) { keymapListener.quickListRenamed(oldItem, newItem); } return true; } }); if (isModified(settings)) { java.util.List<QuickList> result = editor.apply(); keymapListener.processCurrentKeymapChanged(result.toArray(new QuickList[result.size()])); QuickListsManager.getInstance().setQuickLists(result); } }
private void reset(final Keymap keymap, final QuickList[] allQuickLists, String filter, @Nullable KeyboardShortcut shortcut) { myKeymap = keymap; final PathsKeeper pathsKeeper = new PathsKeeper(); pathsKeeper.storePaths(); myRoot.removeAllChildren(); ActionManager actionManager = ActionManager.getInstance(); Project project = PlatformDataKeys.PROJECT.getData(DataManager.getInstance().getDataContext(myComponent)); Group mainGroup = ActionsTreeUtil.createMainGroup(project, myKeymap, allQuickLists, filter, true, filter != null && filter.length() > 0 ? ActionsTreeUtil.isActionFiltered(filter, true) : (shortcut != null ? ActionsTreeUtil.isActionFiltered(actionManager, myKeymap, shortcut) : null)); if ((filter != null && filter.length() > 0 || shortcut != null) && mainGroup.initIds().isEmpty()){ mainGroup = ActionsTreeUtil.createMainGroup(project, myKeymap, allQuickLists, filter, false, filter != null && filter.length() > 0 ? ActionsTreeUtil.isActionFiltered(filter, false) : ActionsTreeUtil.isActionFiltered(actionManager, myKeymap, shortcut)); } myRoot = ActionsTreeUtil.createNode(mainGroup); myMainGroup = mainGroup; MyModel model = (MyModel)myTree.getModel(); model.setRoot(myRoot); model.nodeStructureChanged(myRoot); pathsKeeper.restorePaths(); }
public Object getValueAt(Object value, int column) { if (!(value instanceof DefaultMutableTreeNode)) { return "???"; } if (column == 0) { return value; } else if (column == 1) { Object userObject = ((DefaultMutableTreeNode)value).getUserObject(); if (userObject instanceof QuickList) { userObject = ((QuickList)userObject).getActionId(); } if (userObject instanceof String) { Shortcut[] shortcuts = myKeymap.getShortcuts((String)userObject); return KeymapUtil.getShortcutsText(shortcuts); } else { return ""; } } else { return "???"; } }
@Nullable private String getPath(DefaultMutableTreeNode node) { final Object userObject = node.getUserObject(); if (userObject instanceof String) { String actionId = (String)userObject; final TreeNode parent = node.getParent(); if (parent instanceof DefaultMutableTreeNode) { final Object object = ((DefaultMutableTreeNode)parent).getUserObject(); if (object instanceof Group) { return ((Group)object).getActionQualifiedPath(actionId); } } return myMainGroup.getActionQualifiedPath(actionId); } if (userObject instanceof Group) { return ((Group)userObject).getQualifiedPath(); } if (userObject instanceof QuickList) { return ((QuickList)userObject).getDisplayName(); } return null; }
@Override public void quickListRenamed(final QuickList oldQuickList, final QuickList newQuickList){ for (Keymap keymap : getAllKeymaps()) { KeymapImpl impl = (KeymapImpl)keymap; String actionId = oldQuickList.getActionId(); String newActionId = newQuickList.getActionId(); Shortcut[] shortcuts = impl.getShortcuts(actionId); if (shortcuts != null) { for (Shortcut shortcut : shortcuts) { impl.removeShortcut(actionId, shortcut); impl.addShortcut(newActionId, shortcut); } } } myQuickListsModified = true; }
private static Group createQuickListsGroup(final Condition<AnAction> filtered, final String filter, final boolean forceFiltering, final QuickList[] quickLists) { Arrays.sort(quickLists, new Comparator<QuickList>() { public int compare(QuickList l1, QuickList l2) { return l1.getActionId().compareTo(l2.getActionId()); } }); Group group = new Group(KeyMapBundle.message("quick.lists.group.title"), null, null); for (QuickList quickList : quickLists) { if (filtered != null && filtered.value(ActionManagerEx.getInstanceEx().getAction(quickList.getActionId()))) { group.addQuickList(quickList); } else if (SearchUtil.isComponentHighlighted(quickList.getDisplayName(), filter, forceFiltering, null)) { group.addQuickList(quickList); } else if (filtered == null && StringUtil.isEmpty(filter)) { group.addQuickList(quickList); } } return group; }
private void updateRightPanel(final QuickList quickList) { final int index = myQuickListsList.getSelectedIndex(); if (myQuickListPanel != null && myCurrentIndex > -1 && myCurrentIndex < myQuickListsModel.getSize()) { updateList(myCurrentIndex); myKeymapListener.processCurrentKeymapChanged(getCurrentQuickListIds()); } Project project = PlatformDataKeys.PROJECT.getData(DataManager.getInstance().getDataContext(this)); myQuickListPanel = new QuickListPanel(quickList, getCurrentQuickListIds(), project); final DocumentAdapter documentAdapter = new DocumentAdapter() { protected void textChanged(DocumentEvent e) { updateList(index); } }; myQuickListPanel.addNameListener(documentAdapter); myQuickListPanel.addDescriptionListener(documentAdapter); myRightPanel.add(myQuickListPanel.getPanel(), BorderLayout.CENTER); myCurrentIndex = index; }
private void updateList(int index) { if (myQuickListPanel == null) return; QuickList oldQuickList = (QuickList)myQuickListsModel.getElementAt(index); QuickList newQuickList = createNewQuickListAt(); if (oldQuickList != null) { newQuickList.getExternalInfo().copy(oldQuickList.getExternalInfo()); } myQuickListsModel.setElementAt(newQuickList, index); if (oldQuickList != null && !newQuickList.getName().equals(oldQuickList.getName())) { myKeymapListener.quickListRenamed(oldQuickList, newQuickList); } }
private void reset(final Keymap keymap, final QuickList[] allQuickLists, String filter, @Nullable KeyboardShortcut shortcut) { myKeymap = keymap; final PathsKeeper pathsKeeper = new PathsKeeper(); pathsKeeper.storePaths(); myRoot.removeAllChildren(); ActionManager actionManager = ActionManager.getInstance(); Project project = DataManager.getInstance().getDataContext(myComponent).getData(CommonDataKeys.PROJECT); Group mainGroup = ActionsTreeUtil.createMainGroup(project, myKeymap, allQuickLists, filter, true, filter != null && filter.length() > 0 ? ActionsTreeUtil.isActionFiltered(filter, true) : (shortcut != null ? ActionsTreeUtil.isActionFiltered(actionManager, myKeymap, shortcut) : null)); if ((filter != null && filter.length() > 0 || shortcut != null) && mainGroup.initIds().isEmpty()){ mainGroup = ActionsTreeUtil.createMainGroup(project, myKeymap, allQuickLists, filter, false, filter != null && filter.length() > 0 ? ActionsTreeUtil.isActionFiltered(filter, false) : ActionsTreeUtil.isActionFiltered(actionManager, myKeymap, shortcut)); } myRoot = ActionsTreeUtil.createNode(mainGroup); myMainGroup = mainGroup; MyModel model = (MyModel)myTree.getModel(); model.setRoot(myRoot); model.nodeStructureChanged(myRoot); pathsKeeper.restorePaths(); }
public void addAll(Group group) { for (Object o : group.getChildren()) { if (o instanceof String) { addActionId((String)o); } else if (o instanceof QuickList) { addQuickList((QuickList)o); } else if (o instanceof Group) { addGroup((Group)o); } else if (o instanceof AnSeparator) { addSeparator(); } } }
@Override public void quickListRenamed(final QuickList oldQuickList, final QuickList newQuickList) { for (Keymap keymap : getAllKeymaps()) { KeymapImpl impl = (KeymapImpl)keymap; String actionId = oldQuickList.getActionId(); String newActionId = newQuickList.getActionId(); Shortcut[] shortcuts = impl.getShortcuts(actionId); if (shortcuts != null) { for (Shortcut shortcut : shortcuts) { impl.removeShortcut(actionId, shortcut); impl.addShortcut(newActionId, shortcut); } } } myQuickListsModified = true; }
@Override public void reset() { myQuickListsModel.removeAllElements(); for (QuickList list : QuickListsManager.getInstance().getAllQuickLists()) { myQuickListsModel.addElement(list); } SwingUtilities.invokeLater(new Runnable() { @Override public void run() { if (!myQuickListsModel.isEmpty()) { myQuickListsList.setSelectedIndex(0); } } }); }
private void updateRightPanel(final QuickList quickList) { final int index = myQuickListsList.getSelectedIndex(); if (myQuickListPanel != null && myCurrentIndex > -1 && myCurrentIndex < myQuickListsModel.getSize()) { updateList(myCurrentIndex); myKeymapListener.processCurrentKeymapChanged(getCurrentQuickListIds()); } myQuickListPanel = new QuickListPanel(quickList, getCurrentQuickListIds()); final DocumentAdapter documentAdapter = new DocumentAdapter() { @Override protected void textChanged(DocumentEvent e) { updateList(index); } }; myQuickListPanel.addNameListener(documentAdapter); myQuickListPanel.addDescriptionListener(documentAdapter); myRightPanel.add(myQuickListPanel.getPanel(), BorderLayout.CENTER); myCurrentIndex = index; }
@Nullable public String getSelectedActionId() { Object userObject = getSelectedObject(); if (userObject instanceof String) return (String)userObject; if (userObject instanceof QuickList) return ((QuickList)userObject).getActionId(); if (userObject instanceof Group) return ((Group)userObject).getId(); return null; }
public KeyboardShortcutDialog(Component component, String actionId, final QuickList[] quickLists) { super(component, true); setTitle(KeyMapBundle.message("keyboard.shortcut.dialog.title")); myActionId = actionId; final Project project = CommonDataKeys.PROJECT.getData(DataManager.getInstance().getDataContext(component)); myMainGroup = ActionsTreeUtil.createMainGroup(project, myKeymap, quickLists, null, false, null); //without current filter myEnableSecondKeystroke = new JCheckBox(); UIUtil.applyStyle(UIUtil.ComponentStyle.SMALL, myEnableSecondKeystroke); myEnableSecondKeystroke.setBorder(new EmptyBorder(4, 0, 0, 2)); myEnableSecondKeystroke.setFocusable(false); myKeystrokePreview = new JLabel(" "); myConflictInfoArea = new JTextArea(""); myConflictInfoArea.setFocusable(false); init(); }
@NotNull @Override public Component getListCellRendererComponent(@NotNull JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); Icon icon = null; String actionId = (String)value; if (QuickList.SEPARATOR_ID.equals(actionId)) { setText("-------------"); } else { AnAction action = ActionManager.getInstance().getAction(actionId); setText(action != null ? action.getTemplatePresentation().getText() : actionId); if (action != null) { Icon actionIcon = action.getTemplatePresentation().getIcon(); if (actionIcon != null) { icon = actionIcon; } } if (actionId.startsWith(QuickList.QUICK_LIST_PREFIX)) { icon = AllIcons.Actions.QuickList; } setIcon(ActionsTree.getEvenIcon(icon)); } return this; }
public Set<String> initIds(){ for (Object child : myChildren) { if (child instanceof String) { myIds.add((String)child); } else if (child instanceof QuickList) { myIds.add(((QuickList)child).getActionId()); } else if (child instanceof Group) { myIds.addAll(((Group)child).initIds()); } } return myIds; }
public EditQuickListDialog(Project project, QuickList list, QuickList[] allQuickLists) { super(project, true); myProject = project; myList = list; myAllQuickLists = allQuickLists; setTitle(KeyMapBundle.message("edit.quick.list.dialog.title")); init(); }
protected void doOKAction() { ListModel model = myPanel.getActionsList().getModel(); int size = model.getSize(); String[] ids = new String[size]; for (int i = 0; i < size; i++) { String actionId = (String)model.getElementAt(i); ids[i] = actionId; } myList = new QuickList(myPanel.getDisplayName(), myPanel.getDescription(), ids, myList.isReadonly()); super.doOKAction(); }
@Nullable public String getSelectedActionId() { Object userObject = getSelectedObject(); if (userObject instanceof String) return (String)userObject; if (userObject instanceof QuickList) return ((QuickList)userObject).getActionId(); return null; }
public KeyboardShortcutDialog(Component component, String actionId, final QuickList[] quickLists) { super(component, true); setTitle(KeyMapBundle.message("keyboard.shortcut.dialog.title")); myActionId = actionId; final Project project = PlatformDataKeys.PROJECT.getData(DataManager.getInstance().getDataContext(component)); myMainGroup = ActionsTreeUtil.createMainGroup(project, myKeymap, quickLists, null, false, null); //without current filter myEnableSecondKeystroke = new JCheckBox(); UIUtil.applyStyle(UIUtil.ComponentStyle.SMALL, myEnableSecondKeystroke); myEnableSecondKeystroke.setBorder(new EmptyBorder(4, 0, 0, 2)); myEnableSecondKeystroke.setFocusable(false); myKeystrokePreview = new JLabel(" "); myConflictInfoArea = new JTextArea(""); myConflictInfoArea.setFocusable(false); init(); }
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); Icon icon = null; String actionId = (String)value; if (QuickList.SEPARATOR_ID.equals(actionId)) { // TODO[vova,anton]: beautify setText("-------------"); } else { AnAction action = ActionManager.getInstance().getAction(actionId); setText(action != null ? action.getTemplatePresentation().getText() : actionId); if (action != null) { Icon actionIcon = action.getTemplatePresentation().getIcon(); if (actionIcon != null) { icon = actionIcon; } } if (actionId.startsWith(QuickList.QUICK_LIST_PREFIX)) { icon = AllIcons.Actions.QuickList; } setIcon(ActionsTree.getEvenIcon(icon)); } return this; }