Some basic BookmarkView drag+drop functionality

This commit is contained in:
Charles J. Cliffe 2016-10-13 00:41:35 -04:00
parent 824598cb1a
commit 14cf709447
8 changed files with 241 additions and 17 deletions

View File

@ -1901,6 +1901,10 @@ int AppFrame::OnGlobalKeyDown(wxKeyEvent &event) {
return -1; return -1;
} }
if (bookmarkView && bookmarkView->isMouseInView()) {
return -1;
}
DemodulatorInstance *demod = nullptr, *lastDemod = wxGetApp().getDemodMgr().getLastActiveDemodulator(); DemodulatorInstance *demod = nullptr, *lastDemod = wxGetApp().getDemodMgr().getLastActiveDemodulator();
int snap = wxGetApp().getFrequencySnap(); int snap = wxGetApp().getFrequencySnap();
@ -2002,6 +2006,10 @@ int AppFrame::OnGlobalKeyUp(wxKeyEvent &event) {
return -1; return -1;
} }
if (bookmarkView && bookmarkView->isMouseInView()) {
return -1;
}
if (event.ControlDown()) { if (event.ControlDown()) {
return 1; return 1;
} }

View File

@ -25,6 +25,13 @@ void BookmarkMgr::addBookmark(std::string group, DemodulatorInstance *demod) {
bmData[group].insert(be); bmData[group].insert(be);
} }
void BookmarkMgr::addBookmark(std::string group, BookmarkEntry *be) {
std::lock_guard < std::mutex > lock(busy_lock);
bmData[group].insert(be);
}
void BookmarkMgr::removeBookmark(std::string group, BookmarkEntry *be) { void BookmarkMgr::removeBookmark(std::string group, BookmarkEntry *be) {
std::lock_guard < std::mutex > lockData(busy_lock); std::lock_guard < std::mutex > lockData(busy_lock);
std::lock_guard < std::mutex > lockEnt(be->busy_lock); std::lock_guard < std::mutex > lockEnt(be->busy_lock);
@ -93,6 +100,17 @@ void BookmarkMgr::addRecent(DemodulatorInstance *demod) {
} }
void BookmarkMgr::removeRecent(BookmarkEntry *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);
}
}
BookmarkList BookmarkMgr::getRecents() { BookmarkList BookmarkMgr::getRecents() {
return recents; return recents;
} }

View File

@ -40,6 +40,7 @@ public:
void loadFromFile(std::string bookmarkFn); void loadFromFile(std::string bookmarkFn);
void addBookmark(std::string group, DemodulatorInstance *demod); void addBookmark(std::string group, DemodulatorInstance *demod);
void addBookmark(std::string group, BookmarkEntry *be);
void removeBookmark(std::string group, BookmarkEntry *be); void removeBookmark(std::string group, BookmarkEntry *be);
BookmarkList getBookmarks(std::string group); BookmarkList getBookmarks(std::string group);
@ -52,6 +53,7 @@ public:
void updateBookmarks(std::string group); void updateBookmarks(std::string group);
void addRecent(DemodulatorInstance *demod); void addRecent(DemodulatorInstance *demod);
void removeRecent(BookmarkEntry *be);
BookmarkList getRecents(); BookmarkList getRecents();

View File

@ -14,7 +14,7 @@ BookmarkPanel::BookmarkPanel( wxWindow* parent, wxWindowID id, const wxPoint& po
wxBoxSizer* bSizer1; wxBoxSizer* bSizer1;
bSizer1 = new wxBoxSizer( wxVERTICAL ); bSizer1 = new wxBoxSizer( wxVERTICAL );
m_treeView = new wxTreeCtrl( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTR_DEFAULT_STYLE|wxTR_HIDE_ROOT ); m_treeView = new wxTreeCtrl( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTR_DEFAULT_STYLE|wxTR_EDIT_LABELS|wxTR_HAS_VARIABLE_ROW_HEIGHT|wxTR_HIDE_ROOT|wxTR_SINGLE );
bSizer1->Add( m_treeView, 5, wxEXPAND, 5 ); bSizer1->Add( m_treeView, 5, wxEXPAND, 5 );
m_propPanel = new wxPanel( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL ); m_propPanel = new wxPanel( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL );
@ -76,11 +76,17 @@ BookmarkPanel::BookmarkPanel( wxWindow* parent, wxWindowID id, const wxPoint& po
m_updateTimer.SetOwner( this, wxID_ANY ); m_updateTimer.SetOwner( this, wxID_ANY );
// Connect Events // Connect Events
this->Connect( wxEVT_ENTER_WINDOW, wxMouseEventHandler( BookmarkPanel::onEnterWindow ) );
this->Connect( wxEVT_LEAVE_WINDOW, wxMouseEventHandler( BookmarkPanel::onLeaveWindow ) );
m_treeView->Connect( wxEVT_COMMAND_TREE_BEGIN_DRAG, wxTreeEventHandler( BookmarkPanel::onTreeBeginDrag ), NULL, this );
m_treeView->Connect( wxEVT_COMMAND_TREE_BEGIN_LABEL_EDIT, wxTreeEventHandler( BookmarkPanel::onTreeBeginLabelEdit ), NULL, this ); m_treeView->Connect( wxEVT_COMMAND_TREE_BEGIN_LABEL_EDIT, wxTreeEventHandler( BookmarkPanel::onTreeBeginLabelEdit ), NULL, this );
m_treeView->Connect( wxEVT_COMMAND_TREE_DELETE_ITEM, wxTreeEventHandler( BookmarkPanel::onTreeDeleteItem ), NULL, this );
m_treeView->Connect( wxEVT_COMMAND_TREE_END_DRAG, wxTreeEventHandler( BookmarkPanel::onTreeEndDrag ), NULL, this );
m_treeView->Connect( wxEVT_COMMAND_TREE_END_LABEL_EDIT, wxTreeEventHandler( BookmarkPanel::onTreeEndLabelEdit ), NULL, this ); m_treeView->Connect( wxEVT_COMMAND_TREE_END_LABEL_EDIT, wxTreeEventHandler( BookmarkPanel::onTreeEndLabelEdit ), NULL, this );
m_treeView->Connect( wxEVT_COMMAND_TREE_ITEM_ACTIVATED, wxTreeEventHandler( BookmarkPanel::onTreeActivate ), NULL, this ); 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_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_EXPANDED, wxTreeEventHandler( BookmarkPanel::onTreeExpanded ), NULL, this );
m_treeView->Connect( wxEVT_COMMAND_TREE_ITEM_GETTOOLTIP, wxTreeEventHandler( BookmarkPanel::onTreeItemGetTooltip ), NULL, this );
m_treeView->Connect( wxEVT_COMMAND_TREE_ITEM_MENU, wxTreeEventHandler( BookmarkPanel::onTreeItemMenu ), 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_CHANGED, wxTreeEventHandler( BookmarkPanel::onTreeSelect ), NULL, this );
m_treeView->Connect( wxEVT_COMMAND_TREE_SEL_CHANGING, wxTreeEventHandler( BookmarkPanel::onTreeSelectChanging ), NULL, this ); m_treeView->Connect( wxEVT_COMMAND_TREE_SEL_CHANGING, wxTreeEventHandler( BookmarkPanel::onTreeSelectChanging ), NULL, this );
@ -96,11 +102,17 @@ BookmarkPanel::BookmarkPanel( wxWindow* parent, wxWindowID id, const wxPoint& po
BookmarkPanel::~BookmarkPanel() BookmarkPanel::~BookmarkPanel()
{ {
// Disconnect Events // Disconnect Events
this->Disconnect( wxEVT_ENTER_WINDOW, wxMouseEventHandler( BookmarkPanel::onEnterWindow ) );
this->Disconnect( wxEVT_LEAVE_WINDOW, wxMouseEventHandler( BookmarkPanel::onLeaveWindow ) );
m_treeView->Disconnect( wxEVT_COMMAND_TREE_BEGIN_DRAG, wxTreeEventHandler( BookmarkPanel::onTreeBeginDrag ), NULL, this );
m_treeView->Disconnect( wxEVT_COMMAND_TREE_BEGIN_LABEL_EDIT, wxTreeEventHandler( BookmarkPanel::onTreeBeginLabelEdit ), NULL, this ); m_treeView->Disconnect( wxEVT_COMMAND_TREE_BEGIN_LABEL_EDIT, wxTreeEventHandler( BookmarkPanel::onTreeBeginLabelEdit ), NULL, this );
m_treeView->Disconnect( wxEVT_COMMAND_TREE_DELETE_ITEM, wxTreeEventHandler( BookmarkPanel::onTreeDeleteItem ), NULL, this );
m_treeView->Disconnect( wxEVT_COMMAND_TREE_END_DRAG, wxTreeEventHandler( BookmarkPanel::onTreeEndDrag ), NULL, this );
m_treeView->Disconnect( wxEVT_COMMAND_TREE_END_LABEL_EDIT, wxTreeEventHandler( BookmarkPanel::onTreeEndLabelEdit ), NULL, this ); m_treeView->Disconnect( wxEVT_COMMAND_TREE_END_LABEL_EDIT, wxTreeEventHandler( BookmarkPanel::onTreeEndLabelEdit ), NULL, this );
m_treeView->Disconnect( wxEVT_COMMAND_TREE_ITEM_ACTIVATED, wxTreeEventHandler( BookmarkPanel::onTreeActivate ), NULL, this ); 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_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_EXPANDED, wxTreeEventHandler( BookmarkPanel::onTreeExpanded ), NULL, this );
m_treeView->Disconnect( wxEVT_COMMAND_TREE_ITEM_GETTOOLTIP, wxTreeEventHandler( BookmarkPanel::onTreeItemGetTooltip ), NULL, this );
m_treeView->Disconnect( wxEVT_COMMAND_TREE_ITEM_MENU, wxTreeEventHandler( BookmarkPanel::onTreeItemMenu ), 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_CHANGED, wxTreeEventHandler( BookmarkPanel::onTreeSelect ), NULL, this );
m_treeView->Disconnect( wxEVT_COMMAND_TREE_SEL_CHANGING, wxTreeEventHandler( BookmarkPanel::onTreeSelectChanging ), NULL, this ); m_treeView->Disconnect( wxEVT_COMMAND_TREE_SEL_CHANGING, wxTreeEventHandler( BookmarkPanel::onTreeSelectChanging ), NULL, this );

View File

@ -55,13 +55,13 @@
<event name="OnAuiPaneRestore"></event> <event name="OnAuiPaneRestore"></event>
<event name="OnAuiRender"></event> <event name="OnAuiRender"></event>
<event name="OnChar"></event> <event name="OnChar"></event>
<event name="OnEnterWindow"></event> <event name="OnEnterWindow">onEnterWindow</event>
<event name="OnEraseBackground"></event> <event name="OnEraseBackground"></event>
<event name="OnInitDialog"></event> <event name="OnInitDialog"></event>
<event name="OnKeyDown"></event> <event name="OnKeyDown"></event>
<event name="OnKeyUp"></event> <event name="OnKeyUp"></event>
<event name="OnKillFocus"></event> <event name="OnKillFocus"></event>
<event name="OnLeaveWindow"></event> <event name="OnLeaveWindow">onLeaveWindow</event>
<event name="OnLeftDClick"></event> <event name="OnLeftDClick"></event>
<event name="OnLeftDown"></event> <event name="OnLeftDown"></event>
<event name="OnLeftUp"></event> <event name="OnLeftUp"></event>
@ -132,7 +132,7 @@
<property name="resize">Resizable</property> <property name="resize">Resizable</property>
<property name="show">1</property> <property name="show">1</property>
<property name="size"></property> <property name="size"></property>
<property name="style">wxTR_DEFAULT_STYLE|wxTR_HIDE_ROOT</property> <property name="style">wxTR_DEFAULT_STYLE|wxTR_EDIT_LABELS|wxTR_HAS_VARIABLE_ROW_HEIGHT|wxTR_HIDE_ROOT|wxTR_SINGLE</property>
<property name="subclass"></property> <property name="subclass"></property>
<property name="toolbar_pane">0</property> <property name="toolbar_pane">0</property>
<property name="tooltip"></property> <property name="tooltip"></property>
@ -161,11 +161,11 @@
<event name="OnRightUp"></event> <event name="OnRightUp"></event>
<event name="OnSetFocus"></event> <event name="OnSetFocus"></event>
<event name="OnSize"></event> <event name="OnSize"></event>
<event name="OnTreeBeginDrag"></event> <event name="OnTreeBeginDrag">onTreeBeginDrag</event>
<event name="OnTreeBeginLabelEdit">onTreeBeginLabelEdit</event> <event name="OnTreeBeginLabelEdit">onTreeBeginLabelEdit</event>
<event name="OnTreeBeginRDrag"></event> <event name="OnTreeBeginRDrag"></event>
<event name="OnTreeDeleteItem"></event> <event name="OnTreeDeleteItem">onTreeDeleteItem</event>
<event name="OnTreeEndDrag"></event> <event name="OnTreeEndDrag">onTreeEndDrag</event>
<event name="OnTreeEndLabelEdit">onTreeEndLabelEdit</event> <event name="OnTreeEndLabelEdit">onTreeEndLabelEdit</event>
<event name="OnTreeGetInfo"></event> <event name="OnTreeGetInfo"></event>
<event name="OnTreeItemActivated">onTreeActivate</event> <event name="OnTreeItemActivated">onTreeActivate</event>
@ -173,7 +173,7 @@
<event name="OnTreeItemCollapsing"></event> <event name="OnTreeItemCollapsing"></event>
<event name="OnTreeItemExpanded">onTreeExpanded</event> <event name="OnTreeItemExpanded">onTreeExpanded</event>
<event name="OnTreeItemExpanding"></event> <event name="OnTreeItemExpanding"></event>
<event name="OnTreeItemGetTooltip"></event> <event name="OnTreeItemGetTooltip">onTreeItemGetTooltip</event>
<event name="OnTreeItemMenu">onTreeItemMenu</event> <event name="OnTreeItemMenu">onTreeItemMenu</event>
<event name="OnTreeItemMiddleClick"></event> <event name="OnTreeItemMiddleClick"></event>
<event name="OnTreeItemRightClick"></event> <event name="OnTreeItemRightClick"></event>

View File

@ -50,11 +50,17 @@ class BookmarkPanel : public wxPanel
wxTimer m_updateTimer; wxTimer m_updateTimer;
// Virtual event handlers, overide them in your derived class // Virtual event handlers, overide them in your derived class
virtual void onEnterWindow( wxMouseEvent& event ) { event.Skip(); }
virtual void onLeaveWindow( wxMouseEvent& event ) { event.Skip(); }
virtual void onTreeBeginDrag( wxTreeEvent& event ) { event.Skip(); }
virtual void onTreeBeginLabelEdit( wxTreeEvent& event ) { event.Skip(); } virtual void onTreeBeginLabelEdit( wxTreeEvent& event ) { event.Skip(); }
virtual void onTreeDeleteItem( wxTreeEvent& event ) { event.Skip(); }
virtual void onTreeEndDrag( wxTreeEvent& event ) { event.Skip(); }
virtual void onTreeEndLabelEdit( wxTreeEvent& event ) { event.Skip(); } virtual void onTreeEndLabelEdit( wxTreeEvent& event ) { event.Skip(); }
virtual void onTreeActivate( wxTreeEvent& event ) { event.Skip(); } virtual void onTreeActivate( wxTreeEvent& event ) { event.Skip(); }
virtual void onTreeCollapse( wxTreeEvent& event ) { event.Skip(); } virtual void onTreeCollapse( wxTreeEvent& event ) { event.Skip(); }
virtual void onTreeExpanded( wxTreeEvent& event ) { event.Skip(); } virtual void onTreeExpanded( wxTreeEvent& event ) { event.Skip(); }
virtual void onTreeItemGetTooltip( wxTreeEvent& event ) { event.Skip(); }
virtual void onTreeItemMenu( wxTreeEvent& event ) { event.Skip(); } virtual void onTreeItemMenu( wxTreeEvent& event ) { event.Skip(); }
virtual void onTreeSelect( wxTreeEvent& event ) { event.Skip(); } virtual void onTreeSelect( wxTreeEvent& event ) { event.Skip(); }
virtual void onTreeSelectChanging( wxTreeEvent& event ) { event.Skip(); } virtual void onTreeSelectChanging( wxTreeEvent& event ) { event.Skip(); }

View File

@ -14,16 +14,22 @@ BookmarkView::BookmarkView( wxWindow* parent, wxWindowID id, const wxPoint& pos,
recentBranch = m_treeView->AppendItem(rootBranch, "Recents"); recentBranch = m_treeView->AppendItem(rootBranch, "Recents");
doUpdateActive.store(true); doUpdateActive.store(true);
doUpdateBookmarks.store(true);
activeSel = nullptr; activeSel = nullptr;
recentSel = nullptr; recentSel = nullptr;
bookmarksInitialized = false; dragItem = nullptr;
dragItemId = nullptr;
hideProps(); hideProps();
m_propPanel->Hide(); m_propPanel->Hide();
m_updateTimer.Start(500); m_updateTimer.Start(500);
// m_treeView->SetDropEffectAboveItem();
mouseInView.store(false);
} }
void BookmarkView::onUpdateTimer( wxTimerEvent& event ) { void BookmarkView::onUpdateTimer( wxTimerEvent& event ) {
if (doUpdateActive.load()) { if (doUpdateActive.load()) {
doUpdateActiveList(); doUpdateActiveList();
@ -39,6 +45,7 @@ void BookmarkView::onUpdateTimer( wxTimerEvent& event ) {
} }
} }
void BookmarkView::updateTheme() { void BookmarkView::updateTheme() {
wxColour bgColor(ThemeMgr::mgr.currentTheme->generalBackground); wxColour bgColor(ThemeMgr::mgr.currentTheme->generalBackground);
wxColour textColor(ThemeMgr::mgr.currentTheme->text); wxColour textColor(ThemeMgr::mgr.currentTheme->text);
@ -69,10 +76,12 @@ void BookmarkView::updateActiveList() {
doUpdateActive.store(true); doUpdateActive.store(true);
} }
void BookmarkView::updateBookmarks() { void BookmarkView::updateBookmarks() {
doUpdateBookmarks.store(true); doUpdateBookmarks.store(true);
} }
void BookmarkView::updateBookmarks(std::string group) { void BookmarkView::updateBookmarks(std::string group) {
doUpdateBookmarkGroup.insert(group); doUpdateBookmarkGroup.insert(group);
doUpdateBookmarks.store(true); doUpdateBookmarks.store(true);
@ -80,7 +89,6 @@ void BookmarkView::updateBookmarks(std::string group) {
wxTreeItemId BookmarkView::refreshBookmarks() { wxTreeItemId BookmarkView::refreshBookmarks() {
// if (!bookmarksInitialized) {
groupNames = wxGetApp().getBookmarkMgr().getGroups(); groupNames = wxGetApp().getBookmarkMgr().getGroups();
if (!groupNames.size()) { if (!groupNames.size()) {
wxGetApp().getBookmarkMgr().getGroup("Ungrouped"); wxGetApp().getBookmarkMgr().getGroup("Ungrouped");
@ -119,10 +127,9 @@ wxTreeItemId BookmarkView::refreshBookmarks() {
} }
return bmSelFound; return bmSelFound;
// bookmarksInitialized = true;
// }
} }
void BookmarkView::doUpdateActiveList() { void BookmarkView::doUpdateActiveList() {
std::vector<DemodulatorInstance *> &demods = wxGetApp().getDemodMgr().getDemodulators(); std::vector<DemodulatorInstance *> &demods = wxGetApp().getDemodMgr().getDemodulators();
@ -171,19 +178,36 @@ void BookmarkView::doUpdateActiveList() {
if (selItem != nullptr) { if (selItem != nullptr) {
m_treeView->SelectItem(selItem); m_treeView->SelectItem(selItem);
} }
m_treeView->Enable();
m_treeView->ExpandAll();
} }
void BookmarkView::onTreeBeginLabelEdit( wxTreeEvent& event ) { void BookmarkView::onTreeBeginLabelEdit( wxTreeEvent& event ) {
event.Skip(); TreeViewItem* tvi = dynamic_cast<TreeViewItem*>(m_treeView->GetItemData(event.GetItem()));
if (!tvi) {
event.Veto();
return;
} }
if (tvi->type == TreeViewItem::TREEVIEW_ITEM_TYPE_ACTIVE) {
event.Allow();
} else if (tvi->type == TreeViewItem::TREEVIEW_ITEM_TYPE_RECENT) {
event.Veto();
} else if (tvi->type == TreeViewItem::TREEVIEW_ITEM_TYPE_BOOKMARK) {
event.Allow();
} else if (tvi->type == TreeViewItem::TREEVIEW_ITEM_TYPE_GROUP) {
event.Allow();
} else {
event.Veto();
}
}
void BookmarkView::onTreeEndLabelEdit( wxTreeEvent& event ) { void BookmarkView::onTreeEndLabelEdit( wxTreeEvent& event ) {
event.Skip(); event.Skip();
} }
void BookmarkView::onTreeActivate( wxTreeEvent& event ) { void BookmarkView::onTreeActivate( wxTreeEvent& event ) {
if (recentSel) { if (recentSel) {
activateBookmark(recentSel); activateBookmark(recentSel);
@ -193,14 +217,17 @@ void BookmarkView::onTreeActivate( wxTreeEvent& event ) {
} }
} }
void BookmarkView::onTreeCollapse( wxTreeEvent& event ) { void BookmarkView::onTreeCollapse( wxTreeEvent& event ) {
event.Skip(); event.Skip();
} }
void BookmarkView::onTreeExpanded( wxTreeEvent& event ) { void BookmarkView::onTreeExpanded( wxTreeEvent& event ) {
event.Skip(); event.Skip();
} }
void BookmarkView::onTreeItemMenu( wxTreeEvent& event ) { void BookmarkView::onTreeItemMenu( wxTreeEvent& event ) {
if (m_treeView->GetSelection() == bookmarkBranch) { if (m_treeView->GetSelection() == bookmarkBranch) {
wxMenu menu; wxMenu menu;
@ -210,6 +237,7 @@ void BookmarkView::onTreeItemMenu( wxTreeEvent& event ) {
} }
} }
void BookmarkView::onMenuItem(wxCommandEvent& event) { void BookmarkView::onMenuItem(wxCommandEvent& event) {
if (event.GetId() == wxCONTEXT_ADD_GROUP_ID) { if (event.GetId() == wxCONTEXT_ADD_GROUP_ID) {
wxString stringVal = wxGetTextFromUser("Enter Group Name", "Add Group", ""); wxString stringVal = wxGetTextFromUser("Enter Group Name", "Add Group", "");
@ -221,6 +249,11 @@ void BookmarkView::onMenuItem(wxCommandEvent& event) {
} }
bool BookmarkView::isMouseInView() {
return mouseInView.load();
}
void BookmarkView::hideProps() { void BookmarkView::hideProps() {
m_frequencyLabel->Hide(); m_frequencyLabel->Hide();
m_frequencyVal->Hide(); m_frequencyVal->Hide();
@ -239,6 +272,7 @@ void BookmarkView::hideProps() {
m_removeButton->Hide(); m_removeButton->Hide();
} }
void BookmarkView::activeSelection(DemodulatorInstance *dsel) { void BookmarkView::activeSelection(DemodulatorInstance *dsel) {
activeSel = dsel; activeSel = dsel;
recentSel = nullptr; recentSel = nullptr;
@ -268,6 +302,7 @@ void BookmarkView::activeSelection(DemodulatorInstance *dsel) {
this->Layout(); this->Layout();
} }
void BookmarkView::activateBookmark(BookmarkEntry *bmEnt) { void BookmarkView::activateBookmark(BookmarkEntry *bmEnt) {
DemodulatorInstance *newDemod = wxGetApp().getDemodMgr().loadInstance(bmEnt->node); DemodulatorInstance *newDemod = wxGetApp().getDemodMgr().loadInstance(bmEnt->node);
newDemod->run(); newDemod->run();
@ -280,6 +315,7 @@ void BookmarkView::activateBookmark(BookmarkEntry *bmEnt) {
doUpdateActiveList(); doUpdateActiveList();
} }
void BookmarkView::bookmarkSelection(BookmarkEntry *bmSel) { void BookmarkView::bookmarkSelection(BookmarkEntry *bmSel) {
bookmarkSel = bmSel; bookmarkSel = bmSel;
recentSel = nullptr; recentSel = nullptr;
@ -343,6 +379,7 @@ void BookmarkView::recentSelection(BookmarkEntry *bmSel) {
this->Layout(); this->Layout();
} }
void BookmarkView::onTreeSelect( wxTreeEvent& event ) { void BookmarkView::onTreeSelect( wxTreeEvent& event ) {
TreeViewItem* tvi = dynamic_cast<TreeViewItem*>(m_treeView->GetItemData(event.GetItem())); TreeViewItem* tvi = dynamic_cast<TreeViewItem*>(m_treeView->GetItemData(event.GetItem()));
@ -367,14 +404,17 @@ void BookmarkView::onTreeSelect( wxTreeEvent& event ) {
} }
} }
void BookmarkView::onTreeSelectChanging( wxTreeEvent& event ) { void BookmarkView::onTreeSelectChanging( wxTreeEvent& event ) {
event.Skip(); event.Skip();
} }
void BookmarkView::onLabelText( wxCommandEvent& event ) { void BookmarkView::onLabelText( wxCommandEvent& event ) {
event.Skip(); event.Skip();
} }
void BookmarkView::onDoubleClickFreq( wxMouseEvent& event ) { void BookmarkView::onDoubleClickFreq( wxMouseEvent& event ) {
if (activeSel) { if (activeSel) {
wxGetApp().getDemodMgr().setActiveDemodulator(activeSel, false); wxGetApp().getDemodMgr().setActiveDemodulator(activeSel, false);
@ -382,6 +422,7 @@ void BookmarkView::onDoubleClickFreq( wxMouseEvent& event ) {
} }
} }
void BookmarkView::onDoubleClickBandwidth( wxMouseEvent& event ) { void BookmarkView::onDoubleClickBandwidth( wxMouseEvent& event ) {
if (activeSel) { if (activeSel) {
wxGetApp().getDemodMgr().setActiveDemodulator(activeSel, false); wxGetApp().getDemodMgr().setActiveDemodulator(activeSel, false);
@ -389,6 +430,7 @@ void BookmarkView::onDoubleClickBandwidth( wxMouseEvent& event ) {
} }
} }
void BookmarkView::onBookmark( wxCommandEvent& event ) { void BookmarkView::onBookmark( wxCommandEvent& event ) {
if (activeSel) { if (activeSel) {
wxGetApp().getBookmarkMgr().addBookmark("Ungrouped", activeSel); wxGetApp().getBookmarkMgr().addBookmark("Ungrouped", activeSel);
@ -396,6 +438,7 @@ void BookmarkView::onBookmark( wxCommandEvent& event ) {
} }
} }
void BookmarkView::onActivate( wxCommandEvent& event ) { void BookmarkView::onActivate( wxCommandEvent& event ) {
if (recentSel) { if (recentSel) {
activateBookmark(recentSel); activateBookmark(recentSel);
@ -405,6 +448,7 @@ void BookmarkView::onActivate( wxCommandEvent& event ) {
} }
} }
void BookmarkView::onRemove( wxCommandEvent& event ) { void BookmarkView::onRemove( wxCommandEvent& event ) {
if (activeSel != nullptr) { if (activeSel != nullptr) {
wxGetApp().getDemodMgr().setActiveDemodulator(nullptr, false); wxGetApp().getDemodMgr().setActiveDemodulator(nullptr, false);
@ -414,3 +458,125 @@ void BookmarkView::onRemove( wxCommandEvent& event ) {
} }
} }
void BookmarkView::onTreeBeginDrag( wxTreeEvent& event ) {
TreeViewItem* tvi = dynamic_cast<TreeViewItem*>(m_treeView->GetItemData(event.GetItem()));
dragItem = nullptr;
dragItemId = nullptr;
if (!tvi) {
event.Veto();
return;
}
bool bAllow = false;
std::string dragItemName;
if (tvi->type == TreeViewItem::TREEVIEW_ITEM_TYPE_ACTIVE) {
bAllow = true;
dragItemName = tvi->demod->getLabel();
} else if (tvi->type == TreeViewItem::TREEVIEW_ITEM_TYPE_RECENT) {
bAllow = true;
dragItemName = tvi->bookmarkEnt->label;
} else if (tvi->type == TreeViewItem::TREEVIEW_ITEM_TYPE_BOOKMARK) {
bAllow = true;
dragItemName = tvi->bookmarkEnt->label;
}
if (bAllow) {
wxColour bgColor(ThemeMgr::mgr.currentTheme->generalBackground);
wxColour textColor(ThemeMgr::mgr.currentTheme->text);
m_treeView->SetBackgroundColour(textColor);
m_treeView->SetForegroundColour(bgColor);
m_treeView->SetToolTip("Dragging " + dragItemName);
dragItem = tvi;
dragItemId = event.GetItem();
event.Allow();
} else {
event.Veto();
}
}
void BookmarkView::onTreeEndDrag( wxTreeEvent& event ) {
wxColour bgColor(ThemeMgr::mgr.currentTheme->generalBackground);
wxColour textColor(ThemeMgr::mgr.currentTheme->text);
m_treeView->SetBackgroundColour(bgColor);
m_treeView->SetForegroundColour(textColor);
m_treeView->UnsetToolTip();
if (!event.GetItem()) {
event.Veto();
return;
}
TreeViewItem* tvi = dynamic_cast<TreeViewItem*>(m_treeView->GetItemData(event.GetItem()));
if (!tvi) {
if (event.GetItem() == bookmarkBranch) {
if (dragItem && dragItem->type == TreeViewItem::TREEVIEW_ITEM_TYPE_ACTIVE) {
wxGetApp().getBookmarkMgr().addBookmark("Ungrouped", dragItem->demod);
wxGetApp().getBookmarkMgr().updateBookmarks();
}else if (dragItem && dragItem->type == TreeViewItem::TREEVIEW_ITEM_TYPE_RECENT) {
wxGetApp().getBookmarkMgr().removeRecent(dragItem->bookmarkEnt);
wxGetApp().getBookmarkMgr().addBookmark("Ungrouped", dragItem->bookmarkEnt);
m_treeView->Delete(dragItemId);
wxGetApp().getBookmarkMgr().updateBookmarks();
wxGetApp().getBookmarkMgr().updateActiveList();
}
}
return;
}
if (tvi->type == TreeViewItem::TREEVIEW_ITEM_TYPE_GROUP) {
if (dragItem && dragItem->type == TreeViewItem::TREEVIEW_ITEM_TYPE_ACTIVE) { // Active -> Group Item
wxGetApp().getBookmarkMgr().addBookmark(tvi->groupName, dragItem->demod);
wxGetApp().getBookmarkMgr().updateBookmarks();
} else if (dragItem && dragItem->type == TreeViewItem::TREEVIEW_ITEM_TYPE_RECENT) { // Recent -> Group Item
wxGetApp().getBookmarkMgr().removeRecent(dragItem->bookmarkEnt);
wxGetApp().getBookmarkMgr().addBookmark(tvi->groupName, dragItem->bookmarkEnt);
m_treeView->Delete(dragItemId);
wxGetApp().getBookmarkMgr().updateBookmarks();
wxGetApp().getBookmarkMgr().updateActiveList();
}
} else if (tvi->type == TreeViewItem::TREEVIEW_ITEM_TYPE_BOOKMARK) {
if (dragItem && dragItem->type == TreeViewItem::TREEVIEW_ITEM_TYPE_ACTIVE) { // Active -> Same Group
wxGetApp().getBookmarkMgr().addBookmark(tvi->groupName, dragItem->demod);
wxGetApp().getBookmarkMgr().updateBookmarks();
} else if (dragItem && dragItem->type == TreeViewItem::TREEVIEW_ITEM_TYPE_RECENT) { // Recent -> Same Group
wxGetApp().getBookmarkMgr().removeRecent(dragItem->bookmarkEnt);
wxGetApp().getBookmarkMgr().addBookmark(tvi->groupName, dragItem->bookmarkEnt);
m_treeView->Delete(dragItemId);
wxGetApp().getBookmarkMgr().updateBookmarks();
wxGetApp().getBookmarkMgr().updateActiveList();
}
}
}
void BookmarkView::onTreeDeleteItem( wxTreeEvent& event ) {
event.Skip();
}
void BookmarkView::onTreeItemGetTooltip( wxTreeEvent& event ) {
event.Skip();
}
void BookmarkView::onEnterWindow( wxMouseEvent& event ) {
mouseInView.store(true);
}
void BookmarkView::onLeaveWindow( wxMouseEvent& event ) {
mouseInView.store(false);
}

View File

@ -39,6 +39,8 @@ public:
wxTreeItemId refreshBookmarks(); wxTreeItemId refreshBookmarks();
void updateTheme(); void updateTheme();
void onMenuItem(wxCommandEvent& event); void onMenuItem(wxCommandEvent& event);
bool isMouseInView();
protected: protected:
@ -61,16 +63,26 @@ protected:
void onBookmark( wxCommandEvent& event ); void onBookmark( wxCommandEvent& event );
void onActivate( wxCommandEvent& event ); void onActivate( wxCommandEvent& event );
void onRemove( wxCommandEvent& event ); void onRemove( wxCommandEvent& event );
void onTreeBeginDrag( wxTreeEvent& event );
void onTreeEndDrag( wxTreeEvent& event );
void onTreeDeleteItem( wxTreeEvent& event );
void onTreeItemGetTooltip( wxTreeEvent& event );
void onEnterWindow( wxMouseEvent& event );
void onLeaveWindow( wxMouseEvent& event );
std::atomic_bool mouseInView;
wxTreeItemId rootBranch, activeBranch, bookmarkBranch, recentBranch; wxTreeItemId rootBranch, activeBranch, bookmarkBranch, recentBranch;
TreeViewItem *dragItem;
wxTreeItemId dragItemId;
// Bookmarks // Bookmarks
std::atomic_bool doUpdateBookmarks; std::atomic_bool doUpdateBookmarks;
std::set< std::string > doUpdateBookmarkGroup; std::set< std::string > doUpdateBookmarkGroup;
BookmarkNames groupNames; BookmarkNames groupNames;
std::map<std::string, wxTreeItemId> groups; std::map<std::string, wxTreeItemId> groups;
BookmarkEntry *bookmarkSel; BookmarkEntry *bookmarkSel;
bool bookmarksInitialized;
// Active // Active