use of org.rstudio.studio.client.workbench.addins.Addins.RAddin in project rstudio by rstudio.
the class BrowseAddinsDialog method addColumns.
private void addColumns() {
// Package ----
pkgColumn_ = new TextColumn<RAddin>() {
@Override
public String getValue(RAddin addin) {
return addin.getPackage();
}
};
pkgColumn_.setSortable(true);
table_.addColumn(pkgColumn_, new TextHeader("Package"));
table_.setColumnWidth(pkgColumn_, "120px");
// Name ----
nameColumn_ = new TextColumn<RAddin>() {
@Override
public String getValue(RAddin addin) {
return StringUtil.truncate(addin.getName(), 120, "...");
}
};
nameColumn_.setSortable(true);
table_.addColumn(nameColumn_, new TextHeader("Name"));
table_.setColumnWidth(nameColumn_, "120px");
// Description ----
descColumn_ = new TextColumn<RAddin>() {
@Override
public String getValue(RAddin addin) {
return addin.getDescription();
}
};
descColumn_.setSortable(true);
table_.addColumn(descColumn_, new TextHeader("Description"));
table_.addColumnSortHandler(new ColumnSortEvent.Handler() {
@Override
public void onColumnSort(ColumnSortEvent event) {
int index = -1;
if (event.getColumn().equals(pkgColumn_))
index = 0;
else if (event.getColumn().equals(nameColumn_))
index = 1;
else if (event.getColumn().equals(descColumn_))
index = 2;
if (index == -1)
return;
sort(index, event.isSortAscending());
}
});
}
use of org.rstudio.studio.client.workbench.addins.Addins.RAddin in project rstudio by rstudio.
the class ModifyKeyboardShortcutsWidget method collectShortcuts.
private void collectShortcuts() {
final List<KeyboardShortcutEntry> bindings = new ArrayList<KeyboardShortcutEntry>();
SerializedCommandQueue queue = new SerializedCommandQueue();
// Load addins discovered as part of package exports. This registers
// the addin, with the actual keybinding to be registered later,
// if discovered.
queue.addCommand(new SerializedCommand() {
@Override
public void onExecute(final Command continuation) {
RAddins rAddins = addins_.getRAddins();
for (String key : JsUtil.asIterable(rAddins.keys())) {
RAddin addin = rAddins.get(key);
bindings.add(new KeyboardShortcutEntry(addin.getPackage() + "::" + addin.getBinding(), addin.getName(), new KeySequence(), KeyboardShortcutEntry.TYPE_ADDIN, false, AppCommand.Context.Addin));
}
continuation.execute();
}
});
// Load saved addin bindings
queue.addCommand(new SerializedCommand() {
@Override
public void onExecute(final Command continuation) {
addins_.loadBindings(new CommandWithArg<EditorKeyBindings>() {
@Override
public void execute(EditorKeyBindings addinBindings) {
for (String commandId : addinBindings.iterableKeys()) {
EditorKeyBinding addinBinding = addinBindings.get(commandId);
for (KeyboardShortcutEntry binding : bindings) {
if (binding.getId() == commandId) {
List<KeySequence> keys = addinBinding.getKeyBindings();
if (keys.size() >= 1)
binding.setDefaultKeySequence(keys.get(0));
if (keys.size() >= 2) {
for (int i = 1; i < keys.size(); i++) {
bindings.add(new KeyboardShortcutEntry(binding.getId(), binding.getName(), keys.get(i), KeyboardShortcutEntry.TYPE_ADDIN, false, AppCommand.Context.Addin));
}
}
}
}
}
continuation.execute();
}
});
}
});
// Ace loading command
queue.addCommand(new SerializedCommand() {
@Override
public void onExecute(final Command continuation) {
// Ace Commands
JsArray<AceCommand> aceCommands = editorCommands_.getCommands();
for (int i = 0; i < aceCommands.length(); i++) {
AceCommand command = aceCommands.get(i);
JsArrayString shortcuts = command.getBindingsForCurrentPlatform();
if (shortcuts != null) {
String id = command.getInternalName();
String name = command.getDisplayName();
boolean custom = command.isCustomBinding();
for (int j = 0; j < shortcuts.length(); j++) {
String shortcut = shortcuts.get(j);
KeySequence keys = KeySequence.fromShortcutString(shortcut);
int type = KeyboardShortcutEntry.TYPE_EDITOR_COMMAND;
bindings.add(new KeyboardShortcutEntry(id, name, keys, type, custom, AppCommand.Context.Editor));
}
}
}
continuation.execute();
}
});
// RStudio commands
queue.addCommand(new SerializedCommand() {
@Override
public void onExecute(final Command continuation) {
// RStudio Commands
appCommands_.loadBindings(new CommandWithArg<EditorKeyBindings>() {
@Override
public void execute(final EditorKeyBindings customBindings) {
Map<String, AppCommand> commands = commands_.getCommands();
for (Map.Entry<String, AppCommand> entry : commands.entrySet()) {
AppCommand command = entry.getValue();
if (isExcludedCommand(command))
continue;
String id = command.getId();
String name = getAppCommandName(command);
int type = KeyboardShortcutEntry.TYPE_RSTUDIO_COMMAND;
boolean isCustom = customBindings.hasKey(id);
List<KeySequence> keySequences = new ArrayList<KeySequence>();
if (isCustom)
keySequences = customBindings.get(id).getKeyBindings();
else
keySequences.add(command.getKeySequence());
for (KeySequence keys : keySequences) {
KeyboardShortcutEntry binding = new KeyboardShortcutEntry(id, name, keys, type, isCustom, command.getContext());
bindings.add(binding);
}
}
continuation.execute();
}
});
}
});
// Sort and finish up
queue.addCommand(new SerializedCommand() {
@Override
public void onExecute(final Command continuation) {
Collections.sort(bindings, new Comparator<KeyboardShortcutEntry>() {
@Override
public int compare(KeyboardShortcutEntry o1, KeyboardShortcutEntry o2) {
if (o1.getContext() != o2.getContext())
return o1.getContext().compareTo(o2.getContext());
return o1.getName().compareTo(o2.getName());
}
});
originalBindings_ = bindings;
updateData(bindings);
continuation.execute();
}
});
queue.addCommand(new SerializedCommand() {
@Override
public void onExecute(Command continuation) {
if (initialFilterText_ != null) {
filterWidget_.setText(initialFilterText_);
filter();
}
continuation.execute();
}
});
// Exhaust the queue
queue.run();
}
use of org.rstudio.studio.client.workbench.addins.Addins.RAddin 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.studio.client.workbench.addins.Addins.RAddin in project rstudio by rstudio.
the class AddinsMRUList method manageCommand.
private void manageCommand(AppCommand command, List<RAddin> addinsList, KeyMap keyMap, int index) {
if (index >= addinsList.size()) {
command.setEnabled(false);
command.setVisible(false);
return;
}
RAddin addin = addinsList.get(index);
command.setEnabled(true);
command.setVisible(true);
String description = addin.getDescription() + " [" + addin.getId() + "]";
command.setDesc(description);
String name = StringUtil.truncate(addin.getName(), 25, "...");
command.setLabel(name);
List<KeySequence> keys = keyMap.getBindings(addin.getId());
if (keys != null && !keys.isEmpty())
command.setShortcut(new KeyboardShortcut(keys.get(0)));
else
command.setShortcut(null);
}
use of org.rstudio.studio.client.workbench.addins.Addins.RAddin 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