Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a setting to sync the sizes of panels in a dock #19015

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions assets/settings/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@
// workspace when the centered layout is used.
"right_padding": 0.2
},
// Whether to sync the sizes of panels within a dock. This setting takes in a list of dock positions.
// Note that this setting cannot sync size between docks.
"sync_panel_size_within_dock": [],
// The key to use for adding multiple cursors
// Currently "alt" or "cmd_or_ctrl" (also aliased as
// "cmd" and "ctrl") are supported.
Expand Down
8 changes: 8 additions & 0 deletions crates/workspace/src/dock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -579,6 +579,14 @@ impl Dock {
}
}

pub fn resize_all_panels(&mut self, size: Option<Pixels>, cx: &mut ViewContext<Self>) {
for entry in self.panel_entries.iter_mut() {
let size = size.map(|size| size.max(RESIZE_HANDLE_SIZE).round());
entry.panel.set_size(size, cx);
}
cx.notify();
}

pub fn toggle_action(&self) -> Box<dyn Action> {
match self.position {
DockPosition::Left => crate::ToggleLeftDock.boxed_clone(),
Expand Down
54 changes: 42 additions & 12 deletions crates/workspace/src/workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4743,10 +4743,20 @@ impl Render for Workspace {
workspace.left_dock.update(
cx,
|left_dock, cx| {
left_dock.resize_active_panel(
Some(size),
cx,
);
if WorkspaceSettings::get_global(cx)
.sync_panel_size_within_dock
.contains(&DockPosition::Left)
{
left_dock.resize_all_panels(
Some(size),
cx,
);
} else {
left_dock.resize_active_panel(
Some(size),
cx,
);
}
},
);
}
Expand All @@ -4756,10 +4766,20 @@ impl Render for Workspace {
workspace.right_dock.update(
cx,
|right_dock, cx| {
right_dock.resize_active_panel(
Some(size),
cx,
);
if WorkspaceSettings::get_global(cx)
.sync_panel_size_within_dock
.contains(&DockPosition::Right)
{
right_dock.resize_all_panels(
Some(size),
cx,
);
} else {
right_dock.resize_active_panel(
Some(size),
cx,
);
}
},
);
}
Expand All @@ -4769,10 +4789,20 @@ impl Render for Workspace {
workspace.bottom_dock.update(
cx,
|bottom_dock, cx| {
bottom_dock.resize_active_panel(
Some(size),
cx,
);
if WorkspaceSettings::get_global(cx)
.sync_panel_size_within_dock
.contains(&DockPosition::Bottom)
{
bottom_dock.resize_all_panels(
Some(size),
cx,
);
} else {
bottom_dock.resize_active_panel(
Some(size),
cx,
);
}
},
);
}
Expand Down
8 changes: 8 additions & 0 deletions crates/workspace/src/workspace_settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use settings::{Settings, SettingsSources};

use crate::dock::DockPosition;

#[derive(Deserialize)]
pub struct WorkspaceSettings {
pub active_pane_magnification: f32,
Expand All @@ -19,6 +21,7 @@ pub struct WorkspaceSettings {
pub when_closing_with_no_tabs: CloseWindowWhenNoItems,
pub use_system_path_prompts: bool,
pub command_aliases: HashMap<String, String>,
pub sync_panel_size_within_dock: Vec<DockPosition>,
}

#[derive(Copy, Clone, Default, Serialize, Deserialize, JsonSchema)]
Expand Down Expand Up @@ -108,6 +111,11 @@ pub struct WorkspaceSettingsContent {
///
/// Default: true
pub command_aliases: Option<HashMap<String, String>>,
/// Whether to sync the sizes of panels in a dock.
/// When a dock position is on the list, resizing one panel will resize all panels in that dock.
///
/// Default: []
pub sync_panel_size_within_dock: Option<Vec<DockPosition>>,
}

#[derive(Deserialize)]
Expand Down
Loading