Bookmarks: Add delete key handler, fix refresh issues, ensure active selection stays in view on refresh

This commit is contained in:
Charles J. Cliffe 2019-05-29 00:25:02 -04:00
parent 99ecbef373
commit e379cceeb2
5 changed files with 125 additions and 51 deletions

View File

@ -93,6 +93,7 @@ BookmarkPanel::BookmarkPanel( wxWindow* parent, wxWindowID id, const wxPoint& po
m_searchText->Connect( wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler( BookmarkPanel::onSearchText ), NULL, this );
m_clearSearchButton->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( BookmarkPanel::onClearSearch ), NULL, this );
m_treeView->Connect( wxEVT_ENTER_WINDOW, wxMouseEventHandler( BookmarkPanel::onEnterWindow ), NULL, this );
m_treeView->Connect( wxEVT_KEY_UP, wxKeyEventHandler( BookmarkPanel::onKeyUp ), NULL, this );
m_treeView->Connect( wxEVT_LEAVE_WINDOW, wxMouseEventHandler( BookmarkPanel::onLeaveWindow ), NULL, this );
m_treeView->Connect( wxEVT_MOTION, wxMouseEventHandler( BookmarkPanel::onMotion ), NULL, this );
m_treeView->Connect( wxEVT_COMMAND_TREE_BEGIN_DRAG, wxTreeEventHandler( BookmarkPanel::onTreeBeginDrag ), NULL, this );
@ -120,6 +121,7 @@ BookmarkPanel::~BookmarkPanel()
m_searchText->Disconnect( wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler( BookmarkPanel::onSearchText ), NULL, this );
m_clearSearchButton->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( BookmarkPanel::onClearSearch ), NULL, this );
m_treeView->Disconnect( wxEVT_ENTER_WINDOW, wxMouseEventHandler( BookmarkPanel::onEnterWindow ), NULL, this );
m_treeView->Disconnect( wxEVT_KEY_UP, wxKeyEventHandler( BookmarkPanel::onKeyUp ), NULL, this );
m_treeView->Disconnect( wxEVT_LEAVE_WINDOW, wxMouseEventHandler( BookmarkPanel::onLeaveWindow ), NULL, this );
m_treeView->Disconnect( wxEVT_MOTION, wxMouseEventHandler( BookmarkPanel::onMotion ), NULL, this );
m_treeView->Disconnect( wxEVT_COMMAND_TREE_BEGIN_DRAG, wxTreeEventHandler( BookmarkPanel::onTreeBeginDrag ), NULL, this );

View File

@ -27,7 +27,7 @@
<property name="ui_table">UI</property>
<property name="use_enum">0</property>
<property name="use_microsoft_bom">0</property>
<object class="Panel" expanded="1">
<object class="Panel" expanded="0">
<property name="aui_managed">0</property>
<property name="aui_manager_style">wxAUI_MGR_DEFAULT</property>
<property name="bg"></property>
@ -52,16 +52,16 @@
<event name="OnEnterWindow">onEnterWindow</event>
<event name="OnLeaveWindow">onLeaveWindow</event>
<event name="OnMotion">onMotion</event>
<object class="wxBoxSizer" expanded="1">
<object class="wxBoxSizer" expanded="0">
<property name="minimum_size"></property>
<property name="name">bSizer1</property>
<property name="orient">wxVERTICAL</property>
<property name="permission">none</property>
<object class="sizeritem" expanded="1">
<object class="sizeritem" expanded="0">
<property name="border">5</property>
<property name="flag">wxALL|wxEXPAND</property>
<property name="proportion">0</property>
<object class="wxTextCtrl" expanded="1">
<object class="wxTextCtrl" expanded="0">
<property name="BottomDockable">1</property>
<property name="LeftDockable">1</property>
<property name="RightDockable">1</property>
@ -123,11 +123,11 @@
<event name="OnText">onSearchText</event>
</object>
</object>
<object class="sizeritem" expanded="1">
<object class="sizeritem" expanded="0">
<property name="border">5</property>
<property name="flag">wxALL|wxEXPAND</property>
<property name="proportion">0</property>
<object class="wxButton" expanded="1">
<object class="wxButton" expanded="0">
<property name="BottomDockable">1</property>
<property name="LeftDockable">1</property>
<property name="RightDockable">1</property>
@ -196,11 +196,11 @@
<event name="OnButtonClick">onClearSearch</event>
</object>
</object>
<object class="sizeritem" expanded="1">
<object class="sizeritem" expanded="0">
<property name="border">5</property>
<property name="flag">wxEXPAND</property>
<property name="proportion">1</property>
<object class="wxTreeCtrl" expanded="1">
<object class="wxTreeCtrl" expanded="0">
<property name="BottomDockable">1</property>
<property name="LeftDockable">1</property>
<property name="RightDockable">1</property>
@ -253,6 +253,7 @@
<property name="window_name"></property>
<property name="window_style"></property>
<event name="OnEnterWindow">onEnterWindow</event>
<event name="OnKeyUp">onKeyUp</event>
<event name="OnLeaveWindow">onLeaveWindow</event>
<event name="OnMotion">onMotion</event>
<event name="OnTreeBeginDrag">onTreeBeginDrag</event>
@ -266,11 +267,11 @@
<event name="OnTreeSelChanging">onTreeSelectChanging</event>
</object>
</object>
<object class="sizeritem" expanded="1">
<object class="sizeritem" expanded="0">
<property name="border">5</property>
<property name="flag">wxEXPAND</property>
<property name="proportion">0</property>
<object class="wxStaticLine" expanded="1">
<object class="wxStaticLine" expanded="0">
<property name="BottomDockable">1</property>
<property name="LeftDockable">1</property>
<property name="RightDockable">1</property>
@ -324,11 +325,11 @@
<property name="window_style"></property>
</object>
</object>
<object class="sizeritem" expanded="1">
<object class="sizeritem" expanded="0">
<property name="border">5</property>
<property name="flag">wxALL|wxEXPAND</property>
<property name="proportion">0</property>
<object class="wxPanel" expanded="1">
<object class="wxPanel" expanded="0">
<property name="BottomDockable">1</property>
<property name="LeftDockable">1</property>
<property name="RightDockable">1</property>
@ -888,11 +889,11 @@
</object>
</object>
</object>
<object class="sizeritem" expanded="1">
<object class="sizeritem" expanded="0">
<property name="border">5</property>
<property name="flag">wxALL|wxEXPAND</property>
<property name="proportion">0</property>
<object class="wxPanel" expanded="1">
<object class="wxPanel" expanded="0">
<property name="BottomDockable">1</property>
<property name="LeftDockable">1</property>
<property name="RightDockable">1</property>
@ -952,7 +953,7 @@
</object>
</object>
</object>
<object class="wxTimer" expanded="1">
<object class="wxTimer" expanded="0">
<property name="enabled">0</property>
<property name="id">wxID_ANY</property>
<property name="name">m_updateTimer</property>

View File

@ -60,6 +60,7 @@ class BookmarkPanel : public wxPanel
virtual void onSearchTextFocus( wxMouseEvent& event ) { event.Skip(); }
virtual void onSearchText( wxCommandEvent& event ) { event.Skip(); }
virtual void onClearSearch( wxCommandEvent& event ) { event.Skip(); }
virtual void onKeyUp( wxKeyEvent& event ) { event.Skip(); }
virtual void onTreeBeginDrag( wxTreeEvent& event ) { event.Skip(); }
virtual void onTreeEndDrag( wxTreeEvent& event ) { event.Skip(); }
virtual void onTreeActivate( wxTreeEvent& event ) { event.Skip(); }

View File

@ -517,29 +517,73 @@ void BookmarkView::doUpdateActiveList() {
}
void BookmarkView::onKeyUp( wxKeyEvent& event ) {
// Check for active selection
wxTreeItemId itm = m_treeView->GetSelection();
if (itm == nullptr) {
event.Skip();
return;
}
// Create event to pass to appropriate function
wxTreeEvent treeEvent;
treeEvent.SetItem(itm);
// Pull TreeViewItem data
auto tvi = dynamic_cast<TreeViewItem*>(m_treeView->GetItemData(itm));
// Not selected?
if (tvi == nullptr) {
event.Skip();
return;
}
// Handlers
if (event.m_keyCode == WXK_DELETE || event.m_keyCode == WXK_NUMPAD_DELETE) {
if (tvi->type == TreeViewItem::TREEVIEW_ITEM_TYPE_ACTIVE) {
onRemoveActive(treeEvent);
} else if (tvi->type == TreeViewItem::TREEVIEW_ITEM_TYPE_RECENT) {
onRemoveRecent(treeEvent);
} else if (tvi->type == TreeViewItem::TREEVIEW_ITEM_TYPE_BOOKMARK) {
onRemoveBookmark(treeEvent);
} else if (tvi->type == TreeViewItem::TREEVIEW_ITEM_TYPE_RANGE) {
onRemoveRange(treeEvent);
} else if (tvi->type == TreeViewItem::TREEVIEW_ITEM_TYPE_GROUP) {
onRemoveGroup(treeEvent);
}
// TODO: keys for other actions?
}
}
void BookmarkView::onTreeActivate( wxTreeEvent& event ) {
wxTreeItemId itm = event.GetItem();
TreeViewItem* tvi = dynamic_cast<TreeViewItem*>(m_treeView->GetItemData(itm));
if (tvi) {
if (tvi->type == TreeViewItem::TREEVIEW_ITEM_TYPE_ACTIVE) {
if (!tvi->demod->isActive()) {
wxGetApp().setFrequency(tvi->demod->getFrequency());
nextDemod = tvi->demod;
wxGetApp().getDemodMgr().setActiveDemodulator(nextDemod, false);
}
} else if (tvi->type == TreeViewItem::TREEVIEW_ITEM_TYPE_RECENT) {
nextEnt = tvi->bookmarkEnt;
wxGetApp().getBookmarkMgr().removeRecent(tvi->bookmarkEnt);
if (tvi == nullptr) {
event.Skip();
return;
}
activateBookmark(tvi->bookmarkEnt);
} else if (tvi->type == TreeViewItem::TREEVIEW_ITEM_TYPE_BOOKMARK) {
activateBookmark(tvi->bookmarkEnt);
} else if (tvi->type == TreeViewItem::TREEVIEW_ITEM_TYPE_RANGE) {
activateRange(tvi->rangeEnt);
if (tvi->type == TreeViewItem::TREEVIEW_ITEM_TYPE_ACTIVE) {
if (!tvi->demod->isActive()) {
wxGetApp().setFrequency(tvi->demod->getFrequency());
nextDemod = tvi->demod;
wxGetApp().getDemodMgr().setActiveDemodulator(nextDemod, false);
}
} else if (tvi->type == TreeViewItem::TREEVIEW_ITEM_TYPE_RECENT) {
nextEnt = tvi->bookmarkEnt;
wxGetApp().getBookmarkMgr().removeRecent(tvi->bookmarkEnt);
activateBookmark(tvi->bookmarkEnt);
} else if (tvi->type == TreeViewItem::TREEVIEW_ITEM_TYPE_BOOKMARK) {
activateBookmark(tvi->bookmarkEnt);
} else if (tvi->type == TreeViewItem::TREEVIEW_ITEM_TYPE_RANGE) {
activateRange(tvi->rangeEnt);
}
}
@ -647,7 +691,19 @@ void BookmarkView::setExpandState(std::string branchName, bool state) {
}
void BookmarkView::hideProps() {
void BookmarkView::ensureSelectionInView() {
// Ensure current selection is visible; useful when a layout action
// may have covered the active selection
auto sel = m_treeView->GetSelection();
if (sel != nullptr) {
if (!m_treeView->IsVisible(sel)) {
m_treeView->EnsureVisible(sel);
}
}
}
void BookmarkView::hideProps(bool hidePanel) {
m_frequencyLabel->Hide();
m_frequencyVal->Hide();
@ -660,9 +716,13 @@ void BookmarkView::hideProps() {
m_labelText->Hide();
m_labelLabel->Hide();
m_propPanelDivider->Hide();
m_propPanel->Hide();
m_buttonPanel->Hide();
if (hidePanel) {
m_propPanelDivider->Hide();
m_propPanel->Hide();
m_buttonPanel->Hide();
}
refreshLayout();
}
@ -670,6 +730,9 @@ void BookmarkView::showProps() {
m_propPanelDivider->Show();
m_propPanel->Show();
m_propPanel->GetSizer()->Layout();
refreshLayout();
ensureSelectionInView();
}
@ -677,11 +740,16 @@ void BookmarkView::clearButtons() {
m_buttonPanel->Hide();
m_buttonPanel->DestroyChildren();
bookmarkChoice = nullptr;
refreshLayout();
}
void BookmarkView::showButtons() {
m_buttonPanel->Show();
m_buttonPanel->GetSizer()->Layout();
refreshLayout();
ensureSelectionInView();
}
void BookmarkView::refreshLayout() {
@ -821,8 +889,8 @@ void BookmarkView::activeSelection(DemodulatorInstancePtr dsel) {
m_modulationVal->SetLabelText(dsel->getDemodulatorType());
m_labelText->SetValue(dsel->getDemodulatorUserLabel());
hideProps();
hideProps(false);
m_frequencyVal->Show();
m_frequencyLabel->Show();
@ -911,7 +979,7 @@ void BookmarkView::bookmarkSelection(BookmarkEntryPtr bmSel) {
m_modulationVal->SetLabelText(bmSel->type);
m_labelText->SetValue(bmSel->label);
hideProps();
hideProps(false);
m_frequencyVal->Show();
m_frequencyLabel->Show();
@ -944,8 +1012,8 @@ void BookmarkView::recentSelection(BookmarkEntryPtr bmSel) {
m_modulationVal->SetLabelText(bmSel->type);
m_labelText->SetValue(bmSel->label);
hideProps();
hideProps(false);
m_frequencyVal->Show();
m_frequencyLabel->Show();
@ -973,8 +1041,8 @@ void BookmarkView::groupSelection(std::string groupName) {
clearButtons();
hideProps();
hideProps(false);
m_labelText->SetValue(groupName);
m_labelText->Show();
@ -993,8 +1061,8 @@ void BookmarkView::rangeSelection(BookmarkRangeEntryPtr re) {
clearButtons();
hideProps();
hideProps(false);
m_labelText->SetValue(re->label);
m_labelText->Show();
@ -1022,7 +1090,7 @@ void BookmarkView::bookmarkBranchSelection() {
clearButtons();
hideProps();
addButton(m_buttonPanel, BOOKMARK_VIEW_STR_ADD_GROUP, wxCommandEventHandler( BookmarkView::onAddGroup ));
showButtons();
@ -1032,8 +1100,8 @@ void BookmarkView::bookmarkBranchSelection() {
void BookmarkView::recentBranchSelection() {
clearButtons();
hideProps();
hideProps(false);
addButton(m_buttonPanel, BOOKMARK_VIEW_STR_CLEAR_RECENT, wxCommandEventHandler( BookmarkView::onClearRecents ));
showButtons();
@ -1045,8 +1113,8 @@ void BookmarkView::recentBranchSelection() {
void BookmarkView::rangeBranchSelection() {
clearButtons();
hideProps();
hideProps(false);
m_labelText->SetValue(wxT(""));
m_labelText->Show();
m_labelLabel->Show();

View File

@ -96,8 +96,9 @@ protected:
void recentBranchSelection();
void rangeBranchSelection();
void activeBranchSelection();
void hideProps();
void ensureSelectionInView();
void hideProps(bool hidePanel = true);
void showProps();
void onUpdateTimer( wxTimerEvent& event );
@ -105,6 +106,7 @@ protected:
//refresh / rebuild the whole tree item immediatly
void doUpdateActiveList();
void onKeyUp( wxKeyEvent& event );
void onTreeActivate( wxTreeEvent& event );
void onTreeCollapse( wxTreeEvent& event );
void onTreeExpanded( wxTreeEvent& event );