Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #
- # This file is part of Dragonfly.
- # (c) Copyright 2007, 2008 by Christo Butcher
- # Licensed under the LGPL.
- #
- # Dragonfly is free software: you can redistribute it and/or modify it
- # under the terms of the GNU Lesser General Public License as published
- # by the Free Software Foundation, either version 3 of the License, or
- # (at your option) any later version.
- #
- # Dragonfly is distributed in the hope that it will be useful, but
- # WITHOUT ANY WARRANTY; without even the implied warranty of
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- # Lesser General Public License for more details.
- #
- # You should have received a copy of the GNU Lesser General Public
- # License along with Dragonfly. If not, see
- # <http://www.gnu.org/licenses/>.
- #
- # file based on modified https://github.com/t4ngo/dragonfly-modules/blob/master/command-modules/notepad_example.py
- """
- This module is a simple example of Dragonfly use.
- It shows how to use Dragonfly's Grammar, AppContext, and MappingRule
- classes. This module can be activated in the same way as other
- Natlink macros by placing it in the "My Documents\Natlink folder" or
- "Program Files\NetLink/MacroSystem".
- """
- print("vscode grammar loaded")
- from dragonfly import (Grammar, AppContext, MappingRule, Dictation,
- Key, Text, IntegerRef, Integer)
- grammar_context = AppContext(executable="code")
- grammar = Grammar("vscode", context=grammar_context)
- #----------------------------------------------------------
- # general
- #----------------------------------------------------------
- general = MappingRule(
- name="general",
- mapping={
- "palette": Key("cs-p"),
- "quick open": Key("c-p"),
- "open file": Key("c-o"),
- "new window": Key("cs-n"),
- "close window": Key("cs-w"),
- "open settings": Key("c-comma"),
- },
- extras=[
- Dictation("text"),
- ],
- )
- #----------------------------------------------------------
- # editing
- #----------------------------------------------------------
- editing = MappingRule(
- name="editing",
- mapping={
- "cut": Key("c-x"),
- "copy": Key("c-c"),
- "paste": Key("c-v"),
- "move line up": Key("a-up"),
- "move line down": Key("a-down"),
- "copy line up": Key("sa-up"),
- "copy line down": Key("sa-down"),
- "delete line": Key("cs-k"),
- "insert below": Key("c-enter"),
- "insert above": Key("cs-enter"),
- "jump bracket": Key("cs-backslash"),
- "indent": Key("c-]"),
- "outdent": Key("c-["),
- "home": Key("home"),
- "end": Key("end"),
- "top": Key("c-home"),
- "bottom": Key("c-end"),
- "line up": Key("c-up"),
- "line down": Key("c-down"),
- "scroll up": Key("a-pgup"),
- "scroll down": Key("a-pgdown"),
- "fold": Key("cs-["),
- "unfold": Key("cs-]"),
- "comment": Key("c-slash"),
- "block comment": Key("sa-a"),
- },
- extras=[
- Dictation("text"),
- ],
- )
- #----------------------------------------------------------
- # navigation
- #----------------------------------------------------------
- navigation = MappingRule(
- name="navigation",
- mapping={
- "jump to <n>": Key("c-g") + Text("%(n)d") + Key("enter"),
- "go to <text>": Key("c-p") + Text("%(text)s") + Key("enter"),
- },
- extras=[
- IntegerRef("n", 1, 9999),
- Integer("n", 1, 9999),
- Dictation("text"),
- ]
- )
- #----------------------------------------------------------
- # search and replace
- #----------------------------------------------------------
- search = MappingRule(
- name="search",
- mapping={
- "cut loop": Key("c-x"),
- },
- extras=[
- Dictation("text"),
- ],
- )
- #----------------------------------------------------------
- # multi-cursor and selection
- #----------------------------------------------------------
- cursor = MappingRule(
- name="cursor-selection",
- mapping={
- "cut loop": Key("c-x"),
- },
- extras=[
- Dictation("text"),
- ],
- )
- #----------------------------------------------------------
- # Rich languages editing
- #----------------------------------------------------------
- richediting = MappingRule(
- name="rich-editing",
- mapping={
- "cut loop": Key("c-x"),
- },
- extras=[
- Dictation("text"),
- ],
- )
- #----------------------------------------------------------
- # editor management
- #----------------------------------------------------------
- editor_management = MappingRule(
- name="editor-management",
- mapping={
- "cut loop": Key("c-x"),
- },
- extras=[
- Dictation("text"),
- ],
- )
- #----------------------------------------------------------
- # file management
- #----------------------------------------------------------
- file_management = MappingRule(
- name="file-management",
- mapping={
- "cut loop": Key("c-x"),
- },
- extras=[
- Dictation("text"),
- ],
- )
- #----------------------------------------------------------
- # display
- #----------------------------------------------------------
- display = MappingRule(
- name="display",
- mapping={
- "cut loop": Key("c-x"),
- },
- extras=[
- Dictation("text"),
- ],
- )
- #----------------------------------------------------------
- # debug
- #----------------------------------------------------------
- debug = MappingRule(
- name="debug",
- mapping={
- "cut loop": Key("c-x"),
- },
- extras=[
- Dictation("text"),
- ],
- )
- #----------------------------------------------------------
- # terminal
- #----------------------------------------------------------
- terminal = MappingRule(
- name="terminal",
- mapping={
- "cut loop": Key("c-x"),
- },
- extras=[
- Dictation("text"),
- ],
- )
- # Add the action rule to the grammar instance.
- grammar.add_rule(general)
- grammar.add_rule(editing)
- grammar.add_rule(navigation)
- grammar.add_rule(search)
- grammar.add_rule(cursor)
- grammar.add_rule(editing)
- grammar.add_rule(editor_management)
- grammar.add_rule(file_management)
- grammar.add_rule(display)
- grammar.add_rule(debug)
- grammar.add_rule(terminal)
- #---------------------------------------------------------------------------
- # Load the grammar instance and define how to unload it.
- grammar.load()
- # Unload function which will be called by natlink at unload time.
- def unload():
- global grammar
- if grammar: grammar.unload()
- grammar = None
Advertisement
Add Comment
Please, Sign In to add comment