Skip to content

Commit df06133

Browse files
committed
Disable Edit menu Undo/Redo when stack is empty
Wire the title bar's Edit menu Undo/Redo items through can_undo/can_redo hooks on EditorActionHooks so they gray out when there's nothing to do — matches the viewport header behaviour. Updates the roadmap to mark the inspector lock, history panel, and dimmed undo/redo entries complete.
1 parent 9087a80 commit df06133

4 files changed

Lines changed: 36 additions & 4 deletions

File tree

crates/renzora_editor_framework/src/lib.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ pub use toolbar_registry::{ToolEntry, ToolSection, ToolbarRegistry};
4141
pub struct EditorActionHooks {
4242
pub undo: Option<fn(&mut bevy::prelude::World)>,
4343
pub redo: Option<fn(&mut bevy::prelude::World)>,
44+
pub can_undo: Option<fn(&bevy::prelude::World) -> bool>,
45+
pub can_redo: Option<fn(&bevy::prelude::World) -> bool>,
4446
}
4547

4648
/// Debounce state for the auto-save layout system — tracks "dirty since N
@@ -761,6 +763,15 @@ pub fn editor_ui_system(world: &mut World) {
761763
let mut window_queue = world
762764
.remove_resource::<renzora_ui::window_chrome::WindowActionQueue>()
763765
.unwrap_or_default();
766+
let (can_undo, can_redo) = world
767+
.get_resource::<EditorActionHooks>()
768+
.map(|h| {
769+
(
770+
h.can_undo.map(|f| f(world)).unwrap_or(false),
771+
h.can_redo.map(|f| f(world)).unwrap_or(false),
772+
)
773+
})
774+
.unwrap_or((false, false));
764775
let title_action = renzora_ui::title_bar::render_title_bar(
765776
&ctx,
766777
&theme,
@@ -770,6 +781,8 @@ pub fn editor_ui_system(world: &mut World) {
770781
sign_in_open,
771782
signed_in_username.as_deref(),
772783
&mut window_queue,
784+
can_undo,
785+
can_redo,
773786
);
774787

775788
// 6. Document tabs (below title bar)

crates/renzora_ui/src/title_bar.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ pub fn render_title_bar(
6666
sign_in_open: bool,
6767
signed_in_username: Option<&str>,
6868
window_queue: &mut WindowActionQueue,
69+
can_undo: bool,
70+
can_redo: bool,
6971
) -> TitleBarAction {
7072
let mut action = TitleBarAction::None;
7173
let mut any_widget_hovered = false;
@@ -164,11 +166,11 @@ pub fn render_title_bar(
164166
switch_top_menu_on_hover(ui.ctx(), &file_menu.response);
165167

166168
let edit_menu = ui.menu_button("Edit", |ui| {
167-
if ui.button("Undo").clicked() {
169+
if ui.add_enabled(can_undo, egui::Button::new("Undo")).clicked() {
168170
action = TitleBarAction::Undo;
169171
ui.close();
170172
}
171-
if ui.button("Redo").clicked() {
173+
if ui.add_enabled(can_redo, egui::Button::new("Redo")).clicked() {
172174
action = TitleBarAction::Redo;
173175
ui.close();
174176
}

crates/renzora_undo/src/lib.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,9 +149,25 @@ impl Plugin for UndoPlugin {
149149
.resource_mut::<renzora_editor_framework::EditorActionHooks>();
150150
hooks.undo = Some(undo_once);
151151
hooks.redo = Some(redo_once);
152+
hooks.can_undo = Some(can_undo_active);
153+
hooks.can_redo = Some(can_redo_active);
152154
}
153155
}
154156

157+
fn can_undo_active(world: &World) -> bool {
158+
world
159+
.get_resource::<UndoStacks>()
160+
.map(|s| s.can_undo(&s.active))
161+
.unwrap_or(false)
162+
}
163+
164+
fn can_redo_active(world: &World) -> bool {
165+
world
166+
.get_resource::<UndoStacks>()
167+
.map(|s| s.can_redo(&s.active))
168+
.unwrap_or(false)
169+
}
170+
155171
fn shortcut_input(
156172
keys: Res<ButtonInput<KeyCode>>,
157173
bindings: Option<Res<renzora::keybindings::KeyBindings>>,

roadmap.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
- Add property undo/redo history
2424

2525
## Inspector — Views & Filtering
26-
- Add lock inspector to entity (stop following selection)
26+
- Add lock inspector to entity (stop following selection) — [`c5fd231`](https://github.com/renzora/engine/commit/c5fd231)
2727
- Add multi-entity comparison view
2828
- ✅ Add component search/filter — [`3a3e9d2`](https://github.com/renzora/engine/commit/3a3e9d2)
2929
- Add component presets/templates
@@ -93,6 +93,7 @@
9393
## Editor UX — Undo/Redo & Clipboard
9494
- ✅ Add global undo/redo system across all editors — [`63fd98e`](https://github.com/renzora/engine/commit/63fd98e)
9595
- ✅ Wire undo/redo to viewport toolbar and Edit menu — [`cc028c8`](https://github.com/renzora/engine/commit/cc028c8)
96+
- ✅ Add History panel showing undo/redo stack with click-to-jump — [`dfb7b94`](https://github.com/renzora/engine/commit/dfb7b94)
9697
- Add global clipboard for entities/components/nodes
9798

9899
## Editor UX — Layouts & Help
@@ -526,7 +527,7 @@
526527

527528
## Small Bugs / Polish
528529
- Ensure all nav mesh collider types are handled (segment, triangle, polyline, halfspace, custom, voxels currently warn)
529-
- Fix dimmed undo/redo buttons throughout editor (no-op)
530+
- Fix dimmed undo/redo buttons throughout editor (no-op)
530531
- Handle set_menu_item_checked in plugin host
531532

532533
## Documentation

0 commit comments

Comments
 (0)