Skip to content

Commit 4cfe3cd

Browse files
committed
feat(dock): add default_hidden panel configuration
1 parent f4c6988 commit 4cfe3cd

1 file changed

Lines changed: 31 additions & 7 deletions

File tree

src/dock.rs

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,9 @@ pub struct TileLayoutState {
154154
pub(crate) pending_open_requests: Vec<String>,
155155
/// Panel IDs hidden from the Window menu at runtime (overrides `show_in_window_menu()`).
156156
window_menu_hidden: HashSet<String>,
157+
/// Panel IDs that should be hidden in the default layout
158+
/// (overrides `default_visible()` when building tree from scratch).
159+
default_hidden: HashSet<String>,
157160
}
158161

159162
impl TileLayoutState {
@@ -218,7 +221,9 @@ impl TileLayoutState {
218221
let mut visible_panels: Vec<(&str, PanelId)> = self
219222
.panel_id_map
220223
.iter()
221-
.filter(|(_, pid)| self.panels[pid].default_visible())
224+
.filter(|(s, pid)| {
225+
self.panels[pid].default_visible() && !self.default_hidden.contains(s.as_str())
226+
})
222227
.map(|(s, pid)| (s.as_str(), *pid))
223228
.collect();
224229
visible_panels.sort_by_key(|(s, _)| *s);
@@ -349,12 +354,15 @@ impl TileLayoutState {
349354
}
350355

351356
/// Close a panel by its string ID.
352-
pub fn close_panel(&mut self, panel_str_id: &str) {
357+
pub fn close_panel(&mut self, panel_str_id: &str) -> bool {
353358
let Some(&panel_id) = self.panel_id_map.get(panel_str_id) else {
354-
return;
359+
return false;
355360
};
356361
if let Some(&tile_id) = self.panel_tile_map.get(&panel_id) {
357362
self.hide_tile(tile_id);
363+
true
364+
} else {
365+
false
358366
}
359367
}
360368

@@ -418,6 +426,12 @@ impl TileLayoutState {
418426
self.window_menu_hidden.insert(panel_str_id.to_string());
419427
}
420428

429+
/// Mark a panel as hidden in the default layout. This overrides
430+
/// `default_visible()` when building the tree from scratch (no saved layout).
431+
pub fn set_default_hidden(&mut self, panel_str_id: &str) {
432+
self.default_hidden.insert(panel_str_id.to_string());
433+
}
434+
421435
/// Check whether a panel is currently visible in the layout.
422436
pub fn is_panel_visible(&self, panel_str_id: &str) -> bool {
423437
let Some(&panel_id) = self.panel_id_map.get(panel_str_id) else {
@@ -430,14 +444,24 @@ impl TileLayoutState {
430444
}
431445

432446
/// Get a mutable reference to a panel by its string ID, with downcasting.
447+
/// Also searches pending panels not yet moved into the main map.
433448
pub fn get_panel_mut<T: WorkbenchPanel + 'static>(
434449
&mut self,
435450
panel_str_id: &str,
436451
) -> Option<&mut T> {
437-
let panel_id = self.panel_id_map.get(panel_str_id)?;
438-
let panel = self.panels.get_mut(panel_id)?;
439-
// Downcast via Any
440-
(panel.as_mut() as &mut dyn std::any::Any).downcast_mut::<T>()
452+
// First try the built panels map
453+
if let Some(&panel_id) = self.panel_id_map.get(panel_str_id) {
454+
if let Some(panel) = self.panels.get_mut(&panel_id) {
455+
return (panel.as_mut() as &mut dyn std::any::Any).downcast_mut::<T>();
456+
}
457+
}
458+
// Fall back to pending panels (not yet moved into the map)
459+
for pending in &mut self.pending {
460+
if pending.panel.id() == panel_str_id {
461+
return (pending.panel.as_mut() as &mut dyn std::any::Any).downcast_mut::<T>();
462+
}
463+
}
464+
None
441465
}
442466

443467
/// Save the current layout to a file (JSON format).

0 commit comments

Comments
 (0)