diff --git a/lib/tfw/components/source_code_event_handler.py b/lib/tfw/components/source_code_event_handler.py index 993d744..65232d2 100644 --- a/lib/tfw/components/source_code_event_handler.py +++ b/lib/tfw/components/source_code_event_handler.py @@ -63,13 +63,18 @@ class SourceCodeEventHandler(TriggerlessEventHandler): 'select': self.select, 'selectdir': self.select_dir} - self._monitor = DirectoryMonitor(directory) - self._monitor.watch() # This runs on a separate thread + self._monitor = None + self.reload_monitor() @property def monitor(self): return self._monitor + def reload_monitor(self): + if self._monitor: self._monitor.stop() + self._monitor = DirectoryMonitor(self.filemanager.workdir) + self._monitor.watch() # This runs on a separate thread + def read(self, data): try: data['content'] = self.filemanager.file_contents except PermissionError: data['content'] = 'You have no permission to open that file :(' @@ -92,9 +97,10 @@ class SourceCodeEventHandler(TriggerlessEventHandler): def select_dir(self, data): try: self.filemanager.workdir = data['directory'] + self.reload_monitor() try: self.filemanager.select_file(self.filemanager.files[0]) - data['content'] = self.filemanager.file_contents + self.read(data) except IndexError: data['content'] = 'No files in this directory :(' except EnvironmentError: