From dc00fa4022b0ba8f1e75a1ae616980dfe8bd1ec0 Mon Sep 17 00:00:00 2001 From: Tito Date: Tue, 20 Aug 2013 17:45:31 -0300 Subject: [PATCH] Contribution by Chris--- --- Default.sublime-commands | 10 +++++++++ Dictionaries.py | 44 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100644 Default.sublime-commands create mode 100644 Dictionaries.py diff --git a/Default.sublime-commands b/Default.sublime-commands new file mode 100644 index 0000000..9e91689 --- /dev/null +++ b/Default.sublime-commands @@ -0,0 +1,10 @@ +[ + { + "caption": "Dictionaries: Set Language", + "command": "dic_set_language" + }, + { + "caption": "Dictionaries: Set Language (Current View)", + "command": "dic_set_view_language" + } +] \ No newline at end of file diff --git a/Dictionaries.py b/Dictionaries.py new file mode 100644 index 0000000..95590e6 --- /dev/null +++ b/Dictionaries.py @@ -0,0 +1,44 @@ +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) \ No newline at end of file