Skip to content

Commit

Permalink
#10 + disable_keymap_actions option
Browse files Browse the repository at this point in the history
  • Loading branch information
kairyou committed Jun 19, 2015
1 parent 6392bea commit 44822b1
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 80 deletions.
26 changes: 0 additions & 26 deletions Default (Linux).sublime-keymap

This file was deleted.

26 changes: 0 additions & 26 deletions Default (OSX).sublime-keymap

This file was deleted.

26 changes: 0 additions & 26 deletions Default (Windows).sublime-keymap

This file was deleted.

26 changes: 26 additions & 0 deletions Default.sublime-keymap
@@ -0,0 +1,26 @@
[
{
"keys": ["ctrl+alt+h"], "command": "sublime_tmpl",
"args": {"type": "html"}, "context": [{"key": "sublime_tmpl.html"}]
}
,{
"keys": ["ctrl+alt+j"], "command": "sublime_tmpl",
"args": {"type": "js"}, "context": [{"key": "sublime_tmpl.js"}]
}
,{
"keys": ["ctrl+alt+c"], "command": "sublime_tmpl",
"args": {"type": "css"}, "context": [{"key": "sublime_tmpl.css"}]
}
,{
"keys": ["ctrl+alt+p"], "command": "sublime_tmpl",
"args": {"type": "php"}, "context": [{"key": "sublime_tmpl.php"}]
}
,{
"keys": ["ctrl+alt+r"], "command": "sublime_tmpl",
"args": {"type": "ruby"}, "context": [{"key": "sublime_tmpl.ruby"}]
}
,{
"keys": ["ctrl+alt++shift+p"], "command": "sublime_tmpl",
"args": {"type": "python"}, "context": [{"key": "sublime_tmpl.python"}]
}
]
11 changes: 11 additions & 0 deletions README.md
Expand Up @@ -44,6 +44,17 @@ Default key bindings
ctrl+alt+r ruby
ctrl+alt+shift+p python

**Disable shortcuts**

If you’re unhappy with default keymap, you can disable keyboard shortcuts with `disable_keymap_actions` preference of `SublimeTmpl.sublime-settings`.

Use a comma-separated list of action names which default keyboard shortcuts should be disabled. For example, if you want to disable creat `html` and `css` shortcuts, your must set the following value:

"disabled_keymap_actions": "html, css"

To disable all default shortcuts, set value to `all`.


## Features added

- custom template files
Expand Down
3 changes: 2 additions & 1 deletion SublimeTmpl.sublime-settings
Expand Up @@ -37,9 +37,10 @@
"Perl": {
"syntax": "Packages/Perl/Perl.tmLanguage"
},
"disable_keymap_actions": false, // "all"; "html,css"
"date_format" : "%Y-%m-%d %H:%M:%S",
"attr": {
"author": "Your Name" ,
"author": "Your Name",
"email": "you@example.org",
"link": "http://example.org"
}
Expand Down
26 changes: 25 additions & 1 deletion sublime-tmpl.py
Expand Up @@ -10,6 +10,7 @@
import glob
import datetime
import zipfile
import re

PACKAGE_NAME = 'SublimeTmpl'
TMLP_DIR = 'templates'
Expand All @@ -25,7 +26,7 @@
# import sys;print(sys.path)

IS_GTE_ST3 = int(sublime.version()[0]) >= 3

DISABLE_KEYMAP = None

class SublimeTmplCommand(sublime_plugin.TextCommand):

Expand All @@ -34,6 +35,10 @@ def run(self, edit, type='html'):
opts = self.get_settings(type)
tmpl = self.get_code(type)

# print('global', DISABLE_KEYMAP, IS_GTE_ST3);
if DISABLE_KEYMAP:
return False

# print(KEY_SYNTAX in opts)
self.tab = self.creat_tab(view)

Expand Down Expand Up @@ -134,6 +139,25 @@ def set_syntax(self, opts):
if KEY_FILE_EXT in opts:
v.settings().set('default_extension', opts[KEY_FILE_EXT])

class SublimeTmplEventListener(sublime_plugin.EventListener):
def on_query_context(self, view, key, operator, operand, match_all):
settings = sublime.load_settings(PACKAGE_NAME + '.sublime-settings')
disable_keymap_actions = settings.get('disable_keymap_actions', '')
# print ("key1: %s, %s" % (key, disable_keymap_actions))
global DISABLE_KEYMAP
DISABLE_KEYMAP = False;
if not key.startswith('sublime_tmpl.'):
return None
if not disable_keymap_actions: # no disabled actions
return True
elif disable_keymap_actions == 'all' or disable_keymap_actions == True: # disable all actions
DISABLE_KEYMAP = True;
return False
prefix, name = key.split('.')
ret = name not in re.split(r'\s*,\s*', disable_keymap_actions.strip())
# print(name, ret)
DISABLE_KEYMAP = True if not ret else False;
return ret

def plugin_loaded(): # for ST3 >= 3016
# global PACKAGES_PATH
Expand Down

0 comments on commit 44822b1

Please sign in to comment.