From 96ce9090f84190244b03777610af86e083993e6e Mon Sep 17 00:00:00 2001 From: Federico Terzi Date: Tue, 24 Aug 2021 19:53:16 +0200 Subject: [PATCH] feat(modulo): make search bar hint configurable --- espanso-modulo/src/search/config.rs | 3 +++ espanso-modulo/src/search/generator.rs | 1 + espanso-modulo/src/sys/interop/interop.h | 1 + espanso-modulo/src/sys/interop/mod.rs | 1 + espanso-modulo/src/sys/search/mod.rs | 25 +++++++++++++++++------- espanso-modulo/src/sys/search/search.cpp | 12 +++++++----- 6 files changed, 31 insertions(+), 12 deletions(-) diff --git a/espanso-modulo/src/search/config.rs b/espanso-modulo/src/search/config.rs index c0b8a67..69fc542 100644 --- a/espanso-modulo/src/search/config.rs +++ b/espanso-modulo/src/search/config.rs @@ -48,6 +48,9 @@ pub struct SearchConfig { #[serde(default = "default_algorithm")] pub algorithm: String, + + #[serde(default)] + pub hint: Option, } #[derive(Debug, Serialize, Deserialize, Clone)] diff --git a/espanso-modulo/src/search/generator.rs b/espanso-modulo/src/search/generator.rs index 596a0c8..cc55859 100644 --- a/espanso-modulo/src/search/generator.rs +++ b/espanso-modulo/src/search/generator.rs @@ -36,5 +36,6 @@ pub fn generate(config: SearchConfig) -> types::Search { title: config.title, items, icon: config.icon, + hint: config.hint, } } diff --git a/espanso-modulo/src/sys/interop/interop.h b/espanso-modulo/src/sys/interop/interop.h index d5e1365..ccbeb65 100644 --- a/espanso-modulo/src/sys/interop/interop.h +++ b/espanso-modulo/src/sys/interop/interop.h @@ -87,6 +87,7 @@ typedef struct SearchResults { typedef struct SearchMetadata { const char *windowTitle; const char *iconPath; + const char *hintText; } SearchMetadata; // WIZARD diff --git a/espanso-modulo/src/sys/interop/mod.rs b/espanso-modulo/src/sys/interop/mod.rs index 2ffa0d0..e299c68 100644 --- a/espanso-modulo/src/sys/interop/mod.rs +++ b/espanso-modulo/src/sys/interop/mod.rs @@ -105,6 +105,7 @@ pub struct SearchResults { pub struct SearchMetadata { pub windowTitle: *const ::std::os::raw::c_char, pub iconPath: *const ::std::os::raw::c_char, + pub hintText: *const ::std::os::raw::c_char, } pub const WIZARD_MIGRATE_RESULT_SUCCESS: i32 = 0; diff --git a/espanso-modulo/src/sys/search/mod.rs b/espanso-modulo/src/sys/search/mod.rs index d8c99a6..30b6804 100644 --- a/espanso-modulo/src/sys/search/mod.rs +++ b/espanso-modulo/src/sys/search/mod.rs @@ -33,6 +33,7 @@ pub mod types { pub struct Search { pub title: String, pub icon: Option, + pub hint: Option, pub items: Vec, } } @@ -46,6 +47,7 @@ mod interop { pub(crate) struct OwnedSearch { title: CString, icon_path: CString, + hint: CString, items: Vec, pub(crate) interop_items: Vec, _interop: Box, @@ -80,18 +82,27 @@ mod interop { std::ptr::null() }; + let hint = if let Some(hint) = search.hint.as_ref() { + hint.clone() + } else { + "".to_owned() + }; + + let hint = CString::new(hint).expect("unable to convert search icon to CString"); + + let hint_ptr = if search.hint.is_some() { + hint.as_ptr() + } else { + std::ptr::null() + }; + let _interop = Box::new(SearchMetadata { iconPath: icon_path_ptr, windowTitle: title.as_ptr(), + hintText: hint_ptr, }); - Self { - title, - items, - icon_path, - interop_items, - _interop, - } + Self { title, icon_path, hint, items, interop_items, _interop } } } diff --git a/espanso-modulo/src/sys/search/search.cpp b/espanso-modulo/src/sys/search/search.cpp index 4881ef5..b514e95 100644 --- a/espanso-modulo/src/sys/search/search.cpp +++ b/espanso-modulo/src/sys/search/search.cpp @@ -222,11 +222,13 @@ SearchFrame::SearchFrame(const wxString &title, const wxPoint &pos, const wxSize vbox->Add(topBox, 1, wxEXPAND); - helpText = new wxStaticText(panel, wxID_ANY, "Search matches by content or trigger (or type > to see commands)"); - vbox->Add(helpText, 0, wxEXPAND | wxLEFT | wxRIGHT | wxBOTTOM, 10); - wxFont helpFont = helpText->GetFont(); - helpFont.SetPointSize(HELP_TEXT_FONT_SIZE); - helpText->SetFont(helpFont); + if (searchMetadata->hintText) { + helpText = new wxStaticText(panel, wxID_ANY, wxString::FromUTF8(searchMetadata->hintText)); + vbox->Add(helpText, 0, wxEXPAND | wxLEFT | wxRIGHT | wxBOTTOM, 10); + wxFont helpFont = helpText->GetFont(); + helpFont.SetPointSize(HELP_TEXT_FONT_SIZE); + helpText->SetFont(helpFont); + } wxArrayString choices; int resultId = NewControlId();