use of org.rstudio.core.client.command.KeyboardShortcut.KeySequence in project rstudio by rstudio.
the class ModifyKeyboardShortcutsWidget method addColumns.
private void addColumns() {
nameColumn_ = textColumn("Name", new ValueGetter<KeyboardShortcutEntry>() {
@Override
public String getValue(KeyboardShortcutEntry object) {
return object.getName();
}
});
shortcutColumn_ = editableTextColumn("Shortcut", new ValueGetter<KeyboardShortcutEntry>() {
@Override
public String getValue(KeyboardShortcutEntry object) {
KeySequence sequence = object.getKeySequence();
return sequence == null ? "" : sequence.toString();
}
});
typeColumn_ = textColumn("Scope", new ValueGetter<KeyboardShortcutEntry>() {
@Override
public String getValue(KeyboardShortcutEntry object) {
return object.getDisplayType();
}
});
table_.setColumnWidth(typeColumn_, "160px");
}
use of org.rstudio.core.client.command.KeyboardShortcut.KeySequence in project rstudio by rstudio.
the class ModifyKeyboardShortcutsWidget method updateData.
private void updateData(List<KeyboardShortcutEntry> bindings) {
dataProvider_.setList(bindings);
// Loop through and update styling on each row.
for (int i = 0; i < bindings.size(); i++) {
KeyboardShortcutEntry binding = bindings.get(i);
if (binding.isCustomBinding() || binding.isModified()) {
TableRowElement rowEl = table_.getRowElement(i);
DomUtils.toggleClass(rowEl, RES.dataGridStyle().customBindingRow(), binding.isCustomBinding());
DomUtils.toggleClass(rowEl, RES.dataGridStyle().modifiedRow(), binding.isModified());
}
}
// something we could live with.
for (int i = 0; i < bindings.size(); i++) {
KeyboardShortcutEntry cb1 = bindings.get(i);
if (cb1.getKeySequence() == null || cb1.getKeySequence().isEmpty())
continue;
for (int j = 0; j < originalBindings_.size(); j++) {
KeyboardShortcutEntry cb2 = originalBindings_.get(j);
if (cb1.equals(cb2))
continue;
int t1 = cb1.getCommandType();
int t2 = cb2.getCommandType();
// 'dynamic' commands as handled with AppCommands
if (t1 == t2 && cb1.getContext() != cb2.getContext())
continue;
KeySequence ks1 = cb1.getKeySequence();
KeySequence ks2 = cb2.getKeySequence();
if (ks1 == null || ks2 == null || ks1.isEmpty() || ks2.isEmpty())
continue;
boolean hasConflict = ks1.equals(ks2) || ks1.startsWith(ks2, true) || ks2.startsWith(ks1, true);
if (hasConflict) {
// editor commands can be masked by AppCommands and addins
if (t1 == KeyboardShortcutEntry.TYPE_EDITOR_COMMAND && t1 != t2)
addMaskedCommandStyles(i, j, cb2);
else // addins can mask both AppCommands and editor commands
if (t2 == KeyboardShortcutEntry.TYPE_ADDIN && t1 != t2)
addMaskedCommandStyles(i, j, cb2);
else // two commands with the same binding in the same 'group' == conflict
if (t1 == t2)
addConflictCommandStyles(i, j, cb2);
}
}
}
}
use of org.rstudio.core.client.command.KeyboardShortcut.KeySequence 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.core.client.command.KeyboardShortcut.KeySequence 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.core.client.command.KeyboardShortcut.KeySequence 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