use of org.rstudio.core.client.events.EditorKeybindingsChangedEvent 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();
}
Aggregations