Search in sources :

Example 1 with KeyMap

use of org.rstudio.core.client.command.KeyMap in project rstudio by rstudio.

the class AddinsMRUList method finishUpdate.

private void finishUpdate(List<RAddin> addinRegistry) {
    // The list that will eventually hold the backing set
    // of addins that the dummy MRU commands will dispatch to
    List<RAddin> addinList = new ArrayList<RAddin>();
    // Map used for quick lookup of MRU addin ids
    Map<String, RAddin> addinMap = new HashMap<String, RAddin>();
    for (RAddin addin : addinRegistry) addinMap.put(addin.getId(), addin);
    // Collect addins. First, collect addins in the MRU list.
    for (String id : mruEntries_) {
        if (addinList.size() >= MRU_LIST_SIZE)
            break;
        if (addinMap.containsKey(id))
            addinList.add(addinMap.get(id));
    }
    // to the backing list.
    for (RAddin addin : addinRegistry) {
        if (addinList.size() >= MRU_LIST_SIZE)
            break;
        if (!addinList.contains(addin))
            addinList.add(addin);
    }
    // Sort the addins list, favoring addins that have
    // been recently updated.
    Collections.sort(addinList, new Comparator<RAddin>() {

        @Override
        public int compare(RAddin o1, RAddin o2) {
            int compare = 0;
            // Compare first on package name.
            compare = o1.getPackage().compareTo(o2.getPackage());
            if (compare != 0)
                return compare;
            // Then compare on actual name.
            compare = o1.getName().compareTo(o2.getName());
            if (compare != 0)
                return compare;
            return 0;
        }
    });
    // Save the list (so that the dummy commands can be routed properly)
    addinList_ = addinList;
    KeyMap addinsKeyMap = ShortcutManager.INSTANCE.getKeyMap(KeyMapType.ADDIN);
    // Populate up to 15 commands.
    for (int i = 0; i < mruCommands_.length; i++) manageCommand(mruCommands_[i], addinList_, addinsKeyMap, i);
}
Also used : RAddin(org.rstudio.studio.client.workbench.addins.Addins.RAddin) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) KeyMap(org.rstudio.core.client.command.KeyMap)

Example 2 with KeyMap

use of org.rstudio.core.client.command.KeyMap in project rstudio by rstudio.

the class AddinsCommandManager method registerBindings.

private void registerBindings(final EditorKeyBindings bindings, final CommandWithArg<EditorKeyBindings> afterLoad) {
    List<Pair<List<KeySequence>, CommandBinding>> commands = new ArrayList<Pair<List<KeySequence>, CommandBinding>>();
    RAddins rAddins = MainWindowObject.rAddins().get();
    for (String id : bindings.iterableKeys()) {
        List<KeySequence> keyList = bindings.get(id).getKeyBindings();
        RAddin addin = rAddins.get(id);
        if (addin == null)
            continue;
        CommandBinding binding = new AddinCommandBinding(addin);
        commands.add(new Pair<List<KeySequence>, CommandBinding>(keyList, binding));
    }
    KeyMap map = ShortcutManager.INSTANCE.getKeyMap(KeyMapType.ADDIN);
    for (int i = 0; i < commands.size(); i++) {
        map.setBindings(commands.get(i).first, commands.get(i).second);
    }
    if (afterLoad != null)
        afterLoad.execute(bindings);
}
Also used : RAddin(org.rstudio.studio.client.workbench.addins.Addins.RAddin) RAddins(org.rstudio.studio.client.workbench.addins.Addins.RAddins) ArrayList(java.util.ArrayList) AddinCommandBinding(org.rstudio.core.client.command.AddinCommandBinding) CommandBinding(org.rstudio.core.client.command.KeyMap.CommandBinding) AddinCommandBinding(org.rstudio.core.client.command.AddinCommandBinding) ArrayList(java.util.ArrayList) List(java.util.List) KeySequence(org.rstudio.core.client.command.KeyboardShortcut.KeySequence) Pair(org.rstudio.core.client.Pair) KeyMap(org.rstudio.core.client.command.KeyMap)

Aggregations

ArrayList (java.util.ArrayList)2 KeyMap (org.rstudio.core.client.command.KeyMap)2 RAddin (org.rstudio.studio.client.workbench.addins.Addins.RAddin)2 HashMap (java.util.HashMap)1 List (java.util.List)1 Pair (org.rstudio.core.client.Pair)1 AddinCommandBinding (org.rstudio.core.client.command.AddinCommandBinding)1 CommandBinding (org.rstudio.core.client.command.KeyMap.CommandBinding)1 KeySequence (org.rstudio.core.client.command.KeyboardShortcut.KeySequence)1 RAddins (org.rstudio.studio.client.workbench.addins.Addins.RAddins)1