From b51b1ef85e19262e4dfcb0df2b190df54e317d68 Mon Sep 17 00:00:00 2001 From: Divyansh Singh Date: Wed, 5 Apr 2023 16:50:42 +0530 Subject: [PATCH] Save list view as setting. By @diivi (#1621) * feat: add a setting for files list views * separate logic from data class * make mode optional * rename display mode methods * refactor * move code above connect signals comment * reorder code --------- Co-authored-by: yfprojects <62463991+real-yfprojects@users.noreply.github.com> Co-authored-by: Manu <3916435+m3nu@users.noreply.github.com> --- src/vorta/store/settings.py | 12 ++++++++++++ src/vorta/views/diff_result.py | 7 +++++++ src/vorta/views/extract_dialog.py | 7 +++++++ src/vorta/views/partials/treemodel.py | 6 ++---- 4 files changed, 28 insertions(+), 4 deletions(-) diff --git a/src/vorta/store/settings.py b/src/vorta/store/settings.py index bcc358c92..e9761181e 100644 --- a/src/vorta/store/settings.py +++ b/src/vorta/store/settings.py @@ -100,6 +100,18 @@ def get_misc_settings() -> List[Dict[str, str]]: 'type': 'internal', 'label': 'Previous window height', }, + { + 'key': 'diff_files_display_mode', + 'str_value': '0', + 'type': 'internal', + 'label': 'Diff dialog display mode', + }, + { + 'key': 'extract_files_display_mode', + 'str_value': '0', + 'type': 'internal', + 'label': 'Extract dialog display mode', + }, { 'key': 'sourcetab_sort_column', 'str_value': '0', diff --git a/src/vorta/views/diff_result.py b/src/vorta/views/diff_result.py index cf8b9369d..c9aae4fdb 100644 --- a/src/vorta/views/diff_result.py +++ b/src/vorta/views/diff_result.py @@ -9,6 +9,7 @@ from PyQt5.QtCore import QDateTime, QLocale, QMimeData, QModelIndex, QPoint, Qt, QThread, QUrl from PyQt5.QtGui import QColor, QKeySequence from PyQt5.QtWidgets import QApplication, QHeaderView, QMenu, QShortcut, QTreeView +from vorta.store.models import SettingsModel from vorta.utils import get_asset, pretty_bytes, uses_dark_mode from vorta.views.partials.treemodel import ( FileSystemItem, @@ -98,6 +99,8 @@ def __init__(self, archive_newer, archive_older, model: 'DiffTree'): self.archiveNameLabel_2.setText(f'{archive_older.name}') self.comboBoxDisplayMode.currentIndexChanged.connect(self.change_display_mode) + diff_result_display_mode = SettingsModel.get(key='diff_files_display_mode').str_value + self.comboBoxDisplayMode.setCurrentIndex(int(diff_result_display_mode)) self.bFoldersOnTop.toggled.connect(self.sortproxy.keepFoldersOnTop) self.bCollapseAll.clicked.connect(self.treeView.collapseAll) @@ -183,6 +186,10 @@ def change_display_mode(self, selection: int): else: raise Exception("Unknown item in comboBoxDisplayMode with index {}".format(selection)) + SettingsModel.update({SettingsModel.str_value: str(selection)}).where( + SettingsModel.key == 'diff_files_display_mode' + ).execute() + self.model.setMode(mode) def slot_sorted(self, column, order): diff --git a/src/vorta/views/extract_dialog.py b/src/vorta/views/extract_dialog.py index 134197d23..9b2fed4c3 100644 --- a/src/vorta/views/extract_dialog.py +++ b/src/vorta/views/extract_dialog.py @@ -9,6 +9,7 @@ from PyQt5.QtCore import QDateTime, QLocale, QMimeData, QModelIndex, QPoint, Qt, QThread, QUrl from PyQt5.QtGui import QColor, QKeySequence from PyQt5.QtWidgets import QApplication, QDialogButtonBox, QHeaderView, QMenu, QPushButton, QShortcut +from vorta.store.models import SettingsModel from vorta.utils import borg_compat, get_asset, pretty_bytes, uses_dark_mode from vorta.views.utils import get_colored_icon from .partials.treemodel import FileSystemItem, FileTreeModel, FileTreeSortProxyModel, path_to_str, relative_path @@ -88,9 +89,11 @@ def __init__(self, archive, model): self.buttonBox.addButton(self.extractButton, QDialogButtonBox.ButtonRole.AcceptRole) self.archiveNameLabel.setText(f"{archive.name}, {archive.time}") + diff_result_display_mode = SettingsModel.get(key='extract_files_display_mode').str_value # connect signals self.comboBoxDisplayMode.currentIndexChanged.connect(self.change_display_mode) + self.comboBoxDisplayMode.setCurrentIndex(int(diff_result_display_mode)) self.bFoldersOnTop.toggled.connect(self.sortproxy.keepFoldersOnTop) self.bCollapseAll.clicked.connect(self.treeView.collapseAll) @@ -163,6 +166,10 @@ def change_display_mode(self, selection: int): else: raise Exception("Unknown item in comboBoxDisplayMode with index {}".format(selection)) + SettingsModel.update({SettingsModel.str_value: str(selection)}).where( + SettingsModel.key == 'extract_files_display_mode' + ).execute() + self.model.setMode(mode) def treeview_context_menu(self, pos: QPoint): diff --git a/src/vorta/views/partials/treemodel.py b/src/vorta/views/partials/treemodel.py index b95357a6e..71b79899d 100644 --- a/src/vorta/views/partials/treemodel.py +++ b/src/vorta/views/partials/treemodel.py @@ -323,14 +323,12 @@ class DisplayMode(enum.Enum): #: simple list of items FLAT = enum.auto() - def __init__(self, parent=None): + def __init__(self, mode: 'FileTreeModel.DisplayMode' = DisplayMode.TREE, parent=None): """Init.""" super().__init__(parent) self.root: FileSystemItem[T] = FileSystemItem([], None) - #: mode - self.mode: 'FileTreeModel.DisplayMode' = self.DisplayMode.TREE - + self.mode = mode #: flat representation of the tree self._flattened: List[FileSystemItem] = []