-
Notifications
You must be signed in to change notification settings - Fork 367
/
latextools_default_settings.py
88 lines (65 loc) · 2.74 KB
/
latextools_default_settings.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import os
import sublime
import sublime_plugin
from .deprecated_command import deprecate
class LatextoolsOpenDefaultSettingsCommand(sublime_plugin.WindowCommand):
def __init__(self, *args, **kwargs):
super(LatextoolsOpenDefaultSettingsCommand, self).__init__(*args, **kwargs)
self.view = None
def run(self, **args):
file = args.get('file', 'LaTeXTools.sublime-settings')
self.view = sublime.active_window().open_file(
os.path.join(
sublime.packages_path(),
"LaTeXTools",
file
)
)
sublime.set_timeout(self.set_view_readonly, 1)
def set_view_readonly(self):
if self.view is None or self.view.is_loading():
sublime.set_timeout(self.set_view_readonly, 1)
return
self.view.set_read_only(True)
class LatextoolsOpenUserSettingsCommand(sublime_plugin.WindowCommand):
def __init__(self, *args, **kwargs):
super(LatextoolsOpenUserSettingsCommand, self).__init__(*args, **kwargs)
self.view = None
def run(self):
user_settings = os.path.join(
sublime.packages_path(),
"User",
"LaTeXTools.sublime-settings"
)
load_default = False
if not os.path.exists(user_settings):
migrate = sublime.ok_cancel_dialog(
'You do not currently have a personalized '
'LaTeXTools.sublime-settings file.\n\n'
'Create a copy of the default settings file in '
'your User directory?'
)
if migrate:
sublime.active_window().run_command('latextools_migrate')
else:
load_default = True
self.view = sublime.active_window().open_file(user_settings)
if load_default:
sublime.set_timeout(self.set_content, 1)
def set_content(self):
if self.view is None or self.view.is_loading():
sublime.set_timeout(self.set_content, 1)
return
self.view.run_command('latextools_create_empty_user_settings_file')
class LatextoolsCreateEmptyUserSettingsFileCommand(sublime_plugin.TextCommand):
def run(self, edit):
self.view.insert(edit, 0, '{\n\t\n}\n')
self.view.run_command('save')
for sel in self.view.sel():
self.view.sel().subtract(sel)
self.view.sel().add(sublime.Region(3, 3))
def is_visible(self):
return False
deprecate(globals(), 'OpenLatextoolsDefaultSettingsCommand', LatextoolsOpenDefaultSettingsCommand)
deprecate(globals(), 'OpenLatextoolsUserSettingsCommand', LatextoolsOpenUserSettingsCommand)
deprecate(globals(), 'CreateEmptyUserFile', LatextoolsCreateEmptyUserSettingsFileCommand)