diff --git a/lib/tfw/components/source_code_event_handler.py b/lib/tfw/components/source_code_event_handler.py index 1230aa6..4823333 100644 --- a/lib/tfw/components/source_code_event_handler.py +++ b/lib/tfw/components/source_code_event_handler.py @@ -10,9 +10,9 @@ log = logging.getLogger(__name__) class FileManager: def __init__(self, working_directory, selected_file=None, exclude=()): - self._exclude, self.exclude = None, exclude + self._exclude, self.exclude = None, *exclude self._workdir, self.workdir = None, working_directory - self.filename = selected_file or self.files[0] + self._filename, self.filename = None, selected_file or self.files[0] @property def exclude(self): @@ -32,10 +32,15 @@ class FileManager: raise EnvironmentError('"{}" is not a directory!'.format(directory)) self._workdir = directory - def select_file(self, filename): + @property + def filename(self): + return self._filename + + @filename.setter + def filename(self, filename): if not filename in self.files: raise EnvironmentError('No such file in workdir!') - self.filename = filename + self._filename = filename @property def files(self): @@ -99,7 +104,7 @@ class SourceCodeEventHandler(TriggerlessEventHandler): return data def select(self, data): - try: self.filemanager.select_file(data['filename']) + try: self.filemanager.filename = data['filename'] except EnvironmentError: log.exception('Failed to select file "{}"'.format(data['filename'])) return data @@ -108,7 +113,7 @@ class SourceCodeEventHandler(TriggerlessEventHandler): self.filemanager.workdir = data['directory'] self.reload_monitor() try: - self.filemanager.select_file(self.filemanager.files[0]) + self.filemanager.filename = self.filemanager.files[0] self.read(data) except IndexError: data['content'] = 'No files in this directory :('