Skip to content

Commit 7f76de5

Browse files
committed
Added settings for git view
1 parent aa632c6 commit 7f76de5

File tree

6 files changed

+81
-6
lines changed

6 files changed

+81
-6
lines changed

assets/settings/default.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1316,7 +1316,10 @@
13161316
// "hunk_style": "staged_hollow"
13171317
// 2. Show unstaged hunks hollow and staged hunks filled:
13181318
// "hunk_style": "unstaged_hollow"
1319-
"hunk_style": "staged_hollow"
1319+
"hunk_style": "staged_hollow",
1320+
// How file paths are displayed in the git panel.
1321+
// "path_style": "file_name_first" or "file_path_first"
1322+
"path_style": "file_name_first"
13201323
},
13211324
// The list of custom Git hosting providers.
13221325
"git_hosting_providers": [

crates/git_ui/src/git_panel.rs

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ use panel::{
5050
use project::{
5151
Fs, Project, ProjectPath,
5252
git_store::{GitStoreEvent, Repository, RepositoryEvent, RepositoryId, pending_op},
53+
project_settings::{GitPathStyle, ProjectSettings},
5354
};
5455
use serde::{Deserialize, Serialize};
5556
use settings::{Settings, SettingsStore, StatusStyle};
@@ -3955,6 +3956,7 @@ impl GitPanel {
39553956
cx: &Context<Self>,
39563957
) -> AnyElement {
39573958
let path_style = self.project.read(cx).path_style(cx);
3959+
let git_path_style = ProjectSettings::get_global(cx).git.path_style;
39583960
let display_name = entry.display_name(path_style);
39593961

39603962
let active_repo = self
@@ -4063,7 +4065,13 @@ impl GitPanel {
40634065
} else {
40644066
cx.theme().colors().ghost_element_active
40654067
};
4066-
4068+
let name_label =
4069+
|status: FileStatus, label_color: Color, this: Div, label: String| -> Div {
4070+
this.child(
4071+
self.entry_label(label, label_color)
4072+
.when(status.is_deleted(), |this| this.strikethrough()),
4073+
)
4074+
};
40674075
h_flex()
40684076
.id(id)
40694077
.h(self.list_item_height())
@@ -4170,10 +4178,10 @@ impl GitPanel {
41704178
.child(self.entry_label(new_display, label_color))
41714179
})
41724180
.when(old_path.is_none(), |this| {
4173-
this.child(
4174-
self.entry_label(format!("{display_name} "), label_color)
4175-
.when(status.is_deleted(), |this| this.strikethrough()),
4176-
)
4181+
this.
4182+
.when(git_path_style == GitPathStyle::FileNameFirst, |this| {
4183+
name_label(status, label_color, this, format!("{display_name} "))
4184+
})
41774185
.when_some(
41784186
entry.parent_dir(path_style),
41794187
|this, parent| {
@@ -4190,6 +4198,9 @@ impl GitPanel {
41904198
}
41914199
},
41924200
)
4201+
.when(git_path_style == GitPathStyle::FilePathFirst, |this| {
4202+
name_label(status, label_color, this, display_name)
4203+
}),
41934204
}),
41944205
)
41954206
.into_any_element()

crates/project/src/project_settings.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,26 @@ pub struct GitSettings {
348348
///
349349
/// Default: staged_hollow
350350
pub hunk_style: settings::GitHunkStyleSetting,
351+
/// How file paths are displayed in the git gutter.
352+
///
353+
/// Default: file_name_first
354+
pub path_style: GitPathStyle,
355+
}
356+
357+
#[derive(Clone, Copy, Debug, PartialEq, Default)]
358+
pub enum GitPathStyle {
359+
#[default]
360+
FileNameFirst,
361+
FilePathFirst,
362+
}
363+
364+
impl From<settings::GitPathStyle> for GitPathStyle {
365+
fn from(style: settings::GitPathStyle) -> Self {
366+
match style {
367+
settings::GitPathStyle::FileNameFirst => GitPathStyle::FileNameFirst,
368+
settings::GitPathStyle::FilePathFirst => GitPathStyle::FilePathFirst,
369+
}
370+
}
351371
}
352372

353373
#[derive(Clone, Copy, Debug)]
@@ -501,6 +521,7 @@ impl Settings for ProjectSettings {
501521
}
502522
},
503523
hunk_style: git.hunk_style.unwrap(),
524+
path_style: git.path_style.unwrap().into(),
504525
};
505526
Self {
506527
context_servers: project

crates/settings/src/settings_content/project.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,10 @@ pub struct GitSettings {
311311
///
312312
/// Default: staged_hollow
313313
pub hunk_style: Option<GitHunkStyleSetting>,
314+
/// How file paths are displayed in the git gutter.
315+
///
316+
/// Default: file_name_first
317+
pub path_style: Option<GitPathStyle>,
314318
}
315319

316320
#[derive(
@@ -406,6 +410,28 @@ pub enum GitHunkStyleSetting {
406410
UnstagedHollow,
407411
}
408412

413+
#[derive(
414+
Copy,
415+
Clone,
416+
Debug,
417+
PartialEq,
418+
Default,
419+
Serialize,
420+
Deserialize,
421+
JsonSchema,
422+
MergeFrom,
423+
strum::VariantArray,
424+
strum::VariantNames,
425+
)]
426+
#[serde(rename_all = "snake_case")]
427+
pub enum GitPathStyle {
428+
/// Show file name first, then path
429+
#[default]
430+
FileNameFirst,
431+
/// Show full path first
432+
FilePathFirst,
433+
}
434+
409435
#[skip_serializing_none]
410436
#[derive(Clone, Debug, PartialEq, Eq, Default, Serialize, Deserialize, JsonSchema, MergeFrom)]
411437
pub struct DiagnosticsSettingsContent {

crates/settings_ui/src/page_data.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5494,6 +5494,19 @@ pub(crate) fn settings_data(cx: &App) -> Vec<SettingsPage> {
54945494
metadata: None,
54955495
files: USER,
54965496
}),
5497+
SettingsPageItem::SettingItem(SettingItem {
5498+
title: "Show Change Counters",
5499+
description: "When to show change counters in the git gutter.",
5500+
field: Box::new(SettingField {
5501+
json_path: Some("git.show_change_counters"),
5502+
pick: |settings_content| settings_content.git.as_ref()?.show_change_counters.as_ref(),
5503+
write: |settings_content, value| {
5504+
settings_content.git.get_or_insert_default().show_change_counters = value;
5505+
},
5506+
}),
5507+
metadata: None,
5508+
files: USER,
5509+
}),
54975510
],
54985511
},
54995512
SettingsPage {

crates/settings_ui/src/settings_ui.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,7 @@ fn init_renderers(cx: &mut App) {
452452
.add_basic_renderer::<settings::DockPosition>(render_dropdown)
453453
.add_basic_renderer::<settings::GitGutterSetting>(render_dropdown)
454454
.add_basic_renderer::<settings::GitHunkStyleSetting>(render_dropdown)
455+
.add_basic_renderer::<settings::GitShowChangeCounters>(render_dropdown)
455456
.add_basic_renderer::<settings::DiagnosticSeverityContent>(render_dropdown)
456457
.add_basic_renderer::<settings::SeedQuerySetting>(render_dropdown)
457458
.add_basic_renderer::<settings::DoubleClickInMultibuffer>(render_dropdown)

0 commit comments

Comments
 (0)