diff --git a/CLAUDE.md b/CLAUDE.md
index c2936f1..3d472a2 100644
--- a/CLAUDE.md
+++ b/CLAUDE.md
@@ -89,6 +89,7 @@ Never modify: `PROMPT.md` (the user's brief), the user's other projects under `~
| `XDG_DATA_HOME=
/data cargo run -p tunal-core --example ops -- ` (refuses unless XDG_DATA_HOME is inside ``) | job engine + trash smoke run: conflicts, cancel, trash/restore/empty | S007 |
| `cargo run -p tunal -- --gallery --screenshot [--dark] --size 1200x1000` (`--gallery` alone opens it in a window) | every control in rest/hover/pressed/focused/disabled; press squeeze not drawn by the software renderer | S004 |
| `cargo run -p tunal -- --gallery --page menu\|dialog --screenshot [--dark] --size 960x640` | open menu + submenu + two toasts, or dialog + indeterminate toast, over a stand-in folder | S005 |
+| `TUNAL_SETTINGS=<0-4> cargo run -p tunal -- --screenshot --size 1000x700` (`XDG_CONFIG_HOME=`) | settings dialog page over a folder | S013 |
Don't assume a tool exists: check first. When your plan creates a tool, add its row here.
diff --git a/Plans/03 File browsing/S013-settings-context-menus.md b/Plans/03 File browsing/S013-settings-context-menus.md
index f2b783e..7b39111 100644
--- a/Plans/03 File browsing/S013-settings-context-menus.md
+++ b/Plans/03 File browsing/S013-settings-context-menus.md
@@ -10,11 +10,11 @@ A settings dialog and context menus the user edits in the app (add, remove, reor
crates/tunal/src/{actions.rs,config.rs}; crates/tunal/ui/components/{dialog,menu,switch,list-row}.slint.
## Steps
-- [ ] Settings dialog pages: General (hidden files, folders first, restore tabs), View (default view, sort, grouping), Previews (placeholder for S018), Motion (follow system / always reduce / never reduce), Context menus.
-- [ ] Menu model per context (file, folder, multiple items, empty area, trash): action ids + separators; defaults; stored in `menus.toml`.
-- [ ] Menu editor: add from available actions, remove, reorder by drag and by buttons (animated), reset to defaults.
-- [ ] Context menus are built from the model everywhere (views, sidebar entries).
-- [ ] PROGRESS entry, INDEX line, commit `S013: …`
+- [x] Settings dialog pages: General (hidden files, folders first, restore tabs), View (default view, sort, grouping), Previews (placeholder for S018), Motion (follow system / always reduce / never reduce), Context menus.
+- [x] Menu model per context (file, folder, multiple items, empty area, trash): action ids + separators; defaults; stored in `menus.toml`.
+- [x] Menu editor: add from available actions, remove, reorder by drag and by buttons (animated), reset to defaults.
+- [x] Context menus are built from the model everywhere (views, sidebar entries).
+- [x] PROGRESS entry, INDEX line, commit `S013: …`
## End criteria
- `cargo build --workspace`, `cargo clippy --workspace --all-targets -- -D warnings` and `cargo fmt --check` pass.
diff --git a/Plans/INDEX.md b/Plans/INDEX.md
index 2cd7625..f27064e 100644
--- a/Plans/INDEX.md
+++ b/Plans/INDEX.md
@@ -25,7 +25,7 @@ Tracker: https://claude.ai/artifact/4X8YCk3cQjUGyuyCqGuU7v
- [x] [S010 — Tabs, split view, breadcrumbs, history and places](03%20File%20browsing/S010-navigation-shell.md) · Opus medium
- [x] [S011 — File operation actions](03%20File%20browsing/S011-file-op-actions.md) · Sonnet high
- [ ] [S012 — Properties, Open and Open with](03%20File%20browsing/S012-properties-open-with.md) · Sonnet medium
-- [ ] [S013 — Settings dialog and editable context menus](03%20File%20browsing/S013-settings-context-menus.md) · Sonnet high
+- [x] [S013 — Settings dialog and editable context menus](03%20File%20browsing/S013-settings-context-menus.md) · Sonnet high
- [ ] [S014 — In-app drag and drop](03%20File%20browsing/S014-in-app-dnd.md) · Opus medium
## 04 Directory metadata
diff --git a/crates/tunal/src/config.rs b/crates/tunal/src/config.rs
index 00d8c01..8e347ad 100644
--- a/crates/tunal/src/config.rs
+++ b/crates/tunal/src/config.rs
@@ -60,13 +60,60 @@ pub fn store(name: &str, value: &T) {
}
}
+/// Details list or icon grid.
+#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
+#[serde(rename_all = "lowercase")]
+pub enum View {
+ #[default]
+ Details,
+ Grid,
+}
+
+#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
+#[serde(rename_all = "lowercase")]
+pub enum Sort {
+ #[default]
+ Name,
+ Size,
+ Type,
+ Modified,
+}
+
+#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
+#[serde(rename_all = "lowercase")]
+pub enum Group {
+ #[default]
+ None,
+ Type,
+ Modified,
+ Size,
+}
+
+/// Whether motion follows the desktop's animation setting.
+#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
+#[serde(rename_all = "lowercase")]
+pub enum Motion {
+ #[default]
+ System,
+ Reduce,
+ Full,
+}
+
/// `settings.toml`. Later plans add their fields here.
-#[derive(Debug, Serialize, Deserialize)]
+#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(default)]
pub struct Settings {
/// Reopen the tabs of the last session.
pub restore_session: bool,
pub show_sidebar: bool,
+ pub show_hidden: bool,
+ pub folders_first: bool,
+ /// What a new pane starts with.
+ pub view: View,
+ pub sort: Sort,
+ pub sort_descending: bool,
+ pub group: Group,
+ pub motion: Motion,
}
impl Default for Settings {
@@ -74,6 +121,13 @@ impl Default for Settings {
Self {
restore_session: true,
show_sidebar: true,
+ show_hidden: false,
+ folders_first: true,
+ view: View::Details,
+ sort: Sort::Name,
+ sort_descending: false,
+ group: Group::None,
+ motion: Motion::System,
}
}
}
diff --git a/crates/tunal/src/folder/mod.rs b/crates/tunal/src/folder/mod.rs
index 55695b7..ad4861b 100644
--- a/crates/tunal/src/folder/mod.rs
+++ b/crates/tunal/src/folder/mod.rs
@@ -16,6 +16,7 @@ use slint::{Model, ModelNotify, ModelRc, ModelTracker, SharedString, VecModel};
use tunal_core::playlist::Playlist;
use tunal_core::{Entry, Error, Locations, Uri, Watch};
+use crate::config;
use crate::icons::{self, Category};
use crate::{
DetailRow, FolderState, FolderStatus, GridRow, Grouping, MenuEntry, MenuItem, NavKey,
@@ -132,7 +133,7 @@ impl FolderModel {
by_name: HashMap::new(),
rows: Vec::new(),
row_of: HashMap::new(),
- settings: Settings::default(),
+ settings: Settings::from_config(&config::load("settings")),
playlists: Vec::new(),
playlist_path: None,
selected: HashSet::new(),
@@ -569,6 +570,35 @@ impl FolderModel {
self.set_filter(&filter);
}
+ /// The settings dialog changed what applies to panes already open.
+ pub fn apply_config(&self, cfg: &config::Settings) {
+ let (hidden, folders_first) = (cfg.show_hidden, cfg.folders_first);
+ let current = {
+ let s = self.state.borrow();
+ (s.settings.show_hidden, s.settings.folders_first)
+ };
+ if current != (hidden, folders_first) {
+ self.update(|s| {
+ s.show_hidden = hidden;
+ s.folders_first = folders_first;
+ });
+ }
+ }
+
+ /// True when everything selected (or under the cursor) is a folder.
+ pub fn selection_is_dir(&self) -> bool {
+ let s = self.state.borrow();
+ let names: Vec<&Vec> = if s.selected.is_empty() {
+ s.cursor.iter().collect()
+ } else {
+ s.selected.iter().collect()
+ };
+ !names.is_empty()
+ && names
+ .iter()
+ .all(|n| s.by_name.get(*n).is_some_and(|&i| s.items[i].is_dir))
+ }
+
pub fn toggle_hidden(&self) {
self.update(|s| s.show_hidden = !s.show_hidden);
}
@@ -889,21 +919,25 @@ impl FolderModel {
line as i32
}
- /// Enter or double-click: opens the folder at `row` (the cursor row when `None`).
- pub fn activate(&self, row: Option) {
- let target = {
+ /// Enter or double-click: opens the folder at `row` (the cursor row when `None`); a file
+ /// is returned for the caller to open.
+ pub fn activate(&self, row: Option) -> Option {
+ let (uri, is_dir) = {
let s = self.state.borrow();
let row = row.or_else(|| s.cursor.as_ref().and_then(|c| s.row_of.get(c)).copied());
match row.and_then(|r| s.rows.get(r)) {
- Some(Row::Item(i)) if s.items[*i].is_dir => {
- s.dir.as_ref().map(|d| d.join(&s.items[*i].entry.name))
- }
- _ => None,
+ Some(Row::Item(i)) => (
+ s.dir.as_ref().map(|d| d.join(&s.items[*i].entry.name)),
+ s.items[*i].is_dir,
+ ),
+ _ => (None, false),
}
};
- if let Some(dir) = target {
- self.open_travel(dir, Travel::Into);
+ if is_dir {
+ self.open_travel(uri?, Travel::Into);
+ return None;
}
+ uri
}
}
diff --git a/crates/tunal/src/folder/sort.rs b/crates/tunal/src/folder/sort.rs
index 98c8589..0d6ab3b 100644
--- a/crates/tunal/src/folder/sort.rs
+++ b/crates/tunal/src/folder/sort.rs
@@ -7,6 +7,7 @@ use tunal_core::playlist::Ranks;
use super::Item;
use crate::ViewMode;
+use crate::config;
use crate::icons::Category;
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
@@ -39,18 +40,29 @@ pub struct Settings {
pub mode: ViewMode,
}
-impl Default for Settings {
- fn default() -> Self {
+impl Settings {
+ /// A new pane's settings: the defaults chosen in the settings dialog.
+ pub fn from_config(cfg: &config::Settings) -> Self {
Self {
- key: SortKey::Name,
- descending: false,
- folders_first: true,
- group: GroupBy::None,
- show_hidden: false,
+ key: match cfg.sort {
+ config::Sort::Name => SortKey::Name,
+ config::Sort::Size => SortKey::Size,
+ config::Sort::Type => SortKey::Type,
+ config::Sort::Modified => SortKey::Modified,
+ },
+ descending: cfg.sort_descending,
+ folders_first: cfg.folders_first,
+ group: match cfg.group {
+ config::Group::None => GroupBy::None,
+ config::Group::Type => GroupBy::Type,
+ config::Group::Modified => GroupBy::Modified,
+ config::Group::Size => GroupBy::Size,
+ },
+ show_hidden: cfg.show_hidden,
filter: String::new(),
// `TUNAL_VIEW=grid` starts in the grid view (screenshots).
- mode: match std::env::var("TUNAL_VIEW").as_deref() {
- Ok("grid") => ViewMode::Grid,
+ mode: match (std::env::var("TUNAL_VIEW").as_deref(), cfg.view) {
+ (Ok("grid"), _) | (_, config::View::Grid) => ViewMode::Grid,
_ => ViewMode::Details,
},
}
diff --git a/crates/tunal/src/menus.rs b/crates/tunal/src/menus.rs
new file mode 100644
index 0000000..8c55458
--- /dev/null
+++ b/crates/tunal/src/menus.rs
@@ -0,0 +1,175 @@
+//! The context menus, one list of action ids per context, kept in `menus.toml`. A context
+//! the file doesn't name uses its default; ids this build doesn't know are skipped when a menu
+//! is built, so a file written by a newer build still works.
+
+use serde::{Deserialize, Serialize};
+
+use crate::actions::Action;
+use crate::config;
+
+/// Stands for a separator in a list.
+pub const SEPARATOR: &str = "-";
+
+/// What the menu was opened on.
+#[derive(Clone, Copy, Debug, PartialEq, Eq)]
+pub enum Context {
+ File,
+ Folder,
+ Multiple,
+ Empty,
+ Trash,
+}
+
+impl Context {
+ pub const ALL: [Context; 5] = [
+ Self::File,
+ Self::Folder,
+ Self::Multiple,
+ Self::Empty,
+ Self::Trash,
+ ];
+
+ pub fn label(self) -> &'static str {
+ match self {
+ Self::File => "File",
+ Self::Folder => "Folder",
+ Self::Multiple => "Several items",
+ Self::Empty => "Empty area",
+ Self::Trash => "Trash",
+ }
+ }
+
+ /// The menu before the user edits it.
+ pub fn defaults(self) -> Vec {
+ let ids: &[&str] = match self {
+ Self::File => &[
+ "open",
+ "open-with",
+ "-",
+ "cut",
+ "copy",
+ "paste",
+ "-",
+ "copy-path",
+ "rename",
+ "-",
+ "trash",
+ "delete",
+ "-",
+ "properties",
+ ],
+ Self::Folder => &[
+ "open",
+ "-",
+ "cut",
+ "copy",
+ "paste",
+ "-",
+ "copy-path",
+ "rename",
+ "new-folder",
+ "-",
+ "trash",
+ "delete",
+ "-",
+ "properties",
+ ],
+ Self::Multiple => &[
+ "cut",
+ "copy",
+ "-",
+ "copy-path",
+ "-",
+ "trash",
+ "delete",
+ "-",
+ "properties",
+ ],
+ Self::Empty => &[
+ "paste",
+ "new-folder",
+ "-",
+ "copy-path",
+ "-",
+ "properties",
+ "settings",
+ ],
+ Self::Trash => &["restore", "copy", "copy-path", "-", "delete", "empty-trash"],
+ };
+ ids.iter().map(|s| s.to_string()).collect()
+ }
+}
+
+/// `menus.toml`: a context that is missing keeps its default.
+#[derive(Debug, Default, Clone, Serialize, Deserialize)]
+#[serde(default)]
+pub struct Menus {
+ file: Option>,
+ folder: Option>,
+ multiple: Option>,
+ empty: Option>,
+ trash: Option>,
+}
+
+impl Menus {
+ pub fn load() -> Self {
+ config::load("menus")
+ }
+
+ pub fn save(&self) {
+ config::store("menus", self);
+ }
+
+ fn slot(&mut self, ctx: Context) -> &mut Option> {
+ match ctx {
+ Context::File => &mut self.file,
+ Context::Folder => &mut self.folder,
+ Context::Multiple => &mut self.multiple,
+ Context::Empty => &mut self.empty,
+ Context::Trash => &mut self.trash,
+ }
+ }
+
+ /// The ids of `ctx`, edited or default.
+ pub fn ids(&self, ctx: Context) -> Vec {
+ let edited = match ctx {
+ Context::File => &self.file,
+ Context::Folder => &self.folder,
+ Context::Multiple => &self.multiple,
+ Context::Empty => &self.empty,
+ Context::Trash => &self.trash,
+ };
+ edited.clone().unwrap_or_else(|| ctx.defaults())
+ }
+
+ /// The menu as shown: known actions only, `None` for a separator, with no separator at
+ /// either end or twice in a row.
+ pub fn layout(&self, ctx: Context) -> Vec