diff --git a/src/vorta/store/settings.py b/src/vorta/store/settings.py index a02e4e73..bcc358c9 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 11db6075..85b02e20 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.