admin panel keyindings

This commit is contained in:
filipriec
2025-03-23 11:28:39 +01:00
parent 49fe2aa793
commit 993febd204
4 changed files with 50 additions and 2 deletions

View File

@@ -8,6 +8,10 @@ next_option = ["j", "Right"]
previous_option = ["k", "Left"]
select = ["Enter"]
[keybindings.admin]
move_up = ["k"]
move_down = ["j"]
[keybindings.common]
save = ["ctrl+s"]
quit = ["ctrl+q"]

View File

@@ -28,6 +28,8 @@ pub struct ModeKeybindings {
#[serde(default)]
pub intro: HashMap<String, Vec<String>>,
#[serde(default)]
pub admin: HashMap<String, Vec<String>>,
#[serde(default)]
pub read_only: HashMap<String, Vec<String>>,
#[serde(default)]
pub edit: HashMap<String, Vec<String>>,
@@ -58,9 +60,11 @@ impl Config {
/// 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.common, key, modifiers)
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> {

View File

@@ -48,6 +48,7 @@ impl EventHandler {
total_count: u64,
current_position: &mut u64,
intro_state: &mut crate::components::intro::intro::IntroState,
admin_state: &mut crate::components::admin::admin_panel::AdminPanelState,
) -> Result<(bool, String), Box<dyn std::error::Error>> {
if app_state.ui.show_intro {
if let Event::Key(key) = event {
@@ -70,6 +71,44 @@ impl EventHandler {
let key_code = key.code;
let modifiers = key.modifiers;
// Handle admin panel first if visible
if app_state.ui.show_admin {
if let Some(action) = config.get_admin_action(key_code, modifiers) {
match action {
"move_up" => admin_state.previous(),
"move_down" => admin_state.next(),
"select" => {
// Handle selection logic
},
"quit" => app_state.ui.show_admin = false,
// Handle common actions
"save" => {
let message = common::save(
form_state,
grpc_client,
&mut app_state.ui.is_saved,
current_position,
total_count,
).await?;
return Ok((false, message));
},
"revert" => {
let message = common::revert(
form_state,
grpc_client,
current_position,
total_count,
).await?;
return Ok((false, message));
},
_ => {}
}
return Ok((false, format!("Admin: {}", action)));
}
// Block other keybindings when admin panel is visible
return Ok((false, String::new()));
}
if UiStateHandler::toggle_sidebar(
&mut app_state.ui,
config,

View File

@@ -94,6 +94,7 @@ pub async fn run_ui() -> Result<(), Box<dyn std::error::Error>> {
total_count,
&mut current_position,
&mut intro_state,
&mut admin_panel_state,
).await?;
app_state.current_position = current_position;