Closes #4533 (partly at least) Release Notes: - Added `project_panel.sort_mode` option to control explorer file sort (directories first, mixed, files first) ## Summary Adds three sorting modes for the project panel to give users more control over how files and directories are displayed: - **`directories_first`** (default): Current behaviour - directories grouped before files - **`mixed`**: Files and directories sorted together alphabetically - **`files_first`**: filed grouped before directories ## Motivation Users coming from different editors and file managers have different expectations for file sorting. Some prefer directories grouped at the top (traditional), while others prefer the macOS Finder-style mixed sorting where "Apple1/", "apple2.tsx" and "Apple3/" appear alphabetically mixed together. ### Screenshots New sort options in settings: <img width="515" height="160" alt="image" src="https://github.com/user-attachments/assets/8f4e6668-6989-4881-a9bd-ed1f4f0beb40" /> Directories first | Mixed | Files first -------------|-----|----- <img width="328" height="888" alt="image" src="https://github.com/user-attachments/assets/308e5c7a-6e6a-46ba-813d-6e268222925c" /> | <img width="327" height="891" alt="image" src="https://github.com/user-attachments/assets/8274d8ca-b60f-456e-be36-e35a3259483c" /> | <img width="328" height="890" alt="image" src="https://github.com/user-attachments/assets/3c3b1332-cf08-4eaf-9bed-527c00b41529" /> ### Agent usage Copilot-cli/claude-code/codex-cli helped out a lot. I'm not from a rust background, but really wanted this solved, and it gave me a chance to play with some of the coding agents I'm not permitted to use for work stuff --------- Co-authored-by: Smit Barmase <heysmitbarmase@gmail.com>
125 lines
4.2 KiB
Rust
125 lines
4.2 KiB
Rust
use editor::EditorSettings;
|
|
use gpui::Pixels;
|
|
use schemars::JsonSchema;
|
|
use serde::{Deserialize, Serialize};
|
|
use settings::{
|
|
DockSide, ProjectPanelEntrySpacing, ProjectPanelSortMode, RegisterSetting, Settings,
|
|
ShowDiagnostics, ShowIndentGuides,
|
|
};
|
|
use ui::{
|
|
px,
|
|
scrollbars::{ScrollbarVisibility, ShowScrollbar},
|
|
};
|
|
|
|
#[derive(Deserialize, Debug, Clone, Copy, PartialEq, RegisterSetting)]
|
|
pub struct ProjectPanelSettings {
|
|
pub button: bool,
|
|
pub hide_gitignore: bool,
|
|
pub default_width: Pixels,
|
|
pub dock: DockSide,
|
|
pub entry_spacing: ProjectPanelEntrySpacing,
|
|
pub file_icons: bool,
|
|
pub folder_icons: bool,
|
|
pub git_status: bool,
|
|
pub indent_size: f32,
|
|
pub indent_guides: IndentGuidesSettings,
|
|
pub sticky_scroll: bool,
|
|
pub auto_reveal_entries: bool,
|
|
pub auto_fold_dirs: bool,
|
|
pub starts_open: bool,
|
|
pub scrollbar: ScrollbarSettings,
|
|
pub show_diagnostics: ShowDiagnostics,
|
|
pub hide_root: bool,
|
|
pub hide_hidden: bool,
|
|
pub drag_and_drop: bool,
|
|
pub auto_open: AutoOpenSettings,
|
|
pub sort_mode: ProjectPanelSortMode,
|
|
}
|
|
|
|
#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
|
|
pub struct IndentGuidesSettings {
|
|
pub show: ShowIndentGuides,
|
|
}
|
|
|
|
#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
|
|
pub struct ScrollbarSettings {
|
|
/// When to show the scrollbar in the project panel.
|
|
///
|
|
/// Default: inherits editor scrollbar settings
|
|
pub show: Option<ShowScrollbar>,
|
|
}
|
|
|
|
#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
|
|
pub struct AutoOpenSettings {
|
|
pub on_create: bool,
|
|
pub on_paste: bool,
|
|
pub on_drop: bool,
|
|
}
|
|
|
|
impl AutoOpenSettings {
|
|
#[inline]
|
|
pub fn should_open_on_create(self) -> bool {
|
|
self.on_create
|
|
}
|
|
|
|
#[inline]
|
|
pub fn should_open_on_paste(self) -> bool {
|
|
self.on_paste
|
|
}
|
|
|
|
#[inline]
|
|
pub fn should_open_on_drop(self) -> bool {
|
|
self.on_drop
|
|
}
|
|
}
|
|
|
|
impl ScrollbarVisibility for ProjectPanelSettings {
|
|
fn visibility(&self, cx: &ui::App) -> ShowScrollbar {
|
|
self.scrollbar
|
|
.show
|
|
.unwrap_or_else(|| EditorSettings::get_global(cx).scrollbar.show)
|
|
}
|
|
}
|
|
|
|
impl Settings for ProjectPanelSettings {
|
|
fn from_settings(content: &settings::SettingsContent) -> Self {
|
|
let project_panel = content.project_panel.clone().unwrap();
|
|
Self {
|
|
button: project_panel.button.unwrap(),
|
|
hide_gitignore: project_panel.hide_gitignore.unwrap(),
|
|
default_width: px(project_panel.default_width.unwrap()),
|
|
dock: project_panel.dock.unwrap(),
|
|
entry_spacing: project_panel.entry_spacing.unwrap(),
|
|
file_icons: project_panel.file_icons.unwrap(),
|
|
folder_icons: project_panel.folder_icons.unwrap(),
|
|
git_status: project_panel.git_status.unwrap(),
|
|
indent_size: project_panel.indent_size.unwrap(),
|
|
indent_guides: IndentGuidesSettings {
|
|
show: project_panel.indent_guides.unwrap().show.unwrap(),
|
|
},
|
|
sticky_scroll: project_panel.sticky_scroll.unwrap(),
|
|
auto_reveal_entries: project_panel.auto_reveal_entries.unwrap(),
|
|
auto_fold_dirs: project_panel.auto_fold_dirs.unwrap(),
|
|
starts_open: project_panel.starts_open.unwrap(),
|
|
scrollbar: ScrollbarSettings {
|
|
show: project_panel.scrollbar.unwrap().show.map(Into::into),
|
|
},
|
|
show_diagnostics: project_panel.show_diagnostics.unwrap(),
|
|
hide_root: project_panel.hide_root.unwrap(),
|
|
hide_hidden: project_panel.hide_hidden.unwrap(),
|
|
drag_and_drop: project_panel.drag_and_drop.unwrap(),
|
|
auto_open: {
|
|
let auto_open = project_panel.auto_open.unwrap();
|
|
AutoOpenSettings {
|
|
on_create: auto_open.on_create.unwrap(),
|
|
on_paste: auto_open.on_paste.unwrap(),
|
|
on_drop: auto_open.on_drop.unwrap(),
|
|
}
|
|
},
|
|
sort_mode: project_panel
|
|
.sort_mode
|
|
.unwrap_or(ProjectPanelSortMode::DirectoriesFirst),
|
|
}
|
|
}
|
|
}
|