@@ -167,6 +167,27 @@ def on_mount(self) -> None:
167167 else get_colour_map (self ._arguments .colour_map ),
168168 )
169169
170+ def check_action (self , action : str , parameters : tuple [object , ...]) -> bool | None :
171+ """Check if an action is possible to perform right now.
172+
173+ Args:
174+ action: The action to perform.
175+ parameters: The parameters of the action.
176+
177+ Returns:
178+ `True` if it can perform, `False` or `None` if not.
179+ """
180+ if not self .is_mounted :
181+ # Surprisingly it seems that Textual's "dynamic bindings" can
182+ # cause this method to be called before the DOM is up and
183+ # running. This breaks the rule of least astonishment, I'd say,
184+ # but okay let's be defensive... (when I can come up with a nice
185+ # little MRE I'll report it).
186+ return True
187+ if action == Undo .action_name ():
188+ return bool (self ._history ) or None
189+ return True
190+
170191 @on (Mandelbrot .Plotted )
171192 def _update_situation (self , message : Mandelbrot .Plotted ) -> None :
172193 """Update the current situation after the latest plot.
@@ -206,6 +227,7 @@ def _remember(self) -> None:
206227 plot .multibrot ,
207228 )
208229 )
230+ self .refresh_bindings ()
209231
210232 def action_zoom (self , change : float ) -> None :
211233 """Change the zoom value.
@@ -321,6 +343,7 @@ def action_undo_command(self) -> None:
321343 situation = self ._history .pop ()
322344 except IndexError :
323345 return
346+ self .refresh_bindings ()
324347 self .query_one (Mandelbrot ).set (
325348 x_position = situation .x_position ,
326349 y_position = situation .y_position ,
0 commit comments