143{
145
147
148 bool full_list =
search.empty();
149 wxString sep =
L" : ";
150
151 auto get_label = [this, &sep](const Option &opt, bool marked = true) {
152 std::wstring out;
154 const std::wstring *prev = nullptr;
155 for (
const std::wstring *
const s : {
view_params.category || opt.multi_category ? &opt.category_local :
nullptr, &opt.group_local, &opt.label_local})
156 if (s != nullptr && (prev == nullptr || *prev != *s)) {
157 if (out.size() > 2) out += sep;
158 out += *s;
159 prev = s;
160 }
161 return out;
162 };
163
164 auto get_label_english = [this, &sep](const Option &opt, bool marked = true) {
165 std::wstring out;
167 const std::wstring *prev = nullptr;
168 for (
const std::wstring *
const s : {
view_params.category || opt.multi_category ? &opt.category :
nullptr, &opt.group, &opt.label})
169 if (s != nullptr && (prev == nullptr || *prev != *s)) {
170 if (out.size() > 2) out += sep;
171 out += *s;
172 prev = s;
173 }
174 return out;
175 };
176
177 auto get_tooltip = [this, &sep](const Option &opt) {
179 };
180
181 std::vector<uint16_t> matches, matches2;
182 const std::vector<Option> &options =
m_index.options();
183 for (size_t i = 0; i < options.size(); i++) {
184 const Option &opt = options[i];
185 if (full_list) {
186 std::string label =
into_u8(get_label(opt));
187
189 found.emplace_back(FoundOption{label, label,
into_u8(get_tooltip(opt)), i, 0});
190 } else if (type == opt.type){
191 found.emplace_back(FoundOption{label, label,
into_u8(get_tooltip(opt)), i, 0});
192 }
193
194 continue;
195 }
196
197 std::wstring wsearch = boost::nowide::widen(
search);
198 boost::trim_left(wsearch);
199 std::wstring label = get_label(opt, false);
200 std::wstring label_english = get_label_english(opt, false);
201 int score = std::numeric_limits<int>::min();
202 int score2;
203 matches.clear();
205
206
207
208
209
210
211
213 label = std::move(label_english);
214 matches = std::move(matches2);
215 score = score2;
216 }
217 if (score > 90 ) {
219
220 std::string label_u8 =
into_u8(label);
221 std::string label_plain = label_u8;
222
223#ifdef SUPPORTS_MARKUP
224 boost::replace_all(label_plain, std::string(1, char(ImGui::ColorMarkerStart)), "<b>");
225 boost::replace_all(label_plain, std::string(1, char(ImGui::ColorMarkerEnd)), "</b>");
226#else
227 boost::erase_all(label_plain, std::string(1, char(ImGui::ColorMarkerStart)));
228 boost::erase_all(label_plain, std::string(1, char(ImGui::ColorMarkerEnd)));
229#endif
230
232 found.emplace_back(FoundOption{label_plain, label_u8,
into_u8(get_tooltip(opt)), i, score});
233 } else if (type == opt.type) {
234 found.emplace_back(FoundOption{label_plain, label_u8,
into_u8(get_tooltip(opt)), i, score});
235 }
236
237 }
238 }
239
241
244
245 return true;
246}
#define L(s)
Definition ExtrusionEntity.cpp:25
@ TYPE_INVALID
Definition Preset.hpp:245
void sort_found()
Definition Search.hpp:81
OptionViewParameters view_params
Definition Search.hpp:90
PrinterTechnology printer_technology
Definition Search.hpp:78
static char marker_by_type(Preset::Type type, PrinterTechnology pt)
Definition Search.cpp:79
static bool fuzzy_match(const std::wstring &search_pattern, const std::wstring &label, int &out_score, std::vector< uint16_t > &out_matches)
Definition Search.cpp:127
static std::wstring mark_string(const std::wstring &str, const std::vector< uint16_t > &matches, Preset::Type type, PrinterTechnology pt)
Definition Search.cpp:98
std::string into_u8(const wxString &str)
Definition GUI.cpp:549