NumeRe v1.1.4
NumeRe: Framework für Numerische Rechnungen
toolbarsearchctrl.cpp
Go to the documentation of this file.
1/*****************************************************************************
2 NumeRe: Framework fuer Numerische Rechnungen
3 Copyright (C) 2020 Erik Haenel et al.
4
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17******************************************************************************/
18
19#include "toolbarsearchctrl.hpp"
20#include "../NumeReWindow.h"
21#include "../terminal/terminal.hpp"
22#include "../editor/editor.h"
23
24#include <wx/event.h>
25
36bool ToolBarSearchCtrl::selectItem(const wxString& value)
37{
38 size_t record = searchDB.findRecord(value.ToStdString());
39
40 if (record == std::string::npos)
41 return false;
42
43 std::string sTermInput = searchDB.getElement(record, 3);
44
45 if (sTermInput.substr(0, 5) == "help ")
46 m_mainframe->ShowHelp(sTermInput.substr(5));
47 else
48 {
50 edit->InsertText(edit->GetCurrentPos(), sTermInput);
51 edit->GotoPos(edit->GetCurrentPos()+sTermInput.length());
52 }
53
54 return true;
55}
56
57
69wxString ToolBarSearchCtrl::getDragDropText(const wxString& value)
70{
71 size_t record = searchDB.findRecord(value.ToStdString());
72
73 if (record == std::string::npos)
74 return "";
75
76 wxString text = searchDB.getElement(record, 3);
77
78 if (text.substr(0, 5) == "help ")
79 text.erase(0, text.find_first_not_of(' ', 4));
80
81 if (text.find(" ... ") != std::string::npos)
82 text.Replace(" ... ", "\n\t\n");
83
84 return text;
85}
86
87
97wxArrayString ToolBarSearchCtrl::getCandidates(const wxString& enteredText)
98{
99 wxArrayString candidates;
100
101 // Find the matches in the database
102 std::map<double,std::vector<size_t>> matches = searchDB.findRecordsUsingRelevance(enteredText.ToStdString(), std::vector<double>({3.0, 2.0, 1.0}));
103
104 if (!matches.size())
105 return candidates;
106
107 // Format the results for presenting in the
108 // popup of the search control
109 for (auto iter = matches.rbegin(); iter != matches.rend(); ++iter)
110 {
111 for (size_t i = 0; i < iter->second.size(); i++)
112 candidates.Add(searchDB.getElement(iter->second[i], 0) + "~" + searchDB.getElement(iter->second[i], 1));
113 }
114
115 return candidates;
116}
117
118
std::map< double, std::vector< size_t > > findRecordsUsingRelevance(const std::string &_sSearchString, std::vector< double > vWeighting=std::vector< double >()) const
This member function will search multiple search strings in the database and returns a map,...
Definition: database.cpp:413
std::string getElement(size_t i, size_t j) const
This member function will return the contents of the selected database field, or an empty string,...
Definition: database.cpp:245
size_t findRecord(const std::string &_sRecord) const
This member function finds a selected record in the first column of the database table and returns it...
Definition: database.cpp:341
The class of the editor window.
Definition: editor.h:53
bool ShowHelp(const wxString &sDocId)
This member function displays the help page for the selected documentation ID.
NumeReEditor * GetCurrentEditor()
Public access method for accessing the currently viewed editor. Does only return a pointer to the top...
virtual wxArrayString getCandidates(const wxString &enteredText) override
This method returns an array of strings containing possible candidates for the passed search string.
NumeReWindow * m_mainframe
virtual wxString getDragDropText(const wxString &value) override
This member function provides the text to be inserted, when the user drag-drops one of the results....
virtual bool selectItem(const wxString &value) override
This member function performs the actions necessary, when the user selects an item in the popup list ...
NumeRe::DataBase searchDB