Skip to content

Commit

Permalink
Retain source tab sort settings. By @jetchirag (#1649)
Browse files Browse the repository at this point in the history
  • Loading branch information
jetchirag authored Apr 4, 2023
1 parent a64493d commit 6d5e738
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 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': '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 += [
Expand Down
19 changes: 17 additions & 2 deletions src/vorta/views/source_tab.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 6d5e738

Please sign in to comment.