Add settings
This commit is contained in:
parent
d26f76ba90
commit
d023189bda
5 changed files with 36 additions and 28 deletions
|
@ -99,6 +99,8 @@
|
||||||
"project_panel": {
|
"project_panel": {
|
||||||
// Whether to show the git status in the project panel.
|
// Whether to show the git status in the project panel.
|
||||||
"git_status": true,
|
"git_status": true,
|
||||||
|
// Whether to show file icons in the project panel.
|
||||||
|
"file_icons": true,
|
||||||
// Where to dock project panel. Can be 'left' or 'right'.
|
// Where to dock project panel. Can be 'left' or 'right'.
|
||||||
"dock": "left",
|
"dock": "left",
|
||||||
// Default width of the project panel.
|
// Default width of the project panel.
|
||||||
|
|
|
@ -755,19 +755,13 @@ impl LanguageRegistry {
|
||||||
self.get_or_load_language(|config| UniCase::new(config.name.as_ref()) == name)
|
self.get_or_load_language(|config| UniCase::new(config.name.as_ref()) == name)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn icon_for_suffix(
|
pub fn icon_for_suffix(self: &Arc<Self>, suffix: &str) -> Option<Arc<str>> {
|
||||||
self: &Arc<Self>,
|
|
||||||
suffix: &str,
|
|
||||||
) -> Option<Arc<str>> {
|
|
||||||
let state = self.state.read();
|
let state = self.state.read();
|
||||||
state.available_languages
|
state
|
||||||
|
.available_languages
|
||||||
.iter()
|
.iter()
|
||||||
.find(|langauge| {
|
.find(|langauge| langauge.config.path_suffixes.iter().any(|s| s == suffix))
|
||||||
langauge.config.path_suffixes.iter().any(|s| s == suffix)
|
.map(|language| language.config.icon_path.clone())
|
||||||
})
|
|
||||||
.map(|language| {
|
|
||||||
language.config.icon_path.clone()
|
|
||||||
})
|
|
||||||
.flatten()
|
.flatten()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2475,8 +2475,7 @@ impl Project {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn icon_for_path(&self, path: &Path) -> Option<Arc<str>> {
|
pub fn icon_for_path(&self, path: &Path) -> Option<Arc<str>> {
|
||||||
self.languages
|
self.languages.icon_for_suffix(path.extension()?.to_str()?)
|
||||||
.icon_for_suffix(path.extension()?.to_str()?)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn detect_language_for_buffer(
|
fn detect_language_for_buffer(
|
||||||
|
|
|
@ -1168,7 +1168,10 @@ impl ProjectPanel {
|
||||||
}
|
}
|
||||||
|
|
||||||
let end_ix = range.end.min(ix + visible_worktree_entries.len());
|
let end_ix = range.end.min(ix + visible_worktree_entries.len());
|
||||||
let git_status_setting = settings::get::<ProjectPanelSettings>(cx).git_status;
|
let (git_status_setting, show_file_icons) = {
|
||||||
|
let settings = settings::get::<ProjectPanelSettings>(cx);
|
||||||
|
(settings.git_status, settings.file_icons)
|
||||||
|
};
|
||||||
if let Some(worktree) = self.project.read(cx).worktree_for_id(*worktree_id, cx) {
|
if let Some(worktree) = self.project.read(cx).worktree_for_id(*worktree_id, cx) {
|
||||||
let snapshot = worktree.read(cx).snapshot();
|
let snapshot = worktree.read(cx).snapshot();
|
||||||
let root_name = OsStr::new(snapshot.root_name());
|
let root_name = OsStr::new(snapshot.root_name());
|
||||||
|
@ -1182,14 +1185,16 @@ impl ProjectPanel {
|
||||||
for entry in visible_worktree_entries[entry_range].iter() {
|
for entry in visible_worktree_entries[entry_range].iter() {
|
||||||
let status = git_status_setting.then(|| entry.git_status).flatten();
|
let status = git_status_setting.then(|| entry.git_status).flatten();
|
||||||
|
|
||||||
let icon = match entry.kind {
|
let icon = show_file_icons
|
||||||
EntryKind::File(_) => self
|
.then(|| match entry.kind {
|
||||||
.project
|
EntryKind::File(_) => self
|
||||||
.read(cx)
|
.project
|
||||||
.icon_for_path(&entry.path)
|
.read(cx)
|
||||||
.or_else(|| Some(TEXT_FILE_ASSET.into())),
|
.icon_for_path(&entry.path)
|
||||||
_ => None,
|
.or_else(|| Some(TEXT_FILE_ASSET.into())),
|
||||||
};
|
_ => None,
|
||||||
|
})
|
||||||
|
.flatten();
|
||||||
|
|
||||||
let mut details = EntryDetails {
|
let mut details = EntryDetails {
|
||||||
filename: entry
|
filename: entry
|
||||||
|
@ -1283,14 +1288,20 @@ impl ProjectPanel {
|
||||||
Svg::new(icon.to_string())
|
Svg::new(icon.to_string())
|
||||||
.with_color(style.icon_color)
|
.with_color(style.icon_color)
|
||||||
.constrained()
|
.constrained()
|
||||||
|
.with_max_width(style.file_icon_size)
|
||||||
|
.with_max_height(style.file_icon_size)
|
||||||
|
.aligned()
|
||||||
|
.constrained()
|
||||||
|
.with_width(style.file_icon_size)
|
||||||
} else {
|
} else {
|
||||||
Empty::new().constrained()
|
Empty::new()
|
||||||
|
.constrained()
|
||||||
|
.with_max_width(style.directory_icon_size)
|
||||||
|
.with_max_height(style.directory_icon_size)
|
||||||
|
.aligned()
|
||||||
|
.constrained()
|
||||||
|
.with_width(style.directory_icon_size)
|
||||||
}
|
}
|
||||||
.with_max_width(style.file_icon_size)
|
|
||||||
.with_max_height(style.file_icon_size)
|
|
||||||
.aligned()
|
|
||||||
.constrained()
|
|
||||||
.with_width(style.file_icon_size)
|
|
||||||
})
|
})
|
||||||
.with_child(if show_editor && editor.is_some() {
|
.with_child(if show_editor && editor.is_some() {
|
||||||
ChildView::new(editor.as_ref().unwrap(), cx)
|
ChildView::new(editor.as_ref().unwrap(), cx)
|
||||||
|
|
|
@ -13,6 +13,7 @@ pub enum ProjectPanelDockPosition {
|
||||||
#[derive(Deserialize, Debug)]
|
#[derive(Deserialize, Debug)]
|
||||||
pub struct ProjectPanelSettings {
|
pub struct ProjectPanelSettings {
|
||||||
pub git_status: bool,
|
pub git_status: bool,
|
||||||
|
pub file_icons: bool,
|
||||||
pub dock: ProjectPanelDockPosition,
|
pub dock: ProjectPanelDockPosition,
|
||||||
pub default_width: f32,
|
pub default_width: f32,
|
||||||
}
|
}
|
||||||
|
@ -20,6 +21,7 @@ pub struct ProjectPanelSettings {
|
||||||
#[derive(Clone, Default, Serialize, Deserialize, JsonSchema, Debug)]
|
#[derive(Clone, Default, Serialize, Deserialize, JsonSchema, Debug)]
|
||||||
pub struct ProjectPanelSettingsContent {
|
pub struct ProjectPanelSettingsContent {
|
||||||
pub git_status: Option<bool>,
|
pub git_status: Option<bool>,
|
||||||
|
pub file_icons: Option<bool>,
|
||||||
pub dock: Option<ProjectPanelDockPosition>,
|
pub dock: Option<ProjectPanelDockPosition>,
|
||||||
pub default_width: Option<f32>,
|
pub default_width: Option<f32>,
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue