def __init__(self, window: Window, database_file: Gio.File) -> None: super().__init__() filepath = database_file.get_path() self.window = window # Reset headerbar to initial state if it already exists. self.headerbar.title.props.title = database_file.get_basename() self.install_action("clear-keyfile", None, self.on_clear_keyfile) database = self.window.unlocked_db if database: is_current = database.database_manager.path == filepath if is_current: self.database_manager = database.database_manager if not self.database_manager: self.database_manager = DatabaseManager(filepath) if gsecrets.config_manager.get_remember_composite_key(): self._set_last_used_keyfile() if gsecrets.const.IS_DEVEL: self.status_page.props.icon_name = gsecrets.const.APP_ID
def open_local_file(self, file: Gio.File): self._notifications.clear() if file is None: return def error(e): self._notifications.add_simple( _('Cannot load project: ') + str(e), Gtk.MessageType.ERROR) self.buffer.load_from_file(None) ext = os.path.splitext(file.get_basename())[1] if ext != '.tcp': error(Exception(_('Wrong file extenstion'))) return if not file.query_exists(): error( Exception( _('File "{}" is not available').format(file.get_uri()))) return try: self.buffer.load_from_file(file) except lib.CorruptedFileException as e: error(e) except lib.MissingPluginException as e: error(e) except lib.UnavailableCommandException as e: error(e) except GLib.Error as e: error(e)