forked from titoBouzout/Dictionaries
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDictionaries.py
More file actions
59 lines (45 loc) · 1.89 KB
/
Dictionaries.py
File metadata and controls
59 lines (45 loc) · 1.89 KB
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
import sublime, sublime_plugin
import fnmatch, os.path
def find_resources(pattern):
resources = []
if hasattr(sublime, 'find_resources'):
resources = sublime.find_resources(pattern)
else:
for root, dir_names, file_names in os.walk(sublime.packages_path()):
if ".git" in root:
continue
for file_name in file_names:
rel_path = os.path.relpath(os.path.join(root, file_name), sublime.packages_path())
if fnmatch.fnmatch(rel_path.lower(), "*" + pattern.lower()):
resources += [os.path.join('Packages', rel_path).replace(os.sep, "/")]
return resources
class DicSetViewLanguageCommand(sublime_plugin.TextCommand):
def run(self, edit):
items = find_resources("*.dic")
def on_done(i):
if i >= 0:
settings = self.view.settings()
settings.set("dictionary", items[i])
self.view.window().show_quick_panel(items, on_done)
class DicSetLanguageCommand(sublime_plugin.WindowCommand):
def run(self):
items = find_resources("*.dic")
def on_done(i):
if i >= 0:
settings = sublime.load_settings("Preferences.sublime-settings")
settings.set("dictionary", items[i])
sublime.save_settings("Preferences.sublime-settings")
self.window.show_quick_panel(items, on_done)
class FixBug268And295Command(sublime_plugin.EventListener):
def on_post_text_command(self, view, command_name, args):
if command_name == "ignore_word" and not 'ignore' in args:
if args['word'] == '':
view = sublime.active_window().active_view()
args['word'] = view.substr(view.word(view.sel()[0].a))
view.run_command("ignore_word", {"word": args['word'], 'ignore':True})
s = sublime.load_settings("Preferences.sublime-settings")
ignored_words = s.get("ignored_words", [])
ignored_words.append(args['word'])
s.set("ignored_words", list(set(ignored_words)))
view.settings().set("ignored_words", list(set(ignored_words)))
sublime.save_settings("Preferences.sublime-settings")