Bookmarks (cont...) : more understanding, more comments, more fixes. NOW memory management should be clean...

This commit is contained in:
vsonnier 2017-03-04 11:22:29 +01:00
parent 7bab9588e1
commit 925203b4a5
2 changed files with 58 additions and 21 deletions

View File

@ -247,8 +247,15 @@ bool BookmarkView::isKeywordMatch(std::wstring search_str, std::vector<std::wstr
wxTreeItemId BookmarkView::refreshBookmarks() { wxTreeItemId BookmarkView::refreshBookmarks() {
TreeViewItem *prevSel = itemToTVI(m_treeView->GetSelection()); //capture the previously selected item info BY COPY (because the original will be destroyed together with the destroyed tree items) to restore it again after
//having rebuilding the whole tree.
TreeViewItem* prevSel = itemToTVI(m_treeView->GetSelection());
TreeViewItem* prevSelCopy = nullptr;
if (prevSel != NULL) {
prevSelCopy = new TreeViewItem(*prevSel);
}
BookmarkNames groupNames; BookmarkNames groupNames;
wxGetApp().getBookmarkMgr().getGroups(groupNames); wxGetApp().getBookmarkMgr().getGroups(groupNames);
@ -272,7 +279,7 @@ wxTreeItemId BookmarkView::refreshBookmarks() {
wxTreeItemId group_itm = m_treeView->AppendItem(bookmarkBranch, gn_i); wxTreeItemId group_itm = m_treeView->AppendItem(bookmarkBranch, gn_i);
SetTreeItemData(group_itm, tvi); SetTreeItemData(group_itm, tvi);
groups[gn_i] = group_itm; groups[gn_i] = group_itm;
if (prevSel != nullptr && prevSel->type == TreeViewItem::TREEVIEW_ITEM_TYPE_GROUP && gn_i == prevSel->groupName) { if (prevSelCopy != nullptr && prevSelCopy->type == TreeViewItem::TREEVIEW_ITEM_TYPE_GROUP && gn_i == prevSelCopy->groupName) {
bmSelFound = group_itm; bmSelFound = group_itm;
} }
} }
@ -315,7 +322,7 @@ wxTreeItemId BookmarkView::refreshBookmarks() {
wxTreeItemId itm = m_treeView->AppendItem(groupItem, labelVal); wxTreeItemId itm = m_treeView->AppendItem(groupItem, labelVal);
SetTreeItemData(itm, tvi); SetTreeItemData(itm, tvi);
if (prevSel != nullptr && prevSel->type == TreeViewItem::TREEVIEW_ITEM_TYPE_BOOKMARK && prevSel->bookmarkEnt == bmEnt && groupExpanded) { if (prevSelCopy != nullptr && prevSelCopy->type == TreeViewItem::TREEVIEW_ITEM_TYPE_BOOKMARK && prevSelCopy->bookmarkEnt == bmEnt && groupExpanded) {
bmSelFound = itm; bmSelFound = itm;
} }
if (nextEnt == bmEnt) { if (nextEnt == bmEnt) {
@ -328,6 +335,9 @@ wxTreeItemId BookmarkView::refreshBookmarks() {
m_treeView->Expand(groupItem); m_treeView->Expand(groupItem);
} }
} }
delete prevSelCopy;
return bmSelFound; return bmSelFound;
} }
@ -338,7 +348,14 @@ void BookmarkView::doUpdateActiveList() {
// DemodulatorInstance *activeDemodulator = wxGetApp().getDemodMgr().getActiveDemodulator(); // DemodulatorInstance *activeDemodulator = wxGetApp().getDemodMgr().getActiveDemodulator();
DemodulatorInstance *lastActiveDemodulator = wxGetApp().getDemodMgr().getLastActiveDemodulator(); DemodulatorInstance *lastActiveDemodulator = wxGetApp().getDemodMgr().getLastActiveDemodulator();
TreeViewItem *prevSel = itemToTVI(m_treeView->GetSelection()); //capture the previously selected item info BY COPY (because the original will be destroyed together with the destroyed tree items) to restore it again after
//having rebuilding the whole tree.
TreeViewItem* prevSel = itemToTVI(m_treeView->GetSelection());
TreeViewItem* prevSelCopy = nullptr;
if (prevSel != NULL) {
prevSelCopy = new TreeViewItem(*prevSel);
}
// Actives // Actives
m_treeView->DeleteChildren(activeBranch); m_treeView->DeleteChildren(activeBranch);
@ -405,12 +422,11 @@ void BookmarkView::doUpdateActiveList() {
if (nextRange == re_i) { if (nextRange == re_i) {
selItem = itm; selItem = itm;
nextRange = nullptr; nextRange = nullptr;
} else if (!selItem && rangeExpandState && prevSel && prevSel->type == TreeViewItem::TREEVIEW_ITEM_TYPE_RANGE && prevSel->rangeEnt == re_i) { } else if (!selItem && rangeExpandState && prevSelCopy && prevSelCopy->type == TreeViewItem::TREEVIEW_ITEM_TYPE_RANGE && prevSelCopy->rangeEnt == re_i) {
selItem = itm; selItem = itm;
} }
} }
bool recentExpandState = searchState || expandState["recent"]; bool recentExpandState = searchState || expandState["recent"];
// Recents // Recents
@ -453,7 +469,7 @@ void BookmarkView::doUpdateActiveList() {
if (nextEnt == bmr_i) { if (nextEnt == bmr_i) {
selItem = itm; selItem = itm;
nextEnt = nullptr; nextEnt = nullptr;
} else if (!selItem && recentExpandState && prevSel && prevSel->type == TreeViewItem::TREEVIEW_ITEM_TYPE_RECENT && prevSel->bookmarkEnt == bmr_i) { } else if (!selItem && recentExpandState && prevSelCopy && prevSelCopy->type == TreeViewItem::TREEVIEW_ITEM_TYPE_RECENT && prevSelCopy->bookmarkEnt == bmr_i) {
selItem = itm; selItem = itm;
} }
} }
@ -474,9 +490,12 @@ void BookmarkView::doUpdateActiveList() {
m_treeView->Collapse(rangeBranch); m_treeView->Collapse(rangeBranch);
} }
//select the item having the same meaning as the previously selected item
if (selItem != nullptr) { if (selItem != nullptr) {
m_treeView->SelectItem(selItem); m_treeView->SelectItem(selItem);
} }
delete prevSelCopy;
} }
@ -561,11 +580,11 @@ void BookmarkView::onTreeActivate( wxTreeEvent& event ) {
nextDemod = tvi->demod; nextDemod = tvi->demod;
} }
} else if (tvi->type == TreeViewItem::TREEVIEW_ITEM_TYPE_RECENT) { } else if (tvi->type == TreeViewItem::TREEVIEW_ITEM_TYPE_RECENT) {
activateBookmark(tvi->bookmarkEnt);
nextEnt = tvi->bookmarkEnt; nextEnt = tvi->bookmarkEnt;
wxGetApp().getBookmarkMgr().removeRecent(tvi->bookmarkEnt); wxGetApp().getBookmarkMgr().removeRecent(tvi->bookmarkEnt);
wxGetApp().getBookmarkMgr().updateActiveList();
activateBookmark(tvi->bookmarkEnt);
} else if (tvi->type == TreeViewItem::TREEVIEW_ITEM_TYPE_BOOKMARK) { } else if (tvi->type == TreeViewItem::TREEVIEW_ITEM_TYPE_BOOKMARK) {
activateBookmark(tvi->bookmarkEnt); activateBookmark(tvi->bookmarkEnt);
} else if (tvi->type == TreeViewItem::TREEVIEW_ITEM_TYPE_RANGE) { } else if (tvi->type == TreeViewItem::TREEVIEW_ITEM_TYPE_RANGE) {
@ -889,6 +908,7 @@ void BookmarkView::activateBookmark(BookmarkEntryPtr bmEnt) {
newDemod->setActive(true); newDemod->setActive(true);
wxGetApp().bindDemodulator(newDemod); wxGetApp().bindDemodulator(newDemod);
//order immediate refresh of the whole tree.
doUpdateActiveList(); doUpdateActiveList();
} }
@ -1205,11 +1225,11 @@ void BookmarkView::onActivateRecent( wxCommandEvent& /* event */ ) {
TreeViewItem *curSel = itemToTVI(m_treeView->GetSelection()); TreeViewItem *curSel = itemToTVI(m_treeView->GetSelection());
if (curSel && curSel->type == TreeViewItem::TREEVIEW_ITEM_TYPE_RECENT) { if (curSel && curSel->type == TreeViewItem::TREEVIEW_ITEM_TYPE_RECENT) {
BookmarkEntryPtr bookmarkEntToActivate = curSel->bookmarkEnt;
activateBookmark(curSel->bookmarkEnt);
m_treeView->Delete(m_treeView->GetSelection()); m_treeView->Delete(m_treeView->GetSelection());
wxGetApp().getBookmarkMgr().removeRecent(curSel->bookmarkEnt);
wxGetApp().getBookmarkMgr().updateActiveList(); wxGetApp().getBookmarkMgr().removeRecent(bookmarkEntToActivate);
activateBookmark(bookmarkEntToActivate);
} }
} }
@ -1222,9 +1242,9 @@ void BookmarkView::onRemoveRecent ( wxCommandEvent& /* event */ ) {
TreeViewItem *curSel = itemToTVI(m_treeView->GetSelection()); TreeViewItem *curSel = itemToTVI(m_treeView->GetSelection());
if (curSel && curSel->type == TreeViewItem::TREEVIEW_ITEM_TYPE_RECENT) { if (curSel && curSel->type == TreeViewItem::TREEVIEW_ITEM_TYPE_RECENT) {
BookmarkEntryPtr bookmarkEntToRemove = curSel->bookmarkEnt;
m_treeView->Delete(m_treeView->GetSelection()); m_treeView->Delete(m_treeView->GetSelection());
wxGetApp().getBookmarkMgr().removeRecent(curSel->bookmarkEnt); wxGetApp().getBookmarkMgr().removeRecent(bookmarkEntToRemove);
wxGetApp().getBookmarkMgr().updateActiveList(); wxGetApp().getBookmarkMgr().updateActiveList();
} }
} }

View File

@ -25,6 +25,14 @@ public:
bookmarkEnt = nullptr; bookmarkEnt = nullptr;
rangeEnt = nullptr; rangeEnt = nullptr;
}; };
// copy constructor
TreeViewItem(const TreeViewItem& src) {
demod = src.demod;
bookmarkEnt = src.bookmarkEnt;
rangeEnt = src.rangeEnt;
type = src.type;
groupName = src.groupName;
};
virtual ~TreeViewItem() { virtual ~TreeViewItem() {
// //
@ -53,11 +61,17 @@ public:
virtual ~BookmarkView(); virtual ~BookmarkView();
//order an asynchronous refresh/rebuild of the whole tree,
//will take effect at the next onUpdateTimer() occurence.
void updateActiveList(); void updateActiveList();
void updateBookmarks();
bool isKeywordMatch(std::wstring str, std::vector<std::wstring> &keywords);
void updateBookmarks(std::string group);
//order asynchronous updates of the bookmarks,
//will take effect at the next onUpdateTimer() occurence.
void updateBookmarks();
void updateBookmarks(std::string group);
bool isKeywordMatch(std::wstring str, std::vector<std::wstring> &keywords);
wxTreeItemId refreshBookmarks(); wxTreeItemId refreshBookmarks();
void updateTheme(); void updateTheme();
void onMenuItem(wxCommandEvent& event); void onMenuItem(wxCommandEvent& event);
@ -73,7 +87,9 @@ protected:
void activeSelection(DemodulatorInstance *dsel); void activeSelection(DemodulatorInstance *dsel);
void bookmarkSelection(BookmarkEntryPtr bmSel); void bookmarkSelection(BookmarkEntryPtr bmSel);
void rangeSelection(BookmarkRangeEntryPtr re); void rangeSelection(BookmarkRangeEntryPtr re);
void activateBookmark(BookmarkEntryPtr bmEnt); void activateBookmark(BookmarkEntryPtr bmEnt);
void activateRange(BookmarkRangeEntryPtr rangeEnt); void activateRange(BookmarkRangeEntryPtr rangeEnt);
void recentSelection(BookmarkEntryPtr bmSel); void recentSelection(BookmarkEntryPtr bmSel);
void groupSelection(std::string groupName); void groupSelection(std::string groupName);
@ -87,6 +103,7 @@ protected:
void onUpdateTimer( wxTimerEvent& event ); void onUpdateTimer( wxTimerEvent& event );
//refresh / rebuild the whole tree item immediatly
void doUpdateActiveList(); void doUpdateActiveList();
void onTreeBeginLabelEdit( wxTreeEvent& event ); void onTreeBeginLabelEdit( wxTreeEvent& event );