Skip to content

Commit 82bfc40

Browse files
committedFeb 22, 2018
[processing] When searching in toolbox, automatically select
the first visible algorithm if the previously selected item was hidden Avoids hidden selections in the toolbox
1 parent 6a8e423 commit 82bfc40

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed
 

‎python/plugins/processing/gui/ProcessingToolbox.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,12 @@ def textChanged(self):
136136
showTip = ProcessingConfig.getSetting(ProcessingConfig.SHOW_PROVIDERS_TOOLTIP)
137137
if showTip:
138138
self.txtDisabled.setVisible(bool(self.disabledWithMatchingAlgs))
139+
140+
if self.algorithmTree.currentItem() is None or self.algorithmTree.currentItem().isHidden():
141+
# if previously selected item was hidden, auto select the first visible algorithm
142+
first_visible = self._findFirstVisibleAlgorithm(self.algorithmTree.invisibleRootItem())
143+
if first_visible is not None:
144+
self.algorithmTree.setCurrentItem(first_visible)
139145
else:
140146
self.algorithmTree.collapseAll()
141147
self.algorithmTree.invisibleRootItem().child(0).setExpanded(True)
@@ -166,6 +172,27 @@ def _filterItem(self, item, text):
166172
item.setHidden(True)
167173
return False
168174

175+
def _findFirstVisibleAlgorithm(self, item):
176+
"""
177+
Returns the first visible algorithm in the tree widget
178+
"""
179+
if item is None:
180+
return None
181+
if item.childCount() > 0:
182+
for i in range(item.childCount()):
183+
child = item.child(i)
184+
first_visible = self._findFirstVisibleAlgorithm(child)
185+
if first_visible is not None:
186+
return first_visible
187+
return None
188+
elif isinstance(item, TreeAlgorithmItem):
189+
if not item.isHidden():
190+
return item
191+
else:
192+
return None
193+
else:
194+
return None
195+
169196
def addProviderActions(self, provider):
170197
if provider.id() in ProviderActions.actions:
171198
toolbarButton = QToolButton()

0 commit comments

Comments
 (0)
Please sign in to comment.