-
Notifications
You must be signed in to change notification settings - Fork 4
/
open_context_reg_key.py
30 lines (22 loc) · 1.14 KB
/
open_context_reg_key.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import sublime
import sublime_plugin
import subprocess
IS_WINDOWS = sublime.platform() == 'windows'
class OpenContextRegKeyCommand(sublime_plugin.TextCommand):
def run(self, edit, event):
pt = self.view.window_to_text((event['x'], event['y']))
regions = self.view.find_by_selector('entity.name.section')
for region in regions:
if region.contains(pt):
startupinfo = subprocess.STARTUPINFO()
startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
startupinfo.wShowWindow = 11 # force minimized window
reg_key = self.view.substr(region)
subprocess.call('cmd /c REG ADD HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Applets\\Regedit /v LastKey /t REG_SZ /d "{}" /f && start regedit'.format(reg_key), startupinfo=startupinfo)
break
def is_enabled(self, event):
return IS_WINDOWS
def is_visible(self, event):
return self.is_enabled(event) and self.view.match_selector(self.view.window_to_text((event['x'], event['y'])), 'source.reg entity.name.section')
def want_event(self):
return True