-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathSettings.py
57 lines (44 loc) · 1.42 KB
/
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
import sublime, sublime_plugin
from . import QCon as Q
class Settings():
package = {}
def save(self):
sublime.save_settings('sublime-q.sublime-settings')
def add_connection(self, qcon):
con_dicts = self.get('connections')
if not self.has_connection(qcon):
con_dicts.insert(0, qcon.toDict()) #then add to top
self.set('connections', con_dicts)
self.save()
def delete_connection(self, qcon):
con_dicts = self.get('connections')
con_dicts = list(filter(lambda x: not qcon.equals(x), con_dicts))
self.set('connections', con_dicts)
self.save()
def move_to_top(self, qcon):
self.delete_connection(qcon)
self.add_connection(qcon)
def update_connection(self, qcon, new_qcon):
con_dicts = self.get('connections')
for i, c in enumerate(con_dicts): #modify existing qcon
if qcon.equals(c):
con_dicts[i] = new_qcon.toDict()
self.package.set('connections', con_dicts)
self.save()
def has_connection(self, qcon):
con_dicts = self.get('connections')
for c in con_dicts: #modify existing qcon
if qcon.equals(c):
return True
return False
def get(self, key):
if not self.package:
self.package = sublime.load_settings('sublime-q.sublime-settings')
return self.package.get(key)
def set(self, key, value):
self.package.set(key, value)
#actual use
def default_new_connection(self):
return self.get('default_new_connection')
def get_connections(self):
return self.get('connections') or []