add option to toggle search
This commit is contained in:
parent
1e3446bac3
commit
53cceb499e
3 changed files with 168 additions and 14 deletions
|
@ -175,6 +175,7 @@ The possibilities are endless! Here are some powerful examples of what you can b
|
|||
- Most boolean options now need true or false as argument, as Worf is using the same struct for config and command line arguments and this is the only way to merge both data sources
|
||||
- Removed x,y offset and global coords as GTK4 does not support this anymore, similar results can be achieved with `--location`
|
||||
- Removed copy_exec as we are not executing a binary to copy data into the clipboard
|
||||
- `exec-search` not supported
|
||||
|
||||
#### Removed Command Line Arguments
|
||||
- `mode` → Use `show` instead
|
||||
|
|
|
@ -265,9 +265,6 @@ pub struct Config {
|
|||
#[clap(short = 'P', long = "password")]
|
||||
password: Option<String>,
|
||||
|
||||
#[clap(short = 'e', long = "exec-search")]
|
||||
exec_search: Option<bool>, // todo support this
|
||||
|
||||
/// Defines whether the scrollbar is visible
|
||||
#[clap(short = 'b', long = "hide-scroll")]
|
||||
hide_scroll: Option<bool>,
|
||||
|
@ -307,21 +304,28 @@ pub struct Config {
|
|||
#[clap(long = "lines-size-factor")]
|
||||
lines_size_factor: Option<f64>,
|
||||
|
||||
/// How many columns to display at most in the window
|
||||
/// Shows less and wraps if not enough space is available
|
||||
#[clap(short = 'w', long = "columns")]
|
||||
columns: Option<u32>,
|
||||
|
||||
/// Defines how elements are sorted
|
||||
/// Options:
|
||||
/// * Alphabetical
|
||||
/// * Default (no sort applied)
|
||||
#[clap(short = 'O', long = "sort-order")]
|
||||
sort_order: Option<SortOrder>,
|
||||
|
||||
/// Search for given value at startup
|
||||
#[clap(short = 'Q', long = "search")]
|
||||
search: Option<String>,
|
||||
|
||||
#[clap(short = 'o', long = "monitor")]
|
||||
monitor: Option<String>, // todo support this
|
||||
|
||||
#[clap(short = 'r', long = "pre-display-cmd")]
|
||||
pre_display_cmd: Option<String>, // todo support this
|
||||
// #[clap(short = 'o', long = "monitor")]
|
||||
// monitor: Option<String>, // todo support this
|
||||
|
||||
// #[clap(short = 'r', long = "pre-display-cmd")]
|
||||
// pre_display_cmd: Option<String>, // todo support this
|
||||
/// Defines if window is aligned vertically or horizontally.
|
||||
#[clap(long = "orientation")]
|
||||
orientation: Option<Orientation>,
|
||||
|
||||
|
@ -345,6 +349,15 @@ pub struct Config {
|
|||
#[clap(long = "image-size")]
|
||||
image_size: Option<u16>,
|
||||
|
||||
/// If set to `true` the search field will be hidden.
|
||||
#[clap(long = "hide-search")]
|
||||
hide_search: Option<bool>,
|
||||
|
||||
/// can be set to a button to toggle the search bar.
|
||||
/// default is not set.
|
||||
#[clap(long = "key-hide-search")]
|
||||
key_hide_search: Option<String>,
|
||||
|
||||
// key_up: Option<String>, // todo support this
|
||||
// key_down: Option<String>, // todo support this
|
||||
// key_left: Option<String>, // todo support this
|
||||
|
@ -356,16 +369,12 @@ pub struct Config {
|
|||
// key_pgup: Option<String>, // todo support this
|
||||
// key_pgdn: Option<String>, // todo support this
|
||||
// key_expand: Option<String>, // todo support this
|
||||
// key_hide_search: Option<String>, // todo support this
|
||||
|
||||
// key_copy: Option<String>, // todo support this
|
||||
|
||||
// todo re-add this
|
||||
// #[serde(flatten)]
|
||||
// key_custom: Option<HashMap<String, String>>,
|
||||
/// If set to `true` the search field willOption<> be hidden.
|
||||
#[clap(long = "hide-search")]
|
||||
hide_search: Option<bool>,
|
||||
|
||||
/// If enabled, worf will resize according to the amount of displayed rows
|
||||
/// defaults to false
|
||||
#[clap(long = "dynamic-lines")]
|
||||
|
@ -619,6 +628,11 @@ impl Config {
|
|||
self.hide_search.unwrap_or(false)
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn key_hide_search(&self) -> Option<String> {
|
||||
self.key_hide_search.clone()
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn search(&self) -> Option<String> {
|
||||
self.search.clone()
|
||||
|
|
|
@ -232,6 +232,117 @@ pub enum Key {
|
|||
Tilde, // ~
|
||||
}
|
||||
|
||||
impl From<String> for Key {
|
||||
fn from(value: String) -> Self {
|
||||
match value.as_str() {
|
||||
// Letters
|
||||
"A" | "a" => Key::A,
|
||||
"B" | "b" => Key::B,
|
||||
"C" | "c" => Key::C,
|
||||
"D" | "d" => Key::D,
|
||||
"E" | "e" => Key::E,
|
||||
"F" | "f" => Key::F,
|
||||
"G" | "g" => Key::G,
|
||||
"H" | "h" => Key::H,
|
||||
"I" | "i" => Key::I,
|
||||
"J" | "j" => Key::J,
|
||||
"K" | "k" => Key::K,
|
||||
"L" | "l" => Key::L,
|
||||
"M" | "m" => Key::M,
|
||||
"N" | "n" => Key::N,
|
||||
"O" | "o" => Key::O,
|
||||
"P" | "p" => Key::P,
|
||||
"Q" | "q" => Key::Q,
|
||||
"R" | "r" => Key::R,
|
||||
"S" | "s" => Key::S,
|
||||
"T" | "t" => Key::T,
|
||||
"U" | "u" => Key::U,
|
||||
"V" | "v" => Key::V,
|
||||
"W" | "w" => Key::W,
|
||||
"X" | "x" => Key::X,
|
||||
"Y" | "y" => Key::Y,
|
||||
"Z" | "z" => Key::Z,
|
||||
|
||||
// Numbers
|
||||
"0" => Key::Num0,
|
||||
"1" => Key::Num1,
|
||||
"2" => Key::Num2,
|
||||
"3" => Key::Num3,
|
||||
"4" => Key::Num4,
|
||||
"5" => Key::Num5,
|
||||
"6" => Key::Num6,
|
||||
"7" => Key::Num7,
|
||||
"8" => Key::Num8,
|
||||
"9" => Key::Num9,
|
||||
|
||||
// Function keys
|
||||
"F1" => Key::F1,
|
||||
"F2" => Key::F2,
|
||||
"F3" => Key::F3,
|
||||
"F4" => Key::F4,
|
||||
"F5" => Key::F5,
|
||||
"F6" => Key::F6,
|
||||
"F7" => Key::F7,
|
||||
"F8" => Key::F8,
|
||||
"F9" => Key::F9,
|
||||
"F10" => Key::F10,
|
||||
"F11" => Key::F11,
|
||||
"F12" => Key::F12,
|
||||
|
||||
// Navigation / Editing
|
||||
"Escape" => Key::Escape,
|
||||
"Enter" => Key::Enter,
|
||||
"Space" => Key::Space,
|
||||
"Tab" => Key::Tab,
|
||||
"Backspace" => Key::Backspace,
|
||||
"Insert" => Key::Insert,
|
||||
"Delete" => Key::Delete,
|
||||
"Home" => Key::Home,
|
||||
"End" => Key::End,
|
||||
"PageUp" => Key::PageUp,
|
||||
"PageDown" => Key::PageDown,
|
||||
"Left" => Key::Left,
|
||||
"Right" => Key::Right,
|
||||
"Up" => Key::Up,
|
||||
"Down" => Key::Down,
|
||||
|
||||
// Special characters
|
||||
"!" => Key::Exclamation,
|
||||
"@" => Key::At,
|
||||
"#" => Key::Hash,
|
||||
"$" => Key::Dollar,
|
||||
"%" => Key::Percent,
|
||||
"^" => Key::Caret,
|
||||
"&" => Key::Ampersand,
|
||||
"*" => Key::Asterisk,
|
||||
"(" => Key::LeftParen,
|
||||
")" => Key::RightParen,
|
||||
"-" => Key::Minus,
|
||||
"_" => Key::Underscore,
|
||||
"=" => Key::Equal,
|
||||
"+" => Key::Plus,
|
||||
"[" => Key::LeftBracket,
|
||||
"]" => Key::RightBracket,
|
||||
"{" => Key::LeftBrace,
|
||||
"}" => Key::RightBrace,
|
||||
"\\" => Key::Backslash,
|
||||
"|" => Key::Pipe,
|
||||
";" => Key::Semicolon,
|
||||
":" => Key::Colon,
|
||||
"'" => Key::Apostrophe,
|
||||
"\"" => Key::Quote,
|
||||
"," => Key::Comma,
|
||||
"." => Key::Period,
|
||||
"/" => Key::Slash,
|
||||
"?" => Key::Question,
|
||||
"`" => Key::Grave,
|
||||
"~" => Key::Tilde,
|
||||
|
||||
_ => Key::None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<gtk4::gdk::Key> for Key {
|
||||
fn from(value: gdk4::Key) -> Self {
|
||||
match value {
|
||||
|
@ -1001,6 +1112,24 @@ fn setup_key_event_handler<T: Clone + 'static + Send>(
|
|||
ui.window.add_controller(key_controller);
|
||||
}
|
||||
|
||||
fn is_key_match_from_str_opt(
|
||||
str_key_opt: Option<String>,
|
||||
key_detection_type: &KeyDetectionType,
|
||||
key_code: u32,
|
||||
gdk_key: gdk4::Key,
|
||||
) -> bool {
|
||||
if let Some(str_key) = str_key_opt {
|
||||
let key: Key = str_key.into();
|
||||
if key_detection_type == &KeyDetectionType::Code {
|
||||
key == key_code.into()
|
||||
} else {
|
||||
key == gdk_key.to_upper().into()
|
||||
}
|
||||
} else {
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(clippy::too_many_lines)] // todo fix this.
|
||||
fn handle_key_press<T: Clone + 'static + Send>(
|
||||
ui: &Rc<UiElements<T>>,
|
||||
|
@ -1039,10 +1168,11 @@ fn handle_key_press<T: Clone + 'static + Send>(
|
|||
|
||||
log::debug!("received key. code: {key_code}, key: {keyboard_key:?}");
|
||||
|
||||
let detection_type = meta.config.key_detection_type();
|
||||
if let Some(custom_keys) = custom_keys {
|
||||
let mods = modifiers_from_mask(modifier_type);
|
||||
for custom_key in &custom_keys.bindings {
|
||||
let custom_key_match = if meta.config.key_detection_type() == KeyDetectionType::Code {
|
||||
let custom_key_match = if detection_type == KeyDetectionType::Code {
|
||||
custom_key.key == key_code.into()
|
||||
} else {
|
||||
custom_key.key == keyboard_key.to_upper().into()
|
||||
|
@ -1066,6 +1196,15 @@ fn handle_key_press<T: Clone + 'static + Send>(
|
|||
}
|
||||
}
|
||||
|
||||
if is_key_match_from_str_opt(
|
||||
meta.config.key_hide_search(),
|
||||
&detection_type,
|
||||
key_code,
|
||||
keyboard_key,
|
||||
) {
|
||||
ui.search.set_visible(!ui.search.is_visible());
|
||||
}
|
||||
|
||||
match keyboard_key {
|
||||
gdk4::Key::Escape => {
|
||||
if let Err(e) = meta.selected_sender.send(Err(Error::NoSelection)) {
|
||||
|
|
Loading…
Add table
Reference in a new issue