Last active
August 29, 2015 14:03
-
-
Save calmofthestorm/21de73b8a20760456f37 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""A command module for Dragonfly, for controlling eclipse. | |
----------------------------------------------------------------------------- | |
Licensed under the LGPL3. | |
""" | |
from dragonfly import ( | |
MappingRule, | |
AppContext, | |
IntegerRef, | |
Grammar, | |
) | |
from lib.dynamic_aenea import ( | |
DynamicContext, | |
Key, | |
) | |
from proxy_nicknames import AppContext as NixAppContext | |
import json | |
# TODO: We'd put this in a library somewhere. | |
def load_config_command_map(available_commands): | |
# TODO: derive config file from python file by default; put in some confdir | |
config = json.load(open('_app_eclipse.txt'))['commands'] | |
mapping = {} | |
for (spoken, executed) in config.iteritems(): | |
mapping[spoken] = available_commands[executed] | |
return mapping | |
rules = MappingRule( | |
mapping=load_config_command_map({ | |
# Commands: | |
"activate editor": Key("f12"), | |
"apply (fix|correction)": Key("c-1"), | |
"choose editor": Key("cs-e"), | |
"close tab": Key("c-w"), | |
"close all tab": Key("cs-w"), | |
"debug": Key("f11"), | |
"duplicate down [<n>]": Key("ca-down:%(n)d"), | |
"duplicate up [<n>]": Key("ca-up:%(n)d"), | |
"find and replace": Key("c-f"), | |
"go back": Key("a-right"), | |
"go forward": Key("a-left"), | |
"go to line": Key("c-l"), | |
"go to matching bracket": Key("cs-p"), | |
"go to source": Key("f3"), | |
"resume": Key("f8"), | |
"step in [<n>]": Key("f5/50:%(n)d"), | |
"step next [<n>]": Key("f6/50:%(n)d"), | |
"step out [<n>]": Key("f7/50:%(n)d"), | |
"previous tab [<n>]": Key("c-pgup/10:%(n)d"), | |
"next tab [<n>]": Key("c-pgdown/10:%(n)d"), | |
"terminate": Key("c-f2"), # Stop debug session. | |
"terminate all launches": Key("ca-f9"), # Will switch TTY in Linux!! | |
"toggle breakpoint": Key("cs-b"), | |
"toggle comment": Key("c-slash"), | |
"toggle (tab|editor)": Key("c-f6"), | |
"toggle expand": Key("c-m"), | |
"toggle perspective": Key("c-f8"), | |
"toggle view": Key("c-f7"), | |
"save file": Key("c-s"), | |
"save all": Key("cs-s"), | |
"show file menu": Key("apps"), | |
"show content assist": Key("c-space"), | |
"show system menu": Key("a-minus"), | |
"show shortcuts": Key("cs-l"), | |
"show file properties": Key("a-enter"), | |
"show view menu": Key("c-f10"), | |
"show editors": Key("c-e"), | |
}), | |
extras=[ | |
IntegerRef("n", 1, 100), | |
], | |
defaults={ | |
"n": 1 | |
} | |
) | |
winContext1 = AppContext(executable="javaw", title="Eclipse") | |
winContext2 = AppContext(executable="eclipse", title="Eclipse") | |
winContext = winContext1 | winContext2 | |
nixContext = NixAppContext(executable="java", title="Eclipse") | |
grammar = Grammar("Eclipse", context=DynamicContext(winContext, nixContext)) | |
grammar.add_rule(rules) | |
grammar.load() | |
def unload(): | |
"""Unload function which will be called at unload time.""" | |
global grammar | |
if grammar: | |
grammar.unload() | |
grammar = None |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"commands": { | |
"activate editor": "activate editor", | |
"apply (fix|correction)": "apply (fix|correction)", | |
"choose editor": "choose editor", | |
"close tab": "close tab", | |
"close all tab": "close all tab", | |
"debug": "debug", | |
"duplicate down [<n>]": "duplicate down [<n>]", | |
"duplicate up [<n>]": "duplicate up [<n>]", | |
"find and replace": "find and replace", | |
"go back": "go back", | |
"go forward": "go forward", | |
"go to line": "go to line", | |
"go to matching bracket": "go to matching bracket", | |
"go to source": "go to source", | |
"resume": "resume", | |
"step in [<n>]": "step in [<n>]", | |
"step next [<n>]": "step next [<n>]", | |
"step out [<n>]": "step out [<n>]", | |
"previous tab [<n>]": "previous tab [<n>]", | |
"next tab [<n>]": "next tab [<n>]", | |
"terminate": "terminate", | |
"terminate all launches": "terminate all launches", | |
"toggle breakpoint": "toggle breakpoint", | |
"toggle comment": "toggle comment", | |
"toggle (tab|editor)": "toggle (tab|editor)", | |
"toggle expand": "toggle expand", | |
"toggle perspective": "toggle perspective", | |
"toggle view": "toggle view", | |
"save file": "save file", | |
"save all": "save all", | |
"show file menu": "show file menu", | |
"show content assist": "show content assist", | |
"show system menu": "show system menu", | |
"show shortcuts": "show shortcuts", | |
"show file properties": "show file properties", | |
"show view menu": "show view menu", | |
"show editors": "show editors" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment