mirror of
https://github.com/borgbase/vorta
synced 2024-12-21 23:33:13 +00:00
Keep the profile list sorted when adding profiles. By @Parnassius (#1986)
This commit is contained in:
parent
9cabbbd193
commit
6b5f7a7aac
2 changed files with 18 additions and 7 deletions
|
@ -59,10 +59,10 @@ def build_menu(self):
|
|||
cancel_action.triggered.connect(self.app.backup_cancelled_event.emit)
|
||||
else:
|
||||
status.setText(self.tr('Next Task: %s') % next_task_time)
|
||||
profiles = BackupProfileModel.select().order_by(BackupProfileModel.name)
|
||||
profiles = BackupProfileModel.select()
|
||||
if profiles.count() > 1:
|
||||
profile_menu = menu.addMenu(self.tr('Backup Now'))
|
||||
for profile in profiles:
|
||||
for profile in sorted(profiles, key=lambda p: (p.name.casefold(), p.name)):
|
||||
new_item = profile_menu.addAction(profile.name)
|
||||
new_item.triggered.connect(lambda state, i=profile.id: self.app.create_backup_action(i))
|
||||
else:
|
||||
|
|
|
@ -65,7 +65,8 @@ def __init__(self, parent=None):
|
|||
prev_profile_id = SettingsModel.get(key='previous_profile_id')
|
||||
self.current_profile = BackupProfileModel.get_or_none(id=prev_profile_id.str_value)
|
||||
if self.current_profile is None:
|
||||
self.current_profile = BackupProfileModel.select().order_by('name').first()
|
||||
profiles = BackupProfileModel.select()
|
||||
self.current_profile = min(profiles, key=lambda p: (p.name.casefold(), p.name))
|
||||
|
||||
# Load tab models
|
||||
self.repoTab = RepoTab(self.repoTabSlot)
|
||||
|
@ -161,7 +162,8 @@ def populate_profile_selector(self):
|
|||
current_item = None
|
||||
|
||||
# Add items to the QListWidget
|
||||
for profile in BackupProfileModel.select().order_by(BackupProfileModel.name):
|
||||
profiles = BackupProfileModel.select()
|
||||
for profile in sorted(profiles, key=lambda p: (p.name.casefold(), p.name)):
|
||||
item = QListWidgetItem(profile.name)
|
||||
item.setData(Qt.ItemDataRole.UserRole, profile.id)
|
||||
|
||||
|
@ -284,13 +286,22 @@ def profile_imported_event(profile):
|
|||
def profile_add_edit_result(self, profile_name, profile_id):
|
||||
# Profile is renamed
|
||||
if self.profileSelector.currentItem().data(Qt.ItemDataRole.UserRole) == profile_id:
|
||||
self.profileSelector.currentItem().setText(profile_name)
|
||||
profile = self.profileSelector.takeItem(self.profileSelector.currentRow())
|
||||
profile.setText(profile_name)
|
||||
# Profile is added
|
||||
else:
|
||||
profile = QListWidgetItem(profile_name)
|
||||
profile.setData(Qt.ItemDataRole.UserRole, profile_id)
|
||||
self.profileSelector.addItem(profile)
|
||||
self.profileSelector.setCurrentItem(profile)
|
||||
# Insert the profile at the correct position
|
||||
# Both the casefolded and the original name are used as the key to keep the order stable
|
||||
profile_key = (profile.text().casefold(), profile.text())
|
||||
row = 0
|
||||
for i in range(self.profileSelector.count()):
|
||||
item_name = self.profileSelector.item(i).text()
|
||||
if (item_name.casefold(), item_name) < profile_key:
|
||||
row += 1
|
||||
self.profileSelector.insertItem(row, profile)
|
||||
self.profileSelector.setCurrentItem(profile)
|
||||
|
||||
def toggle_misc_visibility(self):
|
||||
if self.miscWidget.isVisible():
|
||||
|
|
Loading…
Reference in a new issue