Fix panic when not specifying a project_panel setting

This commit is contained in:
Antonio Scandurra 2023-05-10 10:43:42 +02:00
parent 9173916ab8
commit 6e3ce6332a
2 changed files with 26 additions and 30 deletions

View File

@ -150,7 +150,8 @@ impl ProjectPanel {
old_dock_position = new_dock_position;
cx.emit(Event::DockPositionChanged);
}
}).detach();
})
.detach();
cx.observe(&project, |this, _, cx| {
this.update_visible_entries(None, cx);
@ -253,8 +254,8 @@ impl ProjectPanel {
}
}
}
},
Event::DockPositionChanged => {},
}
Event::DockPositionChanged => {}
}
})
.detach();
@ -1341,7 +1342,11 @@ impl Entity for ProjectPanel {
impl workspace::dock::Panel for ProjectPanel {
fn position(&self, cx: &gpui::WindowContext) -> DockPosition {
cx.global::<Settings>().project_panel_overrides.dock.into()
cx.global::<Settings>()
.project_panel_overrides
.dock
.map(Into::into)
.unwrap_or(DockPosition::Left)
}
fn position_is_valid(&self, position: DockPosition) -> bool {

View File

@ -132,7 +132,7 @@ impl TelemetrySettings {
}
#[derive(Clone, Copy, Debug, Serialize, Deserialize, JsonSchema, Eq, PartialEq)]
#[serde(rename_all="lowercase")]
#[serde(rename_all = "lowercase")]
pub enum DockPosition {
Left,
Right,
@ -166,17 +166,9 @@ pub enum GitGutter {
pub struct GitGutterConfig {}
#[derive(Clone, Debug, Serialize, Deserialize, JsonSchema)]
#[derive(Clone, Debug, Default, Serialize, Deserialize, JsonSchema)]
pub struct ProjectPanelSettings {
pub dock: DockPosition
}
impl Default for ProjectPanelSettings {
fn default() -> Self {
Self {
dock: DockPosition::Left
}
}
pub dock: Option<DockPosition>,
}
#[derive(Clone, Debug, Default, Serialize, Deserialize, JsonSchema)]
@ -279,23 +271,22 @@ pub struct TerminalSettings {
impl Default for TerminalSettings {
fn default() -> Self {
Self {
shell:Default::default(),
working_directory:Default::default(),
font_size:Default::default(),
font_family:Default::default(),
line_height:Default::default(),
font_features:Default::default(),
env:Default::default(),
blinking:Default::default(),
alternate_scroll:Default::default(),
option_as_meta:Default::default(),
copy_on_select:Default::default(),
shell: Default::default(),
working_directory: Default::default(),
font_size: Default::default(),
font_family: Default::default(),
line_height: Default::default(),
font_features: Default::default(),
env: Default::default(),
blinking: Default::default(),
alternate_scroll: Default::default(),
option_as_meta: Default::default(),
copy_on_select: Default::default(),
dock: DockPosition::Bottom,
}
}
}
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, JsonSchema, Default)]
#[serde(rename_all = "snake_case")]
pub enum TerminalLineHeight {
@ -407,7 +398,7 @@ pub struct SettingsFileContent {
pub autosave: Option<Autosave>,
#[serde(flatten)]
pub editor: EditorSettings,
pub project_panel: ProjectPanelSettings,
pub project_panel: Option<ProjectPanelSettings>,
#[serde(default)]
pub journal: JournalSettings,
#[serde(default)]
@ -502,7 +493,7 @@ impl Settings {
show_call_status_icon: defaults.show_call_status_icon.unwrap(),
vim_mode: defaults.vim_mode.unwrap(),
autosave: defaults.autosave.unwrap(),
project_panel_defaults: Default::default(),
project_panel_defaults: defaults.project_panel.unwrap(),
project_panel_overrides: Default::default(),
editor_defaults: EditorSettings {
tab_size: required(defaults.editor.tab_size),
@ -610,7 +601,7 @@ impl Settings {
}
}
self.editor_overrides = data.editor;
self.project_panel_overrides = data.project_panel;
self.project_panel_overrides = data.project_panel.unwrap_or_default();
self.git_overrides = data.git.unwrap_or_default();
self.journal_overrides = data.journal;
self.terminal_defaults.font_size = data.terminal.font_size;