Bookmark fixes and cleanups:

- Fix Search field not working on Windows 7 (at least), hope I didn't break all the other platforms
- Memory management is tedious there, with lots of BookmarkEntry* / BookmarkRangeEntry* shared and dangling around
  we cannot reasonably know when to clean up safely. So go nuclear and std::shared_ptr those things.
This commit is contained in:
vsonnier 2017-02-28 18:58:54 +01:00
parent 469fc41805
commit b149da864a
4 changed files with 164 additions and 127 deletions

View File

@ -78,10 +78,10 @@ bool BookmarkMgr::loadFromFile(std::string bookmarkFn, bool backup) {
bool loadStatusOk = true;
// Clear any active data
bmData.erase(bmData.begin(),bmData.end());
recents.erase(recents.begin(),recents.end());
ranges.erase(ranges.begin(),ranges.end());
bmDataSorted.erase(bmDataSorted.begin(),bmDataSorted.end());
bmData.clear();
clearRecents();
clearRanges();
bmDataSorted.clear();
// File exists but is not readable
if (loadFile.FileExists() && !loadFile.IsFileReadable()) {
@ -117,7 +117,7 @@ bool BookmarkMgr::loadFromFile(std::string bookmarkFn, bool backup) {
while (view_ranges->hasAnother("range")) {
DataNode *range = view_ranges->getNext("range");
BookmarkRangeEntry *re = new BookmarkRangeEntry;
BookmarkRangeEntryPtr re(new BookmarkRangeEntry);
if (range->hasAnother("label")) range->getNext("label")->element()->get(re->label);
if (range->hasAnother("freq")) range->getNext("freq")->element()->get(re->freq);
@ -143,7 +143,7 @@ bool BookmarkMgr::loadFromFile(std::string bookmarkFn, bool backup) {
setExpandState(groupName, (expandState == "true"));
while (group->hasAnother("modem")) {
DataNode *modem = group->getNext("modem");
BookmarkEntry *be = nodeToBookmark("modem", modem);
BookmarkEntryPtr be = nodeToBookmark("modem", modem);
if (be) {
addBookmark(groupName.c_str(), be);
} else {
@ -159,7 +159,7 @@ bool BookmarkMgr::loadFromFile(std::string bookmarkFn, bool backup) {
while (recent_modems->hasAnother("modem")) {
DataNode *modem = recent_modems->getNext("modem");
BookmarkEntry *be = nodeToBookmark("modem", modem);
BookmarkEntryPtr be = nodeToBookmark("modem", modem);
if (be) {
addRecent(be);
} else {
@ -202,7 +202,7 @@ bool BookmarkMgr::hasBackup(std::string bookmarkFn) {
void BookmarkMgr::addBookmark(std::string group, DemodulatorInstance *demod) {
std::lock_guard < std::mutex > lock(busy_lock);
BookmarkEntry *be = demodToBookmarkEntry(demod);
BookmarkEntryPtr be = demodToBookmarkEntry(demod);
wxGetApp().getDemodMgr().saveInstance(be->node, demod);
@ -210,7 +210,7 @@ void BookmarkMgr::addBookmark(std::string group, DemodulatorInstance *demod) {
bmDataSorted[group] = false;
}
void BookmarkMgr::addBookmark(std::string group, BookmarkEntry *be) {
void BookmarkMgr::addBookmark(std::string group, BookmarkEntryPtr be) {
std::lock_guard < std::mutex > lock(busy_lock);
bmData[group].push_back(be);
@ -218,7 +218,7 @@ void BookmarkMgr::addBookmark(std::string group, BookmarkEntry *be) {
}
void BookmarkMgr::removeBookmark(std::string group, BookmarkEntry *be) {
void BookmarkMgr::removeBookmark(std::string group, BookmarkEntryPtr be) {
std::lock_guard < std::mutex > lockData(busy_lock);
std::lock_guard < std::mutex > lockEnt(be->busy_lock);
@ -229,12 +229,12 @@ void BookmarkMgr::removeBookmark(std::string group, BookmarkEntry *be) {
BookmarkList::iterator i = std::find(bmData[group].begin(), bmData[group].end(), be);
if (i != bmData[group].end()) {
delete *i;
bmData[group].erase(i);
}
}
void BookmarkMgr::removeBookmark(BookmarkEntry *be) {
void BookmarkMgr::removeBookmark(BookmarkEntryPtr be) {
std::lock_guard < std::mutex > lockData(busy_lock);
std::lock_guard < std::mutex > lockEnt(be->busy_lock);
@ -246,7 +246,7 @@ void BookmarkMgr::removeBookmark(BookmarkEntry *be) {
}
}
void BookmarkMgr::moveBookmark(BookmarkEntry *be, std::string group) {
void BookmarkMgr::moveBookmark(BookmarkEntryPtr be, std::string group) {
std::lock_guard < std::mutex > lockData(busy_lock);
std::lock_guard < std::mutex > lockEnt(be->busy_lock);
@ -280,9 +280,7 @@ void BookmarkMgr::removeGroup(std::string group) {
BookmarkMap::iterator i = bmData.find(group);
if (i != bmData.end()) {
for (auto ii : bmData[group]) {
delete ii;
}
bmData.erase(group);
}
}
@ -383,7 +381,7 @@ void BookmarkMgr::addRecent(DemodulatorInstance *demod) {
trimRecents();
}
void BookmarkMgr::addRecent(BookmarkEntry *be) {
void BookmarkMgr::addRecent(BookmarkEntryPtr be) {
std::lock_guard < std::mutex > lock(busy_lock);
recents.push_back(be);
@ -393,11 +391,11 @@ void BookmarkMgr::addRecent(BookmarkEntry *be) {
void BookmarkMgr::removeRecent(BookmarkEntry *be) {
void BookmarkMgr::removeRecent(BookmarkEntryPtr be) {
std::lock_guard < std::mutex > lock(busy_lock);
BookmarkList::iterator bm_i = std::find(recents.begin(),recents.end(), be);
if (bm_i != recents.end()) {
recents.erase(bm_i);
}
@ -412,20 +410,20 @@ BookmarkList BookmarkMgr::getRecents() {
void BookmarkMgr::clearRecents() {
std::lock_guard < std::mutex > lock(busy_lock);
recents.erase(recents.begin(),recents.end());
recents.clear();
}
void BookmarkMgr::trimRecents() {
if (recents.size() > BOOKMARK_RECENTS_MAX) {
delete *(recents.begin());
recents.erase(recents.begin(), recents.begin()+1);
}
}
void BookmarkMgr::addRange(BookmarkRangeEntry *re) {
void BookmarkMgr::addRange(BookmarkRangeEntryPtr re) {
std::lock_guard < std::mutex > lock(busy_lock);
ranges.push_back(re);
@ -434,12 +432,13 @@ void BookmarkMgr::addRange(BookmarkRangeEntry *re) {
void BookmarkMgr::removeRange(BookmarkRangeEntry *re) {
void BookmarkMgr::removeRange(BookmarkRangeEntryPtr re) {
std::lock_guard < std::mutex > lock(busy_lock);
BookmarkRangeList::iterator re_i = std::find(ranges.begin(), ranges.end(), re);
if (re_i != ranges.end()) {
ranges.erase(re_i);
}
}
@ -459,13 +458,14 @@ BookmarkRangeList BookmarkMgr::getRanges() {
void BookmarkMgr::clearRanges() {
std::lock_guard < std::mutex > lock(busy_lock);
ranges.erase(ranges.begin(),ranges.end());
ranges.clear();
}
BookmarkEntry *BookmarkMgr::demodToBookmarkEntry(DemodulatorInstance *demod) {
BookmarkEntry *be = new BookmarkEntry;
BookmarkEntryPtr BookmarkMgr::demodToBookmarkEntry(DemodulatorInstance *demod) {
BookmarkEntryPtr be(new BookmarkEntry);
be->bandwidth = demod->getBandwidth();
be->type = demod->getDemodulatorType();
@ -478,12 +478,13 @@ BookmarkEntry *BookmarkMgr::demodToBookmarkEntry(DemodulatorInstance *demod) {
return be;
}
BookmarkEntry *BookmarkMgr::nodeToBookmark(const char *name_in, DataNode *node) {
BookmarkEntryPtr BookmarkMgr::nodeToBookmark(const char *name_in, DataNode *node) {
if (!node->hasAnother("frequency") || !node->hasAnother("type") || !node->hasAnother("bandwidth")) {
return nullptr;
}
BookmarkEntry *be = new BookmarkEntry();
BookmarkEntryPtr be(new BookmarkEntry());
node->getNext("frequency")->element()->get(be->frequency);
node->getNext("type")->element()->get(be->type);
node->getNext("bandwidth")->element()->get(be->bandwidth);
@ -500,7 +501,7 @@ BookmarkEntry *BookmarkMgr::nodeToBookmark(const char *name_in, DataNode *node)
}
std::wstring BookmarkMgr::getBookmarkEntryDisplayName(BookmarkEntry *bmEnt) {
std::wstring BookmarkMgr::getBookmarkEntryDisplayName(BookmarkEntryPtr bmEnt) {
std::wstring dispName = bmEnt->label;
if (dispName == "") {

View File

@ -7,6 +7,7 @@
#include <vector>
#include <set>
#include <memory>
#include "DemodulatorInstance.h"
@ -44,26 +45,28 @@ public:
long long endFreq;
};
typedef std::shared_ptr<BookmarkEntry> BookmarkEntryPtr;
typedef std::shared_ptr<BookmarkRangeEntry> BookmarkRangeEntryPtr;
struct BookmarkEntryCompare : public std::binary_function<BookmarkEntry *,BookmarkEntry *,bool>
struct BookmarkEntryCompare : public std::binary_function<BookmarkEntryPtr,BookmarkEntryPtr,bool>
{
bool operator()(const BookmarkEntry *a, BookmarkEntry *b) const
bool operator()(const BookmarkEntryPtr a, BookmarkEntryPtr b) const
{
return a->frequency < b->frequency;
}
};
struct BookmarkRangeEntryCompare : public std::binary_function<BookmarkRangeEntry *,BookmarkRangeEntry *,bool>
struct BookmarkRangeEntryCompare : public std::binary_function<BookmarkRangeEntryPtr ,BookmarkRangeEntryPtr ,bool>
{
bool operator()(const BookmarkRangeEntry *a, BookmarkRangeEntry *b) const
bool operator()(const BookmarkRangeEntryPtr a, BookmarkRangeEntryPtr b) const
{
return a->freq < b->freq;
}
};
typedef std::vector<BookmarkEntry *> BookmarkList;
typedef std::vector<BookmarkRangeEntry *> BookmarkRangeList;
typedef std::vector<BookmarkEntryPtr> BookmarkList;
typedef std::vector<BookmarkRangeEntryPtr> BookmarkRangeList;
typedef std::map<std::string, BookmarkList > BookmarkMap;
typedef std::map<std::string, bool > BookmarkMapSorted;
typedef std::vector<std::string> BookmarkNames;
@ -80,10 +83,10 @@ public:
bool hasBackup(std::string bookmarkFn);
void addBookmark(std::string group, DemodulatorInstance *demod);
void addBookmark(std::string group, BookmarkEntry *be);
void removeBookmark(std::string group, BookmarkEntry *be);
void removeBookmark(BookmarkEntry *be);
void moveBookmark(BookmarkEntry *be, std::string group);
void addBookmark(std::string group, BookmarkEntryPtr be);
void removeBookmark(std::string group, BookmarkEntryPtr be);
void removeBookmark(BookmarkEntryPtr be);
void moveBookmark(BookmarkEntryPtr be, std::string group);
void addGroup(std::string group);
void removeGroup(std::string group);
@ -100,26 +103,26 @@ public:
void updateBookmarks(std::string group);
void addRecent(DemodulatorInstance *demod);
void addRecent(BookmarkEntry *be);
void removeRecent(BookmarkEntry *be);
void addRecent(BookmarkEntryPtr be);
void removeRecent(BookmarkEntryPtr be);
BookmarkList getRecents();
void clearRecents();
void addRange(BookmarkRangeEntry *re);
void removeRange(BookmarkRangeEntry *re);
void addRange(BookmarkRangeEntryPtr re);
void removeRange(BookmarkRangeEntryPtr re);
BookmarkRangeList getRanges();
void clearRanges();
static std::wstring getBookmarkEntryDisplayName(BookmarkEntry *bmEnt);
static std::wstring getBookmarkEntryDisplayName(BookmarkEntryPtr bmEnt);
static std::wstring getActiveDisplayName(DemodulatorInstance *demod);
protected:
void trimRecents();
BookmarkEntry *demodToBookmarkEntry(DemodulatorInstance *demod);
BookmarkEntry *nodeToBookmark(const char *name_in, DataNode *node);
BookmarkEntryPtr demodToBookmarkEntry(DemodulatorInstance *demod);
BookmarkEntryPtr nodeToBookmark(const char *name_in, DataNode *node);
BookmarkMap bmData;
BookmarkMapSorted bmDataSorted;

View File

@ -38,7 +38,7 @@ BookmarkViewVisualDragItem::BookmarkViewVisualDragItem(wxString labelValue) : wx
class ActionDialogRemoveBookmark : public ActionDialog {
public:
ActionDialogRemoveBookmark( BookmarkEntry *be ) : ActionDialog(wxGetApp().getAppFrame(), wxID_ANY, wxT("Remove Bookmark?")) {
ActionDialogRemoveBookmark( BookmarkEntryPtr be ) : ActionDialog(wxGetApp().getAppFrame(), wxID_ANY, wxT("Remove Bookmark?")) {
subject = be;
m_questionText->SetLabelText(wxT("Are you sure you want to remove the bookmark\n '" + BookmarkMgr::getBookmarkEntryDisplayName(subject) + "'?"));
}
@ -49,7 +49,7 @@ public:
}
private:
BookmarkEntry *subject;
BookmarkEntryPtr subject;
};
class ActionDialogRemoveGroup : public ActionDialog {
@ -71,7 +71,7 @@ private:
class ActionDialogRemoveRange : public ActionDialog {
public:
ActionDialogRemoveRange( BookmarkRangeEntry *rangeEnt ) : ActionDialog(wxGetApp().getAppFrame(), wxID_ANY, wxT("Remove Range?")) {
ActionDialogRemoveRange( BookmarkRangeEntryPtr rangeEnt ) : ActionDialog(wxGetApp().getAppFrame(), wxID_ANY, wxT("Remove Range?")) {
subject = rangeEnt;
std::wstring name = rangeEnt->label;
@ -90,13 +90,13 @@ public:
}
private:
BookmarkRangeEntry *subject;
BookmarkRangeEntryPtr subject;
};
class ActionDialogUpdateRange : public ActionDialog {
public:
ActionDialogUpdateRange( BookmarkRangeEntry *rangeEnt ) : ActionDialog(wxGetApp().getAppFrame(), wxID_ANY, wxT("Update Range?")) {
ActionDialogUpdateRange( BookmarkRangeEntryPtr rangeEnt ) : ActionDialog(wxGetApp().getAppFrame(), wxID_ANY, wxT("Update Range?")) {
subject = rangeEnt;
std::wstring name = rangeEnt->label;
@ -110,19 +110,17 @@ public:
}
void doClickOK() {
BookmarkRangeEntry *ue = BookmarkView::makeActiveRangeEntry();
BookmarkRangeEntryPtr ue = BookmarkView::makeActiveRangeEntry();
subject->freq = ue->freq;
subject->startFreq = ue->startFreq;
subject->endFreq = ue->endFreq;
delete ue;
wxGetApp().getBookmarkMgr().updateActiveList();
}
private:
BookmarkRangeEntry *subject;
BookmarkRangeEntryPtr subject;
};
@ -152,11 +150,12 @@ BookmarkView::BookmarkView( wxWindow* parent, wxWindowID id, const wxPoint& pos,
hideProps();
m_updateTimer.Start(500);
mouseInView.store(false);
visualDragItem = nullptr;
nextEnt = nullptr;
nextDemod = nullptr;
mouseTracker.setTarget(this);
}
@ -204,7 +203,6 @@ void BookmarkView::updateTheme() {
m_modulationVal->SetForegroundColour(textColor);
m_modulationLabel->SetForegroundColour(textColor);
refreshLayout();
}
@ -243,17 +241,16 @@ wxTreeItemId BookmarkView::refreshBookmarks() {
BookmarkNames groupNames;
wxGetApp().getBookmarkMgr().getGroups(groupNames);
if (doUpdateBookmarkGroup.size()) { // Nothing for the moment..
doUpdateBookmarkGroup.erase(doUpdateBookmarkGroup.begin(), doUpdateBookmarkGroup.end());
}
doUpdateBookmarkGroup.clear();
wxTreeItemId bmSelFound = nullptr;
std::map<std::string, bool> groupExpandState;
bool searchState = (searchKeywords.size() != 0);
groups.erase(groups.begin(),groups.end());
groups.clear();
m_treeView->DeleteChildren(bookmarkBranch);
bool bmExpandState = expandState["bookmark"];
@ -321,8 +318,6 @@ wxTreeItemId BookmarkView::refreshBookmarks() {
m_treeView->Expand(groupItem);
}
}
return bmSelFound;
}
@ -535,6 +530,7 @@ void BookmarkView::onTreeEndLabelEdit( wxTreeEvent& event ) {
void BookmarkView::onTreeActivate( wxTreeEvent& event ) {
wxTreeItemId itm = event.GetItem();
TreeViewItem* tvi = dynamic_cast<TreeViewItem*>(m_treeView->GetItemData(itm));
@ -643,7 +639,10 @@ bool BookmarkView::isMouseInView() {
if (m_labelText->HasFocus()) {
return true;
}
return mouseInView.load();
if (m_searchText->HasFocus()) {
return true;
}
return mouseTracker.mouseInView();
}
@ -725,7 +724,7 @@ void BookmarkView::doBookmarkActive(std::string group, DemodulatorInstance *demo
}
void BookmarkView::doBookmarkRecent(std::string group, BookmarkEntry *be) {
void BookmarkView::doBookmarkRecent(std::string group, BookmarkEntryPtr be) {
wxGetApp().getBookmarkMgr().removeRecent(be);
wxGetApp().getBookmarkMgr().addBookmark(group, be);
nextEnt = be;
@ -734,7 +733,7 @@ void BookmarkView::doBookmarkRecent(std::string group, BookmarkEntry *be) {
}
void BookmarkView::doMoveBookmark(BookmarkEntry *be, std::string group) {
void BookmarkView::doMoveBookmark(BookmarkEntryPtr be, std::string group) {
wxGetApp().getBookmarkMgr().moveBookmark(be, group);
nextEnt = be;
wxGetApp().getBookmarkMgr().updateBookmarks();
@ -750,7 +749,7 @@ void BookmarkView::doRemoveActive(DemodulatorInstance *demod) {
}
void BookmarkView::doRemoveRecent(BookmarkEntry *be) {
void BookmarkView::doRemoveRecent(BookmarkEntryPtr be) {
wxGetApp().getBookmarkMgr().removeRecent(be);
wxGetApp().getBookmarkMgr().updateActiveList();
}
@ -762,9 +761,9 @@ void BookmarkView::doClearRecents() {
void BookmarkView::updateBookmarkChoices() {
if (!bookmarkChoices.empty()) {
bookmarkChoices.erase(bookmarkChoices.begin(),bookmarkChoices.end());
}
bookmarkChoices.clear();
TreeViewItem *activeSel = itemToTVI(m_treeView->GetSelection());
bookmarkChoices.push_back(((activeSel != nullptr && activeSel->type == TreeViewItem::TREEVIEW_ITEM_TYPE_BOOKMARK))?BOOKMARK_VIEW_CHOICE_MOVE:BOOKMARK_VIEW_CHOICE_DEFAULT);
@ -849,7 +848,7 @@ void BookmarkView::activeSelection(DemodulatorInstance *dsel) {
}
void BookmarkView::activateBookmark(BookmarkEntry *bmEnt) {
void BookmarkView::activateBookmark(BookmarkEntryPtr bmEnt) {
DemodulatorInstance *newDemod = wxGetApp().getDemodMgr().loadInstance(bmEnt->node);
nextDemod = newDemod;
@ -875,13 +874,13 @@ void BookmarkView::activateBookmark(BookmarkEntry *bmEnt) {
}
void BookmarkView::activateRange(BookmarkRangeEntry *rangeEnt) {
void BookmarkView::activateRange(BookmarkRangeEntryPtr rangeEnt) {
wxGetApp().setFrequency(rangeEnt->freq);
wxGetApp().getAppFrame()->setViewState(rangeEnt->startFreq + (rangeEnt->endFreq - rangeEnt->startFreq) / 2, rangeEnt->endFreq - rangeEnt->startFreq);
}
void BookmarkView::bookmarkSelection(BookmarkEntry *bmSel) {
void BookmarkView::bookmarkSelection(BookmarkEntryPtr bmSel) {
m_frequencyVal->SetLabelText(frequencyToStr(bmSel->frequency));
m_bandwidthVal->SetLabelText(frequencyToStr(bmSel->bandwidth));
@ -914,7 +913,7 @@ void BookmarkView::bookmarkSelection(BookmarkEntry *bmSel) {
}
void BookmarkView::recentSelection(BookmarkEntry *bmSel) {
void BookmarkView::recentSelection(BookmarkEntryPtr bmSel) {
m_frequencyVal->SetLabelText(frequencyToStr(bmSel->frequency));
m_bandwidthVal->SetLabelText(frequencyToStr(bmSel->bandwidth));
@ -967,7 +966,7 @@ void BookmarkView::groupSelection(std::string groupName) {
}
void BookmarkView::rangeSelection(BookmarkRangeEntry *re) {
void BookmarkView::rangeSelection(BookmarkRangeEntryPtr re) {
clearButtons();
@ -1126,6 +1125,7 @@ void BookmarkView::onLabelText( wxCommandEvent& /* event */ ) {
void BookmarkView::onDoubleClickFreq( wxMouseEvent& /* event */ ) {
TreeViewItem *curSel = itemToTVI(m_treeView->GetSelection());
if (curSel && curSel->type == TreeViewItem::TREEVIEW_ITEM_TYPE_ACTIVE) {
@ -1259,7 +1259,7 @@ void BookmarkView::onRenameGroup( wxCommandEvent& /* event */ ) {
void BookmarkView::onAddRange( wxCommandEvent& /* event */ ) {
BookmarkRangeEntry *re = BookmarkView::makeActiveRangeEntry();
BookmarkRangeEntryPtr re = BookmarkView::makeActiveRangeEntry();
re->label = m_labelText->GetValue();
@ -1424,16 +1424,25 @@ void BookmarkView::onTreeItemGetTooltip( wxTreeEvent& event ) {
}
void BookmarkView::onEnterWindow( wxMouseEvent& /* event */ ) {
mouseInView.store(true);
void BookmarkView::onEnterWindow( wxMouseEvent& event ) {
mouseTracker.OnMouseEnterWindow(event);
#ifdef _WIN32
if (wxGetApp().getAppFrame()->canFocus()) {
this->SetFocus();
}
#endif
}
void BookmarkView::onLeaveWindow( wxMouseEvent& /* event */ ) {
mouseInView.store(false);
void BookmarkView::onLeaveWindow( wxMouseEvent& event ) {
mouseTracker.OnMouseLeftWindow(event);
}
void BookmarkView::onMotion( wxMouseEvent& event ) {
mouseTracker.OnMouseMoved(event);
wxPoint pos = ClientToScreen(event.GetPosition());
pos += wxPoint(30,-10);
@ -1455,11 +1464,26 @@ TreeViewItem *BookmarkView::itemToTVI(wxTreeItemId item) {
return tvi;
}
void BookmarkView::onSearchTextFocus( wxMouseEvent& /* event */ ) {
if (!m_searchText->IsEmpty()) {
if (m_searchText->GetValue() == L"Search..") {
m_searchText->SetValue(L"");
}
void BookmarkView::onSearchTextFocus( wxMouseEvent& event ) {
mouseTracker.OnMouseMoved(event);
//apparently needed ???
m_searchText->SetFocus();
if (m_searchText->GetValue() == L"Search..") {
//select the whole field, so that typing
//replaces the whole text by the new one right away.
m_searchText->SetSelection(-1, -1);
}
else if (!m_searchText->GetValue().Trim().empty()) {
//position at the end of the existing field, so we can append
//or truncate the existing field.
m_searchText->SetInsertionPointEnd();
}
else {
//empty field, restore displaying L"Search.."
m_searchText->SetValue(L"Search..");
m_searchText->SetSelection(-1, -1);
}
}
@ -1467,11 +1491,9 @@ void BookmarkView::onSearchTextFocus( wxMouseEvent& /* event */ ) {
void BookmarkView::onSearchText( wxCommandEvent& event ) {
wstring searchText = m_searchText->GetValue().Trim().Lower().ToStdWstring();
if (!searchKeywords.empty()) {
searchKeywords.erase(searchKeywords.begin(),searchKeywords.end());
}
searchKeywords.clear();
if (searchText.length() != 0) {
if (searchText.length() != 0) {
std::wstringstream searchTextLo(searchText);
wstring tmp;
@ -1480,7 +1502,6 @@ void BookmarkView::onSearchText( wxCommandEvent& event ) {
searchKeywords.push_back(tmp);
// std::wcout << L"Keyword: " << tmp << '\n';
}
}
}
@ -1501,30 +1522,42 @@ void BookmarkView::onClearSearch( wxCommandEvent& /* event */ ) {
m_clearSearchButton->Hide();
m_searchText->SetValue(L"Search..");
m_treeView->SetFocus();
if (!searchKeywords.empty()) {
searchKeywords.erase(searchKeywords.begin(),searchKeywords.end());
}
searchKeywords.clear();
wxGetApp().getBookmarkMgr().updateActiveList();
wxGetApp().getBookmarkMgr().updateBookmarks();
refreshLayout();
}
void BookmarkView::loadDefaultRanges() {
wxGetApp().getBookmarkMgr().addRange(new BookmarkRangeEntry(L"160 Meters",1900000,1800000,2000000));
wxGetApp().getBookmarkMgr().addRange(new BookmarkRangeEntry(L"80 Meters",3750000,3500000,4000000));
wxGetApp().getBookmarkMgr().addRange(new BookmarkRangeEntry(L"60 Meters",5368500,5332000,5405000));
wxGetApp().getBookmarkMgr().addRange(new BookmarkRangeEntry(L"40 Meters",7150000,7000000,7300000));
wxGetApp().getBookmarkMgr().addRange(new BookmarkRangeEntry(L"30 Meters",10125000,10100000,10150000));
wxGetApp().getBookmarkMgr().addRange(new BookmarkRangeEntry(L"20 Meters",14175000,14000000,14350000));
wxGetApp().getBookmarkMgr().addRange(new BookmarkRangeEntry(L"17 Meters",18068180,17044180,19092180));
wxGetApp().getBookmarkMgr().addRange(new BookmarkRangeEntry(L"15 Meters",21225000,21000000,21450000));
wxGetApp().getBookmarkMgr().addRange(new BookmarkRangeEntry(L"12 Meters",24940000,24890000,24990000));
wxGetApp().getBookmarkMgr().addRange(new BookmarkRangeEntry(L"10 Meters",28850000,28000000,29700000));
BookmarkRangeEntryPtr band_160meters(new BookmarkRangeEntry(L"160 Meters", 1900000, 1800000, 2000000));
BookmarkRangeEntryPtr band_80meters(new BookmarkRangeEntry(L"80 Meters", 3750000, 3500000, 4000000));
BookmarkRangeEntryPtr band_60meters(new BookmarkRangeEntry(L"60 Meters", 5368500, 5332000, 5405000));
BookmarkRangeEntryPtr band_40meters(new BookmarkRangeEntry(L"40 Meters", 7150000, 7000000, 7300000));
BookmarkRangeEntryPtr band_30meters(new BookmarkRangeEntry(L"30 Meters", 10125000, 10100000, 10150000));
BookmarkRangeEntryPtr band_20meters(new BookmarkRangeEntry(L"20 Meters", 14175000, 14000000, 14350000));
BookmarkRangeEntryPtr band_17meters(new BookmarkRangeEntry(L"17 Meters", 18068180, 17044180, 19092180));
BookmarkRangeEntryPtr band_15meters(new BookmarkRangeEntry(L"15 Meters", 21225000, 21000000, 21450000));
BookmarkRangeEntryPtr band_12meters(new BookmarkRangeEntry(L"12 Meters", 24940000, 24890000, 24990000));
BookmarkRangeEntryPtr band_10meters(new BookmarkRangeEntry(L"10 Meters", 28850000, 28000000, 29700000));
wxGetApp().getBookmarkMgr().addRange(band_160meters);
wxGetApp().getBookmarkMgr().addRange(band_80meters);
wxGetApp().getBookmarkMgr().addRange(band_60meters);
wxGetApp().getBookmarkMgr().addRange(band_40meters);
wxGetApp().getBookmarkMgr().addRange(band_30meters);
wxGetApp().getBookmarkMgr().addRange(band_20meters);
wxGetApp().getBookmarkMgr().addRange(band_17meters);
wxGetApp().getBookmarkMgr().addRange(band_15meters);
wxGetApp().getBookmarkMgr().addRange(band_12meters);
wxGetApp().getBookmarkMgr().addRange(band_10meters);
}
BookmarkRangeEntry *BookmarkView::makeActiveRangeEntry() {
BookmarkRangeEntry *re = new BookmarkRangeEntry;
BookmarkRangeEntryPtr BookmarkView::makeActiveRangeEntry() {
BookmarkRangeEntryPtr re(new BookmarkRangeEntry);
re->freq = wxGetApp().getFrequency();
re->startFreq = wxGetApp().getAppFrame()->getViewCenterFreq() - (wxGetApp().getAppFrame()->getViewBandwidth()/2);
re->endFreq = wxGetApp().getAppFrame()->getViewCenterFreq() + (wxGetApp().getAppFrame()->getViewBandwidth()/2);

View File

@ -8,7 +8,7 @@
#include "BookmarkPanel.h"
#include "BookmarkMgr.h"
#include "MouseTracker.h"
class TreeViewItem : public wxTreeItemData {
public:
@ -27,8 +27,8 @@ public:
};
TreeViewItemType type;
BookmarkEntry *bookmarkEnt;
BookmarkRangeEntry *rangeEnt;
BookmarkEntryPtr bookmarkEnt;
BookmarkRangeEntryPtr rangeEnt;
DemodulatorInstance *demod;
std::string groupName;
};
@ -59,15 +59,15 @@ public:
void setExpandState(std::string branchName, bool state);
void loadDefaultRanges();
static BookmarkRangeEntry *makeActiveRangeEntry();
static BookmarkRangeEntryPtr makeActiveRangeEntry();
protected:
void activeSelection(DemodulatorInstance *dsel);
void bookmarkSelection(BookmarkEntry *bmSel);
void rangeSelection(BookmarkRangeEntry *re);
void activateBookmark(BookmarkEntry *bmEnt);
void activateRange(BookmarkRangeEntry *rangeEnt);
void recentSelection(BookmarkEntry *bmSel);
void bookmarkSelection(BookmarkEntryPtr bmSel);
void rangeSelection(BookmarkRangeEntryPtr re);
void activateBookmark(BookmarkEntryPtr bmEnt);
void activateRange(BookmarkRangeEntryPtr rangeEnt);
void recentSelection(BookmarkEntryPtr bmSel);
void groupSelection(std::string groupName);
void bookmarkBranchSelection();
void recentBranchSelection();
@ -111,10 +111,10 @@ protected:
wxButton *addButton(wxWindow *parent, std::string labelVal, wxObjectEventFunction handler);
void doBookmarkActive(std::string group, DemodulatorInstance *demod);
void doBookmarkRecent(std::string group, BookmarkEntry *be);
void doMoveBookmark(BookmarkEntry *be, std::string group);
void doBookmarkRecent(std::string group, BookmarkEntryPtr be);
void doMoveBookmark(BookmarkEntryPtr be, std::string group);
void doRemoveActive(DemodulatorInstance *demod);
void doRemoveRecent(BookmarkEntry *be);
void doRemoveRecent(BookmarkEntryPtr be);
void doClearRecents();
void updateBookmarkChoices();
@ -141,8 +141,8 @@ protected:
TreeViewItem *itemToTVI(wxTreeItemId item);
std::atomic_bool mouseInView;
MouseTracker mouseTracker;
wxTreeItemId rootBranch, activeBranch, bookmarkBranch, recentBranch, rangeBranch;
@ -166,8 +166,8 @@ protected:
std::atomic_bool doUpdateActive;
// Focus
BookmarkEntry *nextEnt;
BookmarkRangeEntry *nextRange;
BookmarkEntryPtr nextEnt;
BookmarkRangeEntryPtr nextRange;
DemodulatorInstance *nextDemod;
// Search