@@ -167,6 +167,27 @@ def on_mount(self) -> None:
167
167
else get_colour_map (self ._arguments .colour_map ),
168
168
)
169
169
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
+
170
191
@on (Mandelbrot .Plotted )
171
192
def _update_situation (self , message : Mandelbrot .Plotted ) -> None :
172
193
"""Update the current situation after the latest plot.
@@ -206,6 +227,7 @@ def _remember(self) -> None:
206
227
plot .multibrot ,
207
228
)
208
229
)
230
+ self .refresh_bindings ()
209
231
210
232
def action_zoom (self , change : float ) -> None :
211
233
"""Change the zoom value.
@@ -321,6 +343,7 @@ def action_undo_command(self) -> None:
321
343
situation = self ._history .pop ()
322
344
except IndexError :
323
345
return
346
+ self .refresh_bindings ()
324
347
self .query_one (Mandelbrot ).set (
325
348
x_position = situation .x_position ,
326
349
y_position = situation .y_position ,
0 commit comments