@@ -81,7 +81,7 @@ class Snippets(QDialog):
81
81
def __init__ (self , parent = None ):
82
82
super (Snippets , self ).__init__ (parent )
83
83
# Create widgets
84
- self .setWindowModality (Qt .NonModal )
84
+ self .setWindowModality (Qt .ApplicationModal )
85
85
self .title = QLabel (self .tr ("Snippet Editor" ))
86
86
self .saveButton = QPushButton (self .tr ("Save" ))
87
87
self .revertButton = QPushButton (self .tr ("Revert" ))
@@ -182,6 +182,9 @@ def __init__(self, parent=None):
182
182
self .deleteSnippetButton .clicked .connect (self .deleteSnippet )
183
183
self .newFolderButton .clicked .connect (self .newFolder )
184
184
185
+ #Read-only until new snippet
186
+ self .readOnly (True )
187
+
185
188
@staticmethod
186
189
def registerAllSnippets ():
187
190
for action in list (filter (lambda x : x .startswith ("Snippets\\ " ), UIAction .getAllRegisteredActions ())):
@@ -239,6 +242,7 @@ def selectFile(self, new, old):
239
242
return
240
243
newSelection = self .files .filePath (new .indexes ()[0 ])
241
244
if QFileInfo (newSelection ).isDir ():
245
+ self .readOnly (True )
242
246
self .clearSelection ()
243
247
return
244
248
@@ -260,6 +264,7 @@ def loadSnippet(self):
260
264
self .snippetDescription .setText (snippetDescription ) if snippetDescription else self .snippetDescription .setText ("" )
261
265
self .keySequenceEdit .setKeySequence (snippetKeys ) if snippetKeys else self .keySequenceEdit .setKeySequence (QKeySequence ("" ))
262
266
self .edit .setPlainText (snippetCode ) if snippetCode else self .edit .setPlainText ("" )
267
+ self .readOnly (False )
263
268
264
269
def newFileDialog (self ):
265
270
(snippetName , ok ) = QInputDialog .getText (self , self .tr ("Snippet Name" ), self .tr ("Snippet Name: " ))
@@ -272,8 +277,20 @@ def newFileDialog(self):
272
277
open (os .path .join (selection , snippetName ), "w" ).close ()
273
278
else :
274
279
open (os .path .join (snippetPath , snippetName ), "w" ).close ()
280
+ self .readOnly (False )
275
281
log_debug ("Snippet %s created." % snippetName )
276
282
283
+ def readOnly (self , flag ):
284
+ self .keySequenceEdit .setEnabled (not flag )
285
+ self .snippetDescription .setReadOnly (flag )
286
+ self .edit .setReadOnly (flag )
287
+ if flag :
288
+ self .snippetDescription .setDisabled (True )
289
+ self .edit .setDisabled (True )
290
+ else :
291
+ self .snippetDescription .setEnabled (True )
292
+ self .edit .setEnabled (True )
293
+
277
294
def deleteSnippet (self ):
278
295
selection = self .tree .selectedIndexes ()[::self .columns ][0 ] #treeview returns each selected element in the row
279
296
snippetName = self .files .fileName (selection )
@@ -282,6 +299,7 @@ def deleteSnippet(self):
282
299
log_debug ("Deleting snippet %s." % snippetName )
283
300
self .clearSelection ()
284
301
self .files .remove (selection )
302
+ self .registerAllSnippets ()
285
303
286
304
def snippetChanged (self ):
287
305
if (self .currentFile == "" or QFileInfo (self .currentFile ).isDir ()):
0 commit comments