Skip to content

Commit f157901

Browse files
committed
widgets.status: disable 'Revert Unstaged Edits' when nothing is selected
Prevent the 'Revert Unstaged Edits...' action from being used when there is nothing to revert. This ensures that the hotkey does not activate when there is nothing to do. Signed-off-by: David Aguilar <davvid@gmail.com>
1 parent 1d9401d commit f157901

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

cola/widgets/status.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,13 @@ def _updated(self):
336336
self.restore_selection()
337337
self.restore_scrollbar()
338338
self.update_column_widths()
339+
self.update_actions()
340+
341+
def update_actions(self, selected=None):
342+
if selected is None:
343+
selected = selection.selection()
344+
can_revert_unstaged_edits = bool(selected.staged or selected.modified)
345+
self.revert_unstaged_edits_action.setEnabled(can_revert_unstaged_edits)
339346

340347
def set_staged(self, items):
341348
"""Adds items to the 'Staged' subtree."""
@@ -770,7 +777,10 @@ def _open_parent_dir(self):
770777
def show_selection(self):
771778
"""Show the selected item."""
772779
# Sync the selection model
773-
selection.selection_model().set_selection(self.selection())
780+
selected = self.selection()
781+
selection.selection_model().set_selection(selected)
782+
self.update_actions(selected=selected)
783+
774784
selected_indexes = self.selected_indexes()
775785
if not selected_indexes:
776786
if self.m.amending():

0 commit comments

Comments
 (0)