Skip to content

Commit

Permalink
Save list view as setting. By @diivi (#1621)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
Co-authored-by: Manu <[email protected]>
  • Loading branch information
3 people authored Apr 5, 2023
1 parent 828e029 commit b51b1ef
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 4 deletions.
12 changes: 12 additions & 0 deletions src/vorta/store/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
7 changes: 7 additions & 0 deletions src/vorta/views/diff_result.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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):
Expand Down
7 changes: 7 additions & 0 deletions src/vorta/views/extract_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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):
Expand Down
6 changes: 2 additions & 4 deletions src/vorta/views/partials/treemodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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] = []

Expand Down

0 comments on commit b51b1ef

Please sign in to comment.