From 183b6b7dd56cc20ea31815fe3025be876c18f411 Mon Sep 17 00:00:00 2001 From: David Mann Date: Tue, 17 Nov 2026 21:17:17 +0100 Subject: [PATCH] dock: a permission for panels that dock only in dock columns (photocraft#12517) `Permissions::docks_outside_columns` (on in `ALL`): without it a panel docks only in dock columns or floats. Any action that leaves it in a frame of the docked tree (a split beside the canvas, an edge of the docked area) is a column-rights breach, so the model refuses it and a drag's dry run shows no drop mark there. Reconcile moves a saved one out of a frame into a dock column. A toolbar sets it so it never lies across the window. --- crates/behavior/src/dock/apply.rs | 17 +++++++--- crates/behavior/src/dock/policy.rs | 25 +++++++++++++-- crates/behavior/src/dock/workspace.rs | 40 +++++++++++++++++++++--- crates/behavior/tests/dock_apply.rs | 45 +++++++++++++++++++++++++++ 4 files changed, 115 insertions(+), 12 deletions(-) diff --git a/crates/behavior/src/dock/apply.rs b/crates/behavior/src/dock/apply.rs index 4772f014c..0f0760a1b 100644 --- a/crates/behavior/src/dock/apply.rs +++ b/crates/behavior/src/dock/apply.rs @@ -22,8 +22,8 @@ impl Layout

{ /// action closed (see [`Self::closed_by`]) so the application can release their state. /// The callback must be stable throughout one call. Registry validation remains with the /// application, particularly Open. The column rights ([`Permissions::collapses`], - /// [`Permissions::shares_column`]) are checked on the result: an action that leaves a panel breaking them, - /// which did not before, is refused, so a drag's dry run refuses it alike. + /// [`Permissions::shares_column`], [`Permissions::docks_outside_columns`]) are checked on the result: an action + /// that leaves a panel breaking them, which did not before, is refused, so a drag's dry run refuses it alike. pub fn apply_with_permissions(&mut self, action: Action

, permissions: impl Fn(&P) -> Permissions) -> Result, DockError> { self.validate()?; let action = match action { @@ -125,10 +125,12 @@ impl Layout

{ } /// The panels that break their column rights: a panel that does not collapse ([`Permissions::collapses`]) in - /// a collapsed column, and every panel of a column (or node of the docked tree) that holds a panel that does - /// not share it ([`Permissions::shares_column`]) beside another panel. + /// a collapsed column, every panel of a column (or node of the docked tree) that holds a panel that does + /// not share it ([`Permissions::shares_column`]) beside another panel, and a panel that docks only in dock + /// columns ([`Permissions::docks_outside_columns`]) in a frame of the docked tree. pub(super) fn column_breaches(&self, permissions: &impl Fn(&P) -> Permissions) -> HashSet

{ let mut breaches = HashSet::new(); + let mut framed = Vec::new(); let mut check = |panels: Vec<&P>, iconic: bool| { if iconic { breaches.extend(panels.iter().filter(|p| !permissions(p).collapses).map(|p| (*p).clone())); @@ -147,9 +149,14 @@ impl Layout

{ check(column.panels().collect(), column.iconic); } } - leaf => check(tree_panels(leaf), false), + leaf => { + let panels = tree_panels(leaf); + framed.extend(panels.iter().filter(|p| !permissions(p).docks_outside_columns).map(|p| (*p).clone())); + check(panels, false); + } } } + breaches.extend(framed); breaches } diff --git a/crates/behavior/src/dock/policy.rs b/crates/behavior/src/dock/policy.rs index 99a9f4005..629008c34 100644 --- a/crates/behavior/src/dock/policy.rs +++ b/crates/behavior/src/dock/policy.rs @@ -26,6 +26,10 @@ pub struct Permissions { /// panels: refused are tab, center, group and seam placements across that boundary in either direction, while a /// new column, a new dock and a float stay allowed. A toolbar takes its own column. pub shares_column: bool, + /// The panel may dock outside a dock column: in a frame of the docked tree, as a split beside another frame or at + /// an edge of the docked area, where it can lie across the window. Without it the panel docks only in dock columns + /// or floats: refused is any action that leaves it in a frame, so a toolbar is always a vertical strip. + pub docks_outside_columns: bool, } impl Default for Permissions { @@ -35,9 +39,18 @@ impl Default for Permissions { } impl Permissions { - /// Every right: the panel moves, floats, closes, takes tabs and splits, collapses and shares its column. - pub const ALL: Self = - Self { movable: true, floatable: true, closable: true, accepts_tabs: true, accepts_splits: true, collapses: true, shares_column: true }; + /// Every right: the panel moves, floats, closes, takes tabs and splits, collapses, shares its column and docks + /// outside dock columns. + pub const ALL: Self = Self { + movable: true, + floatable: true, + closable: true, + accepts_tabs: true, + accepts_splits: true, + collapses: true, + shares_column: true, + docks_outside_columns: true, + }; /// A document canvas: it stays docked and open, and takes neither tabs nor side splits. /// A group dropped on it floats there. An application that opens panels beside its canvas @@ -86,6 +99,12 @@ impl Permissions { self } + /// These permissions with [`Self::docks_outside_columns`] set to `docks_outside_columns`. + pub const fn docks_outside_columns(mut self, docks_outside_columns: bool) -> Self { + self.docks_outside_columns = docks_outside_columns; + self + } + /// A canvas: it can neither move, close nor take tabs. `accepts_splits` and `floatable` /// do not matter, so a canvas that opens panels beside it still counts. pub fn is_protected(self) -> bool { diff --git a/crates/behavior/src/dock/workspace.rs b/crates/behavior/src/dock/workspace.rs index 167ff20dc..d261427ce 100644 --- a/crates/behavior/src/dock/workspace.rs +++ b/crates/behavior/src/dock/workspace.rs @@ -10,7 +10,7 @@ use super::{ DockSide, action::{Action, DockPlacement, Location}, edit::tree_panels, - groups::{Column, PanelPlace, Target}, + groups::{Column, DockEdge, PanelPlace, Target}, layout::Layout, limits::MAX_PANELS, node::Node, @@ -285,8 +285,9 @@ impl Workspace

{ /// A registered panel that `permissions` says cannot close, such as a protected canvas, is /// always shown: at its recorded or default place, else at the outer edge of the docked /// area. A layout that breaks the column rights is repaired: a collapsed column holding a panel that does not - /// collapse ([`Permissions::collapses`]) expands, and a panel that shares no column - /// ([`Permissions::shares_column`]) moves to a column of its own. Pass the panels' own permissions, not + /// collapse ([`Permissions::collapses`]) expands, a panel that shares no column + /// ([`Permissions::shares_column`]) moves to a column of its own, and a panel that docks only in dock columns + /// ([`Permissions::docks_outside_columns`]) moves from a frame to a dock column. Pass the panels' own permissions, not /// [`Permissions::locked`] ones. /// `hidden` keeps at most [`MAX_PANELS`] entries, dropping the oldest unregistered ones first. pub fn reconcile(&mut self, registered: impl Fn(&P) -> bool, permissions: impl Fn(&P) -> Permissions, default: &Workspace

) { @@ -347,10 +348,41 @@ impl Workspace

{ } impl Workspace

{ + /// Moves each panel that docks only in dock columns ([`Permissions::docks_outside_columns`]) out of a frame of the + /// docked tree: to a new dock at the start edge, else a new dock at the end edge, else a column of its own at the + /// outer side of the first docked column. A move the layout refuses leaves the panel where it was. + fn repair_framed(&mut self, permissions: &impl Fn(&P) -> Permissions) { + let framed: Vec

= self + .layout + .panels() + .into_iter() + .filter(|p| !permissions(p).docks_outside_columns && matches!(self.layout.place(p), Some(PanelPlace::Node(_)))) + .cloned() + .collect(); + for panel in framed { + let column_anchor = + self.layout.panels().into_iter().find(|p| *p != &panel && matches!(self.layout.place(p), Some(PanelPlace::Dock { .. }))).cloned(); + let targets = [Some(Target::NewDock { side: DockEdge::Start }), Some(Target::NewDock { side: DockEdge::End })] + .into_iter() + .chain([column_anchor.map(|anchor| Target::At { anchor, placement: DockPlacement::Column { after: false } })]); + for to in targets.flatten() { + let mut layout = self.layout.clone(); + let moved = layout.apply_inner(Action::MovePanel { panel: panel.clone(), to }, &|p| permissions(p).is_protected()).is_ok(); + if moved && layout.validate().is_ok() { + self.layout = layout; + break; + } + } + } + } + /// Moves each panel that shares no column but has company to a column of its own: a new dock column beside its /// column, a new window over its window, or a frame beside its node of the docked tree. Then expands each - /// collapsed column that holds a panel that does not collapse. A repair the layout refuses leaves it as it was. + /// collapsed column that holds a panel that does not collapse, and moves each panel that docks only in dock + /// columns out of a frame of the docked tree into a dock column ([`Self::repair_framed`]). A repair the layout + /// refuses leaves it as it was. fn repair_columns(&mut self, permissions: &impl Fn(&P) -> Permissions) { + self.repair_framed(permissions); let lonely: Vec

= self.layout.panels().into_iter().filter(|p| !permissions(p).shares_column).cloned().collect(); for panel in lonely { let Some(place) = self.layout.place(&panel) else { continue }; diff --git a/crates/behavior/tests/dock_apply.rs b/crates/behavior/tests/dock_apply.rs index 3ed8fc9c9..59d764ad3 100644 --- a/crates/behavior/tests/dock_apply.rs +++ b/crates/behavior/tests/dock_apply.rs @@ -355,6 +355,51 @@ fn a_panel_that_shares_no_column_moves_only_to_a_column_of_its_own() { assert_eq!(sorted(&saved.layout), [1, 2, 3, 4, 6]); } +/// A panel that docks only in dock columns (a toolbar, photocraft#12517) refuses every placement that leaves it in a +/// frame of the docked tree: a split beside the canvas on any side and an edge of the docked area, so it never lies +/// across the window. A new dock, a column beside another and a float still take it, other panels still move while +/// one sits in a frame (only a new breach is refused), and reconcile moves a saved one into a dock column. +#[test] +fn a_panel_that_docks_only_in_columns_never_lands_in_a_frame() { + let strip = |p: &u32| match p { + 2 => Permissions::ALL.shares_column(false).docks_outside_columns(false), + 1 => Permissions::PROTECTED.accepts_splits(true), + _ => Permissions::ALL, + }; + let layout = columns(); + let sides = [DockSide::Top, DockSide::Bottom, DockSide::Start, DockSide::End]; + let framed = sides.iter().map(|side| DockPlacement::Split(*side)).chain(sides.iter().map(|side| DockPlacement::Edge(*side))); + for placement in framed { + let mut moved = layout.clone(); + let action = Action::move_column(2, Target::at(1, placement.clone())); + assert_eq!(moved.apply_with_permissions(action, strip), Err(DockError::NotAllowed), "{placement:?}"); + assert_eq!(moved, layout, "{placement:?}"); + } + for to in [Target::new_dock(DockEdge::Start), Target::at(3, DockPlacement::column(true)), Target::float(window())] { + let mut moved = layout.clone(); + moved.apply_with_permissions(Action::move_column(2, to.clone()), strip).unwrap_or_else(|e| panic!("{to:?}: {e}")); + assert!(!matches!(moved.place(&2), Some(PanelPlace::Node(_))), "{to:?}"); + } + // Without the right the same split takes it, so the refusal above is this right's. + let mut split = layout.clone(); + split + .apply_with_permissions(Action::move_column(2, Target::at(1, DockPlacement::Split(DockSide::Bottom))), |p: &u32| match p { + 2 => Permissions::ALL.shares_column(false), + _ => Permissions::ALL, + }) + .unwrap(); + assert!(matches!(split.place(&2), Some(PanelPlace::Node(_)))); + + // A layout saved with the panel in a frame: other panels still move, and reconcile docks it in a column. + let mut other = split.clone(); + other.apply_with_permissions(Action::move_group(6, Target::at(3, DockPlacement::column(false))), strip).unwrap(); + let mut saved = Workspace::new(split); + saved.reconcile(|_| true, strip, &Workspace::new(columns())); + assert!(matches!(saved.layout.place(&2), Some(PanelPlace::Dock { .. })), "reconcile docks it in a column: {:?}", saved.layout); + assert_eq!(column_of(&saved.layout, 2).panels().collect::>(), [&2]); + assert_eq!(sorted(&saved.layout), [1, 2, 3, 4, 6]); +} + /// A stepped column (a toolbar's) keeps its step count docked, floating and through JSON, and its width moves only /// by steps. #[test]