Skip to content

Commit c71ea03

Browse files
committed
Added settings for git view
1 parent 3d9bf95 commit c71ea03

File tree

7 files changed

+473
-8
lines changed

7 files changed

+473
-8
lines changed

assets/settings/default.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1306,7 +1306,10 @@
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 panel.
1311+
// "path_style": "file_name_first" or "file_path_first"
1312+
"path_style": "file_name_first"
13101313
},
13111314
// The list of custom Git hosting providers.
13121315
"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: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,26 @@ 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+
}
326+
327+
#[derive(Clone, Copy, Debug, PartialEq, Default)]
328+
pub enum GitPathStyle {
329+
#[default]
330+
FileNameFirst,
331+
FilePathFirst,
332+
}
333+
334+
impl From<settings::GitPathStyle> for GitPathStyle {
335+
fn from(style: settings::GitPathStyle) -> Self {
336+
match style {
337+
settings::GitPathStyle::FileNameFirst => GitPathStyle::FileNameFirst,
338+
settings::GitPathStyle::FilePathFirst => GitPathStyle::FilePathFirst,
339+
}
340+
}
321341
}
322342

323343
#[derive(Clone, Copy, Debug)]
@@ -471,6 +491,7 @@ impl Settings for ProjectSettings {
471491
}
472492
},
473493
hunk_style: git.hunk_style.unwrap(),
494+
path_style: git.path_style.unwrap().into(),
474495
};
475496
Self {
476497
context_servers: project

crates/settings/src/settings_content/project.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,10 @@ 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>,
299303
}
300304

301305
#[derive(
@@ -391,6 +395,28 @@ pub enum GitHunkStyleSetting {
391395
UnstagedHollow,
392396
}
393397

398+
#[derive(
399+
Copy,
400+
Clone,
401+
Debug,
402+
PartialEq,
403+
Default,
404+
Serialize,
405+
Deserialize,
406+
JsonSchema,
407+
MergeFrom,
408+
strum::VariantArray,
409+
strum::VariantNames,
410+
)]
411+
#[serde(rename_all = "snake_case")]
412+
pub enum GitPathStyle {
413+
/// Show file name first, then path
414+
#[default]
415+
FileNameFirst,
416+
/// Show full path first
417+
FilePathFirst,
418+
}
419+
394420
#[skip_serializing_none]
395421
#[derive(Clone, Debug, PartialEq, Eq, Default, Serialize, Deserialize, JsonSchema, MergeFrom)]
396422
pub struct DiagnosticsSettingsContent {

0 commit comments

Comments
 (0)