mirror of
https://github.com/cjcliffe/CubicSDR.git
synced 2024-11-23 12:18:37 -05:00
Resolve 'Ungrouped' logic -- replace button with choice list for bookmarking.
This commit is contained in:
parent
2f6e83c55e
commit
73954055e6
@ -75,6 +75,12 @@ BookmarkNames BookmarkMgr::getGroups() {
|
|||||||
return results;
|
return results;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void BookmarkMgr::getGroups(wxArrayString &arr) {
|
||||||
|
for (BookmarkMap::iterator i = bmData.begin(); i!= bmData.end(); ++i) {
|
||||||
|
arr.push_back(i->first);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void BookmarkMgr::updateActiveList() {
|
void BookmarkMgr::updateActiveList() {
|
||||||
BookmarkView *bmv = wxGetApp().getAppFrame()->getBookmarkView();
|
BookmarkView *bmv = wxGetApp().getAppFrame()->getBookmarkView();
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <set>
|
#include <set>
|
||||||
|
#include <wx/arrstr.h>
|
||||||
|
|
||||||
#include "DemodulatorInstance.h"
|
#include "DemodulatorInstance.h"
|
||||||
|
|
||||||
@ -48,6 +49,7 @@ public:
|
|||||||
|
|
||||||
BookmarkGroup getGroup(std::string group);
|
BookmarkGroup getGroup(std::string group);
|
||||||
BookmarkNames getGroups();
|
BookmarkNames getGroups();
|
||||||
|
void getGroups(wxArrayString &arr);
|
||||||
|
|
||||||
void updateActiveList();
|
void updateActiveList();
|
||||||
void updateBookmarks();
|
void updateBookmarks();
|
||||||
|
@ -4,8 +4,12 @@
|
|||||||
#include <wx/menu.h>
|
#include <wx/menu.h>
|
||||||
#include <wx/textdlg.h>
|
#include <wx/textdlg.h>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
#define wxCONTEXT_ADD_GROUP_ID 1000
|
#define wxCONTEXT_ADD_GROUP_ID 1000
|
||||||
|
|
||||||
|
#define BOOKMARK_VIEW_CHOICE_DEFAULT "Bookmark.."
|
||||||
|
#define BOOKMARK_VIEW_CHOICE_NEW "(New Group..)"
|
||||||
|
|
||||||
BookmarkView::BookmarkView( wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style) : BookmarkPanel(parent, id, pos, size, style) {
|
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");
|
rootBranch = m_treeView->AddRoot("Root");
|
||||||
@ -15,6 +19,7 @@ BookmarkView::BookmarkView( wxWindow* parent, wxWindowID id, const wxPoint& pos,
|
|||||||
|
|
||||||
doUpdateActive.store(true);
|
doUpdateActive.store(true);
|
||||||
doUpdateBookmarks.store(true);
|
doUpdateBookmarks.store(true);
|
||||||
|
bookmarkChoice = nullptr;
|
||||||
activeSel = nullptr;
|
activeSel = nullptr;
|
||||||
recentSel = nullptr;
|
recentSel = nullptr;
|
||||||
dragItem = nullptr;
|
dragItem = nullptr;
|
||||||
@ -89,7 +94,6 @@ void BookmarkView::updateBookmarks(std::string group) {
|
|||||||
wxTreeItemId BookmarkView::refreshBookmarks() {
|
wxTreeItemId BookmarkView::refreshBookmarks() {
|
||||||
groupNames = wxGetApp().getBookmarkMgr().getGroups();
|
groupNames = wxGetApp().getBookmarkMgr().getGroups();
|
||||||
if (!groupNames.size()) {
|
if (!groupNames.size()) {
|
||||||
wxGetApp().getBookmarkMgr().getGroup("Ungrouped");
|
|
||||||
groupNames = wxGetApp().getBookmarkMgr().getGroups();
|
groupNames = wxGetApp().getBookmarkMgr().getGroups();
|
||||||
}
|
}
|
||||||
if (doUpdateBookmarkGroup.size()) { // Nothing for the moment..
|
if (doUpdateBookmarkGroup.size()) { // Nothing for the moment..
|
||||||
@ -280,6 +284,7 @@ void BookmarkView::showProps() {
|
|||||||
void BookmarkView::clearButtons() {
|
void BookmarkView::clearButtons() {
|
||||||
m_buttonPanel->Hide();
|
m_buttonPanel->Hide();
|
||||||
m_buttonPanel->DestroyChildren();
|
m_buttonPanel->DestroyChildren();
|
||||||
|
bookmarkChoice = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void BookmarkView::showButtons() {
|
void BookmarkView::showButtons() {
|
||||||
@ -295,7 +300,7 @@ void BookmarkView::refreshLayout() {
|
|||||||
|
|
||||||
wxButton *BookmarkView::makeButton(wxWindow *parent, std::string labelVal, wxObjectEventFunction handler) {
|
wxButton *BookmarkView::makeButton(wxWindow *parent, std::string labelVal, wxObjectEventFunction handler) {
|
||||||
wxButton *nButton = new wxButton( m_buttonPanel, wxID_ANY, labelVal);
|
wxButton *nButton = new wxButton( m_buttonPanel, wxID_ANY, labelVal);
|
||||||
nButton->Connect( wxEVT_COMMAND_BUTTON_CLICKED, handler, NULL, this);
|
nButton->Connect( wxEVT_COMMAND_BUTTON_CLICKED, handler, nullptr, this);
|
||||||
nButton->SetBackgroundColour(ThemeMgr::mgr.currentTheme->generalBackground);
|
nButton->SetBackgroundColour(ThemeMgr::mgr.currentTheme->generalBackground);
|
||||||
return nButton;
|
return nButton;
|
||||||
}
|
}
|
||||||
@ -307,6 +312,60 @@ wxButton *BookmarkView::addButton(wxWindow *parent, std::string labelVal, wxObje
|
|||||||
return nButton;
|
return nButton;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void BookmarkView::updateBookmarkChoices() {
|
||||||
|
if (!bookmarkChoices.empty()) {
|
||||||
|
bookmarkChoices.erase(bookmarkChoices.begin(),bookmarkChoices.end());
|
||||||
|
}
|
||||||
|
bookmarkChoices.push_back(BOOKMARK_VIEW_CHOICE_DEFAULT);
|
||||||
|
wxGetApp().getBookmarkMgr().getGroups(bookmarkChoices);
|
||||||
|
bookmarkChoices.push_back(BOOKMARK_VIEW_CHOICE_NEW);
|
||||||
|
}
|
||||||
|
|
||||||
|
void BookmarkView::addBookmarkChoice(wxWindow *parent) {
|
||||||
|
updateBookmarkChoices();
|
||||||
|
bookmarkChoice = new wxChoice(parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, bookmarkChoices, wxALL|wxEXPAND, wxDefaultValidator, "Bookmark");
|
||||||
|
bookmarkChoice->Connect( wxEVT_COMMAND_CHOICE_SELECTED, (wxObjectEventFunction)&BookmarkView::onBookmarkChoice, nullptr, this);
|
||||||
|
parent->GetSizer()->Add(bookmarkChoice, 0, wxALL | wxEXPAND);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void BookmarkView::onBookmarkChoice( wxCommandEvent &event ) {
|
||||||
|
|
||||||
|
int numSel = bookmarkChoice->GetCount();
|
||||||
|
int sel = bookmarkChoice->GetSelection();
|
||||||
|
|
||||||
|
if (sel == 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
wxString stringVal = "";
|
||||||
|
|
||||||
|
if (sel == (numSel-1)) {
|
||||||
|
stringVal = wxGetTextFromUser("Enter Group Name", "Add Group", "");
|
||||||
|
} else {
|
||||||
|
stringVal = bookmarkChoices[sel];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (stringVal == "") {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
groupSel = stringVal;
|
||||||
|
|
||||||
|
if (activeSel) {
|
||||||
|
wxGetApp().getBookmarkMgr().addBookmark(groupSel, activeSel);
|
||||||
|
wxGetApp().getBookmarkMgr().updateBookmarks();
|
||||||
|
activeSelection(activeSel);
|
||||||
|
}
|
||||||
|
if (recentSel) {
|
||||||
|
wxGetApp().getBookmarkMgr().removeRecent(recentSel);
|
||||||
|
wxGetApp().getBookmarkMgr().addBookmark(groupSel, recentSel);
|
||||||
|
wxGetApp().getBookmarkMgr().updateBookmarks();
|
||||||
|
wxGetApp().getBookmarkMgr().updateActiveList();
|
||||||
|
bookmarkSelection(recentSel);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void BookmarkView::activeSelection(DemodulatorInstance *dsel) {
|
void BookmarkView::activeSelection(DemodulatorInstance *dsel) {
|
||||||
activeSel = dsel;
|
activeSel = dsel;
|
||||||
@ -332,8 +391,8 @@ void BookmarkView::activeSelection(DemodulatorInstance *dsel) {
|
|||||||
m_labelLabel->Show();
|
m_labelLabel->Show();
|
||||||
|
|
||||||
clearButtons();
|
clearButtons();
|
||||||
|
|
||||||
addButton(m_buttonPanel, "Bookmark Active", wxCommandEventHandler( BookmarkView::onBookmarkActive ));
|
addBookmarkChoice(m_buttonPanel);
|
||||||
addButton(m_buttonPanel, "Remove Active", wxCommandEventHandler( BookmarkView::onRemoveActive ));
|
addButton(m_buttonPanel, "Remove Active", wxCommandEventHandler( BookmarkView::onRemoveActive ));
|
||||||
|
|
||||||
showProps();
|
showProps();
|
||||||
@ -417,7 +476,7 @@ void BookmarkView::recentSelection(BookmarkEntry *bmSel) {
|
|||||||
clearButtons();
|
clearButtons();
|
||||||
|
|
||||||
addButton(m_buttonPanel, "Activate Recent", wxCommandEventHandler( BookmarkView::onActivateRecent ));
|
addButton(m_buttonPanel, "Activate Recent", wxCommandEventHandler( BookmarkView::onActivateRecent ));
|
||||||
addButton(m_buttonPanel, "Bookmark Recent", wxCommandEventHandler( BookmarkView::onBookmarkRecent ));
|
addBookmarkChoice(m_buttonPanel);
|
||||||
|
|
||||||
showProps();
|
showProps();
|
||||||
showButtons();
|
showButtons();
|
||||||
@ -531,23 +590,6 @@ void BookmarkView::onDoubleClickBandwidth( wxMouseEvent& event ) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void BookmarkView::onBookmarkActive( wxCommandEvent& event ) {
|
|
||||||
if (activeSel) {
|
|
||||||
wxGetApp().getBookmarkMgr().addBookmark("Ungrouped", activeSel);
|
|
||||||
wxGetApp().getBookmarkMgr().updateBookmarks();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void BookmarkView::onBookmarkRecent( wxCommandEvent& event ) {
|
|
||||||
if (recentSel) {
|
|
||||||
wxGetApp().getBookmarkMgr().removeRecent(recentSel);
|
|
||||||
wxGetApp().getBookmarkMgr().addBookmark("Ungrouped", recentSel);
|
|
||||||
wxGetApp().getBookmarkMgr().updateBookmarks();
|
|
||||||
wxGetApp().getBookmarkMgr().updateActiveList();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void BookmarkView::onRemoveActive( wxCommandEvent& event ) {
|
void BookmarkView::onRemoveActive( wxCommandEvent& event ) {
|
||||||
if (activeSel != nullptr) {
|
if (activeSel != nullptr) {
|
||||||
wxGetApp().getDemodMgr().setActiveDemodulator(nullptr, false);
|
wxGetApp().getDemodMgr().setActiveDemodulator(nullptr, false);
|
||||||
@ -668,7 +710,7 @@ void BookmarkView::onTreeEndDrag( wxTreeEvent& event ) {
|
|||||||
if (dragItem && dragItem->type == TreeViewItem::TREEVIEW_ITEM_TYPE_ACTIVE) {
|
if (dragItem && dragItem->type == TreeViewItem::TREEVIEW_ITEM_TYPE_ACTIVE) {
|
||||||
wxGetApp().getBookmarkMgr().addBookmark("Ungrouped", dragItem->demod);
|
wxGetApp().getBookmarkMgr().addBookmark("Ungrouped", dragItem->demod);
|
||||||
wxGetApp().getBookmarkMgr().updateBookmarks();
|
wxGetApp().getBookmarkMgr().updateBookmarks();
|
||||||
}else if (dragItem && dragItem->type == TreeViewItem::TREEVIEW_ITEM_TYPE_RECENT) {
|
} else if (dragItem && dragItem->type == TreeViewItem::TREEVIEW_ITEM_TYPE_RECENT) {
|
||||||
wxGetApp().getBookmarkMgr().removeRecent(dragItem->bookmarkEnt);
|
wxGetApp().getBookmarkMgr().removeRecent(dragItem->bookmarkEnt);
|
||||||
wxGetApp().getBookmarkMgr().addBookmark("Ungrouped", dragItem->bookmarkEnt);
|
wxGetApp().getBookmarkMgr().addBookmark("Ungrouped", dragItem->bookmarkEnt);
|
||||||
m_treeView->Delete(dragItemId);
|
m_treeView->Delete(dragItemId);
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "BookmarkPanel.h"
|
#include "BookmarkPanel.h"
|
||||||
|
|
||||||
#include "BookmarkMgr.h"
|
#include "BookmarkMgr.h"
|
||||||
|
#include "wx/choice.h"
|
||||||
|
|
||||||
class TreeViewItem : public wxTreeItemData {
|
class TreeViewItem : public wxTreeItemData {
|
||||||
public:
|
public:
|
||||||
@ -81,9 +81,10 @@ protected:
|
|||||||
wxButton *makeButton(wxWindow *parent, std::string labelVal, wxObjectEventFunction handler);
|
wxButton *makeButton(wxWindow *parent, std::string labelVal, wxObjectEventFunction handler);
|
||||||
wxButton *addButton(wxWindow *parent, std::string labelVal, wxObjectEventFunction handler);
|
wxButton *addButton(wxWindow *parent, std::string labelVal, wxObjectEventFunction handler);
|
||||||
|
|
||||||
void onBookmarkActive( wxCommandEvent& event );
|
void updateBookmarkChoices();
|
||||||
void onBookmarkRecent( wxCommandEvent& event );
|
void addBookmarkChoice(wxWindow *parent);
|
||||||
|
void onBookmarkChoice( wxCommandEvent &event );
|
||||||
|
|
||||||
void onRemoveActive( wxCommandEvent& event );
|
void onRemoveActive( wxCommandEvent& event );
|
||||||
void onRemoveBookmark( wxCommandEvent& event );
|
void onRemoveBookmark( wxCommandEvent& event );
|
||||||
|
|
||||||
@ -109,7 +110,8 @@ protected:
|
|||||||
BookmarkNames groupNames;
|
BookmarkNames groupNames;
|
||||||
std::map<std::string, wxTreeItemId> groups;
|
std::map<std::string, wxTreeItemId> groups;
|
||||||
BookmarkEntry *bookmarkSel;
|
BookmarkEntry *bookmarkSel;
|
||||||
|
wxArrayString bookmarkChoices;
|
||||||
|
wxChoice *bookmarkChoice;
|
||||||
|
|
||||||
// Active
|
// Active
|
||||||
std::atomic_bool doUpdateActive;
|
std::atomic_bool doUpdateActive;
|
||||||
|
Loading…
Reference in New Issue
Block a user