diff --git a/src/forms/Bookmark/BookmarkPanel.cpp b/src/forms/Bookmark/BookmarkPanel.cpp index 6d54fef..c60e4f7 100644 --- a/src/forms/Bookmark/BookmarkPanel.cpp +++ b/src/forms/Bookmark/BookmarkPanel.cpp @@ -81,6 +81,7 @@ BookmarkPanel::BookmarkPanel( wxWindow* parent, wxWindowID id, const wxPoint& po m_treeView->Connect( wxEVT_COMMAND_TREE_ITEM_ACTIVATED, wxTreeEventHandler( BookmarkPanel::onTreeActivate ), NULL, this ); m_treeView->Connect( wxEVT_COMMAND_TREE_ITEM_COLLAPSED, wxTreeEventHandler( BookmarkPanel::onTreeCollapse ), NULL, this ); m_treeView->Connect( wxEVT_COMMAND_TREE_ITEM_EXPANDED, wxTreeEventHandler( BookmarkPanel::onTreeExpanded ), NULL, this ); + m_treeView->Connect( wxEVT_COMMAND_TREE_ITEM_MENU, wxTreeEventHandler( BookmarkPanel::onTreeItemMenu ), NULL, this ); m_treeView->Connect( wxEVT_COMMAND_TREE_SEL_CHANGED, wxTreeEventHandler( BookmarkPanel::onTreeSelect ), NULL, this ); m_treeView->Connect( wxEVT_COMMAND_TREE_SEL_CHANGING, wxTreeEventHandler( BookmarkPanel::onTreeSelectChanging ), NULL, this ); m_labelText->Connect( wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler( BookmarkPanel::onLabelText ), NULL, this ); @@ -100,6 +101,7 @@ BookmarkPanel::~BookmarkPanel() m_treeView->Disconnect( wxEVT_COMMAND_TREE_ITEM_ACTIVATED, wxTreeEventHandler( BookmarkPanel::onTreeActivate ), NULL, this ); m_treeView->Disconnect( wxEVT_COMMAND_TREE_ITEM_COLLAPSED, wxTreeEventHandler( BookmarkPanel::onTreeCollapse ), NULL, this ); m_treeView->Disconnect( wxEVT_COMMAND_TREE_ITEM_EXPANDED, wxTreeEventHandler( BookmarkPanel::onTreeExpanded ), NULL, this ); + m_treeView->Disconnect( wxEVT_COMMAND_TREE_ITEM_MENU, wxTreeEventHandler( BookmarkPanel::onTreeItemMenu ), NULL, this ); m_treeView->Disconnect( wxEVT_COMMAND_TREE_SEL_CHANGED, wxTreeEventHandler( BookmarkPanel::onTreeSelect ), NULL, this ); m_treeView->Disconnect( wxEVT_COMMAND_TREE_SEL_CHANGING, wxTreeEventHandler( BookmarkPanel::onTreeSelectChanging ), NULL, this ); m_labelText->Disconnect( wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler( BookmarkPanel::onLabelText ), NULL, this ); diff --git a/src/forms/Bookmark/BookmarkPanel.fbp b/src/forms/Bookmark/BookmarkPanel.fbp index f79f744..5352bc0 100644 --- a/src/forms/Bookmark/BookmarkPanel.fbp +++ b/src/forms/Bookmark/BookmarkPanel.fbp @@ -174,7 +174,7 @@ onTreeExpanded - + onTreeItemMenu diff --git a/src/forms/Bookmark/BookmarkPanel.h b/src/forms/Bookmark/BookmarkPanel.h index bb07915..adf25e8 100644 --- a/src/forms/Bookmark/BookmarkPanel.h +++ b/src/forms/Bookmark/BookmarkPanel.h @@ -55,6 +55,7 @@ class BookmarkPanel : public wxPanel virtual void onTreeActivate( wxTreeEvent& event ) { event.Skip(); } virtual void onTreeCollapse( wxTreeEvent& event ) { event.Skip(); } virtual void onTreeExpanded( wxTreeEvent& event ) { event.Skip(); } + virtual void onTreeItemMenu( wxTreeEvent& event ) { event.Skip(); } virtual void onTreeSelect( wxTreeEvent& event ) { event.Skip(); } virtual void onTreeSelectChanging( wxTreeEvent& event ) { event.Skip(); } virtual void onLabelText( wxCommandEvent& event ) { event.Skip(); } diff --git a/src/forms/Bookmark/BookmarkView.cpp b/src/forms/Bookmark/BookmarkView.cpp index a6d2d00..dd1657b 100644 --- a/src/forms/Bookmark/BookmarkView.cpp +++ b/src/forms/Bookmark/BookmarkView.cpp @@ -1,6 +1,10 @@ #include "BookmarkView.h" #include "CubicSDR.h" +#include +#include +#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) { rootBranch = m_treeView->AddRoot("Root"); @@ -8,9 +12,10 @@ BookmarkView::BookmarkView( wxWindow* parent, wxWindowID id, const wxPoint& pos, bookmarkBranch = m_treeView->AppendItem(rootBranch, "Bookmarks"); recentBranch = m_treeView->AppendItem(rootBranch, "Recents"); - doUpdateActive = false; + doUpdateActive.store(true); activeSel = nullptr; recentSel = nullptr; + bookmarksInitialized = false; hideProps(); m_propPanel->Hide(); @@ -19,10 +24,10 @@ BookmarkView::BookmarkView( wxWindow* parent, wxWindowID id, const wxPoint& pos, } void BookmarkView::onUpdateTimer( wxTimerEvent& event ) { - if (doUpdateActive) { + if (doUpdateActive.load()) { doUpdateActiveList(); - doUpdateActive = false; + doUpdateActive.store(false); } } @@ -53,7 +58,35 @@ void BookmarkView::updateTheme() { void BookmarkView::updateActiveList() { - doUpdateActive = true; + doUpdateActive.store(true); +} + +void BookmarkView::refreshBookmarks() { +// if (!bookmarksInitialized) { + groupNames = wxGetApp().getBookmarkMgr().getGroups(); + if (!groupNames.size()) { + wxGetApp().getBookmarkMgr().getGroup("Uncategorized"); + groupNames = wxGetApp().getBookmarkMgr().getGroups(); + } + for (auto gn_i : groupNames) { + if (groups.find(gn_i) == groups.end()) { + groups[gn_i] = m_treeView->AppendItem(bookmarkBranch, gn_i); + } + + wxTreeItemId groupItem = groups[gn_i]; + m_treeView->DeleteChildren(groupItem); + + std::vector &groupEnts = groupEntries[groupItem]; + groupEnts.erase(groupEnts.begin(),groupEnts.end()); + + BookmarkGroup bmList = wxGetApp().getBookmarkMgr().getGroup(gn_i); + for (auto bmEnt : bmList) { + wxTreeItemId bmItem = m_treeView->AppendItem(groupItem, bmEnt->label); + groupEnts.push_back(bmItem); + } + } +// bookmarksInitialized = true; +// } } void BookmarkView::doUpdateActiveList() { @@ -81,6 +114,9 @@ void BookmarkView::doUpdateActiveList() { } } + // Bookmarks + refreshBookmarks(); + // Recents BookmarkList bmRecents = wxGetApp().getBookmarkMgr().getRecents(); recentItems.erase(recentItems.begin(),recentItems.end()); @@ -124,6 +160,26 @@ void BookmarkView::onTreeExpanded( wxTreeEvent& event ) { event.Skip(); } +void BookmarkView::onTreeItemMenu( wxTreeEvent& event ) { + if (m_treeView->GetSelection() == bookmarkBranch) { + wxMenu menu; + menu.Append(wxCONTEXT_ADD_GROUP_ID, "Add Group"); + menu.Connect(wxCONTEXT_ADD_GROUP_ID, wxEVT_MENU, (wxObjectEventFunction)&BookmarkView::onMenuItem); + PopupMenu(&menu); + } +} + +void BookmarkView::onMenuItem(wxCommandEvent& event) { + if (event.GetId() == wxCONTEXT_ADD_GROUP_ID) { + wxString stringVal = wxGetTextFromUser("Enter Group Name", "Add Group", ""); + if (stringVal.ToStdString() != "") { + wxGetApp().getBookmarkMgr().getGroup(stringVal.ToStdString()); + wxGetApp().getBookmarkMgr().updateActiveList(); + } + } +} + + void BookmarkView::hideProps() { m_frequencyLabel->Hide(); m_frequencyVal->Hide(); diff --git a/src/forms/Bookmark/BookmarkView.h b/src/forms/Bookmark/BookmarkView.h index a6cd5b0..fd81396 100644 --- a/src/forms/Bookmark/BookmarkView.h +++ b/src/forms/Bookmark/BookmarkView.h @@ -13,7 +13,9 @@ public: void bookmarkSelection(BookmarkEntry *bmSel); void activateBookmark(BookmarkEntry *bmEnt); void recentSelection(BookmarkEntry *bmSel); + void refreshBookmarks(); void updateTheme(); + void onMenuItem(wxCommandEvent& event); protected: @@ -27,6 +29,7 @@ protected: void onTreeActivate( wxTreeEvent& event ); void onTreeCollapse( wxTreeEvent& event ); void onTreeExpanded( wxTreeEvent& event ); + void onTreeItemMenu( wxTreeEvent& event ); void onTreeSelect( wxTreeEvent& event ); void onTreeSelectChanging( wxTreeEvent& event ); void onLabelText( wxCommandEvent& event ); @@ -36,14 +39,22 @@ protected: void onActivate( wxCommandEvent& event ); void onRemove( wxCommandEvent& event ); - bool doUpdateActive; + std::atomic_bool doUpdateActive; wxTreeItemId rootBranch, activeBranch, bookmarkBranch, recentBranch; - std::map groups; - std::map activeItems; - std::map recentItems; - DemodulatorInstance *activeSel; - BookmarkEntry *recentSel; + // Bookmarks + BookmarkNames groupNames; + std::map groups; + std::map > groupEntries; BookmarkEntry *bookmarkSel; + bool bookmarksInitialized; + + // Active + std::map activeItems; + DemodulatorInstance *activeSel; + + // Recent + std::map recentItems; + BookmarkEntry *recentSel; }; \ No newline at end of file