Skip to content

Commit 680e7ef

Browse files
committed
additionally monitor file to fix windows monitoring
1 parent a7e4880 commit 680e7ef

File tree

1 file changed

+15
-18
lines changed

1 file changed

+15
-18
lines changed

__init__.py

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,7 @@ def __init__(self, context, parent=None):
219219
self.watcher = QFileSystemWatcher()
220220
self.watcher.addPath(snippetPath)
221221
self.watcher.directoryChanged.connect(self.snippetDirectoryChanged)
222+
self.watcher.fileChanged.connect(self.snippetDirectoryChanged)
222223
indentation = Settings().get_string("snippets.indentation")
223224
if Settings().get_bool("snippets.syntaxHighlight"):
224225
self.edit = QCodeEditor(SyntaxHighlighter=Pylighter, delimeter = indentation)
@@ -389,6 +390,7 @@ def clearSelection(self):
389390
self.snippetDescription.setText("")
390391
self.edit.clear()
391392
self.tree.clearSelection()
393+
self.watcher.removePath(self.currentFile)
392394
self.currentFile = ""
393395

394396
def askSave(self):
@@ -427,15 +429,13 @@ def selectFile(self, new, old):
427429
return
428430
if len(new.indexes()) == 0:
429431
self.clearSelection()
430-
self.currentFile = ""
431432
self.readOnly(True)
432433
return
433434
newSelection = self.files.filePath(new.indexes()[0])
434435
self.settings.setValue("ui/snippeteditor/selected", newSelection)
435436
if QFileInfo(newSelection).isDir():
436437
self.readOnly(True)
437438
self.clearSelection()
438-
self.currentFile = ""
439439
return
440440

441441
if old and old.length() > 0:
@@ -451,7 +451,10 @@ def selectFile(self, new, old):
451451
self.tree.selectionModel().select(old, QItemSelectionModel.ClearAndSelect | QItemSelectionModel.Rows)
452452
return False
453453

454+
if self.currentFile:
455+
self.watcher.removePath(self.currentFile)
454456
self.currentFile = newSelection
457+
self.watcher.addPath(self.currentFile)
455458
self.loadSnippet()
456459

457460
def loadSnippet(self):
@@ -760,19 +763,13 @@ def launchPlugin(context):
760763
snippets = Snippets(context, parent=context.widget)
761764
snippets.show()
762765

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

Comments
 (0)