refactor: split dashboard modules and share UI sync helpers
Break the oversized overview page into focused dashboard submodules and centralize the repeated validation/save-button refresh flows used by page widgets. This keeps the UI behavior stable while making future edits less fragile and easier to reason about.
This commit is contained in:
+35
-66
@@ -1367,14 +1367,7 @@ fn install_window_actions(
|
||||
let page_ctx = page_ctx.clone();
|
||||
revert_action.connect_activate(move |_, _| {
|
||||
if restore_saved_snapshot(&state) {
|
||||
recompute_validation(&state);
|
||||
refresh_save_button(&state, &save_button);
|
||||
apply_preview_current_config(&page_ctx);
|
||||
let _ = gtk4::prelude::WidgetExt::activate_action(
|
||||
&page_ctx.parent_window,
|
||||
"win.refresh-current-page",
|
||||
None,
|
||||
);
|
||||
refresh_workspace_after_config_change(&state, &save_button, &page_ctx);
|
||||
crate::ui::toast::show_toast(
|
||||
&toast_overlay,
|
||||
"Discarded unsaved changes and restored the last saved state",
|
||||
@@ -1394,14 +1387,7 @@ fn install_window_actions(
|
||||
let page_ctx = page_ctx.clone();
|
||||
undo_action.connect_activate(move |_, _| {
|
||||
if restore_saved_snapshot(&state) {
|
||||
recompute_validation(&state);
|
||||
refresh_save_button(&state, &save_button);
|
||||
apply_preview_current_config(&page_ctx);
|
||||
let _ = gtk4::prelude::WidgetExt::activate_action(
|
||||
&page_ctx.parent_window,
|
||||
"win.refresh-current-page",
|
||||
None,
|
||||
);
|
||||
refresh_workspace_after_config_change(&state, &save_button, &page_ctx);
|
||||
crate::ui::toast::show_toast(
|
||||
&toast_overlay,
|
||||
"Discarded unsaved changes and restored the last saved state",
|
||||
@@ -1431,14 +1417,7 @@ fn install_window_actions(
|
||||
}
|
||||
|
||||
if changed {
|
||||
recompute_validation(&state);
|
||||
refresh_save_button(&state, &save_button);
|
||||
apply_preview_current_config(&page_ctx);
|
||||
let _ = gtk4::prelude::WidgetExt::activate_action(
|
||||
&page_ctx.parent_window,
|
||||
"win.refresh-current-page",
|
||||
None,
|
||||
);
|
||||
refresh_workspace_after_config_change(&state, &save_button, &page_ctx);
|
||||
crate::ui::toast::show_toast(&toast_overlay, "Redo applied");
|
||||
} else {
|
||||
crate::ui::toast::show_toast(&toast_overlay, "Nothing to redo");
|
||||
@@ -1535,14 +1514,7 @@ fn install_window_actions(
|
||||
&state,
|
||||
) {
|
||||
Ok(path) => {
|
||||
recompute_validation(&state);
|
||||
refresh_save_button(&state, &save_button);
|
||||
apply_preview_current_config(&page_ctx);
|
||||
let _ = gtk4::prelude::WidgetExt::activate_action(
|
||||
&page_ctx.parent_window,
|
||||
"win.refresh-current-page",
|
||||
None,
|
||||
);
|
||||
refresh_workspace_after_config_change(&state, &save_button, &page_ctx);
|
||||
crate::ui::toast::show_toast(
|
||||
&toast_overlay,
|
||||
&format!("Loaded safety backup from {}", path.display()),
|
||||
@@ -1565,14 +1537,7 @@ fn install_window_actions(
|
||||
let settings = settings.cloned();
|
||||
reset_defaults_action.connect_activate(move |_, _| {
|
||||
if reset_config_to_defaults(&state, settings.as_ref()) {
|
||||
recompute_validation(&state);
|
||||
refresh_save_button(&state, &save_button);
|
||||
apply_preview_current_config(&page_ctx);
|
||||
let _ = gtk4::prelude::WidgetExt::activate_action(
|
||||
&page_ctx.parent_window,
|
||||
"win.refresh-current-page",
|
||||
None,
|
||||
);
|
||||
refresh_workspace_after_config_change(&state, &save_button, &page_ctx);
|
||||
crate::ui::toast::show_toast(
|
||||
&toast_overlay,
|
||||
"Reset the current config and preview defaults",
|
||||
@@ -2559,19 +2524,7 @@ fn load_config_into_state(
|
||||
if let Some(settings) = settings {
|
||||
let _ = settings.set_string("last-config-path", &path.display().to_string());
|
||||
}
|
||||
recompute_validation(state);
|
||||
refresh_save_button(state, save_button);
|
||||
apply_preview_current_config(page_ctx);
|
||||
let _ = gtk4::prelude::WidgetExt::activate_action(
|
||||
&page_ctx.parent_window,
|
||||
"win.refresh-current-page",
|
||||
None,
|
||||
);
|
||||
let _ = gtk4::prelude::WidgetExt::activate_action(
|
||||
&page_ctx.parent_window,
|
||||
"win.refresh-layer-stack",
|
||||
None,
|
||||
);
|
||||
refresh_workspace_after_config_load(state, save_button, page_ctx);
|
||||
crate::ui::toast::show_toast(
|
||||
toast_overlay,
|
||||
&format!("Switched active config to {label}"),
|
||||
@@ -2802,6 +2755,34 @@ fn apply_preview_current_config(page_ctx: &PageBuildContext) {
|
||||
pages::apply_live_preview_now(page_ctx);
|
||||
}
|
||||
|
||||
fn refresh_workspace_after_config_change(
|
||||
state: &Arc<Mutex<AppState>>,
|
||||
save_button: &libadwaita::SplitButton,
|
||||
page_ctx: &PageBuildContext,
|
||||
) {
|
||||
recompute_validation(state);
|
||||
refresh_save_button(state, save_button);
|
||||
apply_preview_current_config(page_ctx);
|
||||
let _ = gtk4::prelude::WidgetExt::activate_action(
|
||||
&page_ctx.parent_window,
|
||||
"win.refresh-current-page",
|
||||
None,
|
||||
);
|
||||
}
|
||||
|
||||
fn refresh_workspace_after_config_load(
|
||||
state: &Arc<Mutex<AppState>>,
|
||||
save_button: &libadwaita::SplitButton,
|
||||
page_ctx: &PageBuildContext,
|
||||
) {
|
||||
refresh_workspace_after_config_change(state, save_button, page_ctx);
|
||||
let _ = gtk4::prelude::WidgetExt::activate_action(
|
||||
&page_ctx.parent_window,
|
||||
"win.refresh-layer-stack",
|
||||
None,
|
||||
);
|
||||
}
|
||||
|
||||
fn reload_config_from_disk(
|
||||
state: &Arc<Mutex<AppState>>,
|
||||
save_button: &libadwaita::SplitButton,
|
||||
@@ -2836,19 +2817,7 @@ fn reload_config_from_disk(
|
||||
if let Some(settings) = settings {
|
||||
let _ = settings.set_string("last-config-path", &path.display().to_string());
|
||||
}
|
||||
recompute_validation(state);
|
||||
refresh_save_button(state, save_button);
|
||||
apply_preview_current_config(page_ctx);
|
||||
let _ = gtk4::prelude::WidgetExt::activate_action(
|
||||
&page_ctx.parent_window,
|
||||
"win.refresh-current-page",
|
||||
None,
|
||||
);
|
||||
let _ = gtk4::prelude::WidgetExt::activate_action(
|
||||
&page_ctx.parent_window,
|
||||
"win.refresh-layer-stack",
|
||||
None,
|
||||
);
|
||||
refresh_workspace_after_config_load(state, save_button, page_ctx);
|
||||
crate::ui::toast::show_toast(toast_overlay, "Reloaded config from disk");
|
||||
true
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user