Add bookmark group context menu

This commit is contained in:
Charles J. Cliffe 2016-10-06 21:08:45 -04:00
parent 020cef12c9
commit fab41f30be
5 changed files with 81 additions and 11 deletions

View File

@ -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 );

View File

@ -174,7 +174,7 @@
<event name="OnTreeItemExpanded">onTreeExpanded</event>
<event name="OnTreeItemExpanding"></event>
<event name="OnTreeItemGetTooltip"></event>
<event name="OnTreeItemMenu"></event>
<event name="OnTreeItemMenu">onTreeItemMenu</event>
<event name="OnTreeItemMiddleClick"></event>
<event name="OnTreeItemRightClick"></event>
<event name="OnTreeKeyDown"></event>

View File

@ -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(); }

View File

@ -1,6 +1,10 @@
#include "BookmarkView.h"
#include "CubicSDR.h"
#include <wx/menu.h>
#include <wx/textdlg.h>
#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<wxTreeItemId> &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();

View File

@ -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<std::string, wxTreeItemId> groups;
std::map<wxTreeItemId, DemodulatorInstance *> activeItems;
std::map<wxTreeItemId, BookmarkEntry *> recentItems;
DemodulatorInstance *activeSel;
BookmarkEntry *recentSel;
// Bookmarks
BookmarkNames groupNames;
std::map<std::string, wxTreeItemId> groups;
std::map<wxTreeItemId, std::vector<wxTreeItemId> > groupEntries;
BookmarkEntry *bookmarkSel;
bool bookmarksInitialized;
// Active
std::map<wxTreeItemId, DemodulatorInstance *> activeItems;
DemodulatorInstance *activeSel;
// Recent
std::map<wxTreeItemId, BookmarkEntry *> recentItems;
BookmarkEntry *recentSel;
};