Persist advanced options expand/collapse state per section
Each ExpanderRow now remembers its expanded state between sessions using a per-section key stored in SessionState. Replaces the global detailed_mode toggle with granular per-section persistence.
This commit is contained in:
@@ -189,6 +189,7 @@ pub struct SessionState {
|
|||||||
pub watermark_enabled: Option<bool>,
|
pub watermark_enabled: Option<bool>,
|
||||||
pub rename_enabled: Option<bool>,
|
pub rename_enabled: Option<bool>,
|
||||||
pub last_seen_version: Option<String>,
|
pub last_seen_version: Option<String>,
|
||||||
|
pub expanded_sections: std::collections::HashMap<String, bool>,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct SessionStore {
|
pub struct SessionStore {
|
||||||
|
|||||||
@@ -102,6 +102,19 @@ pub struct AppState {
|
|||||||
pub job_config: Rc<RefCell<JobConfig>>,
|
pub job_config: Rc<RefCell<JobConfig>>,
|
||||||
pub detailed_mode: bool,
|
pub detailed_mode: bool,
|
||||||
pub batch_queue: Rc<RefCell<BatchQueue>>,
|
pub batch_queue: Rc<RefCell<BatchQueue>>,
|
||||||
|
pub expanded_sections: Rc<RefCell<std::collections::HashMap<String, bool>>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl AppState {
|
||||||
|
/// Get the expanded state for a named section, falling back to the skill level default
|
||||||
|
pub fn is_section_expanded(&self, section: &str) -> bool {
|
||||||
|
self.expanded_sections.borrow().get(section).copied().unwrap_or(self.detailed_mode)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Set and persist an expander's state
|
||||||
|
pub fn set_section_expanded(&self, section: &str, expanded: bool) {
|
||||||
|
self.expanded_sections.borrow_mut().insert(section.to_string(), expanded);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A queued batch of images with their processing settings
|
/// A queued batch of images with their processing settings
|
||||||
@@ -300,6 +313,7 @@ fn build_ui(app: &adw::Application) {
|
|||||||
output_dir: Rc::new(RefCell::new(None)),
|
output_dir: Rc::new(RefCell::new(None)),
|
||||||
detailed_mode: app_cfg.skill_level.is_advanced(),
|
detailed_mode: app_cfg.skill_level.is_advanced(),
|
||||||
batch_queue: Rc::new(RefCell::new(BatchQueue::default())),
|
batch_queue: Rc::new(RefCell::new(BatchQueue::default())),
|
||||||
|
expanded_sections: Rc::new(RefCell::new(sess_state.expanded_sections.clone())),
|
||||||
job_config: Rc::new(RefCell::new(JobConfig {
|
job_config: Rc::new(RefCell::new(JobConfig {
|
||||||
resize_enabled: if remember { sess_state.resize_enabled.unwrap_or(true) } else { true },
|
resize_enabled: if remember { sess_state.resize_enabled.unwrap_or(true) } else { true },
|
||||||
resize_width: if remember { sess_state.resize_width.unwrap_or(1200) } else { 1200 },
|
resize_width: if remember { sess_state.resize_width.unwrap_or(1200) } else { 1200 },
|
||||||
@@ -574,6 +588,9 @@ fn build_ui(app: &adw::Application) {
|
|||||||
state.rename_enabled = Some(cfg.rename_enabled);
|
state.rename_enabled = Some(cfg.rename_enabled);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Always save expanded section states
|
||||||
|
state.expanded_sections = app_state_for_close.expanded_sections.borrow().clone();
|
||||||
|
|
||||||
let _ = session.save(&state);
|
let _ = session.save(&state);
|
||||||
glib::Propagation::Proceed
|
glib::Propagation::Proceed
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -98,8 +98,16 @@ pub fn build_adjustments_page(state: &AppState) -> adw::NavigationPage {
|
|||||||
.title("Advanced Adjustments")
|
.title("Advanced Adjustments")
|
||||||
.subtitle("Brightness, contrast, saturation, effects")
|
.subtitle("Brightness, contrast, saturation, effects")
|
||||||
.show_enable_switch(false)
|
.show_enable_switch(false)
|
||||||
|
.expanded(state.is_section_expanded("adjustments-advanced"))
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
|
{
|
||||||
|
let st = state.clone();
|
||||||
|
adjust_expander.connect_expanded_notify(move |row| {
|
||||||
|
st.set_section_expanded("adjustments-advanced", row.is_expanded());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// Brightness slider (-100 to +100)
|
// Brightness slider (-100 to +100)
|
||||||
let brightness_row = adw::ActionRow::builder()
|
let brightness_row = adw::ActionRow::builder()
|
||||||
.title("Brightness")
|
.title("Brightness")
|
||||||
|
|||||||
@@ -343,9 +343,16 @@ pub fn build_compress_page(state: &AppState) -> adw::NavigationPage {
|
|||||||
let advanced_expander = adw::ExpanderRow::builder()
|
let advanced_expander = adw::ExpanderRow::builder()
|
||||||
.title("Per-Format Quality")
|
.title("Per-Format Quality")
|
||||||
.subtitle("Fine-tune quality for each format individually")
|
.subtitle("Fine-tune quality for each format individually")
|
||||||
.expanded(state.detailed_mode)
|
.expanded(state.is_section_expanded("compress-advanced"))
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
|
{
|
||||||
|
let st = state.clone();
|
||||||
|
advanced_expander.connect_expanded_notify(move |row| {
|
||||||
|
st.set_section_expanded("compress-advanced", row.is_expanded());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
let jpeg_row = adw::SpinRow::builder()
|
let jpeg_row = adw::SpinRow::builder()
|
||||||
.title("JPEG Quality")
|
.title("JPEG Quality")
|
||||||
.subtitle("1-100, higher is better quality")
|
.subtitle("1-100, higher is better quality")
|
||||||
|
|||||||
@@ -145,9 +145,16 @@ pub fn build_convert_page(state: &AppState) -> adw::NavigationPage {
|
|||||||
.title("Format Mapping")
|
.title("Format Mapping")
|
||||||
.subtitle("Different input formats can convert to different outputs")
|
.subtitle("Different input formats can convert to different outputs")
|
||||||
.show_enable_switch(false)
|
.show_enable_switch(false)
|
||||||
.expanded(state.detailed_mode)
|
.expanded(state.is_section_expanded("convert-advanced"))
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
|
{
|
||||||
|
let st = state.clone();
|
||||||
|
advanced_expander.connect_expanded_notify(move |row| {
|
||||||
|
st.set_section_expanded("convert-advanced", row.is_expanded());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
let progressive_row = adw::SwitchRow::builder()
|
let progressive_row = adw::SwitchRow::builder()
|
||||||
.title("Progressive JPEG")
|
.title("Progressive JPEG")
|
||||||
.subtitle("Loads gradually in browsers, slightly larger")
|
.subtitle("Loads gradually in browsers, slightly larger")
|
||||||
|
|||||||
@@ -372,9 +372,16 @@ pub fn build_resize_page(state: &AppState) -> adw::NavigationPage {
|
|||||||
.title("Advanced Options")
|
.title("Advanced Options")
|
||||||
.subtitle("Resize algorithm, DPI, upscale behavior")
|
.subtitle("Resize algorithm, DPI, upscale behavior")
|
||||||
.show_enable_switch(false)
|
.show_enable_switch(false)
|
||||||
.expanded(state.detailed_mode)
|
.expanded(state.is_section_expanded("resize-advanced"))
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
|
{
|
||||||
|
let st = state.clone();
|
||||||
|
advanced_expander.connect_expanded_notify(move |row| {
|
||||||
|
st.set_section_expanded("resize-advanced", row.is_expanded());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
let upscale_row = adw::SwitchRow::builder()
|
let upscale_row = adw::SwitchRow::builder()
|
||||||
.title("Allow Upscaling")
|
.title("Allow Upscaling")
|
||||||
.subtitle("Enlarge images smaller than target size")
|
.subtitle("Enlarge images smaller than target size")
|
||||||
|
|||||||
@@ -336,9 +336,16 @@ pub fn build_watermark_page(state: &AppState) -> adw::NavigationPage {
|
|||||||
.title("Advanced Options")
|
.title("Advanced Options")
|
||||||
.subtitle("Opacity, rotation, tiling, margin")
|
.subtitle("Opacity, rotation, tiling, margin")
|
||||||
.show_enable_switch(false)
|
.show_enable_switch(false)
|
||||||
.expanded(state.detailed_mode)
|
.expanded(state.is_section_expanded("watermark-advanced"))
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
|
{
|
||||||
|
let st = state.clone();
|
||||||
|
advanced_expander.connect_expanded_notify(move |row| {
|
||||||
|
st.set_section_expanded("watermark-advanced", row.is_expanded());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// Text color picker
|
// Text color picker
|
||||||
let color_row = adw::ActionRow::builder()
|
let color_row = adw::ActionRow::builder()
|
||||||
.title("Text Color")
|
.title("Text Color")
|
||||||
|
|||||||
Reference in New Issue
Block a user