forked from Adarma/DXL
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dxl.py
67 lines (55 loc) · 2.19 KB
/
Dxl.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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import sublime
import sublime_plugin
import subprocess
import os.path
try:
# try python3 import
import winreg
except ImportError:
# fall back to python2 import
import _winreg as winreg
BASE_PATH = os.path.abspath(os.path.dirname(__file__))
def OpenDxlHelp(text):
helpFiles = [os.path.join(BASE_PATH, "Help\\dxl.chm")]
try:
doorsKey = winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, 'SOFTWARE\\Telelogic\\DOORS', 0, winreg.KEY_READ)
versionCount = winreg.QueryInfoKey(doorsKey)[0]
for index in xrange(0, versionCount):
try:
keyName = winreg.EnumKey(doorsKey, index)
configRegKey = winreg.OpenKey(doorsKey, keyName + '\\Config', 0, winreg.KEY_READ)
RegValue, RegType = winreg.QueryValueEx(configRegKey, "Help System")
helpFiles.append(os.path.join(RegValue, "dxl.chm"))
except:
pass
except:
pass
while helpFiles:
try:
helpFilePath = helpFiles.pop()
with open(helpFilePath, 'r'):
fullPath = os.path.join(BASE_PATH, "Help\\keyhh.exe") + " -#klink " + text + " " + helpFilePath
subprocess.Popen(fullPath)
sublime.status_message(text)
break
except:
pass
class DxlKeywordHelpCommand(sublime_plugin.TextCommand):
def run(self, edit):
curr_view = self.view
curr_sel = curr_view.sel()[0]
if curr_view.match_selector(curr_sel.begin(), 'source.dxl'):
word_end = curr_sel.end()
if curr_sel.empty():
word = curr_view.substr(curr_view.word(word_end)).lower()
else:
word = curr_view.substr(curr_sel).lower()
if word is None or len(word) <= 1:
sublime.status_message('No function selected')
OpenDxlHelp(word)
else:
sublime.status_message("No Help Available")
class CopyFileAsIncludeCommand(sublime_plugin.TextCommand):
def run(self, edit, change="", to=""):
sublime.set_clipboard('#include <' + self.view.file_name().replace(change, to) + '>')
sublime.status_message("Copied file path as #include")