Basic bookmarking test

This commit is contained in:
Charles J. Cliffe 2016-10-06 22:27:12 -04:00
parent fab41f30be
commit 07c55ede21
4 changed files with 93 additions and 14 deletions

View File

@ -66,6 +66,23 @@ void BookmarkMgr::updateActiveList() {
}
}
void BookmarkMgr::updateBookmarks() {
BookmarkView *bmv = wxGetApp().getAppFrame()->getBookmarkView();
if (bmv) {
bmv->updateBookmarks();
}
}
void BookmarkMgr::updateBookmarks(std::string group) {
BookmarkView *bmv = wxGetApp().getAppFrame()->getBookmarkView();
if (bmv) {
bmv->updateBookmarks(group);
}
}
void BookmarkMgr::addRecent(DemodulatorInstance *demod) {
std::lock_guard < std::mutex > lock(busy_lock);
recents.push_back(demodToBookmarkEntry(demod));

View File

@ -48,6 +48,8 @@ public:
BookmarkNames getGroups();
void updateActiveList();
void updateBookmarks();
void updateBookmarks(std::string group);
void addRecent(DemodulatorInstance *demod);
BookmarkList getRecents();

View File

@ -3,6 +3,7 @@
#include <wx/menu.h>
#include <wx/textdlg.h>
#include <algorithm>
#define wxCONTEXT_ADD_GROUP_ID 1000
BookmarkView::BookmarkView( wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style) : BookmarkPanel(parent, id, pos, size, style) {
@ -29,6 +30,13 @@ void BookmarkView::onUpdateTimer( wxTimerEvent& event ) {
doUpdateActive.store(false);
}
if (doUpdateBookmarks.load()) {
wxTreeItemId bmSel = refreshBookmarks();
if (bmSel) {
m_treeView->SelectItem(bmSel);
}
doUpdateBookmarks.store(false);
}
}
void BookmarkView::updateTheme() {
@ -61,13 +69,28 @@ void BookmarkView::updateActiveList() {
doUpdateActive.store(true);
}
void BookmarkView::refreshBookmarks() {
void BookmarkView::updateBookmarks() {
doUpdateBookmarks.store(true);
}
void BookmarkView::updateBookmarks(std::string group) {
doUpdateBookmarkGroup.insert(group);
doUpdateBookmarks.store(true);
}
wxTreeItemId BookmarkView::refreshBookmarks() {
// if (!bookmarksInitialized) {
groupNames = wxGetApp().getBookmarkMgr().getGroups();
if (!groupNames.size()) {
wxGetApp().getBookmarkMgr().getGroup("Uncategorized");
wxGetApp().getBookmarkMgr().getGroup("Ungrouped");
groupNames = wxGetApp().getBookmarkMgr().getGroups();
}
if (doUpdateBookmarkGroup.size()) { // Nothing for the moment..
doUpdateBookmarkGroup.erase(doUpdateBookmarkGroup.begin(), doUpdateBookmarkGroup.end());
}
wxTreeItemId bmSelFound = nullptr;
for (auto gn_i : groupNames) {
if (groups.find(gn_i) == groups.end()) {
groups[gn_i] = m_treeView->AppendItem(bookmarkBranch, gn_i);
@ -77,15 +100,23 @@ void BookmarkView::refreshBookmarks() {
m_treeView->DeleteChildren(groupItem);
std::vector<wxTreeItemId> &groupEnts = groupEntries[groupItem];
std::vector<BookmarkEntry *> &groupBMEnts = groupBookmarkEntries[groupItem];
groupEnts.erase(groupEnts.begin(),groupEnts.end());
groupBMEnts.erase(groupBMEnts.begin(),groupBMEnts.end());
BookmarkGroup bmList = wxGetApp().getBookmarkMgr().getGroup(gn_i);
for (auto bmEnt : bmList) {
wxTreeItemId bmItem = m_treeView->AppendItem(groupItem, bmEnt->label);
groupEnts.push_back(bmItem);
groupBMEnts.push_back(bmEnt);
if (bookmarkSel == bmEnt) {
bmSelFound = bmItem;
}
}
}
// bookmarksInitialized = true;
return bmSelFound;
// bookmarksInitialized = true;
// }
}
@ -114,9 +145,6 @@ void BookmarkView::doUpdateActiveList() {
}
}
// Bookmarks
refreshBookmarks();
// Recents
BookmarkList bmRecents = wxGetApp().getBookmarkMgr().getRecents();
recentItems.erase(recentItems.begin(),recentItems.end());
@ -150,6 +178,9 @@ void BookmarkView::onTreeActivate( wxTreeEvent& event ) {
if (recentSel) {
activateBookmark(recentSel);
}
if (bookmarkSel) {
activateBookmark(bookmarkSel);
}
}
void BookmarkView::onTreeCollapse( wxTreeEvent& event ) {
@ -313,14 +344,31 @@ void BookmarkView::onTreeSelect( wxTreeEvent& event ) {
m_propPanel->Show();
recentSelection(recentSel);
} else {
bool bFound = false;
bookmarkSel = nullptr;
for (auto ge_i : groupEntries) {
wxTreeItemId itm = event.GetItem();
for (int i = 0, iMax = ge_i.second.size(); i < iMax; i++) {
if (ge_i.second[i] == itm) {
bookmarkSel = groupBookmarkEntries[ge_i.first][i];
bFound = true;
}
}
}
activeSel = nullptr;
recentSel = nullptr;
m_propPanel->Hide();
hideProps();
if (bFound) {
m_propPanel->Show();
bookmarkSelection(bookmarkSel);
} else {
m_propPanel->Hide();
hideProps();
wxGetApp().getDemodMgr().setActiveDemodulator(activeSel, false);
}
this->Layout();
wxGetApp().getDemodMgr().setActiveDemodulator(activeSel, false);
}
}
@ -347,13 +395,19 @@ void BookmarkView::onDoubleClickBandwidth( wxMouseEvent& event ) {
}
void BookmarkView::onBookmark( wxCommandEvent& event ) {
event.Skip();
if (activeSel) {
wxGetApp().getBookmarkMgr().addBookmark("Ungrouped", activeSel);
wxGetApp().getBookmarkMgr().updateBookmarks();
}
}
void BookmarkView::onActivate( wxCommandEvent& event ) {
if (recentSel) {
activateBookmark(recentSel);
}
if (bookmarkSel) {
activateBookmark(bookmarkSel);
}
}
void BookmarkView::onRemove( wxCommandEvent& event ) {

View File

@ -9,11 +9,13 @@ public:
BookmarkView( wxWindow* parent, wxWindowID id = wxID_ANY, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( -1, -1 ), long style = wxTAB_TRAVERSAL );
void updateActiveList();
void updateBookmarks();
void updateBookmarks(std::string group);
void activeSelection(DemodulatorInstance *dsel);
void bookmarkSelection(BookmarkEntry *bmSel);
void activateBookmark(BookmarkEntry *bmEnt);
void recentSelection(BookmarkEntry *bmSel);
void refreshBookmarks();
wxTreeItemId refreshBookmarks();
void updateTheme();
void onMenuItem(wxCommandEvent& event);
@ -39,17 +41,21 @@ protected:
void onActivate( wxCommandEvent& event );
void onRemove( wxCommandEvent& event );
std::atomic_bool doUpdateActive;
wxTreeItemId rootBranch, activeBranch, bookmarkBranch, recentBranch;
// Bookmarks
std::atomic_bool doUpdateBookmarks;
std::set< std::string > doUpdateBookmarkGroup;
BookmarkNames groupNames;
std::map<std::string, wxTreeItemId> groups;
std::map<wxTreeItemId, std::vector<wxTreeItemId> > groupEntries;
std::map<wxTreeItemId, std::vector<BookmarkEntry * > > groupBookmarkEntries;
BookmarkEntry *bookmarkSel;
bool bookmarksInitialized;
// Active
std::atomic_bool doUpdateActive;
std::map<wxTreeItemId, DemodulatorInstance *> activeItems;
DemodulatorInstance *activeSel;