HUGE CHANGES TO MODESA
This commit is contained in:
@@ -1,16 +1,16 @@
|
||||
# config.toml
|
||||
[keybindings]
|
||||
|
||||
[keybindings.general]
|
||||
enter_command_mode = [":", "ctrl+;"]
|
||||
|
||||
[keybindings.intro]
|
||||
next_option = ["j", "Right"]
|
||||
previous_option = ["k", "Left"]
|
||||
move_up = ["k", "Up"]
|
||||
move_down = ["j", "Down"]
|
||||
next_option = ["l", "Right"]
|
||||
previous_option = ["h", "Left"]
|
||||
select = ["Enter"]
|
||||
|
||||
[keybindings.admin]
|
||||
move_up = ["k"]
|
||||
move_down = ["j"]
|
||||
toggle_sidebar = ["ctrl+t"]
|
||||
next_field = ["Tab"]
|
||||
prev_field = ["Shift+Tab"]
|
||||
|
||||
[keybindings.common]
|
||||
save = ["ctrl+s"]
|
||||
|
||||
@@ -26,9 +26,7 @@ pub struct Config {
|
||||
#[derive(Debug, Deserialize)]
|
||||
pub struct ModeKeybindings {
|
||||
#[serde(default)]
|
||||
pub intro: HashMap<String, Vec<String>>,
|
||||
#[serde(default)]
|
||||
pub admin: HashMap<String, Vec<String>>,
|
||||
pub general: HashMap<String, Vec<String>>,
|
||||
#[serde(default)]
|
||||
pub read_only: HashMap<String, Vec<String>>,
|
||||
#[serde(default)]
|
||||
@@ -52,20 +50,12 @@ impl Config {
|
||||
Ok(config)
|
||||
}
|
||||
|
||||
/// Gets an action for a key in Intro mode, only checking intro and global bindings
|
||||
pub fn get_intro_action(&self, key: KeyCode, modifiers: KeyModifiers) -> Option<&str> {
|
||||
self.get_action_for_key_in_mode(&self.keybindings.intro, key, modifiers)
|
||||
|
||||
pub fn get_general_action(&self, key: KeyCode, modifiers: KeyModifiers) -> Option<&str> {
|
||||
self.get_action_for_key_in_mode(&self.keybindings.general, key, modifiers)
|
||||
.or_else(|| self.get_action_for_key_in_mode(&self.keybindings.global, key, modifiers))
|
||||
}
|
||||
|
||||
/// Gets an action for a key in Admin mode, checking common and global bindings
|
||||
pub fn get_admin_action(&self, key: KeyCode, modifiers: KeyModifiers) -> Option<&str> {
|
||||
self.get_action_for_key_in_mode(&self.keybindings.admin, key, modifiers)
|
||||
.or_else(|| self.get_action_for_key_in_mode(&self.keybindings.common, key, modifiers))
|
||||
.or_else(|| self.get_action_for_key_in_mode(&self.keybindings.intro, key, modifiers))
|
||||
.or_else(|| self.get_action_for_key_in_mode(&self.keybindings.global, key, modifiers))
|
||||
}
|
||||
|
||||
/// Gets an action for a key in Read-Only mode, also checking common keybindings.
|
||||
pub fn get_read_only_action_for_key(&self, key: KeyCode, modifiers: KeyModifiers) -> Option<&str> {
|
||||
self.get_action_for_key_in_mode(&self.keybindings.read_only, key, modifiers)
|
||||
|
||||
@@ -49,57 +49,86 @@ impl EventHandler {
|
||||
app_state: &mut crate::state::state::AppState,
|
||||
total_count: u64,
|
||||
current_position: &mut u64,
|
||||
intro_state: &mut crate::components::intro::intro::IntroState,
|
||||
) -> Result<(bool, String), Box<dyn std::error::Error>> {
|
||||
if app_state.ui.show_intro {
|
||||
if let Event::Key(key) = event {
|
||||
let action = config.get_intro_action(key.code, key.modifiers);
|
||||
if let Event::Key(key) = event {
|
||||
let key_code = key.code;
|
||||
let modifiers = key.modifiers;
|
||||
|
||||
match action {
|
||||
Some("previous_option") => intro_state.previous_option(),
|
||||
Some("next_option") => intro_state.next_option(),
|
||||
Some("select") => {
|
||||
app_state.ui.show_intro = false;
|
||||
app_state.ui.show_admin = intro_state.selected_option == 1;
|
||||
},
|
||||
_ => {} // Ignore all other keys
|
||||
}
|
||||
}
|
||||
return Ok((false, String::new()));
|
||||
}
|
||||
|
||||
if let Event::Key(key) = event {
|
||||
let key_code = key.code;
|
||||
let modifiers = key.modifiers;
|
||||
|
||||
// Handle admin panel mode
|
||||
if app_state.ui.show_admin {
|
||||
if let Some(action) = config.get_admin_action(key_code, modifiers) {
|
||||
match action {
|
||||
"move_up" => {
|
||||
// Handle up movement using app_state directly
|
||||
app_state.admin_selected_item = app_state.admin_selected_item.saturating_sub(1);
|
||||
}
|
||||
"move_down" => {
|
||||
// Handle down movement using app_state
|
||||
app_state.admin_selected_item = app_state.admin_selected_item.saturating_add(1);
|
||||
}
|
||||
_ => {}
|
||||
// Handle general mode (replaces intro and admin)
|
||||
if app_state.ui.show_general_mode {
|
||||
if let Some(action) = config.get_general_action(key_code, modifiers) {
|
||||
match action {
|
||||
"move_up" => {
|
||||
app_state.general.selected_item = app_state.general.selected_item.saturating_sub(1);
|
||||
return Ok((false, String::new()));
|
||||
}
|
||||
return Ok((false, format!("Admin: {}", action)));
|
||||
"move_down" => {
|
||||
app_state.general.selected_item = app_state.general.selected_item.saturating_add(1);
|
||||
return Ok((false, String::new()));
|
||||
}
|
||||
"next_option" => {
|
||||
app_state.general.current_option = app_state.general.current_option.saturating_add(1);
|
||||
return Ok((false, String::new()));
|
||||
}
|
||||
"previous_option" => {
|
||||
app_state.general.current_option = app_state.general.current_option.saturating_sub(1);
|
||||
return Ok((false, String::new()));
|
||||
}
|
||||
"select" => {
|
||||
// Handle selection based on current view
|
||||
app_state.ui.show_general_mode = false;
|
||||
return Ok((false, "Selected".to_string()));
|
||||
}
|
||||
"toggle_sidebar" => {
|
||||
app_state.ui.show_sidebar = !app_state.ui.show_sidebar;
|
||||
return Ok((false, format!("Sidebar {}",
|
||||
if app_state.ui.show_sidebar { "shown" } else { "hidden" }
|
||||
)));
|
||||
}
|
||||
"next_field" => {
|
||||
// Increment field navigation
|
||||
if form_state.fields.len() > 0 {
|
||||
form_state.current_field = (form_state.current_field + 1) % form_state.fields.len();
|
||||
}
|
||||
return Ok((false, String::new()));
|
||||
}
|
||||
"prev_field" => {
|
||||
// Decrement field navigation
|
||||
if form_state.fields.len() > 0 {
|
||||
form_state.current_field = if form_state.current_field == 0 {
|
||||
form_state.fields.len() - 1
|
||||
} else {
|
||||
form_state.current_field - 1
|
||||
};
|
||||
}
|
||||
return Ok((false, String::new()));
|
||||
}
|
||||
"enter_command_mode" => {
|
||||
self.command_mode = true;
|
||||
self.command_input.clear();
|
||||
self.command_message.clear();
|
||||
return Ok((false, String::new()));
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
return Ok((false, String::new()));
|
||||
}
|
||||
if UiStateHandler::toggle_sidebar(
|
||||
&mut app_state.ui,
|
||||
config,
|
||||
key_code,
|
||||
modifiers,
|
||||
) {
|
||||
return Ok((false, format!("Sidebar {}",
|
||||
if app_state.ui.show_sidebar { "shown" } else { "hidden" }
|
||||
)));
|
||||
}
|
||||
|
||||
// If no general action matched, return to stay in general mode
|
||||
return Ok((false, String::new()));
|
||||
}
|
||||
|
||||
// The rest of the function handles other modes as before
|
||||
// Handle toggling sidebar which is common across modes
|
||||
if UiStateHandler::toggle_sidebar(
|
||||
&mut app_state.ui,
|
||||
config,
|
||||
key_code,
|
||||
modifiers,
|
||||
) {
|
||||
return Ok((false, format!("Sidebar {}",
|
||||
if app_state.ui.show_sidebar { "shown" } else { "hidden" }
|
||||
)));
|
||||
}
|
||||
|
||||
// Handle edit mode first to allow normal character input
|
||||
if self.is_edit_mode {
|
||||
|
||||
@@ -10,6 +10,11 @@ pub struct UiState {
|
||||
pub show_admin: bool,
|
||||
}
|
||||
|
||||
pub struct GeneralState {
|
||||
pub selected_item: usize,
|
||||
pub current_option: usize,
|
||||
}
|
||||
|
||||
pub struct AppState {
|
||||
// Core editor state
|
||||
pub current_dir: String,
|
||||
@@ -17,11 +22,10 @@ pub struct AppState {
|
||||
pub current_position: u64,
|
||||
pub profile_tree: ProfileTreeResponse,
|
||||
pub selected_profile: Option<String>,
|
||||
pub admin_selected_item: usize, // Tracks selection in admin panel
|
||||
pub admin_profiles: Vec<String>, // Stores admin panel data
|
||||
|
||||
// UI preferences
|
||||
pub ui: UiState,
|
||||
pub general: GeneralState,
|
||||
}
|
||||
|
||||
impl AppState {
|
||||
@@ -35,8 +39,6 @@ impl AppState {
|
||||
current_position: 0,
|
||||
profile_tree: ProfileTreeResponse::default(),
|
||||
selected_profile: None,
|
||||
admin_selected_item: 0,
|
||||
admin_profiles: Vec::new(),
|
||||
ui: UiState::default(),
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user