summaryrefslogtreecommitdiffstats
path: root/src/commands
diff options
context:
space:
mode:
authorDLFW <daniel@llin.info>2022-08-14 02:04:38 +0200
committerGitHub <noreply@github.com>2022-08-13 20:04:38 -0400
commit6356efaa55830c4ef8ed976a6e89f738ab6e026d (patch)
tree9f6dde209a7c1e085764538edc2d1679bb50ca80 /src/commands
parentd2ef6d44cc09ad3e57642d5839d972d426bfff12 (diff)
Sort options individual per tab (#191)
Sort options (sort criterion, reversion, dir-first, and case-sensitivity) are specific for each tab. Changing sort-options will not have any affect on tabs other than the currently active one. Each new tab will start with the default sort-options.
Diffstat (limited to 'src/commands')
-rw-r--r--src/commands/change_directory.rs7
-rw-r--r--src/commands/delete_files.rs14
-rw-r--r--src/commands/flat.rs8
-rw-r--r--src/commands/new_directory.rs8
-rw-r--r--src/commands/reload.rs16
-rw-r--r--src/commands/rename_file.rs15
-rw-r--r--src/commands/sort.rs19
-rw-r--r--src/commands/tab_ops.rs14
-rw-r--r--src/commands/touch_file.rs14
9 files changed, 82 insertions, 33 deletions
diff --git a/src/commands/change_directory.rs b/src/commands/change_directory.rs
index ad6db26..bc88afb 100644
--- a/src/commands/change_directory.rs
+++ b/src/commands/change_directory.rs
@@ -24,11 +24,16 @@ pub fn change_directory(context: &mut AppContext, path: &path::Path) -> JoshutoR
cd(new_cwd.as_path(), context)?;
let options = context.config_ref().display_options_ref().clone();
let ui_context = context.ui_context_ref().clone();
+ let tab_options = context
+ .tab_context_ref()
+ .curr_tab_ref()
+ .option_ref()
+ .clone();
context
.tab_context_mut()
.curr_tab_mut()
.history_mut()
- .populate_to_root(new_cwd.as_path(), &ui_context, &options)?;
+ .populate_to_root(new_cwd.as_path(), &ui_context, &options, &tab_options)?;
Ok(())
}
diff --git a/src/commands/delete_files.rs b/src/commands/delete_files.rs
index 35a2dfd..59d2b5c 100644
--- a/src/commands/delete_files.rs
+++ b/src/commands/delete_files.rs
@@ -77,10 +77,13 @@ fn _delete_selected_files(
) -> std::io::Result<()> {
delete_files(context, backend, false)?;
+ let curr_tab = context.tab_context_ref().curr_tab_ref();
let options = context.config_ref().display_options_ref().clone();
- let curr_path = context.tab_context_ref().curr_tab_ref().cwd().to_path_buf();
+ let curr_path = curr_tab.cwd().to_path_buf();
+ let tab_option = curr_tab.option_ref().clone();
for tab in context.tab_context_mut().iter_mut() {
- tab.history_mut().reload(&curr_path, &options)?;
+ tab.history_mut()
+ .reload(&curr_path, &options, &tab_option)?;
}
Ok(())
}
@@ -96,10 +99,13 @@ fn _delete_selected_files_background(
) -> std::io::Result<()> {
delete_files(context, backend, true)?;
+ let curr_tab = context.tab_context_ref().curr_tab_ref();
let options = context.config_ref().display_options_ref().clone();
- let curr_path = context.tab_context_ref().curr_tab_ref().cwd().to_path_buf();
+ let curr_path = curr_tab.cwd().to_path_buf();
+ let tab_option = curr_tab.option_ref().clone();
for tab in context.tab_context_mut().iter_mut() {
- tab.history_mut().reload(&curr_path, &options)?;
+ tab.history_mut()
+ .reload(&curr_path, &options, &tab_option)?;
}
Ok(())
}
diff --git a/src/commands/flat.rs b/src/commands/flat.rs
index 632b321..c0e9dfb 100644
--- a/src/commands/flat.rs
+++ b/src/commands/flat.rs
@@ -48,6 +48,11 @@ pub fn flatten(depth: usize, context: &mut AppContext) -> JoshutoResult {
let path = context.tab_context_ref().curr_tab_ref().cwd().to_path_buf();
let options = context.config_ref().display_options_ref().clone();
+ let tab_options = context
+ .tab_context_ref()
+ .curr_tab_ref()
+ .option_ref()
+ .clone();
let mut index: Option<usize> = context
.tab_context_ref()
@@ -69,7 +74,8 @@ pub fn flatten(depth: usize, context: &mut AppContext) -> JoshutoResult {
index = None;
}
- let sort_options = options.sort_options_ref();
+ let sort_options = tab_options.sort_options_ref();
+
contents.sort_by(|f1, f2| sort_options.compare(f1, f2));
let metadata = JoshutoMetadata::from(path.as_path())?;
diff --git a/src/commands/new_directory.rs b/src/commands/new_directory.rs
index 1f56521..482c84e 100644
--- a/src/commands/new_directory.rs
+++ b/src/commands/new_directory.rs
@@ -7,9 +7,15 @@ use crate::history::DirectoryHistory;
pub fn new_directory(context: &mut AppContext, p: &path::Path) -> JoshutoResult {
std::fs::create_dir_all(p)?;
let options = context.config_ref().display_options_ref().clone();
+ let tab_options = context
+ .tab_context_ref()
+ .curr_tab_ref()
+ .option_ref()
+ .clone();
let curr_path = context.tab_context_ref().curr_tab_ref().cwd().to_path_buf();
for tab in context.tab_context_mut().iter_mut() {
- tab.history_mut().reload(&curr_path, &options)?;
+ tab.history_mut()
+ .reload(&curr_path, &options, &tab_options)?;
}
Ok(())
}
diff --git a/src/commands/reload.rs b/src/commands/reload.rs
index f9d423b..fa12565 100644
--- a/src/commands/reload.rs
+++ b/src/commands/reload.rs
@@ -25,13 +25,19 @@ pub fn soft_reload(index: usize, context: &mut AppContext) -> std::io::Result<()
if !paths.is_empty() {
let options = context.config_ref().display_options_ref().clone();
+ let tab_options = context
+ .tab_context_ref()
+ .curr_tab_ref()
+ .option_ref()
+ .clone();
if let Some(history) = context
.tab_context_mut()
.tab_mut(index)
.map(|t| t.history_mut())
{
for path in paths {
- let new_dirlist = create_dirlist_with_history(history, path.as_path(), &options)?;
+ let new_dirlist =
+ create_dirlist_with_history(history, path.as_path(), &options, &tab_options)?;
history.insert(path, new_dirlist);
}
}
@@ -55,13 +61,19 @@ pub fn reload(context: &mut AppContext, index: usize) -> std::io::Result<()> {
if !paths.is_empty() {
let options = context.config_ref().display_options_ref().clone();
+ let tab_options = context
+ .tab_context_ref()
+ .curr_tab_ref()
+ .option_ref()
+ .clone();
if let Some(history) = context
.tab_context_mut()
.tab_mut(index)
.map(|t| t.history_mut())
{
for path in paths {
- let new_dirlist = create_dirlist_with_history(history, path.as_path(), &options)?;
+ let new_dirlist =
+ create_dirlist_with_history(history, path.as_path(), &options, &tab_options)?;
history.insert(path, new_dirlist);
}
}
diff --git a/src/commands/rename_file.rs b/src/commands/rename_file.rs
index cce7ab1..38fb62d 100644
--- a/src/commands/rename_file.rs
+++ b/src/commands/rename_file.rs
@@ -20,17 +20,22 @@ pub fn _rename_file(
}
std::fs::rename(&src, &dest)?;
- let path = context
- .tab_context_ref()
- .curr_tab_ref()
+ let curr_tab = context.tab_context_ref().curr_tab_ref();
+
+ let path = curr_tab
.curr_list_ref()
.map(|lst| lst.file_path().to_path_buf());
if let Some(path) = path {
let options = context.config_ref().display_options_ref().clone();
-
+ let tab_options = context
+ .tab_context_ref()
+ .curr_tab_ref()
+ .option_ref()
+ .clone();
let history = context.tab_context_mut().curr_tab_mut().history_mut();
- let new_dirlist = create_dirlist_with_history(history, path.as_path(), &options)?;
+ let new_dirlist =
+ create_dirlist_with_history(history, path.as_path(), &options, &tab_options)?;
history.insert(path, new_dirlist);
}
Ok(())
diff --git a/src/commands/sort.rs b/src/commands/sort.rs
index ace9daf..51be534 100644
--- a/src/commands/sort.rs
+++ b/src/commands/sort.rs
@@ -6,23 +6,20 @@ use crate::history::DirectoryHistory;
use super::reload;
pub fn set_sort(context: &mut AppContext, method: SortType) -> JoshutoResult {
- context
- .config_mut()
+ let curr_tab = context.tab_context_mut().curr_tab_mut();
+ curr_tab
+ .option_mut()
.sort_options_mut()
.set_sort_method(method);
- for tab in context.tab_context_mut().iter_mut() {
- tab.history_mut().depreciate_all_entries();
- }
+ curr_tab.history_mut().depreciate_all_entries();
refresh(context)
}
pub fn toggle_reverse(context: &mut AppContext) -> JoshutoResult {
- let reversed = !context.config_ref().sort_options_ref().reverse;
- context.config_mut().sort_options_mut().reverse = reversed;
-
- for tab in context.tab_context_mut().iter_mut() {
- tab.history_mut().depreciate_all_entries();
- }
+ let curr_tab = context.tab_context_mut().curr_tab_mut();
+ let reversed = !curr_tab.option_mut().sort_options_ref().reverse;
+ curr_tab.option_mut().sort_options_mut().reverse = reversed;
+ curr_tab.history_mut().depreciate_all_entries();
refresh(context)
}
diff --git a/src/commands/tab_ops.rs b/src/commands/tab_ops.rs
index 32bfeb1..2a7f7fb 100644
--- a/src/commands/tab_ops.rs
+++ b/src/commands/tab_ops.rs
@@ -32,23 +32,31 @@ fn _tab_switch(new_index: usize, context: &mut AppContext) -> std::io::Result<()
};
let options = context.config_ref().display_options_ref().clone();
+ let tab_options = context
+ .tab_context_ref()
+ .curr_tab_ref()
+ .option_ref()
+ .clone();
let history = context.tab_context_mut().curr_tab_mut().history_mut();
if history
- .create_or_soft_update(cwd.as_path(), &options)
+ .create_or_soft_update(cwd.as_path(), &options, &tab_options)
.is_err()
{
history.remove(cwd.as_path());
}
if let Some(cwd_parent) = cwd.parent() {
- if history.create_or_soft_update(cwd_parent, &options).is_err() {
+ if history
+ .create_or_soft_update(cwd_parent, &options, &tab_options)
+ .is_err()
+ {
history.remove(cwd_parent);
}
}
if let Some(file_path) = entry_path {
if history
- .create_or_soft_update(file_path.as_path(), &options)
+ .create_or_soft_update(file_path.as_path(), &options, &tab_options)
.is_err()
{
history.remove(file_path.as_path());
diff --git a/src/commands/touch_file.rs b/src/commands/touch_file.rs
index 19728db..e3b3a59 100644
--- a/src/commands/touch_file.rs
+++ b/src/commands/touch_file.rs
@@ -19,6 +19,7 @@ fn _create_file(file: &path::Path) -> std::io::Result<()> {
}
pub fn touch_file(context: &mut AppContext, arg: &str) -> JoshutoResult {
+ let curr_tab = context.tab_context_ref().curr_tab_ref();
match arg {
"" => {
if let Some(selected_file_path) = context
@@ -41,17 +42,20 @@ pub fn touch_file(context: &mut AppContext, arg: &str) -> JoshutoResult {
}
}
- let path = context
- .tab_context_ref()
- .curr_tab_ref()
+ let path = curr_tab
.curr_list_ref()
.map(|lst| lst.file_path().to_path_buf());
if let Some(path) = path {
let options = context.config_ref().display_options_ref().clone();
-
+ let tab_options = context
+ .tab_context_ref()
+ .curr_tab_ref()
+ .option_ref()
+ .clone();
let history = context.tab_context_mut().curr_tab_mut().history_mut();
- let new_dirlist = create_dirlist_with_history(history, path.as_path(), &options)?;
+ let new_dirlist =
+ create_dirlist_with_history(history, path.as_path(), &options, &tab_options)?;
history.insert(path, new_dirlist);
}
Ok(())