Create more specific dock position settings associated with each panel

This commit is contained in:
Antonio Scandurra 2023-05-10 16:52:10 +02:00
parent e507eadb4b
commit 0ccb4a50e6
4 changed files with 44 additions and 38 deletions

View File

@ -1347,12 +1347,15 @@ impl Entity for ProjectPanel {
impl workspace::dock::Panel for ProjectPanel {
fn position(&self, cx: &gpui::WindowContext) -> DockPosition {
let settings = cx.global::<Settings>();
settings
let dock = settings
.project_panel_overrides
.dock
.or(settings.project_panel_defaults.dock)
.unwrap()
.into()
.unwrap();
match dock {
settings::ProjectPanelDockPosition::Left => DockPosition::Left,
settings::ProjectPanelDockPosition::Right => DockPosition::Right,
}
}
fn position_is_valid(&self, position: DockPosition) -> bool {
@ -1361,7 +1364,13 @@ impl workspace::dock::Panel for ProjectPanel {
fn set_position(&mut self, position: DockPosition, cx: &mut ViewContext<Self>) {
SettingsFile::update(cx, move |settings| {
settings.project_panel.dock = Some(position.into())
let dock = match position {
DockPosition::Left | DockPosition::Bottom => {
settings::ProjectPanelDockPosition::Left
}
DockPosition::Right => settings::ProjectPanelDockPosition::Right,
};
settings.project_panel.dock = Some(dock);
})
}

View File

@ -131,14 +131,6 @@ impl TelemetrySettings {
}
}
#[derive(Clone, Copy, Debug, Serialize, Deserialize, JsonSchema, Eq, PartialEq)]
#[serde(rename_all = "lowercase")]
pub enum DockPosition {
Left,
Right,
Bottom,
}
#[derive(Clone, Debug, Default)]
pub struct CopilotSettings {
pub disabled_globs: Vec<glob::Pattern>,
@ -168,7 +160,14 @@ pub struct GitGutterConfig {}
#[derive(Clone, Debug, Default, Serialize, Deserialize, JsonSchema)]
pub struct ProjectPanelSettings {
pub dock: Option<DockPosition>,
pub dock: Option<ProjectPanelDockPosition>,
}
#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema)]
#[serde(rename_all = "lowercase")]
pub enum ProjectPanelDockPosition {
Left,
Right,
}
#[derive(Clone, Debug, Default, Serialize, Deserialize, JsonSchema)]
@ -265,7 +264,15 @@ pub struct TerminalSettings {
pub alternate_scroll: Option<AlternateScroll>,
pub option_as_meta: Option<bool>,
pub copy_on_select: Option<bool>,
pub dock: Option<DockPosition>,
pub dock: Option<TerminalDockPosition>,
}
#[derive(Copy, Clone, Debug, Serialize, Deserialize, PartialEq, JsonSchema)]
#[serde(rename_all = "lowercase")]
pub enum TerminalDockPosition {
Left,
Bottom,
Right,
}
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, JsonSchema, Default)]

View File

@ -4,7 +4,7 @@ use gpui::{
WeakViewHandle,
};
use project::Project;
use settings::{settings_file::SettingsFile, Settings, WorkingDirectory};
use settings::{settings_file::SettingsFile, Settings, TerminalDockPosition, WorkingDirectory};
use util::ResultExt;
use workspace::{
dock::{DockPosition, Panel},
@ -151,12 +151,17 @@ impl View for TerminalPanel {
impl Panel for TerminalPanel {
fn position(&self, cx: &gpui::WindowContext) -> DockPosition {
let settings = cx.global::<Settings>();
settings
let dock = settings
.terminal_overrides
.dock
.or(settings.terminal_defaults.dock)
.unwrap()
.into()
.into();
match dock {
settings::TerminalDockPosition::Left => DockPosition::Left,
settings::TerminalDockPosition::Bottom => DockPosition::Bottom,
settings::TerminalDockPosition::Right => DockPosition::Right,
}
}
fn position_is_valid(&self, _: DockPosition) -> bool {
@ -165,7 +170,12 @@ impl Panel for TerminalPanel {
fn set_position(&mut self, position: DockPosition, cx: &mut ViewContext<Self>) {
SettingsFile::update(cx, move |settings| {
settings.terminal.dock = Some(position.into());
let dock = match position {
DockPosition::Left => TerminalDockPosition::Left,
DockPosition::Bottom => TerminalDockPosition::Bottom,
DockPosition::Right => TerminalDockPosition::Right,
};
settings.terminal.dock = Some(dock);
});
}

View File

@ -95,26 +95,6 @@ pub enum DockPosition {
Right,
}
impl From<settings::DockPosition> for DockPosition {
fn from(value: settings::DockPosition) -> Self {
match value {
settings::DockPosition::Left => Self::Left,
settings::DockPosition::Bottom => Self::Bottom,
settings::DockPosition::Right => Self::Right,
}
}
}
impl From<DockPosition> for settings::DockPosition {
fn from(value: DockPosition) -> settings::DockPosition {
match value {
DockPosition::Left => settings::DockPosition::Left,
DockPosition::Bottom => settings::DockPosition::Bottom,
DockPosition::Right => settings::DockPosition::Right,
}
}
}
impl DockPosition {
fn to_label(&self) -> &'static str {
match self {