feat(modulo): make search bar hint configurable

This commit is contained in:
Federico Terzi 2021-08-24 19:53:16 +02:00
parent eb7474763b
commit 96ce9090f8
6 changed files with 31 additions and 12 deletions

View File

@ -48,6 +48,9 @@ pub struct SearchConfig {
#[serde(default = "default_algorithm")]
pub algorithm: String,
#[serde(default)]
pub hint: Option<String>,
}
#[derive(Debug, Serialize, Deserialize, Clone)]

View File

@ -36,5 +36,6 @@ pub fn generate(config: SearchConfig) -> types::Search {
title: config.title,
items,
icon: config.icon,
hint: config.hint,
}
}

View File

@ -87,6 +87,7 @@ typedef struct SearchResults {
typedef struct SearchMetadata {
const char *windowTitle;
const char *iconPath;
const char *hintText;
} SearchMetadata;
// WIZARD

View File

@ -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;

View File

@ -33,6 +33,7 @@ pub mod types {
pub struct Search {
pub title: String,
pub icon: Option<String>,
pub hint: Option<String>,
pub items: Vec<SearchItem>,
}
}
@ -46,6 +47,7 @@ mod interop {
pub(crate) struct OwnedSearch {
title: CString,
icon_path: CString,
hint: CString,
items: Vec<OwnedSearchItem>,
pub(crate) interop_items: Vec<SearchItem>,
_interop: Box<SearchMetadata>,
@ -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 }
}
}

View File

@ -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();