From e508e3a34536b9f52f51a82c2b8f7dced9c408e7 Mon Sep 17 00:00:00 2001 From: Vinicius Moreira Date: Tue, 27 Aug 2019 18:39:53 -0300 Subject: [PATCH] put installed app on top after refresh --- bauh/view/qt/thread.py | 20 ++++++++++++++++++-- bauh/view/qt/window.py | 8 ++++++-- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/bauh/view/qt/thread.py b/bauh/view/qt/thread.py index dba2f722..a0e33449 100644 --- a/bauh/view/qt/thread.py +++ b/bauh/view/qt/thread.py @@ -92,12 +92,28 @@ class UpdateSelectedApps(AsyncAction): class RefreshApps(AsyncAction): - def __init__(self, manager: ApplicationManager): + def __init__(self, manager: ApplicationManager, app: ApplicationView = None): super(RefreshApps, self).__init__() self.manager = manager + self.app = app # app that should be on list top def run(self): - self.notify_finished(self.manager.read_installed()) + installed = self.manager.read_installed() + + if installed and self.app: + idx_found, app_found = None, None + for idx, ins in enumerate(installed): + if ins.get_type() == self.app.model.get_type() and ins.base_data.id == self.app.model.base_data.id: + idx_found = idx + app_found = ins + break + + if app_found: + del installed[idx_found] + installed.insert(0, app_found) + + self.notify_finished(installed) + self.app = None class UninstallApp(AsyncAction): diff --git a/bauh/view/qt/window.py b/bauh/view/qt/window.py index ed945992..5cdfa51d 100755 --- a/bauh/view/qt/window.py +++ b/bauh/view/qt/window.py @@ -299,7 +299,7 @@ class ManageWindow(QWidget): self.checkbox_console.setChecked(False) self.textarea_output.hide() - def refresh_apps(self, keep_console: bool = True): + def refresh_apps(self, keep_console: bool = True, top_app: ApplicationView = None): self.filter_types.clear() self.input_search.clear() @@ -309,6 +309,10 @@ class ManageWindow(QWidget): self.ref_checkbox_updates.setVisible(False) self.ref_checkbox_only_apps.setVisible(False) self._begin_action(self.locale_keys['manage_window.status.refreshing'], clear_filters=True) + + if top_app: + self.thread_refresh.app = top_app # the app will be on top when refresh happens + self.thread_refresh.start() def _finish_refresh_apps(self, apps: List[Application]): @@ -736,7 +740,7 @@ class ManageWindow(QWidget): if self._can_notify_user(): util.notify_user(msg='{} ({}) {}'.format(app.model.base_data.name, app.model.get_type(), self.locale_keys['installed'])) - self.refresh_apps() + self.refresh_apps(top_app=app) else: if self._can_notify_user(): util.notify_user('{}: {}'.format(app.model.base_data.name, self.locale_keys['notification.install.failed']))