use of org.rstudio.core.client.command.KeyboardShortcut.KeySequence in project rstudio by rstudio.
the class ModifyKeyboardShortcutsWidget method applyChanges.
private void applyChanges() {
// Build up command diffs for save after application
final EditorKeyBindings editorBindings = EditorKeyBindings.create();
final EditorKeyBindings appBindings = EditorKeyBindings.create();
final EditorKeyBindings addinBindings = EditorKeyBindings.create();
// Loop through all changes and apply based on type
for (Map.Entry<KeyboardShortcutEntry, KeyboardShortcutEntry> entry : changes_.entrySet()) {
KeyboardShortcutEntry newBinding = entry.getValue();
String id = newBinding.getId();
// Get all commands with this ID.
List<KeyboardShortcutEntry> bindingsWithId = new ArrayList<KeyboardShortcutEntry>();
for (KeyboardShortcutEntry binding : originalBindings_) if (binding.getId().equals(id))
bindingsWithId.add(binding);
// Collect all shortcuts.
List<KeySequence> keys = new ArrayList<KeySequence>();
for (KeyboardShortcutEntry binding : bindingsWithId) keys.add(binding.getKeySequence());
int commandType = newBinding.getCommandType();
if (commandType == KeyboardShortcutEntry.TYPE_RSTUDIO_COMMAND)
appBindings.setBindings(id, keys);
else if (commandType == KeyboardShortcutEntry.TYPE_EDITOR_COMMAND)
editorBindings.setBindings(id, keys);
else if (commandType == KeyboardShortcutEntry.TYPE_ADDIN)
addinBindings.setBindings(id, keys);
}
// Tell satellites that they need to update bindings.
appCommands_.addBindingsAndSave(appBindings, new CommandWithArg<EditorKeyBindings>() {
@Override
public void execute(EditorKeyBindings bindings) {
events_.fireEventToAllSatellites(new RStudioKeybindingsChangedEvent(bindings));
}
});
editorCommands_.addBindingsAndSave(editorBindings, new CommandWithArg<EditorKeyBindings>() {
@Override
public void execute(EditorKeyBindings bindings) {
events_.fireEventToAllSatellites(new EditorKeybindingsChangedEvent(bindings));
}
});
addins_.addBindingsAndSave(addinBindings, new CommandWithArg<EditorKeyBindings>() {
@Override
public void execute(EditorKeyBindings bindings) {
events_.fireEvent(new AddinsKeyBindingsChangedEvent(bindings));
}
});
closeDialog();
}
use of org.rstudio.core.client.command.KeyboardShortcut.KeySequence in project rstudio by rstudio.
the class ModifyKeyboardShortcutsWidget method editableTextColumn.
private Column<KeyboardShortcutEntry, String> editableTextColumn(String name, final ValueGetter<KeyboardShortcutEntry> getter) {
EditTextCell editTextCell = new EditTextCell() {
@Override
public void onBrowserEvent(final Context context, final Element parent, final String value, final NativeEvent event, final ValueUpdater<String> updater) {
// handler.
if (event.getType().equals("keyup") && event.getKeyCode() == KeyCodes.KEY_ESCAPE) {
parent.getFirstChildElement().blur();
return;
}
super.onBrowserEvent(context, parent, value, event, updater);
}
};
Column<KeyboardShortcutEntry, String> column = new Column<KeyboardShortcutEntry, String>(editTextCell) {
@Override
public String getValue(KeyboardShortcutEntry binding) {
return getter.getValue(binding);
}
};
column.setFieldUpdater(new FieldUpdater<KeyboardShortcutEntry, String>() {
@Override
public void update(int index, KeyboardShortcutEntry binding, String value) {
KeySequence keys = KeySequence.fromShortcutString(value);
// adding a new key sequence.
if (keys.equals(binding.getOriginalKeySequence())) {
changes_.remove(binding);
binding.restoreOriginalKeySequence();
} else {
KeyboardShortcutEntry newBinding = new KeyboardShortcutEntry(binding.getId(), binding.getName(), keys, binding.getCommandType(), true, binding.getContext());
changes_.put(binding, newBinding);
binding.setKeySequence(keys);
}
table_.setKeyboardSelectedColumn(0);
updateData(dataProvider_.getList());
}
});
column.setSortable(true);
table_.addColumn(column, new TextHeader(name));
return column;
}
use of org.rstudio.core.client.command.KeyboardShortcut.KeySequence in project rstudio by rstudio.
the class ShortcutManager method register.
public void register(int m1, int k1, int m2, int k2, AppCommand command, String groupName, String title, String disableModes) {
KeySequence sequence = new KeySequence();
sequence.add(k1, m1);
sequence.add(k2, m2);
register(sequence, command, groupName, title, disableModes);
}
use of org.rstudio.core.client.command.KeyboardShortcut.KeySequence in project rstudio by rstudio.
the class UserCommandManager method onRegisterUserCommand.
private void onRegisterUserCommand(RegisterUserCommandEvent event) {
final String name = event.getData().getName();
JsArrayString shortcutStrings = event.getData().getShortcuts();
for (int i = 0; i < shortcutStrings.length(); i++) {
String shortcutString = shortcutStrings.get(i);
KeySequence sequence = KeySequence.fromShortcutString(shortcutString);
assert sequence != null : "Failed to parse string '" + shortcutString + "'";
KeyboardShortcut shortcut = new KeyboardShortcut(sequence);
UserCommand command = new UserCommand(name, new Command() {
@Override
public void execute() {
events_.fireEvent(new ExecuteUserCommandEvent(name));
}
});
commandMap_.put(shortcut, command);
}
}
use of org.rstudio.core.client.command.KeyboardShortcut.KeySequence in project rstudio by rstudio.
the class ModifyKeyboardShortcutsWidget method sort.
private void sort(List<KeyboardShortcutEntry> data, final int column, final boolean ascending) {
Collections.sort(data, new Comparator<KeyboardShortcutEntry>() {
@Override
public int compare(KeyboardShortcutEntry o1, KeyboardShortcutEntry o2) {
int result = 0;
if (column == 0) {
result = o1.getName().compareTo(o2.getName());
} else if (column == 1) {
KeySequence k1 = o1.getKeySequence();
KeySequence k2 = o2.getKeySequence();
if (k1 == null && k2 == null)
result = 0;
else if (k1 == null)
result = 1;
else if (k2 == null)
result = -1;
else
result = k1.toString().compareTo(k2.toString());
} else if (column == 2) {
result = o1.getContext().toString().compareTo(o2.getContext().toString());
}
return ascending ? result : -result;
}
});
}
Aggregations