mirror of
https://github.com/storytold/photocraft.git
synced 2026-11-21 09:26:43 +00:00
Merge pull request #14644 from hectorviov/fix/toolbar-group-layout
Toolbar: slots come from a stored group layout that edit.toolbar changes (#14459)
This commit is contained in:
7 files changed
+417
-24
No files matched your search
+118
-1
@@ -1323,12 +1323,129 @@ impl MenuCustomization {
|
||||
}
|
||||
}
|
||||
|
||||
/// Edit › Toolbar: hidden tools and a custom order (tool names as in `ui.set {tool}`).
|
||||
/// Edit › Toolbar: the toolbar's group layout (tool names as in `ui.set {tool}`), plus the older
|
||||
/// flat `hidden` list and the unused `order` list.
|
||||
#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)]
|
||||
#[serde(default, rename_all = "camelCase")]
|
||||
pub struct ToolbarCustomization {
|
||||
/// Tools taken off the toolbar one by one (the Keyboard Shortcuts dialog's Toolbar tab). The
|
||||
/// layout moves each into `extras` as its own group.
|
||||
pub hidden: Vec<String>,
|
||||
pub order: Vec<String>,
|
||||
/// The toolbar's slots in order, each a group of tools in flyout order. `None` is the
|
||||
/// default layout ([`DEFAULT_TOOLBAR`]).
|
||||
pub toolbar: Option<Vec<Vec<String>>>,
|
||||
/// Extra Tools: groups that get no slot of their own. Like `toolbar`, `null` is the default
|
||||
/// (stored as such, so `prefs.reset` of one path finds its default).
|
||||
pub extras: Option<Vec<Vec<String>>>,
|
||||
}
|
||||
|
||||
/// The default toolbar layout: one group per slot, in toolbar order (the same as the toolbar's
|
||||
/// `TOOL_SECTIONS` read slot by slot).
|
||||
pub const DEFAULT_TOOLBAR: &[&[&str]] = &[
|
||||
&["Move", "Artboard"],
|
||||
&["RectMarquee", "EllipseMarquee", "SingleRowMarquee", "SingleColumnMarquee"],
|
||||
&["Lasso", "PolygonLasso", "MagneticLasso"],
|
||||
&["ObjectSelection", "QuickSelection", "MagicWand"],
|
||||
&["Crop", "PerspectiveCrop", "Slice", "SliceSelect"],
|
||||
&["Frame"],
|
||||
&["Eyedropper", "ColorSampler", "Ruler", "Note", "Count"],
|
||||
&["SpotHealing", "Remove", "Healing", "Patch", "ContentAwareMove", "RedEye"],
|
||||
&["Brush", "Pencil", "ColorReplacement", "MixerBrush"],
|
||||
&["CloneStamp", "PatternStamp"],
|
||||
&["HistoryBrush", "ArtHistoryBrush"],
|
||||
&["Eraser", "BackgroundEraser", "MagicEraser"],
|
||||
&["Gradient", "PaintBucket"],
|
||||
&["Blur", "Sharpen", "Smudge"],
|
||||
&["Dodge", "Burn", "Sponge"],
|
||||
&["Pen", "FreeformPen", "CurvaturePen", "AddAnchorPoint", "DeleteAnchorPoint", "ConvertPoint"],
|
||||
&["Type", "VerticalType", "VerticalTypeMask", "HorizontalTypeMask"],
|
||||
&["PathSelection", "DirectSelection"],
|
||||
&["Rectangle", "EllipseShape", "Triangle", "Polygon", "Star", "Line", "CustomShape"],
|
||||
&["Hand", "RotateView"],
|
||||
&["Zoom"],
|
||||
];
|
||||
|
||||
/// A toolbar layout with every name resolved: the slots' groups and the Extra Tools groups.
|
||||
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
|
||||
pub struct ToolbarLayout {
|
||||
pub toolbar: Vec<Vec<String>>,
|
||||
pub extras: Vec<Vec<String>>,
|
||||
}
|
||||
|
||||
impl ToolbarCustomization {
|
||||
/// The tool `name` means, as its canonical name (the `tools.select.<tool>` id with a capital
|
||||
/// first letter, which is the toolbar's `Tool` name). Matches like `ui.set {tool}`: case,
|
||||
/// spaces, `_` and `-` don't count, a marquee may drop "Marquee", and the tool's own name
|
||||
/// works with or without "Tool". `None` for a name that isn't a tool.
|
||||
pub fn tool_name(name: &str) -> Option<String> {
|
||||
let canonical = |key: &str| -> String { key.chars().take(1).flat_map(char::to_uppercase).chain(key.chars().skip(1)).collect() };
|
||||
// Stored layouts hold canonical names: find those without allocating (the toolbar
|
||||
// resolves its layout every frame).
|
||||
if let Some(key) = crate::shell_commands::TOOLS.iter().filter_map(|(id, _, _)| id.strip_prefix("tools.select.")).find(|k| k.eq_ignore_ascii_case(name))
|
||||
{
|
||||
return Some(canonical(key));
|
||||
}
|
||||
let squash = |s: &str| s.to_ascii_lowercase().replace([' ', '_', '-'], "");
|
||||
let n = squash(name);
|
||||
if n.is_empty() {
|
||||
return None;
|
||||
}
|
||||
crate::shell_commands::TOOLS.iter().find_map(|(id, label, _)| {
|
||||
let key = id.strip_prefix("tools.select.")?;
|
||||
let k = key.to_ascii_lowercase();
|
||||
let label = squash(label);
|
||||
let hit = n == k || n == k.replace("marquee", "") || n == label || Some(n.as_str()) == label.strip_suffix("tool");
|
||||
hit.then(|| canonical(key))
|
||||
})
|
||||
}
|
||||
|
||||
/// The layout the toolbar shows. Unknown names are skipped and a tool listed twice keeps its
|
||||
/// first place (the toolbar before the extras); empty groups are dropped. Each `hidden` tool
|
||||
/// leaves its toolbar group for a group of its own in the extras, in toolbar order, and a
|
||||
/// tool listed nowhere is added to the extras as its own group.
|
||||
pub fn layout(&self) -> ToolbarLayout {
|
||||
let hidden: Vec<String> = self.hidden.iter().filter_map(|h| Self::tool_name(h)).collect();
|
||||
let stored = match &self.toolbar {
|
||||
Some(groups) => groups.clone(),
|
||||
None => DEFAULT_TOOLBAR.iter().map(|g| g.iter().map(|t| (*t).to_string()).collect()).collect(),
|
||||
};
|
||||
// `moved` collects the hidden tools when given; without it they stay in their group.
|
||||
fn resolve(groups: &[Vec<String>], seen: &mut Vec<String>, hidden: &[String], mut moved: Option<&mut Vec<Vec<String>>>) -> Vec<Vec<String>> {
|
||||
let mut out = Vec::new();
|
||||
for group in groups {
|
||||
let mut tools = Vec::new();
|
||||
for name in group.iter().filter_map(|n| ToolbarCustomization::tool_name(n)) {
|
||||
if seen.contains(&name) {
|
||||
continue;
|
||||
}
|
||||
seen.push(name.clone());
|
||||
match moved.as_deref_mut() {
|
||||
Some(moved) if hidden.contains(&name) => moved.push(vec![name]),
|
||||
_ => tools.push(name),
|
||||
}
|
||||
}
|
||||
if !tools.is_empty() {
|
||||
out.push(tools);
|
||||
}
|
||||
}
|
||||
out
|
||||
}
|
||||
let mut seen: Vec<String> = Vec::new();
|
||||
let mut moved = Vec::new();
|
||||
let toolbar = resolve(&stored, &mut seen, &hidden, Some(&mut moved));
|
||||
let mut extras = resolve(self.extras.as_deref().unwrap_or_default(), &mut seen, &hidden, None);
|
||||
extras.append(&mut moved);
|
||||
for (id, _, _) in crate::shell_commands::TOOLS {
|
||||
if let Some(name) = Self::tool_name(id.trim_start_matches("tools.select."))
|
||||
&& !seen.contains(&name)
|
||||
{
|
||||
seen.push(name.clone());
|
||||
extras.push(vec![name]);
|
||||
}
|
||||
}
|
||||
ToolbarLayout { toolbar, extras }
|
||||
}
|
||||
}
|
||||
|
||||
/// Layer Mask Display Options (double-click the layer mask's row in the Channels panel, or Mask
|
||||
|
||||
@@ -113,9 +113,22 @@ fn preferences_section(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
Ok(json!({"section": section, "title": title, "values": values}))
|
||||
}
|
||||
|
||||
/// Edit › Toolbar: hide tools and reorder the toolbar.
|
||||
/// Edit › Toolbar: the toolbar's group layout (`toolbar` slots and `extras`, each a list of tool
|
||||
/// groups), and the older flat `hidden` list. Returns the resulting layout.
|
||||
fn toolbar(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
let ids = |k: &str| -> Option<Vec<String>> { p.get(k).and_then(Value::as_array).map(|a| a.iter().filter_map(Value::as_str).map(str::to_string).collect()) };
|
||||
// A list of groups; a bare name is a group of one.
|
||||
let groups = |k: &str| -> Result<Option<Vec<Vec<String>>>> {
|
||||
let Some(v) = p.get(k).filter(|v| !v.is_null()) else { return Ok(None) };
|
||||
let list = v.as_array().ok_or_else(|| bad("edit.toolbar", format!("`{k}` needs a list of tool groups")))?;
|
||||
let group = |g: &Value| match g {
|
||||
Value::Array(a) => Ok(a.iter().filter_map(Value::as_str).map(str::to_string).collect()),
|
||||
Value::String(name) => Ok(vec![name.clone()]),
|
||||
_ => Err(bad("edit.toolbar", format!("`{k}` needs a list of tool groups"))),
|
||||
};
|
||||
list.iter().map(group).collect::<Result<Vec<Vec<String>>>>().map(Some)
|
||||
};
|
||||
let (toolbar, extras) = (groups("toolbar")?, groups("extras")?);
|
||||
s.edit_prefs(|pr| {
|
||||
if p.get("reset").and_then(Value::as_bool) == Some(true) {
|
||||
pr.toolbar = ToolbarCustomization::default();
|
||||
@@ -126,8 +139,22 @@ fn toolbar(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
if let Some(o) = ids("order") {
|
||||
pr.toolbar.order = o;
|
||||
}
|
||||
if toolbar.is_some() || extras.is_some() {
|
||||
let current = pr.toolbar.layout();
|
||||
// Tools a new extras list names leave the current toolbar for it.
|
||||
let named: Vec<String> = extras.iter().flatten().flatten().filter_map(|n| ToolbarCustomization::tool_name(n)).collect();
|
||||
let toolbar =
|
||||
toolbar.clone().unwrap_or_else(|| current.toolbar.iter().map(|g| g.iter().filter(|t| !named.contains(t)).cloned().collect()).collect());
|
||||
let extras = extras.clone().unwrap_or(current.extras);
|
||||
// The new layout holds the hidden tools now; keep it as it was given.
|
||||
let layout = ToolbarCustomization { toolbar: Some(toolbar), extras: Some(extras), ..Default::default() }.layout();
|
||||
pr.toolbar.hidden.clear();
|
||||
pr.toolbar.toolbar = Some(layout.toolbar);
|
||||
pr.toolbar.extras = Some(layout.extras);
|
||||
}
|
||||
});
|
||||
Ok(serde_json::to_value(&s.prefs().toolbar).unwrap_or_default())
|
||||
let layout = s.prefs().toolbar.layout();
|
||||
Ok(json!({"toolbar": layout.toolbar, "extras": layout.extras}))
|
||||
}
|
||||
|
||||
macro_rules! spec {
|
||||
@@ -208,6 +235,14 @@ pub fn specs() -> Vec<CommandSpec> {
|
||||
menus,
|
||||
true
|
||||
),
|
||||
spec!("edit.toolbar", "Toolbar…", ["Edit"], None, r##"{"hidden":["<tool>",…]?,"order":["<tool>",…]?,"reset":bool=false}"##, toolbar, true),
|
||||
spec!(
|
||||
"edit.toolbar",
|
||||
"Toolbar…",
|
||||
["Edit"],
|
||||
None,
|
||||
r##"{"toolbar":[["<tool>",…],…]?,"extras":[["<tool>",…],…]?,"hidden":["<tool>",…]?,"order":["<tool>",…]?,"reset":bool=false}"##,
|
||||
toolbar,
|
||||
true
|
||||
),
|
||||
]
|
||||
}
|
||||
@@ -1056,9 +1056,10 @@ fn select_tool_by_key(app: &mut PhotocraftApp, ctx: &egui::Context, pressed: &im
|
||||
if cycle_shift || pressed(k) {
|
||||
let before = app.ui.tool;
|
||||
let mut group: Vec<Tool> = Tool::ALL.iter().copied().filter(|x| x.key() == t.key() && crate::tool_shortcuts::uses_default(app, *x)).collect();
|
||||
// Shift+key cycles in toolbar flyout order.
|
||||
// Shift+key cycles in the toolbar layout's order, across slots (Edit › Toolbar).
|
||||
if cycle_shift {
|
||||
group.sort_by_key(|x| crate::panels::toolbar::toolbar_position(*x));
|
||||
let order = crate::panels::toolbar::layout_order(&app.session.prefs().toolbar);
|
||||
group.sort_by_key(|x| order.iter().position(|t| t == x).unwrap_or(usize::MAX));
|
||||
}
|
||||
let next_tool = match group.iter().position(|x| *x == app.ui.tool) {
|
||||
Some(i) if shift_switch && !cycle_shift => group[i],
|
||||
|
||||
@@ -870,6 +870,8 @@ mod tool_shift_cycle_order_tests;
|
||||
#[cfg(test)]
|
||||
mod tool_shortcut_tests;
|
||||
#[cfg(test)]
|
||||
mod toolbar_custom_group_layout_tests;
|
||||
#[cfg(test)]
|
||||
mod toolbar_group_order_tests;
|
||||
#[cfg(test)]
|
||||
mod toolbar_more_slot_flyout_tests;
|
||||
|
||||
@@ -69,31 +69,77 @@ pub(crate) fn toolbar_position(tool: Tool) -> usize {
|
||||
TOOL_SECTIONS.iter().flat_map(|section| section.iter()).flat_map(|slot| slot.iter()).position(|&t| t == tool).unwrap_or(usize::MAX)
|
||||
}
|
||||
|
||||
/// [`TOOL_SECTIONS`] without the tools hidden in Edit › Toolbar (`hidden` holds tool names: the
|
||||
/// dialog writes `Tool` debug names, `edit.toolbar` takes any name `Tool::from_name` reads). A
|
||||
/// slot keeps only its visible tools, so its flyout lists just those; a slot with none left is
|
||||
/// dropped, and so is a section with no slots. Each slot carries its index in `TOOL_SECTIONS`,
|
||||
/// so its flyout stays put when other slots are hidden.
|
||||
pub(super) fn visible_sections(hidden: &[String]) -> Vec<Vec<(usize, Vec<Tool>)>> {
|
||||
let hidden: Vec<Tool> = hidden.iter().map(String::as_str).filter_map(Tool::from_name).collect();
|
||||
/// The toolbar's group layout from Edit › Toolbar (`edit.toolbar`), as tools: the slots' groups
|
||||
/// in order, then the Extra Tools groups. Names were resolved by the engine
|
||||
/// (`ToolbarCustomization::layout`), which writes `Tool` debug names.
|
||||
pub(crate) fn tool_layout(custom: &photocraft_engine::prefs::ToolbarCustomization) -> (Vec<Vec<Tool>>, Vec<Vec<Tool>>) {
|
||||
let layout = custom.layout();
|
||||
let tools = |groups: Vec<Vec<String>>| -> Vec<Vec<Tool>> {
|
||||
groups.iter().map(|g| g.iter().filter_map(|n| Tool::from_name(n)).collect::<Vec<Tool>>()).filter(|g| !g.is_empty()).collect()
|
||||
};
|
||||
(tools(layout.toolbar), tools(layout.extras))
|
||||
}
|
||||
|
||||
/// Every tool in layout order: the slots' groups, then the extras. Shift+letter steps through a
|
||||
/// key's tools in this order, across slots.
|
||||
pub(crate) fn layout_order(custom: &photocraft_engine::prefs::ToolbarCustomization) -> Vec<Tool> {
|
||||
let (toolbar, extras) = tool_layout(custom);
|
||||
toolbar.into_iter().chain(extras).flatten().collect()
|
||||
}
|
||||
|
||||
/// The default slot (section, index in [`TOOL_SECTIONS`] read slot by slot) that holds `tool`.
|
||||
fn home_slot(tool: Tool) -> Option<(usize, usize)> {
|
||||
let mut index = 0usize;
|
||||
let mut sections = Vec::new();
|
||||
for section in TOOL_SECTIONS {
|
||||
let mut slots = Vec::new();
|
||||
for (si, section) in TOOL_SECTIONS.iter().enumerate() {
|
||||
for slot in section.iter() {
|
||||
let tools: Vec<Tool> = slot.iter().copied().filter(|tool| !hidden.contains(tool)).collect();
|
||||
if !tools.is_empty() {
|
||||
slots.push((index, tools));
|
||||
if slot.contains(&tool) {
|
||||
return Some((si, index));
|
||||
}
|
||||
index += 1;
|
||||
}
|
||||
if !slots.is_empty() {
|
||||
sections.push(slots);
|
||||
}
|
||||
None
|
||||
}
|
||||
|
||||
/// The slots the toolbar draws: one per toolbar group of the stored layout, in order, each
|
||||
/// listing its group's tools in order. Consecutive groups whose first tools come from the same
|
||||
/// default section share a section, so the default layout keeps its dividers. Each slot carries
|
||||
/// the index of its first tool's default slot in `TOOL_SECTIONS` (or one past the defaults when
|
||||
/// that index is taken), so its flyout stays put when other slots are hidden or moved.
|
||||
pub(crate) fn layout_sections(custom: &photocraft_engine::prefs::ToolbarCustomization) -> Vec<Vec<(usize, Vec<Tool>)>> {
|
||||
let (groups, _) = tool_layout(custom);
|
||||
let defaults: usize = TOOL_SECTIONS.iter().map(|section| section.len()).sum();
|
||||
let mut used: Vec<usize> = Vec::new();
|
||||
let mut sections: Vec<Vec<(usize, Vec<Tool>)>> = Vec::new();
|
||||
let mut last_section = None;
|
||||
for (i, group) in groups.into_iter().enumerate() {
|
||||
let home = group.first().copied().and_then(home_slot);
|
||||
let index = match home {
|
||||
Some((_, slot)) if !used.contains(&slot) => slot,
|
||||
_ => defaults + i,
|
||||
};
|
||||
used.push(index);
|
||||
let section = home.map(|(si, _)| si);
|
||||
if sections.is_empty() || section != last_section {
|
||||
sections.push(Vec::new());
|
||||
}
|
||||
last_section = section;
|
||||
if let Some(current) = sections.last_mut() {
|
||||
current.push((index, group));
|
||||
}
|
||||
}
|
||||
sections
|
||||
}
|
||||
|
||||
/// [`layout_sections`] for the default layout without the tools hidden in Edit › Toolbar
|
||||
/// (`hidden` holds tool names: the dialog writes `Tool` debug names, `edit.toolbar` takes any
|
||||
/// name `Tool::from_name` reads). A slot keeps only its visible tools, so its flyout lists just
|
||||
/// those; a slot with none left is dropped, and so is a section with no slots.
|
||||
#[cfg(test)]
|
||||
pub(super) fn visible_sections(hidden: &[String]) -> Vec<Vec<(usize, Vec<Tool>)>> {
|
||||
layout_sections(&photocraft_engine::prefs::ToolbarCustomization { hidden: hidden.to_vec(), ..Default::default() })
|
||||
}
|
||||
|
||||
/// A primary-button gesture started on this tool; open only after it leaves its hit area.
|
||||
/// Using pointer origin rather than `Response::dragged` also works for click-only icon buttons.
|
||||
pub(super) fn tool_flyout_drag_open(button: Rect, origin: Option<Pos2>, pointer: Option<Pos2>, primary_down: bool) -> bool {
|
||||
@@ -168,7 +214,7 @@ pub fn toolbar(app: &mut PhotocraftApp, ui: &mut egui::Ui) {
|
||||
let t = Tokens::get(ui.ctx());
|
||||
let (_, bx) = toolbar_columns(t.pro);
|
||||
let m = if t.pro { 5i8 } else { 7i8 };
|
||||
let sections = visible_sections(&app.session.prefs().toolbar.hidden);
|
||||
let sections = layout_sections(&app.session.prefs().toolbar);
|
||||
// Two columns when the header chevron asks for them; a column that doesn't fit scrolls.
|
||||
let double = app.ui.panels.toolbar_double;
|
||||
let w = toolbar_width(t.pro, double);
|
||||
|
||||
@@ -0,0 +1,192 @@
|
||||
//! #14459: the toolbar's slots come from a stored group layout that `edit.toolbar` changes. Each
|
||||
//! toolbar group is one slot listing its tools in order, the Extra Tools groups get no slot,
|
||||
//! Shift+letter steps through a key's tools in layout order across slots, an empty toolbar is
|
||||
//! allowed, `reset` brings back the default layout, and older settings still load.
|
||||
|
||||
use egui::{Key, Modifiers, Rect, vec2};
|
||||
use photocraft_engine::prefs::{DEFAULT_TOOLBAR, Preferences, ToolbarCustomization};
|
||||
use serde_json::{Value, json};
|
||||
|
||||
use crate::PhotocraftApp;
|
||||
use crate::panels::toolbar::{TOOL_SECTIONS, layout_sections, toolbar};
|
||||
use crate::state::Tool;
|
||||
use crate::theme::Tokens;
|
||||
|
||||
fn app() -> PhotocraftApp {
|
||||
PhotocraftApp::new(photocraft_engine::Session::new(), crate::Services::default())
|
||||
}
|
||||
|
||||
fn names(groups: &Value) -> Vec<Vec<String>> {
|
||||
serde_json::from_value(groups.clone()).unwrap()
|
||||
}
|
||||
|
||||
fn shift_press(app: &mut PhotocraftApp, key: Key) {
|
||||
let modifiers = Modifiers::SHIFT;
|
||||
let ctx = egui::Context::default();
|
||||
let raw = egui::RawInput {
|
||||
events: vec![egui::Event::ModifiersChanged(modifiers), egui::Event::Key { key, physical_key: None, pressed: true, repeat: false, modifiers }],
|
||||
..Default::default()
|
||||
};
|
||||
ctx.begin_pass(raw);
|
||||
crate::shortcuts::handle(app, &ctx);
|
||||
ctx.end_pass().textures_delta.clear();
|
||||
}
|
||||
|
||||
/// The tool slots the toolbar drew in its last pass (clickable tool-sized buttons).
|
||||
fn tool_buttons(app: &mut PhotocraftApp) -> usize {
|
||||
let ctx = egui::Context::default();
|
||||
PhotocraftApp::setup_context(&ctx, crate::theme::ThemeKind::ALL[0]);
|
||||
for time in [0.0, 0.1] {
|
||||
let mut out = ctx.run_ui(
|
||||
egui::RawInput { time: Some(time), screen_rect: Some(Rect::from_min_size(egui::Pos2::ZERO, vec2(1200.0, 1800.0))), ..Default::default() },
|
||||
|ui| toolbar(app, ui),
|
||||
);
|
||||
out.textures_delta.clear();
|
||||
}
|
||||
let size = egui::Vec2::splat(if Tokens::get(&ctx).pro { 30.0 } else { 36.0 });
|
||||
ctx.viewport(|v| v.prev_pass.widgets.layers().flat_map(|(_, w)| w.iter()).filter(|w| w.rect.size() == size && w.sense.senses_click()).count())
|
||||
}
|
||||
|
||||
/// The slots `layout_sections` gives for the app's stored layout, as tool groups.
|
||||
fn slots(app: &PhotocraftApp) -> Vec<Vec<Tool>> {
|
||||
layout_sections(&app.session.prefs().toolbar).into_iter().flatten().map(|(_, tools)| tools).collect()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn engine_tool_names_are_the_toolbar_tools() {
|
||||
for tool in Tool::ALL {
|
||||
let name = format!("{tool:?}");
|
||||
assert_eq!(ToolbarCustomization::tool_name(&name).as_deref(), Some(name.as_str()), "{tool:?}");
|
||||
assert_eq!(ToolbarCustomization::tool_name(tool.label()).as_deref(), Some(name.as_str()), "{tool:?} by its label");
|
||||
assert_eq!(Tool::from_name(&name), Some(tool));
|
||||
}
|
||||
let defaults: Vec<Vec<String>> = TOOL_SECTIONS.iter().flat_map(|s| s.iter()).map(|slot| slot.iter().map(|t| format!("{t:?}")).collect()).collect();
|
||||
let engine: Vec<Vec<String>> = DEFAULT_TOOLBAR.iter().map(|g| g.iter().map(|t| (*t).to_string()).collect()).collect();
|
||||
assert_eq!(engine, defaults, "the default layout is today's slot order");
|
||||
assert_eq!(ToolbarCustomization::tool_name("not a tool"), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn edit_toolbar_stores_and_returns_the_group_layout() {
|
||||
let mut app = app();
|
||||
let out = app
|
||||
.run(
|
||||
"edit.toolbar",
|
||||
json!({
|
||||
"toolbar": [["Move"], ["Lasso", "elliptical marquee", "Polygonal Lasso Tool"], ["Bogus Tool"], ["move", "Zoom"]],
|
||||
"extras": [["Hand", "Rotate View"], ["Zoom"]],
|
||||
}),
|
||||
)
|
||||
.unwrap();
|
||||
let toolbar = names(&out["toolbar"]);
|
||||
assert_eq!(
|
||||
toolbar,
|
||||
vec![vec!["Move"], vec!["Lasso", "EllipseMarquee", "PolygonLasso"], vec!["Zoom"]],
|
||||
"unknown names skipped, a repeat keeps its first place"
|
||||
);
|
||||
let extras = names(&out["extras"]);
|
||||
assert_eq!(extras[0], vec!["Hand", "RotateView"]);
|
||||
// Every tool listed nowhere is appended to the extras as its own group, once.
|
||||
let listed: Vec<&String> = toolbar.iter().chain(&extras).flatten().collect();
|
||||
assert_eq!(listed.len(), Tool::ALL.len());
|
||||
assert!(extras[1..].iter().all(|g| g.len() == 1));
|
||||
assert_eq!(extras[1], vec!["Artboard"], "the rest follow in toolbar order");
|
||||
// The stored layout is what a second call returns.
|
||||
assert_eq!(app.run("edit.toolbar", json!({"hidden": []})).unwrap(), out);
|
||||
assert!(app.run("edit.toolbar", json!({"toolbar": "Move"})).is_err(), "a layout is a list of groups");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_toolbar_draws_one_slot_per_toolbar_group() {
|
||||
let mut app = app();
|
||||
let all = tool_buttons(&mut app);
|
||||
let defaults: usize = TOOL_SECTIONS.iter().map(|s| s.len()).sum();
|
||||
app.run("edit.toolbar", json!({"toolbar": [["Move"], ["Lasso", "EllipseMarquee"], ["Brush"]]})).unwrap();
|
||||
assert_eq!(slots(&app), vec![vec![Tool::Move], vec![Tool::Lasso, Tool::EllipseMarquee], vec![Tool::Brush]]);
|
||||
assert_eq!(tool_buttons(&mut app), all - defaults + 3, "three slots");
|
||||
// A one-tool group has no flyout; the toolbar draws the triangle only for slots with more.
|
||||
assert_eq!(slots(&app).iter().filter(|s| s.len() > 1).count(), 1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn an_empty_toolbar_list_leaves_no_tool_slots() {
|
||||
let mut app = app();
|
||||
let all = tool_buttons(&mut app);
|
||||
let defaults: usize = TOOL_SECTIONS.iter().map(|s| s.len()).sum();
|
||||
let out = app.run("edit.toolbar", json!({"toolbar": []})).unwrap();
|
||||
assert!(names(&out["toolbar"]).is_empty());
|
||||
assert_eq!(names(&out["extras"]).len(), Tool::ALL.len());
|
||||
assert!(slots(&app).is_empty());
|
||||
assert_eq!(tool_buttons(&mut app), all - defaults);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn shift_letter_cycles_in_layout_order_across_slots() {
|
||||
let mut app = app();
|
||||
// Elliptical Marquee moved into the Lasso group keeps M.
|
||||
app.run("edit.toolbar", json!({"toolbar": [["RectMarquee", "SingleRowMarquee"], ["Lasso", "EllipseMarquee"]]})).unwrap();
|
||||
app.ui.tool = Tool::RectMarquee;
|
||||
shift_press(&mut app, Key::M);
|
||||
assert_eq!(app.ui.tool, Tool::EllipseMarquee);
|
||||
shift_press(&mut app, Key::M);
|
||||
assert_eq!(app.ui.tool, Tool::RectMarquee);
|
||||
// A reordered group steps in its new order: Magic Wand, Quick Selection, Object Selection.
|
||||
app.run("edit.toolbar", json!({"toolbar": [["MagicWand", "QuickSelection", "ObjectSelection"]]})).unwrap();
|
||||
app.ui.tool = Tool::MagicWand;
|
||||
for expected in [Tool::QuickSelection, Tool::ObjectSelection, Tool::MagicWand] {
|
||||
shift_press(&mut app, Key::W);
|
||||
assert_eq!(app.ui.tool, expected);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn reset_restores_the_default_layout() {
|
||||
let mut app = app();
|
||||
app.run("edit.toolbar", json!({"toolbar": [["Zoom", "Move"]]})).unwrap();
|
||||
let out = app.run("edit.toolbar", json!({"reset": true})).unwrap();
|
||||
let toolbar = names(&out["toolbar"]);
|
||||
let expected: Vec<Vec<String>> = DEFAULT_TOOLBAR.iter().map(|g| g.iter().map(|t| (*t).to_string()).collect()).collect();
|
||||
assert_eq!(toolbar, expected);
|
||||
assert!(names(&out["extras"]).is_empty());
|
||||
assert_eq!(slots(&app).len(), TOOL_SECTIONS.iter().map(|s| s.len()).sum::<usize>());
|
||||
assert_eq!(layout_sections(&app.session.prefs().toolbar).len(), TOOL_SECTIONS.len(), "the default keeps its dividers");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn older_settings_still_load() {
|
||||
// Only the flat hidden list: its tools become extras groups, in toolbar order.
|
||||
let prefs: Preferences = serde_json::from_value(json!({"toolbar": {"hidden": ["Sponge", "Move"]}})).unwrap();
|
||||
let layout = prefs.toolbar.layout();
|
||||
assert_eq!(layout.extras, vec![vec!["Move".to_string()], vec!["Sponge".to_string()]]);
|
||||
assert!(layout.toolbar.iter().any(|g| g == &vec!["Dodge".to_string(), "Burn".to_string()]));
|
||||
assert!(layout.toolbar.iter().flatten().all(|t| t != "Sponge" && t != "Move"));
|
||||
// No toolbar fields at all: the default layout.
|
||||
let prefs: Preferences = serde_json::from_value(json!({})).unwrap();
|
||||
assert_eq!(prefs.toolbar.layout().toolbar.len(), DEFAULT_TOOLBAR.len());
|
||||
assert!(prefs.toolbar.layout().extras.is_empty());
|
||||
// A stored layout survives a round trip through the settings file.
|
||||
let mut app = app();
|
||||
app.run("edit.toolbar", json!({"toolbar": [["Brush"]]})).unwrap();
|
||||
let back: Preferences = serde_json::from_str(&app.session.prefs_to_json()).unwrap();
|
||||
assert_eq!(back.toolbar.layout().toolbar, vec![vec!["Brush".to_string()]]);
|
||||
}
|
||||
|
||||
/// CodeRabbit on #14811: `prefs.reset` of one layout path works once `edit.toolbar` stored a custom
|
||||
/// layout. The default layout used to be left out of the stored JSON, so reset found no default
|
||||
/// for `toolbar.toolbar` or `toolbar.extras` and reported an unknown preference.
|
||||
#[test]
|
||||
fn prefs_reset_brings_back_one_part_of_a_custom_layout() {
|
||||
for path in ["toolbar.toolbar", "toolbar.extras"] {
|
||||
let mut app = app();
|
||||
app.run("edit.toolbar", json!({"toolbar": [["Zoom"], ["Hand"]], "extras": [["Move", "Artboard"]]})).unwrap();
|
||||
app.run("prefs.reset", json!({"path": path})).unwrap_or_else(|e| panic!("{path}: {e}"));
|
||||
let custom = ToolbarCustomization::default();
|
||||
let layout = app.session.prefs().toolbar.layout();
|
||||
if path == "toolbar.toolbar" {
|
||||
assert_ne!(layout.toolbar, vec![vec!["Zoom".to_string()], vec!["Hand".to_string()]], "{path}: back to the default groups");
|
||||
assert_eq!(app.session.prefs().toolbar.toolbar, custom.toolbar, "{path}: the stored layout is the default again");
|
||||
} else {
|
||||
assert_eq!(app.session.prefs().toolbar.extras, custom.extras, "{path}: the stored Extra Tools are the default again");
|
||||
}
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -9,7 +9,7 @@ Generated by `cargo xtask scorecard` from `perf/budgets.toml`, `perf/baseline.js
|
||||
| [Performance](#performance) | 3 | 22 | 56 | 90 scenarios: 3 within budget, 22 over budget or failing, 9 tracked only, 52 not run, 4 not measurable yet (baseline 2026-10-05) |
|
||||
| [File compatibility](#file-compatibility) | 11 | 14 | 2 | io corpus: oracle ≥ 148/170, round trip ≥ 169/170; psd-tools corpus: oracle ≥ 249/309, round trip ≥ 308/309; photoshop oracles: oracle ≥ 190/258, round trip ≥ 258/258 |
|
||||
| [Tools](#tools) | 36 | 9 | 0 | |
|
||||
| [Workspace and UI](#workspace-and-ui) | 15 | 6 | 2 | settings that do nothing: 8 of 203 (target 0) |
|
||||
| [Workspace and UI](#workspace-and-ui) | 15 | 6 | 2 | settings that do nothing: 8 of 205 (target 0) |
|
||||
| [Type](#type) | 5 | 5 | 0 | |
|
||||
| [Automation](#automation) | 6 | 4 | 2 | 664 of 664 menu items live (100.0%) |
|
||||
| [Reliability](#reliability) | 5 | 2 | 0 | never-crash lints on 25 of 25 crates; panic_hunt present |
|
||||
@@ -214,7 +214,7 @@ Corpus floors (`crates/io/tests/it/corpus.rs`): the enforced minimums; the corpu
|
||||
|
||||
## Workspace and UI
|
||||
|
||||
**Settings that do nothing: 8 of 203** (target 0, #204). Counted by the prefs audit (`xtask/src/scorecard.rs`): a `Preferences` field counts as read when code outside the prefs model (`prefs.rs` except its `impl Session` blocks; tests excluded; the schema-driven dialog never names a field) accesses `section.field`, or `.section` and `.field` in the same file, or calls a section method that reads `self.field`. It is a heuristic lower bound: a generic name can look read when it isn't.
|
||||
**Settings that do nothing: 8 of 205** (target 0, #204). Counted by the prefs audit (`xtask/src/scorecard.rs`): a `Preferences` field counts as read when code outside the prefs model (`prefs.rs` except its `impl Session` blocks; tests excluded; the schema-driven dialog never names a field) accesses `section.field`, or `.section` and `.field` in the same file, or calls a section method that reads `self.field`. It is a heuristic lower bound: a generic name can look read when it isn't.
|
||||
|
||||
Unread: `general.color_picker`, `workspace.auto_show_hidden_panels`, `workspace.enable_floating_document_window_docking`, `performance.legacy_compositing`, `plug_ins.show_extension_panels`, `plug_ins.allow_scripts_to_connect`, `type_.text_engine`, `enhanced_controls.scrubby_slider_acceleration`.
|
||||
|
||||
|
||||
Reference in new issue
Block a user