Implement support to change working directories in SourceCodeEventHandler

This commit is contained in:
Kristóf Tóth 2018-03-09 08:45:30 +01:00
parent 7858caf51a
commit 9e4fe87d84

View File

@ -58,11 +58,10 @@ class SourceCodeEventHandler(TriggerlessEventHandler):
super().__init__(key)
self.filemanager = FileManager(directory, selected_file=selected_file, exclude=exclude)
self.commands = {
'read': self.read,
'write': self.write,
'select': self.select
}
self.commands = {'read': self.read,
'write': self.write,
'select': self.select,
'selectdir': self.select_dir}
self._monitor = DirectoryMonitor(directory)
self._monitor.watch() # This runs on a separate thread
@ -90,6 +89,11 @@ class SourceCodeEventHandler(TriggerlessEventHandler):
except EnvironmentError: log.exception('Failed to select file "{}"'.format(data['filename']))
return data
def select_dir(self, data):
try: self.filemanager.workdir = data['directory']
except EnvironmentError: log.exception('Failed to select directory "{}"'.format(data['directory']))
return data
def attach_fileinfo(self, data):
data['filename'] = self.filemanager.filename
data['files'] = self.filemanager.files