Skip to content

Commit 10a4c41

Browse files
committed
Added settings for git view
1 parent 9a174dc commit 10a4c41

File tree

6 files changed

+174
-8
lines changed

6 files changed

+174
-8
lines changed

assets/settings/default.json

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1306,7 +1306,27 @@
13061306
// "hunk_style": "staged_hollow"
13071307
// 2. Show unstaged hunks hollow and staged hunks filled:
13081308
// "hunk_style": "unstaged_hollow"
1309-
"hunk_style": "staged_hollow"
1309+
"hunk_style": "staged_hollow",
1310+
// How file paths are displayed in the git gutter.
1311+
// This setting can take three values:
1312+
//
1313+
// 1. Show file name first, then path:
1314+
// "path_style": "file_name_first"
1315+
// 2. Show full path first:
1316+
// "path_style": "file_path_first"
1317+
// 3. Show in tree view format:
1318+
// "path_style": "tree_view"
1319+
"path_style": "file_name_first",
1320+
// When to show change counters in the git gutter.
1321+
// This setting can take three values:
1322+
//
1323+
// 1. Never show change counters:
1324+
// "show_change_counters": "never"
1325+
// 2. Show change counters on hover:
1326+
// "show_change_counters": "on_hover"
1327+
// 3. Always show change counters:
1328+
// "show_change_counters": "always"
1329+
"show_change_counters": "on_hover"
13101330
},
13111331
// The list of custom Git hosting providers.
13121332
"git_hosting_providers": [

crates/git_ui/src/git_panel.rs

Lines changed: 23 additions & 7 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 selected = self.selected_entry == Some(ix);
@@ -4054,7 +4056,13 @@ impl GitPanel {
40544056
} else {
40554057
cx.theme().colors().ghost_element_active
40564058
};
4057-
4059+
let name_label =
4060+
|status: FileStatus, label_color: Color, this: Div, label: String| -> Div {
4061+
this.child(
4062+
self.entry_label(label, label_color)
4063+
.when(status.is_deleted(), |this| this.strikethrough()),
4064+
)
4065+
};
40584066
h_flex()
40594067
.id(id)
40604068
.h(self.list_item_height())
@@ -4153,19 +4161,27 @@ impl GitPanel {
41534161
.items_center()
41544162
.flex_1()
41554163
// .overflow_hidden()
4156-
.child(
4157-
self.entry_label(format!("{display_name} "), label_color)
4158-
.when(status.is_deleted(), |this| this.strikethrough()),
4159-
)
4164+
.when(git_path_style == GitPathStyle::FileNameFirst, |this| {
4165+
name_label(status, label_color, this, format!("{display_name} "))
4166+
})
41604167
.when_some(entry.parent_dir(path_style), |this, parent| {
41614168
if !parent.is_empty() {
41624169
this.child(
4163-
self.entry_label(parent, path_color)
4164-
.when(status.is_deleted(), |this| this.strikethrough()),
4170+
self.entry_label(
4171+
match git_path_style {
4172+
GitPathStyle::FilePathFirst => parent,
4173+
_ => format!("{parent}{}", path_style.separator()),
4174+
},
4175+
path_color,
4176+
)
4177+
.when(status.is_deleted(), |this| this.strikethrough()),
41654178
)
41664179
} else {
41674180
this
41684181
}
4182+
})
4183+
.when(git_path_style == GitPathStyle::FilePathFirst, |this| {
4184+
name_label(status, label_color, this, display_name)
41694185
}),
41704186
)
41714187
.into_any_element()

crates/project/src/project_settings.rs

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,50 @@ pub struct GitSettings {
318318
///
319319
/// Default: staged_hollow
320320
pub hunk_style: settings::GitHunkStyleSetting,
321+
/// How file paths are displayed in the git gutter.
322+
///
323+
/// Default: file_name_first
324+
pub path_style: GitPathStyle,
325+
/// When to show change counters in the git gutter.
326+
///
327+
/// Default: on_hover
328+
pub show_change_counters: GitShowChangeCounters,
329+
}
330+
331+
#[derive(Clone, Copy, Debug, PartialEq, Default)]
332+
pub enum GitPathStyle {
333+
#[default]
334+
FileNameFirst,
335+
FilePathFirst,
336+
TreeView,
337+
}
338+
339+
impl From<settings::GitPathStyle> for GitPathStyle {
340+
fn from(style: settings::GitPathStyle) -> Self {
341+
match style {
342+
settings::GitPathStyle::FileNameFirst => GitPathStyle::FileNameFirst,
343+
settings::GitPathStyle::FilePathFirst => GitPathStyle::FilePathFirst,
344+
settings::GitPathStyle::TreeView => GitPathStyle::TreeView,
345+
}
346+
}
347+
}
348+
349+
#[derive(Clone, Copy, Debug, PartialEq, Default)]
350+
pub enum GitShowChangeCounters {
351+
Never,
352+
#[default]
353+
OnHover,
354+
Always,
355+
}
356+
357+
impl From<settings::GitShowChangeCounters> for GitShowChangeCounters {
358+
fn from(counters: settings::GitShowChangeCounters) -> Self {
359+
match counters {
360+
settings::GitShowChangeCounters::Never => GitShowChangeCounters::Never,
361+
settings::GitShowChangeCounters::OnHover => GitShowChangeCounters::OnHover,
362+
settings::GitShowChangeCounters::Always => GitShowChangeCounters::Always,
363+
}
364+
}
321365
}
322366

323367
#[derive(Clone, Copy, Debug)]
@@ -471,6 +515,8 @@ impl Settings for ProjectSettings {
471515
}
472516
},
473517
hunk_style: git.hunk_style.unwrap(),
518+
path_style: git.path_style.unwrap().into(),
519+
show_change_counters: git.show_change_counters.unwrap().into(),
474520
};
475521
Self {
476522
context_servers: project

crates/settings/src/settings_content/project.rs

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,14 @@ pub struct GitSettings {
296296
///
297297
/// Default: staged_hollow
298298
pub hunk_style: Option<GitHunkStyleSetting>,
299+
/// How file paths are displayed in the git gutter.
300+
///
301+
/// Default: file_name_first
302+
pub path_style: Option<GitPathStyle>,
303+
/// When to show change counters in the git gutter.
304+
///
305+
/// Default: on_hover
306+
pub show_change_counters: Option<GitShowChangeCounters>,
299307
}
300308

301309
#[derive(
@@ -391,6 +399,54 @@ pub enum GitHunkStyleSetting {
391399
UnstagedHollow,
392400
}
393401

402+
#[derive(
403+
Copy,
404+
Clone,
405+
Debug,
406+
PartialEq,
407+
Default,
408+
Serialize,
409+
Deserialize,
410+
JsonSchema,
411+
MergeFrom,
412+
strum::VariantArray,
413+
strum::VariantNames,
414+
)]
415+
#[serde(rename_all = "snake_case")]
416+
pub enum GitPathStyle {
417+
/// Show file name first, then path
418+
#[default]
419+
FileNameFirst,
420+
/// Show full path first
421+
FilePathFirst,
422+
/// Show in tree view format
423+
TreeView,
424+
}
425+
426+
#[derive(
427+
Copy,
428+
Clone,
429+
Debug,
430+
PartialEq,
431+
Default,
432+
Serialize,
433+
Deserialize,
434+
JsonSchema,
435+
MergeFrom,
436+
strum::VariantArray,
437+
strum::VariantNames,
438+
)]
439+
#[serde(rename_all = "snake_case")]
440+
pub enum GitShowChangeCounters {
441+
/// Never show change counters
442+
Never,
443+
/// Show change counters on hover
444+
#[default]
445+
OnHover,
446+
/// Always show change counters
447+
Always,
448+
}
449+
394450
#[skip_serializing_none]
395451
#[derive(Clone, Debug, PartialEq, Eq, Default, Serialize, Deserialize, JsonSchema, MergeFrom)]
396452
pub struct DiagnosticsSettingsContent {

crates/settings_ui/src/page_data.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5476,6 +5476,32 @@ pub(crate) fn settings_data(cx: &App) -> Vec<SettingsPage> {
54765476
metadata: None,
54775477
files: USER,
54785478
}),
5479+
SettingsPageItem::SettingItem(SettingItem {
5480+
title: "Path Style",
5481+
description: "How file paths are displayed in the git gutter.",
5482+
field: Box::new(SettingField {
5483+
json_path: Some("git.path_style"),
5484+
pick: |settings_content| settings_content.git.as_ref()?.path_style.as_ref(),
5485+
write: |settings_content, value| {
5486+
settings_content.git.get_or_insert_default().path_style = value;
5487+
},
5488+
}),
5489+
metadata: None,
5490+
files: USER,
5491+
}),
5492+
SettingsPageItem::SettingItem(SettingItem {
5493+
title: "Show Change Counters",
5494+
description: "When to show change counters in the git gutter.",
5495+
field: Box::new(SettingField {
5496+
json_path: Some("git.show_change_counters"),
5497+
pick: |settings_content| settings_content.git.as_ref()?.show_change_counters.as_ref(),
5498+
write: |settings_content, value| {
5499+
settings_content.git.get_or_insert_default().show_change_counters = value;
5500+
},
5501+
}),
5502+
metadata: None,
5503+
files: USER,
5504+
}),
54795505
],
54805506
},
54815507
SettingsPage {

crates/settings_ui/src/settings_ui.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,8 @@ fn init_renderers(cx: &mut App) {
443443
.add_basic_renderer::<settings::DockPosition>(render_dropdown)
444444
.add_basic_renderer::<settings::GitGutterSetting>(render_dropdown)
445445
.add_basic_renderer::<settings::GitHunkStyleSetting>(render_dropdown)
446+
.add_basic_renderer::<settings::GitPathStyle>(render_dropdown)
447+
.add_basic_renderer::<settings::GitShowChangeCounters>(render_dropdown)
446448
.add_basic_renderer::<settings::DiagnosticSeverityContent>(render_dropdown)
447449
.add_basic_renderer::<settings::SeedQuerySetting>(render_dropdown)
448450
.add_basic_renderer::<settings::DoubleClickInMultibuffer>(render_dropdown)

0 commit comments

Comments
 (0)