Skip to content

A fast file manager for Windows and macOS that never freezes: tabs, dual panes, archives as folders, Quick Look-style previews. A File Explorer and Finder alternative written in Rust.

Each folder keeps its own Details columns when layouts aren't shared (755)

gelenmedyaf857a2070927
diff --git a/crates/rf-app/src/folder_view.rs b/crates/rf-app/src/folder_view.rs
index ca4e9804..50c425a7 100644
--- a/crates/rf-app/src/folder_view.rs
+++ b/crates/rf-app/src/folder_view.rs
@@ -838,6 +838,8 @@ pub struct FolderView {
settings_scroll: ScrollHandle,
/// A wheel click's auto-scroll while it runs (see [`FolderView::begin_autoscroll`]).
autoscroll: Option<AutoScroll>,
+ /// The Details columns this folder was given in it (see [`FolderView::col_prefs`]); `None`: those of Settings.
+ own_cols: Option<crate::settings::ColumnPrefs>,
pub focus: FocusHandle,
/// Re-select this name after the next load (e.g. after going up a level).
reselect: Option<String>,
@@ -1033,7 +1035,7 @@ impl FolderView {
// folders show (and sort by) size on disk or the sum of their files, as set
this.resort_for_sizes(cx);
// turning a commit column on loads the commits
- if this.git.is_some() && this.git_commits.is_none() && Self::commit_cols_on(cx) {
+ if this.git.is_some() && this.git_commits.is_none() && this.commit_cols_on(cx) {
this.refresh_git(cx);
}
// another Git program was chosen: what it says of this folder
@@ -1130,6 +1132,7 @@ impl FolderView {
scroll: UniformListScrollHandle::new(),
settings_scroll: ScrollHandle::new(),
autoscroll: None,
+ own_cols: None,
focus: cx.focus_handle(),
reselect: None,
menu_after_load: None,
@@ -1722,7 +1725,7 @@ impl FolderView {
self.git = None;
return;
};
- let commits = Self::commit_cols_on(cx);
+ let commits = self.commit_cols_on(cx);
let d = dir.clone();
let work = cx.background_spawn(async move {
let root = rf_win::git::repo_root(&d)?;
@@ -1829,8 +1832,8 @@ impl FolderView {
self.images.update(cx, |c, cx| c.overlay(index, device, cx))
}
- fn commit_cols_on(cx: &App) -> bool {
- let c = &cx.global::<crate::settings::Settings>().columns;
+ fn commit_cols_on(&self, cx: &App) -> bool {
+ let c = self.col_prefs(cx);
c.git_message || c.git_author || c.git_date || c.git_hash
}
@@ -3155,6 +3158,11 @@ impl FolderView {
}
fn apply_folder_layout_inner(&mut self, cx: &mut Context<Self>) {
+ // the folder's own Details columns, when it keeps its own layout (issue 755)
+ self.own_cols = match self.location().clone() {
+ Location::Path(p) if !cx.global::<crate::settings::Settings>().sync_layout => crate::layouts::columns(&p, cx),
+ _ => None,
+ };
let s = cx.global::<crate::settings::Settings>().clone();
let first = !std::mem::replace(&mut self.layout_seeded, true);
if s.sync_layout {
@@ -5612,7 +5620,7 @@ impl FolderView {
/// …then the commit columns (message, author, date, hash) at 7..11.
fn col_widths(&self, cx: &App) -> [f32; 11] {
self.col_live.unwrap_or_else(|| {
- let c = &cx.global::<crate::settings::Settings>().columns;
+ let c = self.col_prefs(cx);
let (a, b, g) = (c.widths, c.extra_widths, c.git_widths);
self.auto_cols.apply([a[0], a[1], a[2], a[3], b[0], b[1], b[2], g[0], g[1], g[2], g[3]].map(f32::from))
})
@@ -5621,7 +5629,7 @@ impl FolderView {
/// The Name column is about a third of the list by default in the Explorer look; otherwise the other columns leave the spare room.
fn name_fixed(&self, cx: &App) -> Option<f32> {
self.name_live.or_else(|| {
- let w = cx.global::<crate::settings::Settings>().columns.name_width;
+ let w = self.col_prefs(cx).name_width;
if w > 0 {
Some(f32::from(w))
} else if cx.global::<crate::settings::Settings>().windows_file_explorer_theme {
@@ -5641,7 +5649,7 @@ impl FolderView {
/// repository, sync with cloud files, location in search), then as many as fit the pane
/// in priority order — the name column keeps at least 180 px.
fn visible_cols(&self, cx: &App) -> Cols {
- let c = &cx.global::<crate::settings::Settings>().columns;
+ let c = self.col_prefs(cx);
const PINNED: u32 = 0x80000;
let cloud = c.sync && self.location().path().is_some() && {
match self.cloud_cache.get() {
@@ -5982,7 +5990,7 @@ impl FolderView {
(key, cell.into_any_element())
})
.collect();
- in_col_order(&col_order(&cx.global::<crate::settings::Settings>().columns.order), cells)
+ in_col_order(&col_order(&self.col_prefs(cx).order), cells)
})
.children(self.props_header_cells(p, cx))))
// (the room left over, once the Name column has a width of its own)
@@ -5990,12 +5998,37 @@ impl FolderView {
}
/// A header dropped on another: the dragged column takes that one's place, and the order is kept in Settings.
+ /// The Details columns shown here: the folder's own when it was given some in it (Settings › Layout › the same layout in all
+ /// folders off; issue 755), else those of Settings.
+ pub(crate) fn col_prefs<'a>(&'a self, cx: &'a App) -> &'a crate::settings::ColumnPrefs {
+ self.own_cols.as_ref().unwrap_or(&cx.global::<crate::settings::Settings>().columns)
+ }
+
+ /// Changes the Details columns: with each folder keeping its own layout, those of this folder (from Settings' the first time);
+ /// with one layout everywhere, or where the place is not a folder (a search, a tag), those of Settings.
+ pub(crate) fn update_cols(&mut self, cx: &mut Context<Self>, f: impl FnOnce(&mut crate::settings::ColumnPrefs)) {
+ let own = match self.location() {
+ Location::Path(p) if !cx.global::<crate::settings::Settings>().sync_layout => Some(p.clone()),
+ _ => None,
+ };
+ match own {
+ Some(dir) => {
+ let mut c = self.col_prefs(cx).clone();
+ f(&mut c);
+ crate::layouts::set_columns(&dir, c.clone(), cx);
+ self.own_cols = Some(c);
+ }
+ None => crate::settings::update(cx, |s| f(&mut s.columns)),
+ }
+ cx.notify();
+ }
+
fn move_column(&mut self, from: ColKey, to: ColKey, cx: &mut Context<Self>) {
if from == to {
return;
}
- let order = col_moved(&col_order(&cx.global::<crate::settings::Settings>().columns.order), from, to);
- crate::settings::update(cx, |s| s.columns.order = order.iter().map(|k| k.name().to_string()).collect());
+ let order = col_moved(&col_order(&self.col_prefs(cx).order), from, to);
+ self.update_cols(cx, |c| c.order = order.iter().map(|k| k.name().to_string()).collect());
cx.notify();
}
@@ -6027,7 +6060,7 @@ impl FolderView {
let most = f32::from(self.content_width) - 20. - self.gutter() - 60.;
let w = want.clamp(120., most.max(120.));
self.name_live = None;
- crate::settings::update(cx, |s| s.columns.name_width = w as u16);
+ self.update_cols(cx, |c| c.name_width = w as u16);
cx.notify();
}
@@ -6043,7 +6076,7 @@ impl FolderView {
4..=6 => d.extra_widths[ix - 4],
_ => d.git_widths[(ix - 7).min(3)],
};
- crate::settings::update(cx, |s| Self::store_col_width(&mut s.columns, ix, stock));
+ self.update_cols(cx, |c| Self::store_col_width(c, ix, stock));
cx.notify();
}
@@ -6060,16 +6093,16 @@ impl FolderView {
}
if let Some(n) = v.name_live.take() {
v.col_drag = None;
- crate::settings::update(cx, |s| s.columns.name_width = n.round().clamp(120., 4000.) as u16);
+ v.update_cols(cx, |c| c.name_width = n.round().clamp(120., 4000.) as u16);
}
if let Some(w) = v.col_live.take() {
v.col_drag = None;
// only the columns that were dragged: the live widths of the others are measured ones, and storing them would
// end their being automatic
let dragged = std::mem::take(&mut v.col_dragged);
- crate::settings::update(cx, |s| {
+ v.update_cols(cx, |c| {
for ix in (0..w.len()).filter(|ix| dragged & (1 << ix) != 0) {
- Self::store_col_width(&mut s.columns, ix, auto_cols::kept(ix, w[ix]));
+ Self::store_col_width(c, ix, auto_cols::kept(ix, w[ix]));
}
});
}
@@ -6505,7 +6538,7 @@ impl FolderView {
};
cells.push((ColKey::Size, cell.into_any_element()));
}
- in_col_order(&col_order(&cx.global::<crate::settings::Settings>().columns.order), cells)
+ in_col_order(&col_order(&self.col_prefs(cx).order), cells)
})
.children(prop_cells)))
// (not while a menu is open: the details stood behind the right-click menu, a Discord report)
diff --git a/crates/rf-app/src/folder_view/auto_cols.rs b/crates/rf-app/src/folder_view/auto_cols.rs
index 53bd0635..832730dc 100644
--- a/crates/rf-app/src/folder_view/auto_cols.rs
+++ b/crates/rf-app/src/folder_view/auto_cols.rs
@@ -150,7 +150,7 @@ impl FolderView {
let rem = f32::from(window.rem_size());
let dir = if self.is_search() { None } else { self.location().path().map(|p| p.to_path_buf()) };
let store = &cx.global::<crate::tags::Tags>().0;
- let tagged: Vec<&rf_core::tags::Tagged> = match (&dir, prefs.columns.tags) {
+ let tagged: Vec<&rf_core::tags::Tagged> = match (&dir, self.col_prefs(cx).tags) {
(Some(d), true) => store.tagged_in(d).collect(),
_ => Vec::new(),
};
diff --git a/crates/rf-app/src/folder_view/prop_cols.rs b/crates/rf-app/src/folder_view/prop_cols.rs
index 18245277..9ac387d9 100644
--- a/crates/rf-app/src/folder_view/prop_cols.rs
+++ b/crates/rf-app/src/folder_view/prop_cols.rs
@@ -237,7 +237,7 @@ impl FolderView {
/// The chosen columns (with the widths of a drag in progress); empty, without any allocation, when
/// none is chosen.
fn props_chosen(&self, cx: &App) -> ChosenColumns {
- let s = &cx.global::<crate::settings::Settings>().columns.properties;
+ let s = &self.col_prefs(cx).properties;
if s.is_empty() || !self.props_applicable() {
return ChosenColumns::default();
}
@@ -262,7 +262,7 @@ impl FolderView {
/// Pixels the visible property columns take; the fixed columns share what is left.
pub(super) fn props_used_width(&self, cx: &App) -> f32 {
- if cx.global::<crate::settings::Settings>().columns.properties.is_empty() {
+ if self.col_prefs(cx).properties.is_empty() {
return 0.;
}
self.props_visible(cx).iter().map(|(_, c)| f32::from(c.width)).sum()
@@ -317,10 +317,10 @@ impl FolderView {
if ev.click_count >= 2 {
// a double click gives the column its usual width back
this.props.drag = None;
- crate::settings::update(cx, move |s| {
- let mut c = ChosenColumns::from_setting(&s.columns.properties);
+ this.update_cols(cx, move |cols| {
+ let mut c = ChosenColumns::from_setting(&cols.properties);
c.set_width(ix, pc::DEFAULT_WIDTH);
- s.columns.properties = c.to_setting();
+ cols.properties = c.to_setting();
});
return;
}
@@ -368,15 +368,15 @@ impl FolderView {
}
v.props.drag = None;
if let Some(n) = v.name_live.take() {
- crate::settings::update(cx, |s| s.columns.name_width = n.round().clamp(120., 4000.) as u16);
+ v.update_cols(cx, |c| c.name_width = n.round().clamp(120., 4000.) as u16);
}
if let Some(widths) = v.props.live.take() {
- crate::settings::update(cx, move |s| {
- let mut c = ChosenColumns::from_setting(&s.columns.properties);
+ v.update_cols(cx, move |cols| {
+ let mut c = ChosenColumns::from_setting(&cols.properties);
for (i, w) in widths.iter().enumerate() {
c.set_width(i, *w);
}
- s.columns.properties = c.to_setting();
+ cols.properties = c.to_setting();
});
}
});
@@ -867,29 +867,37 @@ impl FolderView {
/// A right click on the details header: the fixed columns, the chosen properties, "Diğer sütunlar…".
pub(super) fn show_header_menu(&mut self, pos: Point<Pixels>, window: &mut Window, cx: &mut Context<Self>) {
- let c = cx.global::<crate::settings::Settings>().columns.clone();
- let fixed = |label: &str, on: bool, set: fn(&mut crate::settings::Settings)| {
- Item::action(label.to_string(), MenuIcon::None, move |_, cx| crate::settings::update(cx, set)).checked(on)
+ let c = self.col_prefs(cx).clone();
+ // (each change goes to this folder's own columns or to Settings', as the view decides: `update_cols`)
+ let me = cx.entity().downgrade();
+ let fixed = |label: &str, on: bool, set: fn(&mut crate::settings::ColumnPrefs)| {
+ let me = me.clone();
+ Item::action(label.to_string(), MenuIcon::None, move |_, cx| {
+ let _ = me.update(cx, |v, cx| v.update_cols(cx, set));
+ })
+ .checked(on)
};
let mut items = vec![
- fixed(t!("Değiştirme tarihi"), c.modified, |s| s.columns.modified = !s.columns.modified),
- fixed(t!("Oluşturma tarihi"), c.created, |s| s.columns.created = !s.columns.created),
- fixed(t!("Tür"), c.kind, |s| s.columns.kind = !s.columns.kind),
- fixed(t!("Boyut"), c.size, |s| s.columns.size = !s.columns.size),
+ fixed(t!("Değiştirme tarihi"), c.modified, |c| c.modified = !c.modified),
+ fixed(t!("Oluşturma tarihi"), c.created, |c| c.created = !c.created),
+ fixed(t!("Tür"), c.kind, |c| c.kind = !c.kind),
+ fixed(t!("Boyut"), c.size, |c| c.size = !c.size),
];
let chosen = self.props_chosen(cx);
if !chosen.is_empty() {
items.push(Item::Separator);
for col in chosen.iter() {
- let name = col.name.clone();
+ let (name, me) = (col.name.clone(), me.clone());
items.push(
Item::action(label_of(&col.name), MenuIcon::None, move |_, cx| {
let name = name.clone();
- crate::settings::update(cx, move |s| {
- let mut c = ChosenColumns::from_setting(&s.columns.properties);
- c.toggle(&name, pc::DEFAULT_WIDTH);
- s.columns.properties = c.to_setting();
- })
+ let _ = me.update(cx, |v, cx| {
+ v.update_cols(cx, move |cols| {
+ let mut c = ChosenColumns::from_setting(&cols.properties);
+ c.toggle(&name, pc::DEFAULT_WIDTH);
+ cols.properties = c.to_setting();
+ })
+ });
})
.checked(true),
);
@@ -897,8 +905,10 @@ impl FolderView {
}
items.push(Item::Separator);
// (opened after the menu has closed, so the chooser takes the focus the menu gives back)
- items.push(Item::action(t!("Diğer sütunlar…"), MenuIcon::Lucide(L::Columns3), |window, cx| {
- window.defer(cx, crate::prop_chooser::open)
+ let chooser_for = me.clone();
+ items.push(Item::action(t!("Diğer sütunlar…"), MenuIcon::Lucide(L::Columns3), move |window, cx| {
+ let me = chooser_for.clone();
+ window.defer(cx, move |window, cx| crate::prop_chooser::open_for(Some(me), window, cx))
}));
fluent_menu::show(Menu { quick: Vec::new(), items }, pos, window, cx);
}
diff --git a/crates/rf-app/src/folder_view/sort_ext.rs b/crates/rf-app/src/folder_view/sort_ext.rs
index 093a7bd8..19596dd3 100644
--- a/crates/rf-app/src/folder_view/sort_ext.rs
+++ b/crates/rf-app/src/folder_view/sort_ext.rs
@@ -318,7 +318,7 @@ impl FolderView {
/// (the same test `visible_cols` makes, without the width the pane has).
fn sync_column_possible(&self, cx: &App) -> bool {
const PINNED: u32 = sortkeys::ATTR_PINNED;
- if !cx.global::<crate::settings::Settings>().columns.sync || self.location().path().is_none() {
+ if !self.col_prefs(cx).sync || self.location().path().is_none() {
return false;
}
match self.cloud_cache.get() {
diff --git a/crates/rf-app/src/layouts.rs b/crates/rf-app/src/layouts.rs
index 5d22fb32..cca6bbbd 100644
--- a/crates/rf-app/src/layouts.rs
+++ b/crates/rf-app/src/layouts.rs
@@ -164,6 +164,82 @@ pub fn set(path: &Path, layout: FolderLayout, cx: &mut App) {
.detach();
}
+// ------------------------------------------------------------------ a folder's own Details columns
+
+/// The Details columns a folder was given in it (Settings › Layout › "Use the same layout and sorting in all folders" off; issue 755:
+/// "it doesn't matter whether I turn it ON or OFF, the layout still applies to all folders": the columns were one set for every
+/// folder). In a file of their own, `folder-columns.json`, so `layouts.json` stays as older builds read it. A folder without an entry
+/// shows the columns of Settings.
+#[derive(Default)]
+struct FolderColumns {
+ map: HashMap<String, crate::settings::ColumnPrefs>,
+ loaded: bool,
+ dirty_gen: u64,
+}
+impl Global for FolderColumns {}
+
+fn columns_file() -> Option<std::path::PathBuf> {
+ crate::settings::app_dir().map(|d| d.join("folder-columns.json"))
+}
+
+fn columns_store(cx: &mut App) -> &mut FolderColumns {
+ if !cx.has_global::<FolderColumns>() {
+ cx.set_global(FolderColumns::default());
+ }
+ let c = cx.global_mut::<FolderColumns>();
+ if !c.loaded {
+ c.loaded = true;
+ if let Some(text) = columns_file().and_then(|f| std::fs::read_to_string(f).ok()) {
+ c.map = serde_json::from_str(&text).unwrap_or_default();
+ }
+ }
+ c
+}
+
+/// The columns `path` was given in it, if any.
+pub fn columns(path: &Path, cx: &mut App) -> Option<crate::settings::ColumnPrefs> {
+ columns_store(cx).map.get(&key(path)).cloned()
+}
+
+/// Keeps `cols` as `path`'s own columns (written in the background, a burst of changes once).
+pub fn set_columns(path: &Path, cols: crate::settings::ColumnPrefs, cx: &mut App) {
+ let s = columns_store(cx);
+ if s.map.get(&key(path)) == Some(&cols) {
+ return;
+ }
+ if s.map.len() >= MAX {
+ let drop: Vec<String> = s.map.keys().take(MAX / 2).cloned().collect();
+ for k in drop {
+ s.map.remove(&k);
+ }
+ }
+ s.map.insert(key(path), cols);
+ s.dirty_gen += 1;
+ let gen_ = s.dirty_gen;
+ cx.spawn(async move |cx| {
+ cx.background_executor().timer(std::time::Duration::from_millis(800)).await;
+ let _ = cx.update(|cx| {
+ let s = columns_store(cx);
+ if s.dirty_gen != gen_ {
+ return;
+ }
+ let Ok(text) = serde_json::to_string(&s.map) else { return };
+ if let Some(f) = columns_file() {
+ std::thread::spawn(move || {
+ if let Some(d) = f.parent() {
+ let _ = std::fs::create_dir_all(d);
+ }
+ let tmp = f.with_extension("json.tmp");
+ if std::fs::write(&tmp, text).is_ok() {
+ let _ = std::fs::rename(&tmp, &f);
+ }
+ });
+ }
+ });
+ })
+ .detach();
+}
+
#[cfg(test)]
mod tests {
use std::collections::HashMap;
diff --git a/crates/rf-app/src/prop_chooser.rs b/crates/rf-app/src/prop_chooser.rs
index 800d8be9..51f252a4 100644
--- a/crates/rf-app/src/prop_chooser.rs
+++ b/crates/rf-app/src/prop_chooser.rs
@@ -22,13 +22,14 @@ use crate::theme::{self, Palette};
struct Host(Option<(AnyWindowHandle, Entity<ChooserView>, Option<FocusHandle>)>);
impl Global for Host {}
-/// Opens the chooser over the window.
-pub fn open(window: &mut Window, cx: &mut App) {
+/// Opens the chooser over the window for the folder view `target`: what is ticked goes to that view's columns (the folder's own, or Settings',
+/// as the view decides: issue 755). `None`: Settings' columns.
+pub fn open_for(target: Option<WeakEntity<crate::folder_view::FolderView>>, window: &mut Window, cx: &mut App) {
if is_open(window, cx) {
return;
}
let restore = window.focused(cx);
- let view = cx.new(|cx| ChooserView::new(window, cx));
+ let view = cx.new(|cx| ChooserView::new(target, window, cx));
view.read(cx).input.clone().update(cx, |s, cx| s.focus(window, cx));
cx.set_global(Host(Some((window.window_handle(), view, restore))));
window.refresh();
@@ -63,6 +64,8 @@ struct ChooserView {
focus: FocusHandle,
/// A line under the list (the limit was reached).
note: Option<SharedString>,
+ /// The folder view whose columns are chosen (see [`open_for`]).
+ target: Option<WeakEntity<crate::folder_view::FolderView>>,
_sub: Subscription,
}
@@ -77,7 +80,7 @@ fn category_name(c: Option<Category>) -> &'static str {
}
impl ChooserView {
- fn new(window: &mut Window, cx: &mut Context<Self>) -> Self {
+ fn new(target: Option<WeakEntity<crate::folder_view::FolderView>>, window: &mut Window, cx: &mut Context<Self>) -> Self {
let input = cx.new(|cx| InputState::new(window, cx).placeholder(t!("Özellik ara…")));
let sub = cx.subscribe_in(&input, window, |this, _, ev: &InputEvent, _, cx| {
if let InputEvent::Change = ev {
@@ -93,6 +96,7 @@ impl ChooserView {
scroll: UniformListScrollHandle::new(),
focus: cx.focus_handle(),
note: None,
+ target,
_sub: sub,
};
this.refilter(cx);
@@ -124,20 +128,27 @@ impl ChooserView {
let Some(info) = self.all.get(ix) else { return };
let (name, width) = (info.canonical.clone(), info.default_width);
let mut full = false;
- crate::settings::update(cx, |s| {
- let mut c = ChosenColumns::from_setting(&s.columns.properties);
+ let mut change = |cols: &mut crate::settings::ColumnPrefs| {
+ let mut c = ChosenColumns::from_setting(&cols.properties);
let had = c.contains(&name);
c.toggle(&name, width);
full = !had && !c.contains(&name);
- s.columns.properties = c.to_setting();
- });
+ cols.properties = c.to_setting();
+ };
+ match self.target.as_ref().and_then(|t| t.upgrade()) {
+ Some(view) => view.update(cx, |v, cx| v.update_cols(cx, change)),
+ None => crate::settings::update(cx, |s| change(&mut s.columns)),
+ }
self.note = full.then(|| format!("{} {}", t!("Bu kadar özellik sütunu seçilebilir:"), pc::MAX_COLUMNS).into());
cx.notify();
}
fn render_rows(&mut self, range: std::ops::Range<usize>, window: &mut Window, cx: &mut Context<Self>) -> Vec<AnyElement> {
let p = Palette::for_window(window);
- let chosen = ChosenColumns::from_setting(&cx.global::<crate::settings::Settings>().columns.properties);
+ let chosen = match self.target.as_ref().and_then(|t| t.upgrade()) {
+ Some(view) => ChosenColumns::from_setting(&view.read(cx).col_prefs(cx).properties),
+ None => ChosenColumns::from_setting(&cx.global::<crate::settings::Settings>().columns.properties),
+ };
let mut out = Vec::with_capacity(range.len());
for r in range {
let Some(row) = self.rows.get(r).copied() else { break };