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);
}
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);
}
Aggregations