mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-12-02 20:18:38 -05:00
Workspaces: built-in workspaces open their panel again
Switching to Essentials Classic, Automation, Layout, Painting, Printing and Proofing, Typography, Web or Touch, or resetting one, brought its panel to the front of its group but no longer opened it from a column collapsed to icons, so the panel stayed hidden. A workspace record keeps the panel open from the icons again: each built-in names its panel, a workspace left or saved keeps the one open then, and switching or Reset opens it. A recorded panel the new layout does not show from icons stays closed. Workspaces saved without the field open none. The Essentials Classic test checks the open panel again, and new tests cover Painting, Automation, switching back as left, Reset, saved workspaces and the preferences' JSON.
This commit is contained in:
1 parent
a735b49248
commit
1c9efecfb6
1 file changed
+77
@@ -64,6 +64,10 @@ pub struct WorkspaceRecord {
|
||||
/// Tabs closed together by a panel shortcut.
|
||||
#[serde(skip_serializing_if = "Vec::is_empty")]
|
||||
pub docking_hidden_groups: Vec<Vec<String>>,
|
||||
/// The panel open from a column collapsed to icons (built-in workspaces: the panel the
|
||||
/// workspace is for; workspaces saved without this field: none).
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub open_panel: Option<String>,
|
||||
/// The tool each flyout group of the main Tools shows (built-in workspaces: the first).
|
||||
pub tools_last_used: LastUsed<String>,
|
||||
/// The toolbars made with New Toolbar in this workspace (built-in workspaces: none).
|
||||
@@ -87,6 +91,7 @@ impl Default for WorkspaceRecord {
|
||||
status_bar: true,
|
||||
help_bar: true,
|
||||
docking_hidden_groups: Vec::new(),
|
||||
open_panel: None,
|
||||
tools_last_used: LastUsed::default(),
|
||||
toolbars: Vec::new(),
|
||||
}
|
||||
@@ -245,25 +250,30 @@ pub fn builtins() -> Vec<Builtin> {
|
||||
x.rulers = true;
|
||||
x.toolbar_advanced = true;
|
||||
x.task_bar = false;
|
||||
x.open_panel = Some("color".into());
|
||||
}),
|
||||
w("Automation", &["layers", "actions"], &|x| {
|
||||
x.control_bar = true;
|
||||
x.toolbar_advanced = true;
|
||||
x.open_panel = Some("actions".into());
|
||||
}),
|
||||
w("Layout", &["layers", "align"], &|x| {
|
||||
x.control_bar = true;
|
||||
x.rulers = true;
|
||||
x.toolbar_advanced = true;
|
||||
x.open_panel = Some("align".into());
|
||||
}),
|
||||
w("Painting", &["brushes"], &|x| {
|
||||
x.control_bar = true;
|
||||
x.toolbar_advanced = true;
|
||||
x.open_panel = Some("brushes".into());
|
||||
})
|
||||
.double_tools(),
|
||||
w("Printing and Proofing", &["info"], &|x| {
|
||||
x.control_bar = true;
|
||||
x.rulers = true;
|
||||
x.toolbar_advanced = true;
|
||||
x.open_panel = Some("info".into());
|
||||
}),
|
||||
w("Tracing", &["layers"], &|x| {
|
||||
x.control_bar = true;
|
||||
@@ -274,16 +284,19 @@ pub fn builtins() -> Vec<Builtin> {
|
||||
x.control_bar = true;
|
||||
x.rulers = true;
|
||||
x.toolbar_advanced = true;
|
||||
x.open_panel = Some("character".into());
|
||||
}),
|
||||
w("Web", &["symbols"], &|x| {
|
||||
x.control_bar = true;
|
||||
x.rulers = true;
|
||||
x.toolbar_advanced = true;
|
||||
x.open_panel = Some("symbols".into());
|
||||
}),
|
||||
w(TOUCH, &["align"], &|x| {
|
||||
x.control_bar = true;
|
||||
x.toolbar_advanced = true;
|
||||
x.task_bar = true;
|
||||
x.open_panel = Some("align".into());
|
||||
}),
|
||||
]
|
||||
}
|
||||
@@ -387,6 +400,7 @@ pub fn record(ui: &UiState) -> WorkspaceRecord {
|
||||
status_bar: ui.status_bar,
|
||||
help_bar: ui.help_bar,
|
||||
docking_hidden_groups: ui.docking_hidden_groups.clone(),
|
||||
open_panel: ui.open_panel.clone(),
|
||||
tools_last_used: ui.tools_last_used.clone(),
|
||||
toolbars: ui.custom_toolbars.clone(),
|
||||
}
|
||||
@@ -412,6 +426,7 @@ fn apply_record(ui: &mut UiState, w: &WorkspaceRecord) {
|
||||
ui.status_bar = w.status_bar;
|
||||
ui.help_bar = w.help_bar;
|
||||
ui.docking_hidden_groups = w.docking_hidden_groups.clone();
|
||||
ui.open_panel = w.open_panel.clone();
|
||||
ui.tools_last_used = w.tools_last_used.clone();
|
||||
ui.custom_toolbars = w.toolbars.clone();
|
||||
crate::custom_toolbars::sanitize(&mut ui.custom_toolbars);
|
||||
@@ -450,10 +465,19 @@ pub fn switch(app: &mut VectorcraftApp, key: &str) -> Result<String, String> {
|
||||
let w = ui.workspaces.edited.get(&id).cloned().unwrap_or_else(|| saved_record(&ui.workspaces, &id));
|
||||
apply_record(ui, &w);
|
||||
crate::panel_docking::reconcile(&mut ui.dock_workspace);
|
||||
close_stale_flyout(ui);
|
||||
crate::panel_docking::show_panels(app);
|
||||
Ok(name)
|
||||
}
|
||||
|
||||
/// Close the open panel when the layout now in use does not show it from a column collapsed to
|
||||
/// icons (it was moved, expanded or closed).
|
||||
fn close_stale_flyout(ui: &mut UiState) {
|
||||
if ui.open_panel.as_ref().is_some_and(|panel| !crate::panel_docking::layout_of(ui).opens_in_flyout(panel)) {
|
||||
ui.open_panel = None;
|
||||
}
|
||||
}
|
||||
|
||||
/// Reset the current workspace to the way it was saved, dropping its changes.
|
||||
pub fn reset(app: &mut VectorcraftApp) -> String {
|
||||
let ui = &mut app.ui;
|
||||
@@ -467,6 +491,7 @@ pub fn reset(app: &mut VectorcraftApp) -> String {
|
||||
apply_record(ui, &w);
|
||||
ui.custom_toolbars = toolbars;
|
||||
crate::panel_docking::reconcile(&mut ui.dock_workspace);
|
||||
close_stale_flyout(ui);
|
||||
crate::panel_docking::show_panels(app);
|
||||
current_name(&app.ui).to_string()
|
||||
}
|
||||
@@ -715,12 +740,64 @@ mod tests {
|
||||
switch(&mut app, "Essentials Classic").unwrap();
|
||||
assert!(app.ui.control_bar && app.ui.view.rulers && app.ui.toolbar_advanced);
|
||||
assert!(front(&app.ui, "color"));
|
||||
assert_eq!(app.ui.open_panel.as_deref(), Some("color"));
|
||||
assert_eq!(current_name(&app.ui), "Essentials Classic");
|
||||
switch(&mut app, "essentials").unwrap();
|
||||
assert!(!app.ui.control_bar && !app.ui.view.rulers);
|
||||
assert_eq!(app.ui.open_panel, None);
|
||||
assert_eq!(app.ui.brightness, crate::theme::Brightness::Light);
|
||||
}
|
||||
|
||||
/// A built-in workspace shows the panel it is for, from its collapsed column too: the second
|
||||
/// panel it brings forward (Automation's Actions) as well as the only one (Painting's
|
||||
/// Brushes). A panel closed there stays closed when the workspace is left and switched back
|
||||
/// to, and Reset opens it again.
|
||||
#[test]
|
||||
fn builtin_workspaces_show_their_panel_after_switch_and_reset() {
|
||||
let showing = crate::panel_docking::showing;
|
||||
let mut app = app();
|
||||
for (name, panel) in [("Painting", "brushes"), ("Automation", "actions"), ("Essentials Classic", "color")] {
|
||||
switch(&mut app, name).unwrap();
|
||||
assert!(showing(&app.ui, panel), "{name} shows {panel}");
|
||||
}
|
||||
assert!(crate::panel_docking::layout_of(&app.ui).opens_in_flyout(&"color".to_string()), "Classic's Color opens from its icon");
|
||||
app.ui.open_panel = None;
|
||||
switch(&mut app, ESSENTIALS).unwrap();
|
||||
assert!(!showing(&app.ui, "color"), "Essentials opens no panel");
|
||||
switch(&mut app, "Essentials Classic").unwrap();
|
||||
assert!(!showing(&app.ui, "color"), "Classic comes back as it was left");
|
||||
reset(&mut app);
|
||||
assert!(showing(&app.ui, "color"), "Reset Essentials Classic shows Color again");
|
||||
}
|
||||
|
||||
/// A saved workspace keeps the panel open from its icons, through the preferences' JSON too; a
|
||||
/// workspace saved without that field opens none, and one naming a panel its layout does not
|
||||
/// show from icons opens none either.
|
||||
#[test]
|
||||
fn saved_workspaces_restore_the_open_panel() {
|
||||
let mut app = app();
|
||||
switch(&mut app, "Essentials Classic").unwrap();
|
||||
save_as(&mut app.ui, "Colors").unwrap();
|
||||
switch(&mut app, ESSENTIALS).unwrap();
|
||||
assert_eq!(app.ui.open_panel, None);
|
||||
switch(&mut app, "Colors").unwrap();
|
||||
assert_eq!(app.ui.open_panel.as_deref(), Some("color"));
|
||||
let id = id_of(&app.ui, "Colors");
|
||||
let back: UiState = serde_json::from_value(serde_json::to_value(&app.ui).unwrap()).unwrap();
|
||||
assert_eq!(back.workspaces.records[&id].open_panel.as_deref(), Some("color"));
|
||||
let mut old = serde_json::to_value(&back.workspaces.records[&id]).unwrap();
|
||||
assert!(old.as_object_mut().unwrap().remove("openPanel").is_some());
|
||||
let old: WorkspaceRecord = serde_json::from_value(old).unwrap();
|
||||
assert_eq!(old.open_panel, None);
|
||||
switch(&mut app, ESSENTIALS).unwrap();
|
||||
app.ui.workspaces.edited.get_mut(&id).unwrap().open_panel = Some("no-such-panel".into());
|
||||
switch(&mut app, "Colors").unwrap();
|
||||
assert_eq!(app.ui.open_panel, None, "switching opens no panel the layout's icons lack");
|
||||
app.ui.workspaces.records.get_mut(&id).unwrap().open_panel = Some("no-such-panel".into());
|
||||
reset(&mut app);
|
||||
assert_eq!(app.ui.open_panel, None, "Reset opens no panel the layout's icons lack");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn save_apply_round_trip() {
|
||||
let mut app = app();
|
||||
|
||||
Reference in new issue
Block a user