From c2fef8d624799bc4c89cc2f3534aad0116c93b3d Mon Sep 17 00:00:00 2001 From: Sergey Zhuravlevich Date: Thu, 7 Jan 2021 09:38:33 +0100 Subject: [PATCH 1/4] Prioritize dialog: allow adding multiple criteria at once Adding criteria to the prioritizations list one-by-one can be tedious. This commit enables extended selection in the criteria list and implements adding multiple items. Multiple criteria can be selected with conventional methods, such as holding down Ctrl or Shift keys and clicking the items or holding down the left mouse button and hovering the cursor over the list. All items also can be selected with Ctrl+A. Signed-off-by: Sergey Zhuravlevich --- core/gui/prioritize_dialog.py | 7 ++++--- qt/prioritize_dialog.py | 1 + 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/core/gui/prioritize_dialog.py b/core/gui/prioritize_dialog.py index 7437497e..62f57619 100644 --- a/core/gui/prioritize_dialog.py +++ b/core/gui/prioritize_dialog.py @@ -72,9 +72,10 @@ class PrioritizeDialog(GUIObject): # Add selected criteria in criteria_list to prioritization_list. if self.criteria_list.selected_index is None: return - crit = self.criteria[self.criteria_list.selected_index] - self.prioritizations.append(crit) - del crit + for i in self.criteria_list.selected_indexes: + crit = self.criteria[i] + self.prioritizations.append(crit) + del crit self.prioritization_list[:] = [crit.display for crit in self.prioritizations] def remove_selected(self): diff --git a/qt/prioritize_dialog.py b/qt/prioritize_dialog.py index d3e76322..3fb1ef02 100644 --- a/qt/prioritize_dialog.py +++ b/qt/prioritize_dialog.py @@ -102,6 +102,7 @@ class PrioritizeDialog(QDialog): self.promptLabel.setWordWrap(True) self.categoryCombobox = QComboBox() self.criteriaListView = QListView() + self.criteriaListView.setSelectionMode(QAbstractItemView.ExtendedSelection) self.addCriteriaButton = QPushButton( self.style().standardIcon(QStyle.SP_ArrowRight), "" ) From 32dcd90b50f43a7af8d38ac99c8e6f18022b0cb0 Mon Sep 17 00:00:00 2001 From: Sergey Zhuravlevich Date: Thu, 7 Jan 2021 10:02:49 +0100 Subject: [PATCH 2/4] Prioritize dialog: allow removing multiple prioritizations at once Removing prioritizations one-by-one can be tedious. This commit enables extended selection in the prioritizations list. Multiple items can be selected with conventional methods, such as holding down Ctrl or Shift key and clicking the items or holding down the left mouse button and hovering the cursor over the list. All items also can be selected with Ctrl+A. Multiple items drag-n-drop is also possible. To avoid confusion, the selection in the prioritizations list is cleared after the items are removed or drag-n-dropped. Signed-off-by: Sergey Zhuravlevich --- core/gui/prioritize_dialog.py | 1 + qt/prioritize_dialog.py | 2 ++ 2 files changed, 3 insertions(+) diff --git a/core/gui/prioritize_dialog.py b/core/gui/prioritize_dialog.py index 62f57619..adcd8515 100644 --- a/core/gui/prioritize_dialog.py +++ b/core/gui/prioritize_dialog.py @@ -80,6 +80,7 @@ class PrioritizeDialog(GUIObject): def remove_selected(self): self.prioritization_list.remove_selected() + self.prioritization_list.select([]) def perform_reprioritization(self): self.app.reprioritize_groups(self._sort_key) diff --git a/qt/prioritize_dialog.py b/qt/prioritize_dialog.py index 3fb1ef02..07d2d961 100644 --- a/qt/prioritize_dialog.py +++ b/qt/prioritize_dialog.py @@ -50,6 +50,7 @@ class PrioritizationList(ListviewModel): strMimeData = bytes(mimeData.data(MIME_INDEXES)).decode() indexes = list(map(int, strMimeData.split(","))) self.model.move_indexes(indexes, row) + self.view.selectionModel().clearSelection() return True def mimeData(self, indexes): @@ -114,6 +115,7 @@ class PrioritizeDialog(QDialog): self.prioritizationListView.setDragEnabled(True) self.prioritizationListView.setDragDropMode(QAbstractItemView.InternalMove) self.prioritizationListView.setSelectionBehavior(QAbstractItemView.SelectRows) + self.prioritizationListView.setSelectionMode(QAbstractItemView.ExtendedSelection) self.buttonBox = QDialogButtonBox() self.buttonBox.setStandardButtons(QDialogButtonBox.Cancel | QDialogButtonBox.Ok) From 116ac18e1348441f41cba505b1980922d3394d59 Mon Sep 17 00:00:00 2001 From: Sergey Zhuravlevich Date: Thu, 7 Jan 2021 17:13:17 +0100 Subject: [PATCH 3/4] Prioritize dialog: add/remove criteria on double clicking an item Signed-off-by: Sergey Zhuravlevich --- qt/prioritize_dialog.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/qt/prioritize_dialog.py b/qt/prioritize_dialog.py index 07d2d961..81785648 100644 --- a/qt/prioritize_dialog.py +++ b/qt/prioritize_dialog.py @@ -85,7 +85,9 @@ class PrioritizeDialog(QDialog): self.model.view = self self.addCriteriaButton.clicked.connect(self.model.add_selected) + self.criteriaListView.doubleClicked.connect(self.model.add_selected) self.removeCriteriaButton.clicked.connect(self.model.remove_selected) + self.prioritizationListView.doubleClicked.connect(self.model.remove_selected) self.buttonBox.accepted.connect(self.accept) self.buttonBox.rejected.connect(self.reject) From b5a3313f800de5c0527de49f6fd49e6b7e53ad8e Mon Sep 17 00:00:00 2001 From: Sergey Zhuravlevich Date: Thu, 7 Jan 2021 17:31:51 +0100 Subject: [PATCH 4/4] Prioritize dialog: fix drag-n-drop putting items before the last item When the items in the prioritizations list were drag-n-dropped to the empty space, the row was equal to -1 and the dropped items ended up being moved to the position before the last item. Fixing the row value helps to avoid that behavior. Signed-off-by: Sergey Zhuravlevich --- qt/prioritize_dialog.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/qt/prioritize_dialog.py b/qt/prioritize_dialog.py index 81785648..0b291952 100644 --- a/qt/prioritize_dialog.py +++ b/qt/prioritize_dialog.py @@ -47,6 +47,12 @@ class PrioritizationList(ListviewModel): # to know where the drop took place. if parentIndex.isValid(): return False + # "When row and column are -1 it means that the dropped data should be considered as + # dropped directly on parent." + # Moving items to row -1 would put them before the last item. Fix the row to drop the + # dragged items after the last item. + if row < 0: + row = len(self.model) - 1 strMimeData = bytes(mimeData.data(MIME_INDEXES)).decode() indexes = list(map(int, strMimeData.split(","))) self.model.move_indexes(indexes, row)