summaryrefslogtreecommitdiffstats
path: root/src/browser
diff options
context:
space:
mode:
authorCanop <cano.petrole@gmail.com>2021-04-05 15:04:47 +0200
committerCanop <cano.petrole@gmail.com>2021-04-05 15:04:47 +0200
commit61911a7c39d44aa0cba70718afeca5084d26a889 (patch)
tree7c59f38b20ed8277996d65e1dc89349ddacf3dc9 /src/browser
parent685836c7a465f992e6a4f2a3f4c2feca23df3403 (diff)
rename some types to bring them closer from their use
The AppState was named this way when there was only one panel. Now it's not the whole app state anymore.
Diffstat (limited to 'src/browser')
-rw-r--r--src/browser/browser_state.rs82
1 files changed, 41 insertions, 41 deletions
diff --git a/src/browser/browser_state.rs b/src/browser/browser_state.rs
index 9dae74c..8dd5311 100644
--- a/src/browser/browser_state.rs
+++ b/src/browser/browser_state.rs
@@ -85,7 +85,7 @@ impl BrowserState {
con: &AppContext,
in_new_panel: bool,
keep_pattern: bool,
- ) -> Result<AppStateCmdResult, ProgramError> {
+ ) -> Result<CmdResult, ProgramError> {
let tree = self.displayed_tree();
let line = tree.selected_line();
let mut target = line.target().to_path_buf();
@@ -98,7 +98,7 @@ impl BrowserState {
}
}
let dam = Dam::unlimited();
- Ok(AppStateCmdResult::from_optional_state(
+ Ok(CmdResult::from_optional_state(
BrowserState::new(
target,
if keep_pattern {
@@ -116,9 +116,9 @@ impl BrowserState {
match open::that(&target) {
Ok(exit_status) => {
info!("open returned with exit_status {:?}", exit_status);
- Ok(AppStateCmdResult::Keep)
+ Ok(CmdResult::Keep)
}
- Err(e) => Ok(AppStateCmdResult::DisplayError(format!("{:?}", e))),
+ Err(e) => Ok(CmdResult::DisplayError(format!("{:?}", e))),
}
}
}
@@ -128,9 +128,9 @@ impl BrowserState {
screen: Screen,
con: &AppContext,
in_new_panel: bool,
- ) -> AppStateCmdResult {
+ ) -> CmdResult {
match &self.displayed_tree().selected_line().path.parent() {
- Some(path) => AppStateCmdResult::from_optional_state(
+ Some(path) => CmdResult::from_optional_state(
BrowserState::new(
path.to_path_buf(),
self.displayed_tree().options.without_pattern(),
@@ -140,13 +140,13 @@ impl BrowserState {
),
in_new_panel,
),
- None => AppStateCmdResult::DisplayError("no parent found".to_string()),
+ None => CmdResult::DisplayError("no parent found".to_string()),
}
}
}
-impl AppState for BrowserState {
+impl PanelState for BrowserState {
fn set_mode(&mut self, mode: Mode) {
debug!("BrowserState::set_mode({:?})", mode);
@@ -190,11 +190,11 @@ impl AppState for BrowserState {
change_options: &dyn Fn(&mut TreeOptions),
in_new_panel: bool,
con: &AppContext,
- ) -> AppStateCmdResult {
+ ) -> CmdResult {
let tree = self.displayed_tree();
let mut options = tree.options.clone();
change_options(&mut options);
- AppStateCmdResult::from_optional_state(
+ CmdResult::from_optional_state(
BrowserState::new(tree.root().clone(), options, screen, con, &Dam::unlimited()),
in_new_panel,
)
@@ -210,9 +210,9 @@ impl AppState for BrowserState {
y: u16,
_screen: Screen,
_con: &AppContext,
- ) -> Result<AppStateCmdResult, ProgramError> {
+ ) -> Result<CmdResult, ProgramError> {
self.displayed_tree_mut().try_select_y(y as i32);
- Ok(AppStateCmdResult::Keep)
+ Ok(CmdResult::Keep)
}
fn on_double_click(
@@ -221,14 +221,14 @@ impl AppState for BrowserState {
y: u16,
screen: Screen,
con: &AppContext,
- ) -> Result<AppStateCmdResult, ProgramError> {
+ ) -> Result<CmdResult, ProgramError> {
if self.displayed_tree().selection == y as usize {
self.open_selection_stay_in_broot(screen, con, false, false)
} else {
// A double click always come after a simple click at
// same position. If it's not the selected line, it means
// the click wasn't on a selectable/openable tree line
- Ok(AppStateCmdResult::Keep)
+ Ok(CmdResult::Keep)
}
}
@@ -236,12 +236,12 @@ impl AppState for BrowserState {
&mut self,
pat: InputPattern,
_con: &AppContext,
- ) -> Result<AppStateCmdResult, ProgramError> {
+ ) -> Result<CmdResult, ProgramError> {
if pat.is_none() {
self.filtered_tree = None;
}
self.pending_pattern = pat;
- Ok(AppStateCmdResult::Keep)
+ Ok(CmdResult::Keep)
}
fn on_internal(
@@ -252,7 +252,7 @@ impl AppState for BrowserState {
trigger_type: TriggerType,
cc: &CmdContext,
screen: Screen,
- ) -> Result<AppStateCmdResult, ProgramError> {
+ ) -> Result<CmdResult, ProgramError> {
let con = &cc.con;
let page_height = BrowserState::page_height(screen);
let bang = input_invocation
@@ -266,12 +266,12 @@ impl AppState for BrowserState {
self.tree.make_selection_visible(page_height);
}
self.filtered_tree = None;
- AppStateCmdResult::Keep
+ CmdResult::Keep
} else if self.tree.selection > 0 {
self.tree.selection = 0;
- AppStateCmdResult::Keep
+ CmdResult::Keep
} else {
- AppStateCmdResult::PopState
+ CmdResult::PopState
}
}
Internal::focus => internal_focus::on_internal(
@@ -291,59 +291,59 @@ impl AppState for BrowserState {
bang,
con,
),
- None => AppStateCmdResult::DisplayError("no parent found".to_string()),
+ None => CmdResult::DisplayError("no parent found".to_string()),
},
Internal::open_stay => self.open_selection_stay_in_broot(screen, con, bang, false)?,
Internal::open_stay_filter => self.open_selection_stay_in_broot(screen, con, bang, true)?,
Internal::line_down => {
let count = get_arg(input_invocation, internal_exec, 1);
self.displayed_tree_mut().move_selection(count, page_height, true);
- AppStateCmdResult::Keep
+ CmdResult::Keep
}
Internal::line_up => {
let count = get_arg(input_invocation, internal_exec, 1);
self.displayed_tree_mut().move_selection(-count, page_height, true);
- AppStateCmdResult::Keep
+ CmdResult::Keep
}
Internal::line_down_no_cycle => {
let count = get_arg(input_invocation, internal_exec, 1);
self.displayed_tree_mut().move_selection(count, page_height, false);
- AppStateCmdResult::Keep
+ CmdResult::Keep
}
Internal::line_up_no_cycle => {
let count = get_arg(input_invocation, internal_exec, 1);
self.displayed_tree_mut().move_selection(-count, page_height, false);
- AppStateCmdResult::Keep
+ CmdResult::Keep
}
Internal::previous_match => {
self.displayed_tree_mut().try_select_previous_match();
- AppStateCmdResult::Keep
+ CmdResult::Keep
}
Internal::next_match => {
self.displayed_tree_mut().try_select_next_match();
- AppStateCmdResult::Keep
+ CmdResult::Keep
}
Internal::previous_same_depth => {
self.displayed_tree_mut().try_select_previous_same_depth();
- AppStateCmdResult::Keep
+ CmdResult::Keep
}
Internal::next_same_depth => {
self.displayed_tree_mut().try_select_next_same_depth();
- AppStateCmdResult::Keep
+ CmdResult::Keep
}
Internal::page_down => {
let tree = self.displayed_tree_mut();
if page_height < tree.lines.len() as i32 {
tree.try_scroll(page_height, page_height);
}
- AppStateCmdResult::Keep
+ CmdResult::Keep
}
Internal::page_up => {
let tree = self.displayed_tree_mut();
if page_height < tree.lines.len() as i32 {
tree.try_scroll(-page_height, page_height);
}
- AppStateCmdResult::Keep
+ CmdResult::Keep
}
Internal::panel_left => {
if cc.areas.is_first() && cc.areas.nb_pos < cc.con.max_panels_count {
@@ -358,7 +358,7 @@ impl AppState for BrowserState {
)
} else {
// we let the app handle other cases
- AppStateCmdResult::HandleInApp(Internal::panel_left)
+ CmdResult::HandleInApp(Internal::panel_left)
}
}
Internal::panel_right => {
@@ -380,7 +380,7 @@ impl AppState for BrowserState {
} else {
// we ask the app to handle other cases :
// focus the panel to the right or close the leftest one
- AppStateCmdResult::HandleInApp(Internal::panel_right)
+ CmdResult::HandleInApp(Internal::panel_right)
}
}
Internal::parent => self.go_to_parent(screen, con, bang),
@@ -397,17 +397,17 @@ impl AppState for BrowserState {
}
Internal::select_first => {
self.displayed_tree_mut().try_select_first();
- AppStateCmdResult::Keep
+ CmdResult::Keep
}
Internal::select_last => {
let page_height = BrowserState::page_height(screen);
self.displayed_tree_mut().try_select_last(page_height);
- AppStateCmdResult::Keep
+ CmdResult::Keep
}
Internal::start_end_panel => {
if cc.panel_purpose.is_arg_edition() {
debug!("start_end understood as end");
- AppStateCmdResult::ClosePanel {
+ CmdResult::ClosePanel {
validate_purpose: true,
panel_ref: PanelReference::Active,
}
@@ -443,21 +443,21 @@ impl AppState for BrowserState {
Internal::total_search => {
if let Some(tree) = &self.filtered_tree {
if tree.total_search {
- AppStateCmdResult::DisplayError(
+ CmdResult::DisplayError(
"search was already total - all children have been rated".to_owned(),
)
} else {
self.pending_pattern = tree.options.pattern.clone();
self.total_search_required = true;
- AppStateCmdResult::Keep
+ CmdResult::Keep
}
} else {
- AppStateCmdResult::DisplayError(
+ CmdResult::DisplayError(
"this verb can be used only after a search".to_owned(),
)
}
}
- Internal::quit => AppStateCmdResult::Quit,
+ Internal::quit => CmdResult::Quit,
_ => self.on_internal_generic(
w,
internal_exec,
@@ -475,7 +475,7 @@ impl AppState for BrowserState {
con: &AppContext,
) -> Status {
let mut ssb = con.standard_status.builder(
- AppStateType::Tree,
+ PanelStateType::Tree,
self.selection(),
);
ssb.has_previous_state = has_previous_state;