1
0
Fork 0
mirror of https://github.com/borgbase/vorta synced 2025-01-03 05:36:19 +00:00

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>
This commit is contained in:
Divyansh Singh 2023-04-05 16:50:42 +05:30 committed by GitHub
parent 828e02953b
commit b51b1ef85e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 28 additions and 4 deletions

View file

@ -100,6 +100,18 @@ def get_misc_settings() -> List[Dict[str, str]]:
'type': 'internal', 'type': 'internal',
'label': 'Previous window height', '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', 'key': 'sourcetab_sort_column',
'str_value': '0', 'str_value': '0',

View file

@ -9,6 +9,7 @@
from PyQt5.QtCore import QDateTime, QLocale, QMimeData, QModelIndex, QPoint, Qt, QThread, QUrl from PyQt5.QtCore import QDateTime, QLocale, QMimeData, QModelIndex, QPoint, Qt, QThread, QUrl
from PyQt5.QtGui import QColor, QKeySequence from PyQt5.QtGui import QColor, QKeySequence
from PyQt5.QtWidgets import QApplication, QHeaderView, QMenu, QShortcut, QTreeView 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.utils import get_asset, pretty_bytes, uses_dark_mode
from vorta.views.partials.treemodel import ( from vorta.views.partials.treemodel import (
FileSystemItem, FileSystemItem,
@ -98,6 +99,8 @@ def __init__(self, archive_newer, archive_older, model: 'DiffTree'):
self.archiveNameLabel_2.setText(f'{archive_older.name}') self.archiveNameLabel_2.setText(f'{archive_older.name}')
self.comboBoxDisplayMode.currentIndexChanged.connect(self.change_display_mode) 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.bFoldersOnTop.toggled.connect(self.sortproxy.keepFoldersOnTop)
self.bCollapseAll.clicked.connect(self.treeView.collapseAll) self.bCollapseAll.clicked.connect(self.treeView.collapseAll)
@ -183,6 +186,10 @@ def change_display_mode(self, selection: int):
else: else:
raise Exception("Unknown item in comboBoxDisplayMode with index {}".format(selection)) 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) self.model.setMode(mode)
def slot_sorted(self, column, order): def slot_sorted(self, column, order):

View file

@ -9,6 +9,7 @@
from PyQt5.QtCore import QDateTime, QLocale, QMimeData, QModelIndex, QPoint, Qt, QThread, QUrl from PyQt5.QtCore import QDateTime, QLocale, QMimeData, QModelIndex, QPoint, Qt, QThread, QUrl
from PyQt5.QtGui import QColor, QKeySequence from PyQt5.QtGui import QColor, QKeySequence
from PyQt5.QtWidgets import QApplication, QDialogButtonBox, QHeaderView, QMenu, QPushButton, QShortcut 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.utils import borg_compat, get_asset, pretty_bytes, uses_dark_mode
from vorta.views.utils import get_colored_icon from vorta.views.utils import get_colored_icon
from .partials.treemodel import FileSystemItem, FileTreeModel, FileTreeSortProxyModel, path_to_str, relative_path 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.buttonBox.addButton(self.extractButton, QDialogButtonBox.ButtonRole.AcceptRole)
self.archiveNameLabel.setText(f"{archive.name}, {archive.time}") self.archiveNameLabel.setText(f"{archive.name}, {archive.time}")
diff_result_display_mode = SettingsModel.get(key='extract_files_display_mode').str_value
# connect signals # connect signals
self.comboBoxDisplayMode.currentIndexChanged.connect(self.change_display_mode) self.comboBoxDisplayMode.currentIndexChanged.connect(self.change_display_mode)
self.comboBoxDisplayMode.setCurrentIndex(int(diff_result_display_mode))
self.bFoldersOnTop.toggled.connect(self.sortproxy.keepFoldersOnTop) self.bFoldersOnTop.toggled.connect(self.sortproxy.keepFoldersOnTop)
self.bCollapseAll.clicked.connect(self.treeView.collapseAll) self.bCollapseAll.clicked.connect(self.treeView.collapseAll)
@ -163,6 +166,10 @@ def change_display_mode(self, selection: int):
else: else:
raise Exception("Unknown item in comboBoxDisplayMode with index {}".format(selection)) 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) self.model.setMode(mode)
def treeview_context_menu(self, pos: QPoint): def treeview_context_menu(self, pos: QPoint):

View file

@ -323,14 +323,12 @@ class DisplayMode(enum.Enum):
#: simple list of items #: simple list of items
FLAT = enum.auto() FLAT = enum.auto()
def __init__(self, parent=None): def __init__(self, mode: 'FileTreeModel.DisplayMode' = DisplayMode.TREE, parent=None):
"""Init.""" """Init."""
super().__init__(parent) super().__init__(parent)
self.root: FileSystemItem[T] = FileSystemItem([], None) self.root: FileSystemItem[T] = FileSystemItem([], None)
#: mode self.mode = mode
self.mode: 'FileTreeModel.DisplayMode' = self.DisplayMode.TREE
#: flat representation of the tree #: flat representation of the tree
self._flattened: List[FileSystemItem] = [] self._flattened: List[FileSystemItem] = []