mirror of
https://github.com/borgbase/vorta
synced 2024-12-21 23:33:13 +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:
parent
828e02953b
commit
b51b1ef85e
4 changed files with 28 additions and 4 deletions
|
@ -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',
|
||||
|
|
|
@ -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):
|
||||
|
|
|
@ -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):
|
||||
|
|
|
@ -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] = []
|
||||
|
||||
|
|
Loading…
Reference in a new issue