mirror of
https://github.com/avatao-content/baseimage-tutorial-framework
synced 2024-11-22 19:41:32 +00:00
Refactor DirectoryMonitor handling in SourceCodeEventHandler
This commit is contained in:
parent
3b241a3930
commit
0e4be3c22f
@ -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:
|
||||
|
Loading…
Reference in New Issue
Block a user