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:
+10
-20
@@ -1,7 +1,8 @@
|
||||
use crate::ui::pages::PageBuildContext;
|
||||
use crate::ui::pages::{
|
||||
apply_live_preview_now, refresh_current_page_later, sync_config_ui, PageBuildContext,
|
||||
};
|
||||
use crate::ui::toast::show_toast;
|
||||
use crate::ui::widgets::tool_page;
|
||||
use crate::window::{recompute_validation, refresh_save_button};
|
||||
use gtk4::prelude::*;
|
||||
use libadwaita::prelude::*;
|
||||
use mangotune::config::parser::Parser;
|
||||
@@ -45,24 +46,12 @@ pub fn build_page(ctx: &PageBuildContext) -> gtk4::ScrolledWindow {
|
||||
|
||||
let launch_row = libadwaita::ActionRow::builder()
|
||||
.title("Open raw text editor")
|
||||
.subtitle("Launch a dedicated editor window with apply and reload actions")
|
||||
.subtitle("Launch a dedicated editor window with apply and buffer-revert actions")
|
||||
.build();
|
||||
launch_row.add_css_class("control-row");
|
||||
|
||||
let button_box = gtk4::Box::new(gtk4::Orientation::Horizontal, 8);
|
||||
let open_button = gtk4::Button::with_label("Open Editor");
|
||||
open_button.add_css_class("suggested-action");
|
||||
let reload_button = gtk4::Button::with_label("Refresh Snapshot");
|
||||
button_box.append(&reload_button);
|
||||
button_box.append(&open_button);
|
||||
|
||||
let ctx_reload = ctx.clone();
|
||||
let source_row_reload = source_row.clone();
|
||||
let stats_row_reload = stats_row.clone();
|
||||
reload_button.connect_clicked(move |_| {
|
||||
source_row_reload.set_subtitle(¤t_config_path(&ctx_reload));
|
||||
stats_row_reload.set_subtitle(¤t_stats_label(&ctx_reload));
|
||||
});
|
||||
|
||||
let ctx_open = ctx.clone();
|
||||
let source_row_open = source_row.clone();
|
||||
@@ -73,7 +62,7 @@ pub fn build_page(ctx: &PageBuildContext) -> gtk4::ScrolledWindow {
|
||||
open_editor_window(&ctx_open);
|
||||
});
|
||||
|
||||
launch_row.add_suffix(&button_box);
|
||||
launch_row.add_suffix(&open_button);
|
||||
session_group.add(&launch_row);
|
||||
|
||||
let workflow_group = tool_page::append_custom_section(
|
||||
@@ -107,7 +96,7 @@ fn open_editor_window(ctx: &PageBuildContext) {
|
||||
let (outer, body, footer_row) = tool_page::build_utility_window_shell(
|
||||
"Manual editing",
|
||||
"Raw Config Editor",
|
||||
"Apply updates back into MangoTune when you want the dashboard and page controls to reflect them. Reload discards unsaved raw edits and restores the current in-memory config.",
|
||||
"Apply updates back into MangoTune when you want the dashboard and page controls to reflect them. Revert Buffer discards unsaved raw edits and restores the current in-memory config.",
|
||||
);
|
||||
|
||||
let buffer = gtk4::TextBuffer::new(None::<>k4::TextTagTable>);
|
||||
@@ -139,7 +128,7 @@ fn open_editor_window(ctx: &PageBuildContext) {
|
||||
|
||||
let spacer = gtk4::Box::new(gtk4::Orientation::Horizontal, 0);
|
||||
spacer.set_hexpand(true);
|
||||
let reload = gtk4::Button::with_label("Reload");
|
||||
let reload = gtk4::Button::with_label("Revert Buffer");
|
||||
let apply = gtk4::Button::with_label("Apply to Workspace");
|
||||
apply.add_css_class("suggested-action");
|
||||
footer_row.append(&spacer);
|
||||
@@ -162,8 +151,9 @@ fn open_editor_window(ctx: &PageBuildContext) {
|
||||
}
|
||||
|
||||
update_footer(&footer_apply, &text);
|
||||
recompute_validation(&ctx_apply.state);
|
||||
refresh_save_button(&ctx_apply.state, &ctx_apply.save_button);
|
||||
sync_config_ui(&ctx_apply);
|
||||
apply_live_preview_now(&ctx_apply);
|
||||
refresh_current_page_later(&ctx_apply.parent_window);
|
||||
show_toast(
|
||||
&ctx_apply.toast_overlay,
|
||||
"Applied raw text changes to the workspace",
|
||||
|
||||
Reference in New Issue
Block a user