@@ -80,6 +80,9 @@ def add(self, text, key="", scope="", icon="", flags=sublime.HIDDEN, region_id="
80
80
if region_id in self .region_ids :
81
81
raise Exception ("Error: ID " + region_id + " already used." )
82
82
83
+ if region_id :
84
+ self .region_ids .append (region_id )
85
+
83
86
space = (" " * int (padding ))
84
87
text = space + text + space
85
88
@@ -102,8 +105,6 @@ def add(self, text, key="", scope="", icon="", flags=sublime.HIDDEN, region_id="
102
105
self .view .run_command ("append_text_view" , args = {"text" : "\n " , "key" : "" , "scope" : "" , "icon" : "" , "flags" : sublime .HIDDEN })
103
106
104
107
self .view .set_read_only (True )
105
- if region_id :
106
- self .region_ids .append (region_id )
107
108
108
109
def addTitle (self , text , key = "" , scope = "javascriptenhancements.title" , icon = "" , flags = sublime .DRAW_EMPTY | sublime .DRAW_NO_OUTLINE , region_id = "" , padding = 2 , display_block = True , insert_point = None , replace_points = []):
109
110
space_padding = (" " * int (padding ))
@@ -113,6 +114,7 @@ def addTitle(self, text, key="", scope="javascriptenhancements.title", icon="",
113
114
114
115
self .add ("\n \n NOTE: See the keymap " )
115
116
self .addLink ("here" , "https://github.com/pichillilorenzo/JavaScriptEnhancements/wiki" , "link" )
117
+ self .add (" " )
116
118
117
119
def addSubTitle (self , text , key = "" , scope = "javascriptenhancements.subtitle" , icon = "" , flags = sublime .DRAW_EMPTY | sublime .DRAW_NO_OUTLINE , region_id = "" , padding = 1 , display_block = True , insert_point = None , replace_points = []):
118
120
self .add (text , key = key , scope = scope , icon = icon , flags = flags , region_id = region_id , padding = padding , display_block = display_block , insert_point = insert_point , replace_points = replace_points )
@@ -136,8 +138,9 @@ def addInput(self, value=" ", label=None, key="input", scope="javascriptenhancem
136
138
137
139
if label :
138
140
self .add (label )
139
- self . add ( value , key = key , scope = scope , icon = icon , flags = flags , region_id = region_id , padding = padding , display_block = display_block , insert_point = insert_point , replace_points = replace_points )
141
+
140
142
self .region_input_ids .append (region_id )
143
+ self .add (value , key = key , scope = scope , icon = icon , flags = flags , region_id = region_id , padding = padding , display_block = display_block , insert_point = insert_point , replace_points = replace_points )
141
144
142
145
def updateInput (self , value , key = "input" , scope = "javascriptenhancements.input" , icon = "" , flags = sublime .DRAW_EMPTY | sublime .DRAW_NO_OUTLINE , region_id = "" , padding = 1 , display_block = False , insert_point = None , replace_points = []):
143
146
@@ -150,6 +153,7 @@ def updateInput(self, value, key="input", scope="javascriptenhancements.input",
150
153
raise Exception ("Error: ID " + region_id + " already used." )
151
154
152
155
self .region_input_ids .append (region_id )
156
+ self .updateInputState ()
153
157
154
158
def addSelect (self , default_option , options , label = None , key = "select" , scope = "javascriptenhancements.input" , icon = "" , flags = sublime .DRAW_EMPTY | sublime .DRAW_NO_OUTLINE , region_id = "" , padding = 1 , display_block = False , insert_point = None , replace_points = []):
155
159
@@ -161,8 +165,8 @@ def addSelect(self, default_option, options, label=None, key="select", scope="ja
161
165
162
166
if label :
163
167
self .add (label )
164
- self .add (options [default_option ] + " ▼" , key = key , scope = scope , icon = icon , flags = flags , region_id = region_id , padding = padding , display_block = display_block , insert_point = insert_point , replace_points = replace_points )
165
168
self .region_input_ids .append (region_id )
169
+ self .add (options [default_option ] + " ▼" , key = key , scope = scope , icon = icon , flags = flags , region_id = region_id , padding = padding , display_block = display_block , insert_point = insert_point , replace_points = replace_points )
166
170
167
171
self .addEventListener ("drag_select" , key + "." + scope , lambda view : sublime .set_timeout_async (lambda : self .view .window ().show_quick_panel (options , lambda index : self .updateSelect (index , options , key = key , scope = scope , icon = icon , flags = flags , region_id = region_id , padding = padding , display_block = display_block , insert_point = insert_point , replace_points = replace_points ))))
168
172
@@ -171,54 +175,27 @@ def updateSelect(self, index, options, key="select", scope="javascriptenhancemen
171
175
return
172
176
173
177
self .replaceById (region_id , options [index ] + " ▼" , key = key , scope = scope , icon = icon , flags = flags , region_id = region_id , padding = padding , display_block = display_block , insert_point = insert_point , replace_points = replace_points )
178
+
179
+ if not region_id :
180
+ raise Exception ("Error: ID isn't setted." )
181
+
182
+ if region_id in self .region_input_ids :
183
+ raise Exception ("Error: ID " + region_id + " already used." )
184
+
174
185
self .region_input_ids .append (region_id )
186
+ self .updateInputState ()
175
187
176
188
def addLink (self , text , link , scope , key = "click" , icon = "" , flags = sublime .DRAW_NO_FILL | sublime .DRAW_NO_OUTLINE | sublime .DRAW_SOLID_UNDERLINE , region_id = "" , padding = 0 , display_block = False , insert_point = None , replace_points = []):
177
189
self .add (text , key = key , scope = scope , icon = icon , flags = flags , region_id = region_id , padding = padding , display_block = display_block , insert_point = insert_point , replace_points = replace_points )
178
190
179
191
self .addEventListener ("drag_select" , key + "." + scope , lambda view : sublime .active_window ().run_command ("open_url" , args = {"url" : link }))
180
192
181
- def addExplorer (self , scope , key = "click" , icon = "" , flags = sublime .DRAW_EMPTY | sublime .DRAW_NO_OUTLINE , region_id = "" , padding = 1 , display_block = False , insert_point = None , replace_points = []):
182
- self .addButton ("..." , callback = lambda view : self .openExplorer (), key = key , scope = scope , icon = icon , flags = flags , region_id = region_id , padding = padding , display_block = display_block , insert_point = insert_point , replace_points = replace_points )
183
-
184
- def openExplorer (self , path = "" ):
185
-
186
- path = path .strip ()
187
- if path :
188
- pass
189
- elif self .view_caller and self .view_caller .file_name ():
190
- path = self .view_caller .file_name ()
191
- elif self .window .folders ():
192
- path = self .window .folders ()[0 ]
193
- else :
194
- sublime .error_message ('JavaScript Enhancements: No place to open Explorer to' )
195
- return False
196
-
197
- if not os .path .isdir (path ):
198
- path = os .path .dirname (path )
193
+ def addFolderExplorer (self , scope , region_input_id , start_path = "" , key = "click" , icon = "" , flags = sublime .DRAW_EMPTY | sublime .DRAW_NO_OUTLINE , region_id = "" , padding = 1 , display_block = False , insert_point = None , replace_points = [], only_dir = False , only_file = False ):
199
194
200
- dirs = []
201
- files = []
195
+ folder_explorer = FolderExplorer (self .view , start_path = start_path , callback_choose = lambda path : self .updateInput (path , region_id = region_input_id ), only_dir = only_dir , only_file = only_file )
202
196
203
- for item in os .listdir (path ):
204
- abspath = os .path .join (path , item )
205
- is_dir = os .path .isdir (abspath )
206
- if is_dir :
207
- dirs .append (abspath )
208
- else :
209
- files .append (abspath )
210
-
211
- html = "<ul>"
212
-
213
- for d in dirs :
214
- html += "<li> DIR: <a>" + os .path .basename (d ) + "</a></li>"
215
-
216
- for f in files :
217
- html += "<li> FILE: <a>" + os .path .basename (f ) + "</a></li>"
218
-
219
- html += "</ul>"
220
- html += "<a>Choose</a>"
221
- sublime .set_timeout_async (lambda : self .view .show_popup (html , 0 , 5 , 500 , 500 ), 50 )
197
+ self .add (text = " " )
198
+ self .addButton ("..." , callback = lambda view : folder_explorer .open ( self .getInput (region_input_id ) ), key = key , scope = scope , icon = icon , flags = flags , region_id = region_id , padding = padding , display_block = display_block , insert_point = insert_point , replace_points = replace_points )
222
199
223
200
def getInput (self , region_input_id ):
224
201
region = self .view .get_regions (region_input_id )
@@ -441,6 +418,12 @@ def run(self, edit, **args):
441
418
if "region_id" in args and args .get ("region_id" ):
442
419
view .add_regions (args .get ("region_id" ), [region ], scope , icon , flags )
443
420
421
+ class EraseTextViewCommand (sublime_plugin .TextCommand ):
422
+ def run (self , edit , ** args ):
423
+ view = self .view
424
+ region = sublime .Region (0 , view .size ())
425
+ view .erase (edit , region )
426
+
444
427
class WindowViewKeypressCommand (sublime_plugin .TextCommand ):
445
428
def run (self , edit , ** args ):
446
429
view = self .view
0 commit comments