From 6d5e7381079de58c9509821f5124b67fcc5a7808 Mon Sep 17 00:00:00 2001 From: jetchirag Date: Tue, 4 Apr 2023 17:48:50 +0530 Subject: [PATCH] Retain source tab sort settings. By @jetchirag (#1649) --- src/vorta/store/settings.py | 12 ++++++++++++ src/vorta/views/source_tab.py | 19 +++++++++++++++++-- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/src/vorta/store/settings.py b/src/vorta/store/settings.py index a02e4e73c..bcc358c92 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': 'sourcetab_sort_column', + 'str_value': '0', + 'type': 'internal', + 'label': 'Source Tab Sort Column', + }, + { + 'key': 'sourcetab_sort_order', + 'str_value': '0', + 'type': 'internal', + 'label': 'Source Tab Sort Order', + }, ] if sys.platform == 'darwin': settings += [ diff --git a/src/vorta/views/source_tab.py b/src/vorta/views/source_tab.py index 11db6075c..85b02e207 100644 --- a/src/vorta/views/source_tab.py +++ b/src/vorta/views/source_tab.py @@ -88,6 +88,7 @@ def __init__(self, parent=None): self.updateButton.clicked.connect(self.sources_update) self.excludePatternsField.textChanged.connect(self.save_exclude_patterns) self.excludeIfPresentField.textChanged.connect(self.save_exclude_if_present) + header.sortIndicatorChanged.connect(self.update_sort_order) # Connect to palette change QApplication.instance().paletteChanged.connect(lambda p: self.set_icons()) @@ -244,13 +245,27 @@ def populate_from_profile(self): for source in SourceFileModel.select().where(SourceFileModel.profile == profile): self.add_source_to_table(source, False) - # Initially, sort entries by path name in ascending order - self.sourceFilesWidget.sortItems(SourceColumn.Path, QtCore.Qt.AscendingOrder) + # Fetch the Sort by Column and order + sourcetab_sort_column = int(SettingsModel.get(key='sourcetab_sort_column').str_value) + sourcetab_sort_order = int(SettingsModel.get(key='sourcetab_sort_order').str_value) + + # Sort items as per settings + self.sourceFilesWidget.sortItems(sourcetab_sort_column, sourcetab_sort_order) + self.excludePatternsField.appendPlainText(profile.exclude_patterns) self.excludeIfPresentField.appendPlainText(profile.exclude_if_present) self.excludePatternsField.textChanged.connect(self.save_exclude_patterns) self.excludeIfPresentField.textChanged.connect(self.save_exclude_if_present) + def update_sort_order(self, column: int, order: int): + """Save selected sort by column and order to settings""" + SettingsModel.update({SettingsModel.str_value: str(column)}).where( + SettingsModel.key == 'sourcetab_sort_column' + ).execute() + SettingsModel.update({SettingsModel.str_value: str(order)}).where( + SettingsModel.key == 'sourcetab_sort_order' + ).execute() + def sources_update(self): """ Update each row in the sources table.