Search in sources :

Example 1 with AddinsKeyBindingsChangedEvent

use of org.rstudio.studio.client.workbench.addins.AddinsKeyBindingsChangedEvent 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();
}
Also used : EditorKeyBindings(org.rstudio.core.client.command.EditorCommandManager.EditorKeyBindings) ArrayList(java.util.ArrayList) EditorKeybindingsChangedEvent(org.rstudio.core.client.events.EditorKeybindingsChangedEvent) JsArrayString(com.google.gwt.core.client.JsArrayString) RStudioKeybindingsChangedEvent(org.rstudio.core.client.events.RStudioKeybindingsChangedEvent) AddinsKeyBindingsChangedEvent(org.rstudio.studio.client.workbench.addins.AddinsKeyBindingsChangedEvent) Map(java.util.Map) HashMap(java.util.HashMap) KeySequence(org.rstudio.core.client.command.KeyboardShortcut.KeySequence)

Aggregations

JsArrayString (com.google.gwt.core.client.JsArrayString)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 EditorKeyBindings (org.rstudio.core.client.command.EditorCommandManager.EditorKeyBindings)1 KeySequence (org.rstudio.core.client.command.KeyboardShortcut.KeySequence)1 EditorKeybindingsChangedEvent (org.rstudio.core.client.events.EditorKeybindingsChangedEvent)1 RStudioKeybindingsChangedEvent (org.rstudio.core.client.events.RStudioKeybindingsChangedEvent)1 AddinsKeyBindingsChangedEvent (org.rstudio.studio.client.workbench.addins.AddinsKeyBindingsChangedEvent)1