@@ -219,6 +219,7 @@ def __init__(self, context, parent=None):
219
219
self .watcher = QFileSystemWatcher ()
220
220
self .watcher .addPath (snippetPath )
221
221
self .watcher .directoryChanged .connect (self .snippetDirectoryChanged )
222
+ self .watcher .fileChanged .connect (self .snippetDirectoryChanged )
222
223
indentation = Settings ().get_string ("snippets.indentation" )
223
224
if Settings ().get_bool ("snippets.syntaxHighlight" ):
224
225
self .edit = QCodeEditor (SyntaxHighlighter = Pylighter , delimeter = indentation )
@@ -389,6 +390,7 @@ def clearSelection(self):
389
390
self .snippetDescription .setText ("" )
390
391
self .edit .clear ()
391
392
self .tree .clearSelection ()
393
+ self .watcher .removePath (self .currentFile )
392
394
self .currentFile = ""
393
395
394
396
def askSave (self ):
@@ -427,15 +429,13 @@ def selectFile(self, new, old):
427
429
return
428
430
if len (new .indexes ()) == 0 :
429
431
self .clearSelection ()
430
- self .currentFile = ""
431
432
self .readOnly (True )
432
433
return
433
434
newSelection = self .files .filePath (new .indexes ()[0 ])
434
435
self .settings .setValue ("ui/snippeteditor/selected" , newSelection )
435
436
if QFileInfo (newSelection ).isDir ():
436
437
self .readOnly (True )
437
438
self .clearSelection ()
438
- self .currentFile = ""
439
439
return
440
440
441
441
if old and old .length () > 0 :
@@ -451,7 +451,10 @@ def selectFile(self, new, old):
451
451
self .tree .selectionModel ().select (old , QItemSelectionModel .ClearAndSelect | QItemSelectionModel .Rows )
452
452
return False
453
453
454
+ if self .currentFile :
455
+ self .watcher .removePath (self .currentFile )
454
456
self .currentFile = newSelection
457
+ self .watcher .addPath (self .currentFile )
455
458
self .loadSnippet ()
456
459
457
460
def loadSnippet (self ):
@@ -760,19 +763,13 @@ def launchPlugin(context):
760
763
snippets = Snippets (context , parent = context .widget )
761
764
snippets .show ()
762
765
763
- if __name__ == '__main__' :
764
- app = QApplication (sys .argv )
765
- snippets = Snippets (None )
766
- snippets .show ()
767
- sys .exit (app .exec_ ())
768
- else :
769
- Snippets .registerAllSnippets ()
770
- UIAction .registerAction ("Snippets\\ Snippet Editor..." )
771
- UIAction .registerAction ("Snippets\\ Rerun Last Snippet" )
772
- UIAction .registerAction ("Snippets\\ Reload All Snippets" )
773
- UIActionHandler .globalActions ().bindAction ("Snippets\\ Snippet Editor..." , UIAction (launchPlugin ))
774
- UIActionHandler .globalActions ().bindAction ("Snippets\\ Rerun Last Snippet" , UIAction (rerunLastSnippet ))
775
- UIActionHandler .globalActions ().bindAction ("Snippets\\ Reload All Snippets" , UIAction (reloadActions ))
776
- Menu .mainMenu ("Plugins" ).addAction ("Snippets\\ Snippet Editor..." , "Snippet" )
777
- Menu .mainMenu ("Plugins" ).addAction ("Snippets\\ Rerun Last Snippet" , "Snippet" )
778
- Menu .mainMenu ("Plugins" ).addAction ("Snippets\\ Reload All Snippets" , "Snippet" )
766
+ Snippets .registerAllSnippets ()
767
+ UIAction .registerAction ("Snippets\\ Snippet Editor..." )
768
+ UIAction .registerAction ("Snippets\\ Rerun Last Snippet" )
769
+ UIAction .registerAction ("Snippets\\ Reload All Snippets" )
770
+ UIActionHandler .globalActions ().bindAction ("Snippets\\ Snippet Editor..." , UIAction (launchPlugin ))
771
+ UIActionHandler .globalActions ().bindAction ("Snippets\\ Rerun Last Snippet" , UIAction (rerunLastSnippet ))
772
+ UIActionHandler .globalActions ().bindAction ("Snippets\\ Reload All Snippets" , UIAction (reloadActions ))
773
+ Menu .mainMenu ("Plugins" ).addAction ("Snippets\\ Snippet Editor..." , "Snippet" )
774
+ Menu .mainMenu ("Plugins" ).addAction ("Snippets\\ Rerun Last Snippet" , "Snippet" )
775
+ Menu .mainMenu ("Plugins" ).addAction ("Snippets\\ Reload All Snippets" , "Snippet" )
0 commit comments