1- import sublime , sublime_plugin , sys , os
1+ import sublime , sublime_plugin , sys , os , imp
22
33sys .path .append (os .path .dirname (__file__ ))
4- from SQLToolsModels import Log , Settings , Connection , Selection , Window , View , Const , History , Storage
4+ import SQLToolsModels as STM
5+
6+ # force reloading models when update
7+ try :
8+ # python 3.0 to 3.3
9+ import imp
10+ imp .reload (STM )
11+ except Exception as e :
12+ pass
13+
14+ try :
15+ # python 3.4 and newer
16+ import importlib
17+ importlib .reload (STM )
18+ except Exception as e :
19+ pass
520
621class ST (sublime_plugin .EventListener ):
722 conn = None
@@ -13,7 +28,7 @@ class ST(sublime_plugin.EventListener):
1328
1429 @staticmethod
1530 def bootstrap ():
16- ST .connectionList = Settings .getConnections ()
31+ ST .connectionList = STM . Settings .getConnections ()
1732 ST .checkDefaultConnection ()
1833
1934 @staticmethod
@@ -42,11 +57,11 @@ def setConnection(index):
4257 ST .conn = ST .connectionList .get (connListNames [index ])
4358 ST .loadConnectionData ()
4459
45- Log .debug ('Connection {0} selected' .format (ST .conn ))
60+ STM . Log .debug ('Connection {0} selected' .format (ST .conn ))
4661
4762 @staticmethod
4863 def showConnectionMenu ():
49- ST .connectionList = Settings .getConnections ()
64+ ST .connectionList = STM . Settings .getConnections ()
5065 if len (ST .connectionList ) == 0 :
5166 sublime .message_dialog ('You need to setup your connections first.' )
5267 return
@@ -88,18 +103,18 @@ def getAutoCompleteList(self, word):
88103
89104 @staticmethod
90105 def checkDefaultConnection ():
91- default = Connection .loadDefaultConnectionName ()
106+ default = STM . Connection .loadDefaultConnectionName ()
92107 if not default :
93108 return
94109 try :
95110 ST .conn = ST .connectionList .get (default )
96111 ST .loadConnectionData ()
97112 except Exception as e :
98- Log .debug ("Invalid connection setted" )
113+ STM . Log .debug ("Invalid connection setted" )
99114
100115 @staticmethod
101116 def display (content , name = "SQLTools Result" ):
102- if not sublime .load_settings (Const .SETTINGS_FILENAME ).get ('show_result_on_window' ):
117+ if not sublime .load_settings (STM . Const .SETTINGS_FILENAME ).get ('show_result_on_window' ):
103118 resultContainer = Window ().create_output_panel (name )
104119 Window ().run_command ("show_panel" , {"panel" : "output." + name })
105120 else :
@@ -143,11 +158,11 @@ def run(self):
143158 ST .showConnectionMenu ()
144159 return
145160
146- if len (History .queries ) == 0 :
161+ if len (STM . History .queries ) == 0 :
147162 sublime .message_dialog ('History is empty.' )
148163 return
149164 try :
150- Window ().show_quick_panel (History .queries , lambda index : ST .conn .execute (History .get (index ), ST .display ) if index != - 1 else None )
165+ Window ().show_quick_panel (STM . History .queries , lambda index : ST .conn .execute (STM . History .get (index ), ST .display ) if index != - 1 else None )
151166 except Exception :
152167 pass
153168
@@ -157,20 +172,20 @@ def run(self):
157172 ST .showConnectionMenu ()
158173 return
159174
160- query = Selection .get ()
175+ query = STM . Selection .get ()
161176 ST .conn .execute (query , ST .display )
162177
163178class StSaveQuery (sublime_plugin .WindowCommand ):
164179 def run (self ):
165- Storage .promptQueryAlias ()
180+ STM . Storage .promptQueryAlias ()
166181
167182class StListQueries (sublime_plugin .WindowCommand ):
168183 def run (self ):
169184 if not ST .conn :
170185 ST .showConnectionMenu ()
171186 return
172187
173- queries = Storage .getSavedQueries ().get ('queries' )
188+ queries = STM . Storage .getSavedQueries ().get ('queries' )
174189
175190 if len (queries ) == 0 :
176191 sublime .message_dialog ('No saved queries.' )
@@ -188,7 +203,7 @@ def run(self):
188203
189204class StRemoveSavedQuery (sublime_plugin .WindowCommand ):
190205 def run (self ):
191- queries = Storage .getSavedQueries ().get ('queries' )
206+ queries = STM . Storage .getSavedQueries ().get ('queries' )
192207
193208 if len (queries ) == 0 :
194209 sublime .message_dialog ('No saved queries.' )
@@ -200,15 +215,15 @@ def run(self):
200215 queriesArray .append ([alias , query ])
201216 queriesArray .sort ()
202217 try :
203- Window ().show_quick_panel (queriesArray , lambda index : Storage .removeQuery (queriesArray [index ][0 ]) if index != - 1 else None )
218+ Window ().show_quick_panel (queriesArray , lambda index : STM . Storage .removeQuery (queriesArray [index ][0 ]) if index != - 1 else None )
204219 except Exception :
205220 pass
206221
207222class StFormat (sublime_plugin .TextCommand ):
208223 def run (self , edit ):
209- Selection .formatSql (edit )
224+ STM . Selection .formatSql (edit )
210225
211226def plugin_loaded ():
212- Log .debug (__name__ + ' loaded successfully' )
227+ STM . Log .debug (__name__ + ' loaded successfully' )
213228
214229 ST .bootstrap ()
0 commit comments