2017-01-02 21:27:08 -05:00
// Copyright (c) Charles J. Cliffe
// SPDX-License-Identifier: GPL-2.0+
2016-10-06 21:08:45 -04:00
# include <wx/menu.h>
# include <wx/textdlg.h>
2017-01-02 01:29:27 -05:00
2016-10-06 22:27:12 -04:00
# include <algorithm>
2016-12-26 21:56:19 -05:00
# include <wchar.h>
2016-11-20 23:26:38 -05:00
2017-01-02 01:29:27 -05:00
# include "BookmarkView.h"
# include "CubicSDR.h"
# include "ActionDialog.h"
2016-10-06 21:08:45 -04:00
# define wxCONTEXT_ADD_GROUP_ID 1000
2016-11-20 23:26:38 -05:00
# define BOOKMARK_VIEW_CHOICE_DEFAULT "Bookmark.."
2016-12-12 20:17:47 -05:00
# define BOOKMARK_VIEW_CHOICE_MOVE "Move to.."
2016-11-20 23:26:38 -05:00
# define BOOKMARK_VIEW_CHOICE_NEW "(New Group..)"
2016-11-21 20:47:16 -05:00
# define BOOKMARK_VIEW_STR_ADD_GROUP "Add Group"
# define BOOKMARK_VIEW_STR_ADD_GROUP_DESC "Enter Group Name"
2016-12-12 20:17:47 -05:00
# define BOOKMARK_VIEW_STR_UNNAMED "Unnamed"
2016-12-17 21:14:13 -05:00
# define BOOKMARK_VIEW_STR_CLEAR_RECENT "Clear Recents"
# define BOOKMARK_VIEW_STR_RENAME_GROUP "Rename Group"
2016-12-16 22:05:25 -05:00
2016-12-27 00:06:25 -05:00
2016-12-16 22:05:25 -05:00
BookmarkViewVisualDragItem : : BookmarkViewVisualDragItem ( wxString labelValue ) : wxDialog ( NULL , wxID_ANY , L " " , wxPoint ( 20 , 20 ) , wxSize ( - 1 , - 1 ) , wxSTAY_ON_TOP | wxALL ) {
wxBoxSizer * sizer = new wxBoxSizer ( wxVERTICAL ) ;
wxStaticText * label = new wxStaticText ( this , wxID_ANY , labelValue , wxDefaultPosition , wxDefaultSize , wxEXPAND ) ;
sizer - > Add ( label , 1 , wxALL | wxEXPAND , 5 ) ;
SetSizerAndFit ( sizer ) ;
Show ( ) ;
}
2016-12-23 18:45:25 -05:00
class ActionDialogRemoveBookmark : public ActionDialog {
public :
2017-02-28 12:58:54 -05:00
ActionDialogRemoveBookmark ( BookmarkEntryPtr be ) : ActionDialog ( wxGetApp ( ) . getAppFrame ( ) , wxID_ANY , wxT ( " Remove Bookmark? " ) ) {
2016-12-23 18:45:25 -05:00
subject = be ;
m_questionText - > SetLabelText ( wxT ( " Are you sure you want to remove the bookmark \n ' " + BookmarkMgr : : getBookmarkEntryDisplayName ( subject ) + " '? " ) ) ;
}
void doClickOK ( ) {
wxGetApp ( ) . getBookmarkMgr ( ) . removeBookmark ( subject ) ;
wxGetApp ( ) . getBookmarkMgr ( ) . updateBookmarks ( ) ;
}
private :
2017-02-28 12:58:54 -05:00
BookmarkEntryPtr subject ;
2016-12-23 18:45:25 -05:00
} ;
class ActionDialogRemoveGroup : public ActionDialog {
public :
ActionDialogRemoveGroup ( std : : string groupName ) : ActionDialog ( wxGetApp ( ) . getAppFrame ( ) , wxID_ANY , wxT ( " Remove Group? " ) ) {
subject = groupName ;
m_questionText - > SetLabelText ( wxT ( " Warning: Are you sure you want to remove the group \n ' " + subject + " ' AND ALL BOOKMARKS WITHIN IT? " ) ) ;
}
void doClickOK ( ) {
wxGetApp ( ) . getBookmarkMgr ( ) . removeGroup ( subject ) ;
wxGetApp ( ) . getBookmarkMgr ( ) . updateBookmarks ( ) ;
}
private :
std : : string subject ;
} ;
2016-12-27 00:06:25 -05:00
class ActionDialogRemoveRange : public ActionDialog {
public :
2017-02-28 12:58:54 -05:00
ActionDialogRemoveRange ( BookmarkRangeEntryPtr rangeEnt ) : ActionDialog ( wxGetApp ( ) . getAppFrame ( ) , wxID_ANY , wxT ( " Remove Range? " ) ) {
2016-12-27 00:06:25 -05:00
subject = rangeEnt ;
std : : wstring name = rangeEnt - > label ;
if ( name . length ( ) = = 0 ) {
std : : string wstr = frequencyToStr ( rangeEnt - > startFreq ) + " - " + frequencyToStr ( rangeEnt - > endFreq ) ;
name = std : : wstring ( wstr . begin ( ) , wstr . end ( ) ) ;
}
m_questionText - > SetLabelText ( L " Are you sure you want to remove the range \n ' " + name + L " '? " ) ;
}
void doClickOK ( ) {
wxGetApp ( ) . getBookmarkMgr ( ) . removeRange ( subject ) ;
wxGetApp ( ) . getBookmarkMgr ( ) . updateActiveList ( ) ;
}
private :
2017-02-28 12:58:54 -05:00
BookmarkRangeEntryPtr subject ;
2016-12-27 00:06:25 -05:00
} ;
2017-01-24 23:14:39 -05:00
class ActionDialogUpdateRange : public ActionDialog {
public :
2017-02-28 12:58:54 -05:00
ActionDialogUpdateRange ( BookmarkRangeEntryPtr rangeEnt ) : ActionDialog ( wxGetApp ( ) . getAppFrame ( ) , wxID_ANY , wxT ( " Update Range? " ) ) {
2017-01-24 23:14:39 -05:00
subject = rangeEnt ;
std : : wstring name = rangeEnt - > label ;
if ( name . length ( ) = = 0 ) {
std : : string wstr = frequencyToStr ( rangeEnt - > startFreq ) + " - " + frequencyToStr ( rangeEnt - > endFreq ) ;
name = std : : wstring ( wstr . begin ( ) , wstr . end ( ) ) ;
}
m_questionText - > SetLabelText ( L " Are you sure you want to update the range \n ' " + name + L " ' to the active range? " ) ;
}
void doClickOK ( ) {
2017-02-28 12:58:54 -05:00
BookmarkRangeEntryPtr ue = BookmarkView : : makeActiveRangeEntry ( ) ;
2017-01-24 23:14:39 -05:00
subject - > freq = ue - > freq ;
subject - > startFreq = ue - > startFreq ;
subject - > endFreq = ue - > endFreq ;
2017-02-28 12:58:54 -05:00
2017-01-24 23:14:39 -05:00
wxGetApp ( ) . getBookmarkMgr ( ) . updateActiveList ( ) ;
}
private :
2017-02-28 12:58:54 -05:00
BookmarkRangeEntryPtr subject ;
2017-01-24 23:14:39 -05:00
} ;
2016-12-27 00:06:25 -05:00
2016-12-23 18:45:25 -05:00
2016-12-16 22:05:25 -05:00
2016-09-13 22:59:21 -04:00
BookmarkView : : BookmarkView ( wxWindow * parent , wxWindowID id , const wxPoint & pos , const wxSize & size , long style ) : BookmarkPanel ( parent , id , pos , size , style ) {
2016-10-05 19:10:01 -04:00
2016-09-29 20:47:38 -04:00
rootBranch = m_treeView - > AddRoot ( " Root " ) ;
activeBranch = m_treeView - > AppendItem ( rootBranch , " Active " ) ;
2016-12-27 00:06:25 -05:00
rangeBranch = m_treeView - > AppendItem ( rootBranch , " View Ranges " ) ;
2016-09-29 20:47:38 -04:00
bookmarkBranch = m_treeView - > AppendItem ( rootBranch , " Bookmarks " ) ;
2016-10-05 19:10:01 -04:00
recentBranch = m_treeView - > AppendItem ( rootBranch , " Recents " ) ;
2016-11-25 22:19:19 -05:00
expandState [ " active " ] = true ;
2016-12-27 13:01:19 -05:00
expandState [ " range " ] = false ;
2016-11-25 22:19:19 -05:00
expandState [ " bookmark " ] = true ;
expandState [ " recent " ] = true ;
2016-10-06 21:08:45 -04:00
doUpdateActive . store ( true ) ;
2016-10-13 00:41:35 -04:00
doUpdateBookmarks . store ( true ) ;
2016-11-20 23:26:38 -05:00
bookmarkChoice = nullptr ;
2016-10-13 00:41:35 -04:00
dragItem = nullptr ;
dragItemId = nullptr ;
2016-11-26 00:39:41 -05:00
editingLabel = false ;
2016-10-05 19:10:01 -04:00
2016-12-26 21:56:19 -05:00
m_clearSearchButton - > Hide ( ) ;
2016-09-28 20:37:39 -04:00
hideProps ( ) ;
2016-10-05 19:10:01 -04:00
m_updateTimer . Start ( 500 ) ;
2017-02-28 12:58:54 -05:00
2016-12-16 22:05:25 -05:00
visualDragItem = nullptr ;
2016-12-17 20:47:32 -05:00
nextEnt = nullptr ;
nextDemod = nullptr ;
2017-02-28 12:58:54 -05:00
mouseTracker . setTarget ( this ) ;
2016-09-14 22:49:32 -04:00
}
2017-03-02 16:10:17 -05:00
BookmarkView : : ~ BookmarkView ( ) {
dragItem = nullptr ;
dragItemId = nullptr ;
editingLabel = false ;
visualDragItem = nullptr ;
nextEnt = nullptr ;
nextDemod = nullptr ;
}
2016-10-13 00:41:35 -04:00
2017-01-24 23:14:39 -05:00
void BookmarkView : : onUpdateTimer ( wxTimerEvent & /* event */ ) {
2016-12-27 15:36:33 -05:00
if ( ! this - > IsShown ( ) ) {
return ;
}
2016-10-06 21:08:45 -04:00
if ( doUpdateActive . load ( ) ) {
2016-09-14 22:49:32 -04:00
doUpdateActiveList ( ) ;
2016-10-06 21:08:45 -04:00
doUpdateActive . store ( false ) ;
2016-09-14 22:49:32 -04:00
}
2016-10-06 22:27:12 -04:00
if ( doUpdateBookmarks . load ( ) ) {
2017-03-06 13:51:27 -05:00
2016-10-06 22:27:12 -04:00
wxTreeItemId bmSel = refreshBookmarks ( ) ;
if ( bmSel ) {
m_treeView - > SelectItem ( bmSel ) ;
2017-03-06 13:51:27 -05:00
}
2016-10-06 22:27:12 -04:00
doUpdateBookmarks . store ( false ) ;
}
2016-09-14 22:10:27 -04:00
}
2016-10-13 00:41:35 -04:00
2016-09-29 21:57:23 -04:00
void BookmarkView : : updateTheme ( ) {
wxColour bgColor ( ThemeMgr : : mgr . currentTheme - > generalBackground ) ;
wxColour textColor ( ThemeMgr : : mgr . currentTheme - > text ) ;
wxColour btn ( ThemeMgr : : mgr . currentTheme - > button ) ;
wxColour btnHl ( ThemeMgr : : mgr . currentTheme - > buttonHighlight ) ;
2016-11-14 23:16:08 -05:00
SetBackgroundColour ( bgColor ) ;
2016-11-08 01:35:34 -05:00
2016-09-29 21:57:23 -04:00
m_treeView - > SetBackgroundColour ( bgColor ) ;
m_treeView - > SetForegroundColour ( textColor ) ;
m_propPanel - > SetBackgroundColour ( bgColor ) ;
m_propPanel - > SetForegroundColour ( textColor ) ;
2017-01-25 15:28:44 -05:00
m_buttonPanel - > SetBackgroundColour ( bgColor ) ;
m_buttonPanel - > SetForegroundColour ( textColor ) ;
2016-09-29 21:57:23 -04:00
m_labelLabel - > SetForegroundColour ( textColor ) ;
m_frequencyVal - > SetForegroundColour ( textColor ) ;
m_frequencyLabel - > SetForegroundColour ( textColor ) ;
m_bandwidthVal - > SetForegroundColour ( textColor ) ;
m_bandwidthLabel - > SetForegroundColour ( textColor ) ;
m_modulationVal - > SetForegroundColour ( textColor ) ;
m_modulationLabel - > SetForegroundColour ( textColor ) ;
2017-01-25 15:28:44 -05:00
2016-12-27 14:46:50 -05:00
refreshLayout ( ) ;
2016-09-29 21:57:23 -04:00
}
2016-09-14 22:10:27 -04:00
void BookmarkView : : updateActiveList ( ) {
2016-10-06 21:08:45 -04:00
doUpdateActive . store ( true ) ;
}
2016-10-13 00:41:35 -04:00
2016-10-06 22:27:12 -04:00
void BookmarkView : : updateBookmarks ( ) {
doUpdateBookmarks . store ( true ) ;
}
2016-10-13 00:41:35 -04:00
2016-10-06 22:27:12 -04:00
void BookmarkView : : updateBookmarks ( std : : string group ) {
doUpdateBookmarkGroup . insert ( group ) ;
doUpdateBookmarks . store ( true ) ;
}
2016-12-26 21:56:19 -05:00
bool BookmarkView : : isKeywordMatch ( std : : wstring search_str , std : : vector < std : : wstring > & keywords ) {
wstring str = search_str ;
std : : transform ( str . begin ( ) , str . end ( ) , str . begin ( ) , towlower ) ;
for ( auto k : keywords ) {
2016-12-27 00:06:25 -05:00
if ( str . find ( k ) = = wstring : : npos ) {
return false ;
2016-12-26 21:56:19 -05:00
}
}
2016-12-27 00:06:25 -05:00
return true ;
2016-12-26 21:56:19 -05:00
}
2016-10-06 22:27:12 -04:00
wxTreeItemId BookmarkView : : refreshBookmarks ( ) {
2016-11-21 20:12:10 -05:00
2017-03-04 05:22:29 -05:00
//capture the previously selected item info BY COPY (because the original will be destroyed together with the destroyed tree items) to restore it again after
//having rebuilding the whole tree.
TreeViewItem * prevSel = itemToTVI ( m_treeView - > GetSelection ( ) ) ;
TreeViewItem * prevSelCopy = nullptr ;
if ( prevSel ! = NULL ) {
prevSelCopy = new TreeViewItem ( * prevSel ) ;
}
2016-11-21 20:12:10 -05:00
BookmarkNames groupNames ;
wxGetApp ( ) . getBookmarkMgr ( ) . getGroups ( groupNames ) ;
2017-02-28 12:58:54 -05:00
doUpdateBookmarkGroup . clear ( ) ;
2016-10-06 22:27:12 -04:00
wxTreeItemId bmSelFound = nullptr ;
2016-11-25 22:19:19 -05:00
std : : map < std : : string , bool > groupExpandState ;
2016-12-26 21:56:19 -05:00
bool searchState = ( searchKeywords . size ( ) ! = 0 ) ;
2016-11-25 22:19:19 -05:00
2017-02-28 12:58:54 -05:00
groups . clear ( ) ;
2016-11-25 22:19:19 -05:00
m_treeView - > DeleteChildren ( bookmarkBranch ) ;
bool bmExpandState = expandState [ " bookmark " ] ;
for ( auto gn_i : groupNames ) {
TreeViewItem * tvi = new TreeViewItem ( ) ;
tvi - > type = TreeViewItem : : TREEVIEW_ITEM_TYPE_GROUP ;
tvi - > groupName = gn_i ;
wxTreeItemId group_itm = m_treeView - > AppendItem ( bookmarkBranch , gn_i ) ;
2017-03-02 16:10:17 -05:00
SetTreeItemData ( group_itm , tvi ) ;
2016-11-25 22:19:19 -05:00
groups [ gn_i ] = group_itm ;
2017-03-04 05:22:29 -05:00
if ( prevSelCopy ! = nullptr & & prevSelCopy - > type = = TreeViewItem : : TREEVIEW_ITEM_TYPE_GROUP & & gn_i = = prevSelCopy - > groupName ) {
2016-12-12 20:17:47 -05:00
bmSelFound = group_itm ;
}
2016-11-25 22:19:19 -05:00
}
2016-12-26 21:56:19 -05:00
if ( searchState | | bmExpandState ) {
2016-11-25 22:19:19 -05:00
m_treeView - > Expand ( bookmarkBranch ) ;
2016-12-27 13:49:47 -05:00
} else {
m_treeView - > Collapse ( bookmarkBranch ) ;
2016-11-25 22:19:19 -05:00
}
2016-10-06 21:08:45 -04:00
for ( auto gn_i : groupNames ) {
wxTreeItemId groupItem = groups [ gn_i ] ;
2016-11-25 22:19:19 -05:00
2016-12-26 21:56:19 -05:00
bool groupExpanded = searchState | | wxGetApp ( ) . getBookmarkMgr ( ) . getExpandState ( gn_i ) ;
2016-11-25 22:19:19 -05:00
2016-11-21 20:12:10 -05:00
BookmarkList bmList = wxGetApp ( ) . getBookmarkMgr ( ) . getBookmarks ( gn_i ) ;
2016-12-17 20:47:32 -05:00
for ( auto & bmEnt : bmList ) {
2016-12-26 21:56:19 -05:00
std : : wstring labelVal = BookmarkMgr : : getBookmarkEntryDisplayName ( bmEnt ) ;
if ( searchState ) {
std : : string freqStr = frequencyToStr ( bmEnt - > frequency ) ;
std : : string bwStr = frequencyToStr ( bmEnt - > bandwidth ) ;
2016-12-27 00:06:25 -05:00
std : : wstring fullText = labelVal +
L " " + bmEnt - > userLabel +
L " " + std : : to_wstring ( bmEnt - > frequency ) +
L " " + std : : wstring ( freqStr . begin ( ) , freqStr . end ( ) ) +
L " " + std : : wstring ( bwStr . begin ( ) , bwStr . end ( ) ) +
L " " + std : : wstring ( bmEnt - > type . begin ( ) , bmEnt - > type . end ( ) ) ;
if ( ! isKeywordMatch ( fullText , searchKeywords ) ) {
2016-12-26 21:56:19 -05:00
continue ;
}
}
2016-10-10 22:28:48 -04:00
TreeViewItem * tvi = new TreeViewItem ( ) ;
tvi - > type = TreeViewItem : : TREEVIEW_ITEM_TYPE_BOOKMARK ;
tvi - > bookmarkEnt = bmEnt ;
tvi - > groupName = gn_i ;
2016-11-25 23:21:32 -05:00
2016-12-12 20:17:47 -05:00
wxTreeItemId itm = m_treeView - > AppendItem ( groupItem , labelVal ) ;
2017-03-02 16:10:17 -05:00
SetTreeItemData ( itm , tvi ) ;
2017-03-04 05:22:29 -05:00
if ( prevSelCopy ! = nullptr & & prevSelCopy - > type = = TreeViewItem : : TREEVIEW_ITEM_TYPE_BOOKMARK & & prevSelCopy - > bookmarkEnt = = bmEnt & & groupExpanded ) {
2016-10-10 22:28:48 -04:00
bmSelFound = itm ;
2016-10-06 22:27:12 -04:00
}
2016-12-17 20:47:32 -05:00
if ( nextEnt = = bmEnt ) {
bmSelFound = itm ;
nextEnt = nullptr ;
}
2016-10-06 21:08:45 -04:00
}
2016-11-25 22:19:19 -05:00
if ( groupExpanded ) {
m_treeView - > Expand ( groupItem ) ;
}
2016-10-06 21:08:45 -04:00
}
2017-03-04 05:22:29 -05:00
delete prevSelCopy ;
2016-10-06 22:27:12 -04:00
return bmSelFound ;
2016-09-14 22:49:32 -04:00
}
2016-10-13 00:41:35 -04:00
2016-09-14 22:49:32 -04:00
void BookmarkView : : doUpdateActiveList ( ) {
2016-09-14 22:10:27 -04:00
std : : vector < DemodulatorInstance * > & demods = wxGetApp ( ) . getDemodMgr ( ) . getDemodulators ( ) ;
2016-12-17 20:47:32 -05:00
// DemodulatorInstance *activeDemodulator = wxGetApp().getDemodMgr().getActiveDemodulator();
DemodulatorInstance * lastActiveDemodulator = wxGetApp ( ) . getDemodMgr ( ) . getLastActiveDemodulator ( ) ;
2016-09-14 22:10:27 -04:00
2017-03-04 05:22:29 -05:00
//capture the previously selected item info BY COPY (because the original will be destroyed together with the destroyed tree items) to restore it again after
//having rebuilding the whole tree.
TreeViewItem * prevSel = itemToTVI ( m_treeView - > GetSelection ( ) ) ;
TreeViewItem * prevSelCopy = nullptr ;
if ( prevSel ! = NULL ) {
prevSelCopy = new TreeViewItem ( * prevSel ) ;
}
2016-12-15 21:53:51 -05:00
2016-10-05 19:10:01 -04:00
// Actives
2017-03-04 03:02:15 -05:00
m_treeView - > DeleteChildren ( activeBranch ) ;
2016-09-14 22:10:27 -04:00
2016-11-25 22:19:19 -05:00
bool activeExpandState = expandState [ " active " ] ;
2016-12-26 21:56:19 -05:00
bool searchState = ( searchKeywords . size ( ) ! = 0 ) ;
2016-11-25 22:19:19 -05:00
2016-09-29 20:47:38 -04:00
wxTreeItemId selItem = nullptr ;
2016-09-14 22:10:27 -04:00
for ( auto demod_i : demods ) {
2016-12-27 13:49:47 -05:00
wxString activeLabel = BookmarkMgr : : getActiveDisplayName ( demod_i ) ;
if ( searchState ) {
std : : string freqStr = frequencyToStr ( demod_i - > getFrequency ( ) ) ;
std : : string bwStr = frequencyToStr ( demod_i - > getBandwidth ( ) ) ;
std : : string mtype = demod_i - > getDemodulatorType ( ) ;
std : : wstring fullText = activeLabel . ToStdWstring ( ) +
L " " + demod_i - > getDemodulatorUserLabel ( ) +
L " " + std : : to_wstring ( demod_i - > getFrequency ( ) ) +
L " " + std : : wstring ( freqStr . begin ( ) , freqStr . end ( ) ) +
L " " + std : : wstring ( bwStr . begin ( ) , bwStr . end ( ) ) +
L " " + std : : wstring ( mtype . begin ( ) , mtype . end ( ) ) ;
if ( ! isKeywordMatch ( fullText , searchKeywords ) ) {
continue ;
}
}
2016-10-10 22:28:48 -04:00
TreeViewItem * tvi = new TreeViewItem ( ) ;
tvi - > type = TreeViewItem : : TREEVIEW_ITEM_TYPE_ACTIVE ;
tvi - > demod = demod_i ;
2016-12-27 13:49:47 -05:00
2016-11-14 23:52:50 -05:00
wxTreeItemId itm = m_treeView - > AppendItem ( activeBranch , activeLabel ) ;
2017-03-02 16:10:17 -05:00
SetTreeItemData ( itm , tvi ) ;
2016-10-10 22:28:48 -04:00
2016-12-17 20:47:32 -05:00
if ( nextDemod ! = nullptr & & nextDemod = = demod_i ) {
selItem = itm ;
nextDemod = nullptr ;
} else if ( ! selItem & & activeExpandState & & lastActiveDemodulator & & lastActiveDemodulator = = demod_i ) {
2016-09-29 20:47:38 -04:00
selItem = itm ;
}
}
2016-11-25 22:19:19 -05:00
2016-12-27 13:49:47 -05:00
bool rangeExpandState = searchState ? false : expandState [ " range " ] ;
2016-12-27 00:06:25 -05:00
BookmarkRangeList bmRanges = wxGetApp ( ) . getBookmarkMgr ( ) . getRanges ( ) ;
2017-03-04 03:02:15 -05:00
m_treeView - > DeleteChildren ( rangeBranch ) ;
2016-12-27 00:06:25 -05:00
for ( auto & re_i : bmRanges ) {
TreeViewItem * tvi = new TreeViewItem ( ) ;
tvi - > type = TreeViewItem : : TREEVIEW_ITEM_TYPE_RANGE ;
tvi - > rangeEnt = re_i ;
std : : wstring labelVal = re_i - > label ;
if ( labelVal = = " " ) {
std : : string wstr = frequencyToStr ( re_i - > startFreq ) + " - " + frequencyToStr ( re_i - > endFreq ) ;
labelVal = std : : wstring ( wstr . begin ( ) , wstr . end ( ) ) ;
}
wxTreeItemId itm = m_treeView - > AppendItem ( rangeBranch , labelVal ) ;
2017-03-02 16:10:17 -05:00
SetTreeItemData ( itm , tvi ) ;
2016-12-27 00:06:25 -05:00
if ( nextRange = = re_i ) {
selItem = itm ;
nextRange = nullptr ;
2017-03-04 05:22:29 -05:00
} else if ( ! selItem & & rangeExpandState & & prevSelCopy & & prevSelCopy - > type = = TreeViewItem : : TREEVIEW_ITEM_TYPE_RANGE & & prevSelCopy - > rangeEnt = = re_i ) {
2016-12-27 00:06:25 -05:00
selItem = itm ;
}
}
2017-03-04 05:22:29 -05:00
2016-12-26 21:56:19 -05:00
bool recentExpandState = searchState | | expandState [ " recent " ] ;
2016-10-05 19:10:01 -04:00
// Recents
BookmarkList bmRecents = wxGetApp ( ) . getBookmarkMgr ( ) . getRecents ( ) ;
2017-03-04 03:02:15 -05:00
m_treeView - > DeleteChildren ( recentBranch ) ;
2016-10-05 19:10:01 -04:00
2016-12-17 20:47:32 -05:00
for ( auto & bmr_i : bmRecents ) {
2016-10-10 22:28:48 -04:00
TreeViewItem * tvi = new TreeViewItem ( ) ;
tvi - > type = TreeViewItem : : TREEVIEW_ITEM_TYPE_RECENT ;
tvi - > bookmarkEnt = bmr_i ;
2016-11-25 23:21:32 -05:00
std : : wstring labelVal ;
bmr_i - > node - > child ( " user_label " ) - > element ( ) - > get ( labelVal ) ;
2016-12-26 21:56:19 -05:00
2016-11-25 23:21:32 -05:00
if ( labelVal = = " " ) {
std : : string wstr = frequencyToStr ( bmr_i - > frequency ) + " " + bmr_i - > type ;
labelVal = std : : wstring ( wstr . begin ( ) , wstr . end ( ) ) ;
}
2016-12-26 21:56:19 -05:00
if ( searchKeywords . size ( ) ) {
std : : string freqStr = frequencyToStr ( bmr_i - > frequency ) ;
std : : string bwStr = frequencyToStr ( bmr_i - > bandwidth ) ;
2016-12-27 00:06:25 -05:00
std : : wstring fullText = labelVal +
L " " + bmr_i - > userLabel +
L " " + std : : to_wstring ( bmr_i - > frequency ) +
L " " + std : : wstring ( freqStr . begin ( ) , freqStr . end ( ) ) +
L " " + std : : wstring ( bwStr . begin ( ) , bwStr . end ( ) ) +
L " " + std : : wstring ( bmr_i - > type . begin ( ) , tvi - > bookmarkEnt - > type . end ( ) ) ;
2016-12-26 21:56:19 -05:00
2016-12-27 00:06:25 -05:00
if ( ! isKeywordMatch ( fullText , searchKeywords ) ) {
2016-12-26 21:56:19 -05:00
continue ;
}
}
2016-11-25 23:21:32 -05:00
wxTreeItemId itm = m_treeView - > AppendItem ( recentBranch , labelVal ) ;
2017-03-02 16:10:17 -05:00
SetTreeItemData ( itm , tvi ) ;
2016-12-17 20:47:32 -05:00
if ( nextEnt = = bmr_i ) {
selItem = itm ;
nextEnt = nullptr ;
2017-03-04 05:22:29 -05:00
} else if ( ! selItem & & recentExpandState & & prevSelCopy & & prevSelCopy - > type = = TreeViewItem : : TREEVIEW_ITEM_TYPE_RECENT & & prevSelCopy - > bookmarkEnt = = bmr_i ) {
2016-10-05 19:10:01 -04:00
selItem = itm ;
}
}
2016-11-25 22:19:19 -05:00
if ( activeExpandState ) {
m_treeView - > Expand ( activeBranch ) ;
2016-12-27 13:49:47 -05:00
} else {
m_treeView - > Collapse ( activeBranch ) ;
2016-11-25 22:19:19 -05:00
}
if ( recentExpandState ) {
m_treeView - > Expand ( recentBranch ) ;
2016-12-27 13:49:47 -05:00
} else {
m_treeView - > Collapse ( recentBranch ) ;
2016-11-25 22:19:19 -05:00
}
2016-12-27 00:06:25 -05:00
if ( rangeExpandState ) {
m_treeView - > Expand ( rangeBranch ) ;
2016-12-27 13:49:47 -05:00
} else {
m_treeView - > Collapse ( rangeBranch ) ;
2016-12-27 00:06:25 -05:00
}
2016-12-27 13:49:47 -05:00
2017-03-04 05:22:29 -05:00
//select the item having the same meaning as the previously selected item
2016-09-29 20:47:38 -04:00
if ( selItem ! = nullptr ) {
m_treeView - > SelectItem ( selItem ) ;
2016-09-14 22:10:27 -04:00
}
2017-03-04 05:22:29 -05:00
delete prevSelCopy ;
2016-09-13 22:59:21 -04:00
}
2016-10-13 00:41:35 -04:00
2016-09-13 22:59:21 -04:00
void BookmarkView : : onTreeActivate ( wxTreeEvent & event ) {
2017-02-28 12:58:54 -05:00
2016-11-26 00:39:41 -05:00
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 ( ) ) {
2016-12-23 20:07:49 -05:00
wxGetApp ( ) . getDemodMgr ( ) . setActiveDemodulator ( tvi - > demod , true ) ;
2016-11-26 00:39:41 -05:00
wxGetApp ( ) . getDemodMgr ( ) . setActiveDemodulator ( tvi - > demod , false ) ;
2016-12-23 20:07:49 -05:00
wxGetApp ( ) . setFrequency ( tvi - > demod - > getFrequency ( ) ) ;
2016-12-17 20:47:32 -05:00
nextDemod = tvi - > demod ;
2016-11-26 00:39:41 -05:00
}
2016-12-15 21:53:51 -05:00
} else if ( tvi - > type = = TreeViewItem : : TREEVIEW_ITEM_TYPE_RECENT ) {
2017-03-04 05:22:29 -05:00
2016-12-17 20:47:32 -05:00
nextEnt = tvi - > bookmarkEnt ;
2017-03-03 14:33:14 -05:00
wxGetApp ( ) . getBookmarkMgr ( ) . removeRecent ( tvi - > bookmarkEnt ) ;
2017-03-04 05:22:29 -05:00
activateBookmark ( tvi - > bookmarkEnt ) ;
2016-12-15 21:53:51 -05:00
} else if ( tvi - > type = = TreeViewItem : : TREEVIEW_ITEM_TYPE_BOOKMARK ) {
activateBookmark ( tvi - > bookmarkEnt ) ;
2016-12-27 00:06:25 -05:00
} else if ( tvi - > type = = TreeViewItem : : TREEVIEW_ITEM_TYPE_RANGE ) {
activateRange ( tvi - > rangeEnt ) ;
2016-11-26 00:39:41 -05:00
}
}
2016-09-13 22:59:21 -04:00
}
2016-10-13 00:41:35 -04:00
2016-09-13 22:59:21 -04:00
void BookmarkView : : onTreeCollapse ( wxTreeEvent & event ) {
2016-12-26 21:56:19 -05:00
bool searchState = ( searchKeywords . size ( ) ! = 0 ) ;
if ( searchState ) {
event . Skip ( ) ;
return ;
}
2016-11-25 22:19:19 -05:00
if ( event . GetItem ( ) = = activeBranch ) {
expandState [ " active " ] = false ;
} else if ( event . GetItem ( ) = = bookmarkBranch ) {
expandState [ " bookmark " ] = false ;
} else if ( event . GetItem ( ) = = recentBranch ) {
expandState [ " recent " ] = false ;
2016-12-27 00:06:25 -05:00
} else if ( event . GetItem ( ) = = rangeBranch ) {
expandState [ " range " ] = false ;
2016-12-26 21:56:19 -05:00
} else {
TreeViewItem * tvi = itemToTVI ( event . GetItem ( ) ) ;
if ( tvi ! = nullptr ) {
if ( tvi - > type = = TreeViewItem : : TREEVIEW_ITEM_TYPE_GROUP ) {
wxGetApp ( ) . getBookmarkMgr ( ) . setExpandState ( tvi - > groupName , false ) ;
}
}
2016-11-25 22:19:19 -05:00
2016-12-26 21:56:19 -05:00
}
2016-09-13 22:59:21 -04:00
}
2016-10-13 00:41:35 -04:00
2016-09-13 22:59:21 -04:00
void BookmarkView : : onTreeExpanded ( wxTreeEvent & event ) {
2016-12-26 21:56:19 -05:00
bool searchState = ( searchKeywords . size ( ) ! = 0 ) ;
if ( searchState ) {
event . Skip ( ) ;
return ;
}
2016-11-25 22:19:19 -05:00
if ( event . GetItem ( ) = = activeBranch ) {
expandState [ " active " ] = true ;
} else if ( event . GetItem ( ) = = bookmarkBranch ) {
expandState [ " bookmark " ] = true ;
} else if ( event . GetItem ( ) = = recentBranch ) {
expandState [ " recent " ] = true ;
2016-12-27 00:06:25 -05:00
} else if ( event . GetItem ( ) = = rangeBranch ) {
expandState [ " range " ] = true ;
2016-12-26 21:56:19 -05:00
} else {
TreeViewItem * tvi = itemToTVI ( event . GetItem ( ) ) ;
if ( tvi ! = nullptr ) {
if ( tvi - > type = = TreeViewItem : : TREEVIEW_ITEM_TYPE_GROUP ) {
wxGetApp ( ) . getBookmarkMgr ( ) . setExpandState ( tvi - > groupName , true ) ;
}
}
2016-11-25 22:19:19 -05:00
}
2016-09-13 22:59:21 -04:00
}
2016-10-13 00:41:35 -04:00
2017-01-24 23:14:39 -05:00
void BookmarkView : : onTreeItemMenu ( wxTreeEvent & /* event */ ) {
2016-10-06 21:08:45 -04:00
if ( m_treeView - > GetSelection ( ) = = bookmarkBranch ) {
wxMenu menu ;
2016-11-21 20:47:16 -05:00
menu . Append ( wxCONTEXT_ADD_GROUP_ID , BOOKMARK_VIEW_STR_ADD_GROUP ) ;
menu . Connect ( wxCONTEXT_ADD_GROUP_ID , wxEVT_MENU , ( wxObjectEventFunction ) & BookmarkView : : onMenuItem , nullptr , this ) ;
2016-10-06 21:08:45 -04:00
PopupMenu ( & menu ) ;
}
}
2016-10-13 00:41:35 -04:00
2016-10-06 21:08:45 -04:00
void BookmarkView : : onMenuItem ( wxCommandEvent & event ) {
if ( event . GetId ( ) = = wxCONTEXT_ADD_GROUP_ID ) {
2016-11-10 20:43:01 -05:00
onAddGroup ( event ) ;
2016-10-06 21:08:45 -04:00
}
}
2016-10-13 00:41:35 -04:00
bool BookmarkView : : isMouseInView ( ) {
2016-12-27 00:06:25 -05:00
if ( editingLabel ) {
return true ;
}
if ( m_labelText - > HasFocus ( ) ) {
return true ;
}
2017-02-28 12:58:54 -05:00
if ( m_searchText - > HasFocus ( ) ) {
return true ;
}
return mouseTracker . mouseInView ( ) ;
2016-10-13 00:41:35 -04:00
}
2016-12-27 13:01:19 -05:00
bool BookmarkView : : getExpandState ( std : : string branchName ) {
return expandState [ branchName ] ;
}
void BookmarkView : : setExpandState ( std : : string branchName , bool state ) {
expandState [ branchName ] = state ;
}
2016-09-28 20:37:39 -04:00
void BookmarkView : : hideProps ( ) {
m_frequencyLabel - > Hide ( ) ;
m_frequencyVal - > Hide ( ) ;
m_bandwidthLabel - > Hide ( ) ;
m_bandwidthVal - > Hide ( ) ;
m_modulationVal - > Hide ( ) ;
m_modulationLabel - > Hide ( ) ;
m_labelText - > Hide ( ) ;
m_labelLabel - > Hide ( ) ;
2016-11-14 23:16:08 -05:00
m_propPanel - > Hide ( ) ;
2016-11-08 01:35:34 -05:00
m_buttonPanel - > Hide ( ) ;
}
2016-11-14 23:16:08 -05:00
void BookmarkView : : showProps ( ) {
m_propPanel - > Show ( ) ;
m_propPanel - > GetSizer ( ) - > Layout ( ) ;
}
2016-11-08 01:35:34 -05:00
void BookmarkView : : clearButtons ( ) {
m_buttonPanel - > Hide ( ) ;
2016-11-14 23:16:08 -05:00
m_buttonPanel - > DestroyChildren ( ) ;
2016-11-20 23:26:38 -05:00
bookmarkChoice = nullptr ;
2016-11-08 01:35:34 -05:00
}
void BookmarkView : : showButtons ( ) {
m_buttonPanel - > Show ( ) ;
m_buttonPanel - > GetSizer ( ) - > Layout ( ) ;
}
2016-11-14 23:16:08 -05:00
void BookmarkView : : refreshLayout ( ) {
GetSizer ( ) - > Layout ( ) ;
Update ( ) ;
2016-12-27 14:46:50 -05:00
Refresh ( ) ;
2016-11-14 23:16:08 -05:00
}
2016-11-08 01:35:34 -05:00
wxButton * BookmarkView : : makeButton ( wxWindow * parent , std : : string labelVal , wxObjectEventFunction handler ) {
wxButton * nButton = new wxButton ( m_buttonPanel , wxID_ANY , labelVal ) ;
2016-11-20 23:26:38 -05:00
nButton - > Connect ( wxEVT_COMMAND_BUTTON_CLICKED , handler , nullptr , this ) ;
2017-01-25 15:28:44 -05:00
wxColour bgColor ( ThemeMgr : : mgr . currentTheme - > generalBackground ) ;
wxColour textColor ( ThemeMgr : : mgr . currentTheme - > text ) ;
nButton - > SetBackgroundColour ( bgColor ) ;
nButton - > SetForegroundColour ( textColor ) ;
2016-11-08 01:35:34 -05:00
return nButton ;
}
wxButton * BookmarkView : : addButton ( wxWindow * parent , std : : string labelVal , wxObjectEventFunction handler ) {
wxButton * nButton = makeButton ( parent , labelVal , handler ) ;
parent - > GetSizer ( ) - > Add ( nButton , 0 , wxEXPAND ) ;
return nButton ;
2016-09-28 20:37:39 -04:00
}
2016-11-21 20:47:16 -05:00
void BookmarkView : : doBookmarkActive ( std : : string group , DemodulatorInstance * demod ) {
wxGetApp ( ) . getBookmarkMgr ( ) . addBookmark ( group , demod ) ;
wxGetApp ( ) . getBookmarkMgr ( ) . updateBookmarks ( ) ;
}
2017-02-28 12:58:54 -05:00
void BookmarkView : : doBookmarkRecent ( std : : string group , BookmarkEntryPtr be ) {
2017-03-03 14:33:14 -05:00
2016-11-21 20:47:16 -05:00
wxGetApp ( ) . getBookmarkMgr ( ) . addBookmark ( group , be ) ;
2016-12-17 20:47:32 -05:00
nextEnt = be ;
2017-03-03 14:33:14 -05:00
wxGetApp ( ) . getBookmarkMgr ( ) . removeRecent ( be ) ;
2016-11-21 20:47:16 -05:00
wxGetApp ( ) . getBookmarkMgr ( ) . updateBookmarks ( ) ;
bookmarkSelection ( be ) ;
}
2017-02-28 12:58:54 -05:00
void BookmarkView : : doMoveBookmark ( BookmarkEntryPtr be , std : : string group ) {
2016-11-25 22:19:19 -05:00
wxGetApp ( ) . getBookmarkMgr ( ) . moveBookmark ( be , group ) ;
2016-12-17 20:47:32 -05:00
nextEnt = be ;
2016-11-25 22:19:19 -05:00
wxGetApp ( ) . getBookmarkMgr ( ) . updateBookmarks ( ) ;
bookmarkSelection ( be ) ;
}
2016-12-17 20:47:32 -05:00
void BookmarkView : : doRemoveActive ( DemodulatorInstance * demod ) {
wxGetApp ( ) . getDemodMgr ( ) . setActiveDemodulator ( nullptr , true ) ;
wxGetApp ( ) . getDemodMgr ( ) . setActiveDemodulator ( nullptr , false ) ;
wxGetApp ( ) . removeDemodulator ( demod ) ;
wxGetApp ( ) . getDemodMgr ( ) . deleteThread ( demod ) ;
}
2017-02-28 12:58:54 -05:00
void BookmarkView : : doRemoveRecent ( BookmarkEntryPtr be ) {
2016-12-17 21:14:13 -05:00
wxGetApp ( ) . getBookmarkMgr ( ) . removeRecent ( be ) ;
wxGetApp ( ) . getBookmarkMgr ( ) . updateActiveList ( ) ;
}
void BookmarkView : : doClearRecents ( ) {
wxGetApp ( ) . getBookmarkMgr ( ) . clearRecents ( ) ;
wxGetApp ( ) . getBookmarkMgr ( ) . updateActiveList ( ) ;
}
2016-11-20 23:26:38 -05:00
void BookmarkView : : updateBookmarkChoices ( ) {
2017-02-28 12:58:54 -05:00
bookmarkChoices . clear ( ) ;
2016-12-15 21:53:51 -05:00
TreeViewItem * activeSel = itemToTVI ( m_treeView - > GetSelection ( ) ) ;
bookmarkChoices . push_back ( ( ( activeSel ! = nullptr & & activeSel - > type = = TreeViewItem : : TREEVIEW_ITEM_TYPE_BOOKMARK ) ) ? BOOKMARK_VIEW_CHOICE_MOVE : BOOKMARK_VIEW_CHOICE_DEFAULT ) ;
2016-11-20 23:26:38 -05:00
wxGetApp ( ) . getBookmarkMgr ( ) . getGroups ( bookmarkChoices ) ;
bookmarkChoices . push_back ( BOOKMARK_VIEW_CHOICE_NEW ) ;
}
void BookmarkView : : addBookmarkChoice ( wxWindow * parent ) {
updateBookmarkChoices ( ) ;
2017-03-15 21:22:29 -04:00
bookmarkChoice = new wxChoice ( parent , wxID_ANY , wxDefaultPosition , wxDefaultSize , bookmarkChoices , wxEXPAND , wxDefaultValidator , " Bookmark " ) ;
2016-11-20 23:26:38 -05:00
bookmarkChoice - > Connect ( wxEVT_COMMAND_CHOICE_SELECTED , ( wxObjectEventFunction ) & BookmarkView : : onBookmarkChoice , nullptr , this ) ;
parent - > GetSizer ( ) - > Add ( bookmarkChoice , 0 , wxALL | wxEXPAND ) ;
}
2017-01-24 23:14:39 -05:00
void BookmarkView : : onBookmarkChoice ( wxCommandEvent & /* event */ ) {
2016-12-15 21:53:51 -05:00
TreeViewItem * tvi = itemToTVI ( m_treeView - > GetSelection ( ) ) ;
2016-11-20 23:26:38 -05:00
int numSel = bookmarkChoice - > GetCount ( ) ;
int sel = bookmarkChoice - > GetSelection ( ) ;
if ( sel = = 0 ) {
return ;
}
wxString stringVal = " " ;
if ( sel = = ( numSel - 1 ) ) {
2016-11-21 20:47:16 -05:00
stringVal = wxGetTextFromUser ( BOOKMARK_VIEW_STR_ADD_GROUP_DESC , BOOKMARK_VIEW_STR_ADD_GROUP , " " ) ;
2016-11-20 23:26:38 -05:00
} else {
stringVal = bookmarkChoices [ sel ] ;
}
if ( stringVal = = " " ) {
return ;
}
2016-12-15 21:53:51 -05:00
if ( tvi ! = nullptr ) {
if ( tvi - > type = = TreeViewItem : : TREEVIEW_ITEM_TYPE_ACTIVE ) {
doBookmarkActive ( stringVal . ToStdString ( ) , tvi - > demod ) ;
}
if ( tvi - > type = = TreeViewItem : : TREEVIEW_ITEM_TYPE_RECENT ) {
doBookmarkRecent ( stringVal . ToStdString ( ) , tvi - > bookmarkEnt ) ;
}
if ( tvi - > type = = TreeViewItem : : TREEVIEW_ITEM_TYPE_BOOKMARK ) {
doMoveBookmark ( tvi - > bookmarkEnt , stringVal . ToStdString ( ) ) ;
}
2016-12-12 20:17:47 -05:00
}
2016-11-20 23:26:38 -05:00
}
2016-10-13 00:41:35 -04:00
2016-09-28 20:37:39 -04:00
void BookmarkView : : activeSelection ( DemodulatorInstance * dsel ) {
m_frequencyVal - > SetLabelText ( frequencyToStr ( dsel - > getFrequency ( ) ) ) ;
m_bandwidthVal - > SetLabelText ( frequencyToStr ( dsel - > getBandwidth ( ) ) ) ;
m_modulationVal - > SetLabelText ( dsel - > getDemodulatorType ( ) ) ;
2016-11-14 23:52:50 -05:00
m_labelText - > SetValue ( dsel - > getDemodulatorUserLabel ( ) ) ;
2016-09-28 20:37:39 -04:00
hideProps ( ) ;
m_frequencyVal - > Show ( ) ;
m_frequencyLabel - > Show ( ) ;
2016-11-08 01:35:34 -05:00
2016-09-28 20:37:39 -04:00
m_bandwidthVal - > Show ( ) ;
m_bandwidthLabel - > Show ( ) ;
m_modulationVal - > Show ( ) ;
m_modulationLabel - > Show ( ) ;
m_labelText - > Show ( ) ;
m_labelLabel - > Show ( ) ;
2016-11-08 01:35:34 -05:00
clearButtons ( ) ;
2016-11-20 23:26:38 -05:00
addBookmarkChoice ( m_buttonPanel ) ;
2016-11-08 01:35:34 -05:00
addButton ( m_buttonPanel , " Remove Active " , wxCommandEventHandler ( BookmarkView : : onRemoveActive ) ) ;
2016-11-14 23:16:08 -05:00
showProps ( ) ;
2016-11-08 01:35:34 -05:00
showButtons ( ) ;
2016-11-14 23:16:08 -05:00
refreshLayout ( ) ;
2016-09-28 20:37:39 -04:00
}
2016-10-13 00:41:35 -04:00
2017-02-28 12:58:54 -05:00
void BookmarkView : : activateBookmark ( BookmarkEntryPtr bmEnt ) {
2016-10-05 19:10:01 -04:00
DemodulatorInstance * newDemod = wxGetApp ( ) . getDemodMgr ( ) . loadInstance ( bmEnt - > node ) ;
2016-11-26 00:39:41 -05:00
2016-12-17 20:47:32 -05:00
nextDemod = newDemod ;
2016-12-27 00:06:25 -05:00
2016-12-17 20:47:32 -05:00
wxTreeItemId selItem = m_treeView - > GetSelection ( ) ;
if ( selItem ) {
m_treeView - > SelectItem ( selItem , false ) ;
}
2016-12-27 00:06:25 -05:00
2016-11-26 00:39:41 -05:00
long long freq = newDemod - > getFrequency ( ) ;
long long currentFreq = wxGetApp ( ) . getFrequency ( ) ;
long long currentRate = wxGetApp ( ) . getSampleRate ( ) ;
if ( ( abs ( freq - currentFreq ) > currentRate / 2 ) | | ( abs ( currentFreq - freq ) > currentRate / 2 ) ) {
wxGetApp ( ) . setFrequency ( freq ) ;
}
2016-10-05 19:10:01 -04:00
newDemod - > run ( ) ;
newDemod - > setActive ( true ) ;
wxGetApp ( ) . bindDemodulator ( newDemod ) ;
2016-12-17 20:47:32 -05:00
2017-03-04 05:22:29 -05:00
//order immediate refresh of the whole tree.
2016-10-05 19:10:01 -04:00
doUpdateActiveList ( ) ;
}
2016-10-13 00:41:35 -04:00
2017-02-28 12:58:54 -05:00
void BookmarkView : : activateRange ( BookmarkRangeEntryPtr rangeEnt ) {
2016-12-27 00:46:12 -05:00
wxGetApp ( ) . setFrequency ( rangeEnt - > freq ) ;
2016-12-27 00:06:25 -05:00
wxGetApp ( ) . getAppFrame ( ) - > setViewState ( rangeEnt - > startFreq + ( rangeEnt - > endFreq - rangeEnt - > startFreq ) / 2 , rangeEnt - > endFreq - rangeEnt - > startFreq ) ;
}
2017-02-28 12:58:54 -05:00
void BookmarkView : : bookmarkSelection ( BookmarkEntryPtr bmSel ) {
2016-10-05 19:10:01 -04:00
m_frequencyVal - > SetLabelText ( frequencyToStr ( bmSel - > frequency ) ) ;
m_bandwidthVal - > SetLabelText ( frequencyToStr ( bmSel - > bandwidth ) ) ;
m_modulationVal - > SetLabelText ( bmSel - > type ) ;
m_labelText - > SetValue ( bmSel - > label ) ;
hideProps ( ) ;
m_frequencyVal - > Show ( ) ;
m_frequencyLabel - > Show ( ) ;
m_bandwidthVal - > Show ( ) ;
m_bandwidthLabel - > Show ( ) ;
m_modulationVal - > Show ( ) ;
m_modulationLabel - > Show ( ) ;
m_labelText - > Show ( ) ;
m_labelLabel - > Show ( ) ;
2016-11-08 01:35:34 -05:00
clearButtons ( ) ;
2016-12-12 20:17:47 -05:00
addBookmarkChoice ( m_buttonPanel ) ;
2016-11-08 01:35:34 -05:00
addButton ( m_buttonPanel , " Activate Bookmark " , wxCommandEventHandler ( BookmarkView : : onActivateBookmark ) ) ;
addButton ( m_buttonPanel , " Remove Bookmark " , wxCommandEventHandler ( BookmarkView : : onRemoveBookmark ) ) ;
2016-12-12 20:17:47 -05:00
2016-11-14 23:16:08 -05:00
showProps ( ) ;
2016-11-08 01:35:34 -05:00
showButtons ( ) ;
2016-11-14 23:16:08 -05:00
refreshLayout ( ) ;
2016-10-05 19:10:01 -04:00
}
2017-02-28 12:58:54 -05:00
void BookmarkView : : recentSelection ( BookmarkEntryPtr bmSel ) {
2016-10-05 19:10:01 -04:00
m_frequencyVal - > SetLabelText ( frequencyToStr ( bmSel - > frequency ) ) ;
m_bandwidthVal - > SetLabelText ( frequencyToStr ( bmSel - > bandwidth ) ) ;
m_modulationVal - > SetLabelText ( bmSel - > type ) ;
m_labelText - > SetValue ( bmSel - > label ) ;
hideProps ( ) ;
m_frequencyVal - > Show ( ) ;
m_frequencyLabel - > Show ( ) ;
m_bandwidthVal - > Show ( ) ;
m_bandwidthLabel - > Show ( ) ;
m_modulationVal - > Show ( ) ;
m_modulationLabel - > Show ( ) ;
m_labelText - > Show ( ) ;
m_labelLabel - > Show ( ) ;
2016-11-08 01:35:34 -05:00
clearButtons ( ) ;
2016-10-05 19:10:01 -04:00
2016-11-20 23:26:38 -05:00
addBookmarkChoice ( m_buttonPanel ) ;
2016-11-25 22:19:19 -05:00
addButton ( m_buttonPanel , " Activate Recent " , wxCommandEventHandler ( BookmarkView : : onActivateRecent ) ) ;
2016-12-17 21:14:13 -05:00
addButton ( m_buttonPanel , " Remove Recent " , wxCommandEventHandler ( BookmarkView : : onRemoveRecent ) ) ;
2016-11-08 01:35:34 -05:00
2016-11-14 23:16:08 -05:00
showProps ( ) ;
2016-11-08 01:35:34 -05:00
showButtons ( ) ;
2016-11-14 23:16:08 -05:00
refreshLayout ( ) ;
2016-10-05 19:10:01 -04:00
}
2016-11-10 20:43:01 -05:00
void BookmarkView : : groupSelection ( std : : string groupName ) {
2016-12-27 00:06:25 -05:00
clearButtons ( ) ;
hideProps ( ) ;
2017-03-16 23:23:21 -04:00
m_labelText - > SetValue ( groupName ) ;
2016-12-27 00:06:25 -05:00
2017-03-16 23:23:21 -04:00
m_labelText - > Show ( ) ;
m_labelLabel - > Show ( ) ;
2016-12-27 00:06:25 -05:00
addButton ( m_buttonPanel , " Remove Group " , wxCommandEventHandler ( BookmarkView : : onRemoveGroup ) ) ;
2017-03-16 23:23:21 -04:00
showProps ( ) ;
2016-12-27 00:06:25 -05:00
showButtons ( ) ;
refreshLayout ( ) ;
}
2016-11-10 20:43:01 -05:00
2017-02-28 12:58:54 -05:00
void BookmarkView : : rangeSelection ( BookmarkRangeEntryPtr re ) {
2016-12-27 00:06:25 -05:00
2016-11-10 20:43:01 -05:00
clearButtons ( ) ;
hideProps ( ) ;
2016-12-27 00:06:25 -05:00
m_labelText - > SetValue ( re - > label ) ;
m_labelText - > Show ( ) ;
m_labelLabel - > Show ( ) ;
2016-11-10 20:43:01 -05:00
2016-12-27 00:06:25 -05:00
m_frequencyVal - > Show ( ) ;
m_frequencyLabel - > Show ( ) ;
2016-12-12 20:17:47 -05:00
2016-12-27 00:06:25 -05:00
std : : string strFreq = frequencyToStr ( re - > startFreq ) + " - " + frequencyToStr ( re - > endFreq ) ;
2016-12-12 20:17:47 -05:00
2016-12-27 00:06:25 -05:00
m_frequencyVal - > SetLabelText ( std : : wstring ( strFreq . begin ( ) , strFreq . end ( ) ) ) ;
2016-11-10 20:43:01 -05:00
2016-12-27 00:06:25 -05:00
showProps ( ) ;
2016-12-12 20:17:47 -05:00
2016-12-27 00:06:25 -05:00
addButton ( m_buttonPanel , " Go to Range " , wxCommandEventHandler ( BookmarkView : : onActivateRange ) ) ;
2017-01-24 23:14:39 -05:00
addButton ( m_buttonPanel , " Update Range " , wxCommandEventHandler ( BookmarkView : : onUpdateRange ) ) - > SetToolTip ( " Update range by setting it to the active range. " ) ;
2016-12-27 00:06:25 -05:00
addButton ( m_buttonPanel , " Remove Range " , wxCommandEventHandler ( BookmarkView : : onRemoveRange ) ) ;
2016-11-10 20:43:01 -05:00
showButtons ( ) ;
2016-11-14 23:16:08 -05:00
refreshLayout ( ) ;
2016-11-10 20:43:01 -05:00
}
void BookmarkView : : bookmarkBranchSelection ( ) {
clearButtons ( ) ;
hideProps ( ) ;
2016-11-21 20:47:16 -05:00
addButton ( m_buttonPanel , BOOKMARK_VIEW_STR_ADD_GROUP , wxCommandEventHandler ( BookmarkView : : onAddGroup ) ) ;
2016-11-10 20:43:01 -05:00
showButtons ( ) ;
2016-11-14 23:16:08 -05:00
refreshLayout ( ) ;
2016-11-10 20:43:01 -05:00
}
void BookmarkView : : recentBranchSelection ( ) {
2016-12-17 21:14:13 -05:00
clearButtons ( ) ;
2016-11-10 20:43:01 -05:00
hideProps ( ) ;
2016-12-17 21:14:13 -05:00
addButton ( m_buttonPanel , BOOKMARK_VIEW_STR_CLEAR_RECENT , wxCommandEventHandler ( BookmarkView : : onClearRecents ) ) ;
showButtons ( ) ;
refreshLayout ( ) ;
2016-11-10 20:43:01 -05:00
this - > Layout ( ) ;
}
2016-12-27 00:06:25 -05:00
void BookmarkView : : rangeBranchSelection ( ) {
clearButtons ( ) ;
hideProps ( ) ;
2016-12-27 13:01:19 -05:00
m_labelText - > SetValue ( wxT ( " " ) ) ;
2016-12-27 00:06:25 -05:00
m_labelText - > Show ( ) ;
m_labelLabel - > Show ( ) ;
showProps ( ) ;
addButton ( m_buttonPanel , " Add Active Range " , wxCommandEventHandler ( BookmarkView : : onAddRange ) ) ;
showButtons ( ) ;
refreshLayout ( ) ;
this - > Layout ( ) ;
}
2016-11-10 20:43:01 -05:00
void BookmarkView : : activeBranchSelection ( ) {
hideProps ( ) ;
this - > Layout ( ) ;
}
2016-10-13 00:41:35 -04:00
2016-09-13 22:59:21 -04:00
void BookmarkView : : onTreeSelect ( wxTreeEvent & event ) {
2016-11-10 20:43:01 -05:00
wxTreeItemId itm = event . GetItem ( ) ;
TreeViewItem * tvi = dynamic_cast < TreeViewItem * > ( m_treeView - > GetItemData ( itm ) ) ;
2016-10-10 22:28:48 -04:00
if ( ! tvi ) {
2016-11-10 20:43:01 -05:00
if ( itm = = bookmarkBranch ) {
2016-11-10 21:48:57 -05:00
bookmarkBranchSelection ( ) ;
2016-11-10 20:43:01 -05:00
} else if ( itm = = activeBranch ) {
2016-11-10 21:48:57 -05:00
activeBranchSelection ( ) ;
2016-11-10 20:43:01 -05:00
} else if ( itm = = recentBranch ) {
2016-11-10 21:48:57 -05:00
recentBranchSelection ( ) ;
2016-12-27 00:06:25 -05:00
} else if ( itm = = rangeBranch ) {
rangeBranchSelection ( ) ;
2016-11-10 20:43:01 -05:00
} else {
hideProps ( ) ;
this - > Layout ( ) ;
}
2016-10-10 22:28:48 -04:00
return ;
}
if ( tvi - > type = = TreeViewItem : : TREEVIEW_ITEM_TYPE_ACTIVE ) {
2016-12-17 20:47:32 -05:00
activeSelection ( tvi - > demod ) ;
2016-11-26 00:39:41 -05:00
if ( tvi - > demod - > isActive ( ) ) {
2016-12-17 20:47:32 -05:00
wxGetApp ( ) . getDemodMgr ( ) . setActiveDemodulator ( nullptr , true ) ;
2016-11-26 00:39:41 -05:00
wxGetApp ( ) . getDemodMgr ( ) . setActiveDemodulator ( tvi - > demod , false ) ;
}
2016-10-10 22:28:48 -04:00
} else if ( tvi - > type = = TreeViewItem : : TREEVIEW_ITEM_TYPE_RECENT ) {
recentSelection ( tvi - > bookmarkEnt ) ;
} else if ( tvi - > type = = TreeViewItem : : TREEVIEW_ITEM_TYPE_BOOKMARK ) {
bookmarkSelection ( tvi - > bookmarkEnt ) ;
2016-11-10 20:43:01 -05:00
} else if ( tvi - > type = = TreeViewItem : : TREEVIEW_ITEM_TYPE_GROUP ) {
groupSelection ( tvi - > groupName ) ;
2016-12-27 00:06:25 -05:00
} else if ( tvi - > type = = TreeViewItem : : TREEVIEW_ITEM_TYPE_RANGE ) {
rangeSelection ( tvi - > rangeEnt ) ;
2016-09-28 20:37:39 -04:00
} else {
2016-10-10 22:28:48 -04:00
hideProps ( ) ;
2016-09-28 20:37:39 -04:00
this - > Layout ( ) ;
}
2016-09-13 22:59:21 -04:00
}
2016-10-13 00:41:35 -04:00
2016-09-13 22:59:21 -04:00
void BookmarkView : : onTreeSelectChanging ( wxTreeEvent & event ) {
event . Skip ( ) ;
}
2016-10-13 00:41:35 -04:00
2017-01-24 23:14:39 -05:00
void BookmarkView : : onLabelText ( wxCommandEvent & /* event */ ) {
2016-11-25 23:21:32 -05:00
std : : wstring newLabel = m_labelText - > GetValue ( ) . ToStdWstring ( ) ;
2016-12-15 21:53:51 -05:00
TreeViewItem * curSel = itemToTVI ( m_treeView - > GetSelection ( ) ) ;
if ( curSel ! = nullptr ) {
if ( curSel - > type = = TreeViewItem : : TREEVIEW_ITEM_TYPE_ACTIVE ) {
curSel - > demod - > setDemodulatorUserLabel ( newLabel ) ;
wxGetApp ( ) . getBookmarkMgr ( ) . updateActiveList ( ) ;
} else if ( curSel - > type = = TreeViewItem : : TREEVIEW_ITEM_TYPE_BOOKMARK ) {
curSel - > bookmarkEnt - > label = m_labelText - > GetValue ( ) . ToStdWstring ( ) ;
curSel - > bookmarkEnt - > node - > child ( " user_label " ) - > element ( ) - > set ( newLabel ) ;
wxGetApp ( ) . getBookmarkMgr ( ) . updateBookmarks ( ) ;
} else if ( curSel - > type = = TreeViewItem : : TREEVIEW_ITEM_TYPE_RECENT ) {
curSel - > bookmarkEnt - > label = m_labelText - > GetValue ( ) . ToStdWstring ( ) ;
curSel - > bookmarkEnt - > node - > child ( " user_label " ) - > element ( ) - > set ( newLabel ) ;
wxGetApp ( ) . getBookmarkMgr ( ) . updateActiveList ( ) ;
2016-12-27 00:06:25 -05:00
} else if ( curSel - > type = = TreeViewItem : : TREEVIEW_ITEM_TYPE_RANGE ) {
curSel - > rangeEnt - > label = m_labelText - > GetValue ( ) . ToStdWstring ( ) ;
wxGetApp ( ) . getBookmarkMgr ( ) . updateActiveList ( ) ;
2017-03-16 23:23:21 -04:00
} else if ( curSel - > type = = TreeViewItem : : TREEVIEW_ITEM_TYPE_GROUP ) {
std : : string newGroupName = m_labelText - > GetValue ( ) . ToStdString ( ) ;
if ( newGroupName ! = " " & & newGroupName ! = curSel - > groupName ) {
wxGetApp ( ) . getBookmarkMgr ( ) . renameGroup ( curSel - > groupName , newGroupName ) ;
wxGetApp ( ) . getBookmarkMgr ( ) . updateBookmarks ( ) ;
}
2016-12-15 21:53:51 -05:00
}
2016-11-25 23:21:32 -05:00
}
2016-12-15 21:53:51 -05:00
// else if (groupSel != "") {
2016-12-12 20:17:47 -05:00
// std::string newGroupName = m_labelText->GetValue().ToStdString();
// wxGetApp().getBookmarkMgr().renameGroup(groupSel, newGroupName);
// groupSel = newGroupName;
// wxGetApp().getBookmarkMgr().updateBookmarks();
// }
2016-09-13 22:59:21 -04:00
}
2016-10-13 00:41:35 -04:00
2017-01-24 23:14:39 -05:00
void BookmarkView : : onDoubleClickFreq ( wxMouseEvent & /* event */ ) {
2017-02-28 12:58:54 -05:00
2016-12-15 21:53:51 -05:00
TreeViewItem * curSel = itemToTVI ( m_treeView - > GetSelection ( ) ) ;
if ( curSel & & curSel - > type = = TreeViewItem : : TREEVIEW_ITEM_TYPE_ACTIVE ) {
2016-12-17 20:47:32 -05:00
wxGetApp ( ) . getDemodMgr ( ) . setActiveDemodulator ( nullptr , true ) ;
2016-12-15 21:53:51 -05:00
wxGetApp ( ) . getDemodMgr ( ) . setActiveDemodulator ( curSel - > demod , false ) ;
2016-09-29 20:47:38 -04:00
wxGetApp ( ) . showFrequencyInput ( FrequencyDialog : : FrequencyDialogTarget : : FDIALOG_TARGET_DEFAULT ) ;
}
}
2016-10-13 00:41:35 -04:00
2017-01-24 23:14:39 -05:00
void BookmarkView : : onDoubleClickBandwidth ( wxMouseEvent & /* event */ ) {
2016-12-15 21:53:51 -05:00
TreeViewItem * curSel = itemToTVI ( m_treeView - > GetSelection ( ) ) ;
if ( curSel & & curSel - > type = = TreeViewItem : : TREEVIEW_ITEM_TYPE_ACTIVE ) {
2016-12-17 20:47:32 -05:00
wxGetApp ( ) . getDemodMgr ( ) . setActiveDemodulator ( nullptr , true ) ;
2016-12-15 21:53:51 -05:00
wxGetApp ( ) . getDemodMgr ( ) . setActiveDemodulator ( curSel - > demod , false ) ;
2016-09-29 20:47:38 -04:00
wxGetApp ( ) . showFrequencyInput ( FrequencyDialog : : FrequencyDialogTarget : : FDIALOG_TARGET_BANDWIDTH ) ;
}
}
2016-10-13 00:41:35 -04:00
2017-01-24 23:14:39 -05:00
void BookmarkView : : onRemoveActive ( wxCommandEvent & /* event */ ) {
2016-12-15 21:53:51 -05:00
TreeViewItem * curSel = itemToTVI ( m_treeView - > GetSelection ( ) ) ;
if ( curSel & & curSel - > type = = TreeViewItem : : TREEVIEW_ITEM_TYPE_ACTIVE ) {
2016-11-26 00:39:41 -05:00
if ( editingLabel ) {
return ;
}
2016-12-17 20:47:32 -05:00
doRemoveActive ( curSel - > demod ) ;
2017-03-04 03:02:15 -05:00
m_treeView - > Delete ( m_treeView - > GetSelection ( ) ) ;
2016-09-28 20:37:39 -04:00
}
2016-09-13 22:59:21 -04:00
}
2016-10-13 00:41:35 -04:00
2017-01-24 23:14:39 -05:00
void BookmarkView : : onRemoveBookmark ( wxCommandEvent & /* event */ ) {
2016-11-26 00:39:41 -05:00
if ( editingLabel ) {
return ;
}
2016-12-15 21:53:51 -05:00
TreeViewItem * curSel = itemToTVI ( m_treeView - > GetSelection ( ) ) ;
if ( curSel & & curSel - > type = = TreeViewItem : : TREEVIEW_ITEM_TYPE_BOOKMARK ) {
2016-12-23 18:45:25 -05:00
ActionDialog : : showDialog ( new ActionDialogRemoveBookmark ( curSel - > bookmarkEnt ) ) ;
2016-11-10 21:48:57 -05:00
}
2016-11-08 01:35:34 -05:00
}
2017-01-24 23:14:39 -05:00
void BookmarkView : : onActivateBookmark ( wxCommandEvent & /* event */ ) {
2016-12-15 21:53:51 -05:00
TreeViewItem * curSel = itemToTVI ( m_treeView - > GetSelection ( ) ) ;
if ( curSel & & curSel - > type = = TreeViewItem : : TREEVIEW_ITEM_TYPE_BOOKMARK ) {
activateBookmark ( curSel - > bookmarkEnt ) ;
2016-11-08 01:35:34 -05:00
}
}
2017-01-24 23:14:39 -05:00
void BookmarkView : : onActivateRecent ( wxCommandEvent & /* event */ ) {
2016-12-15 21:53:51 -05:00
TreeViewItem * curSel = itemToTVI ( m_treeView - > GetSelection ( ) ) ;
if ( curSel & & curSel - > type = = TreeViewItem : : TREEVIEW_ITEM_TYPE_RECENT ) {
2017-03-04 05:22:29 -05:00
BookmarkEntryPtr bookmarkEntToActivate = curSel - > bookmarkEnt ;
2017-03-06 13:51:27 -05:00
//let removeRecent() + activateBookmark() refresh the tree
//and delete the recent node properly...
2017-03-04 05:22:29 -05:00
wxGetApp ( ) . getBookmarkMgr ( ) . removeRecent ( bookmarkEntToActivate ) ;
2017-03-06 13:51:27 -05:00
2017-03-04 05:22:29 -05:00
activateBookmark ( bookmarkEntToActivate ) ;
2016-11-08 01:35:34 -05:00
}
}
2017-01-24 23:14:39 -05:00
void BookmarkView : : onRemoveRecent ( wxCommandEvent & /* event */ ) {
2016-12-17 21:14:13 -05:00
if ( editingLabel ) {
return ;
}
TreeViewItem * curSel = itemToTVI ( m_treeView - > GetSelection ( ) ) ;
if ( curSel & & curSel - > type = = TreeViewItem : : TREEVIEW_ITEM_TYPE_RECENT ) {
2017-03-04 05:22:29 -05:00
BookmarkEntryPtr bookmarkEntToRemove = curSel - > bookmarkEnt ;
2017-03-06 13:51:27 -05:00
//let removeRecent() + updateActiveList() refresh the tree
//and delete the recent node properly...
2017-03-04 05:22:29 -05:00
wxGetApp ( ) . getBookmarkMgr ( ) . removeRecent ( bookmarkEntToRemove ) ;
2016-12-17 21:14:13 -05:00
wxGetApp ( ) . getBookmarkMgr ( ) . updateActiveList ( ) ;
}
}
2017-01-24 23:14:39 -05:00
void BookmarkView : : onClearRecents ( wxCommandEvent & /* event */ ) {
2016-12-17 21:14:13 -05:00
if ( editingLabel ) {
return ;
}
doClearRecents ( ) ;
}
2017-01-24 23:14:39 -05:00
void BookmarkView : : onAddGroup ( wxCommandEvent & /* event */ ) {
2016-11-21 20:47:16 -05:00
wxString stringVal = wxGetTextFromUser ( BOOKMARK_VIEW_STR_ADD_GROUP_DESC , BOOKMARK_VIEW_STR_ADD_GROUP , " " ) ;
2016-11-10 20:43:01 -05:00
if ( stringVal . ToStdString ( ) ! = " " ) {
2016-11-21 20:47:16 -05:00
wxGetApp ( ) . getBookmarkMgr ( ) . addGroup ( stringVal . ToStdString ( ) ) ;
2016-11-10 20:43:01 -05:00
wxGetApp ( ) . getBookmarkMgr ( ) . updateBookmarks ( ) ;
}
}
2016-12-12 20:17:47 -05:00
2017-01-24 23:14:39 -05:00
void BookmarkView : : onRemoveGroup ( wxCommandEvent & /* event */ ) {
2016-11-26 00:39:41 -05:00
if ( editingLabel ) {
return ;
}
2016-12-15 21:53:51 -05:00
TreeViewItem * curSel = itemToTVI ( m_treeView - > GetSelection ( ) ) ;
if ( curSel & & curSel - > type = = TreeViewItem : : TREEVIEW_ITEM_TYPE_GROUP ) {
2016-12-23 18:45:25 -05:00
ActionDialog : : showDialog ( new ActionDialogRemoveGroup ( curSel - > groupName ) ) ;
2016-11-25 22:19:19 -05:00
}
2016-11-10 20:43:01 -05:00
}
2017-01-24 23:14:39 -05:00
void BookmarkView : : onAddRange ( wxCommandEvent & /* event */ ) {
2017-02-28 12:58:54 -05:00
BookmarkRangeEntryPtr re = BookmarkView : : makeActiveRangeEntry ( ) ;
2017-01-24 23:14:39 -05:00
2016-12-27 00:06:25 -05:00
re - > label = m_labelText - > GetValue ( ) ;
2017-01-24 23:14:39 -05:00
2016-12-27 00:06:25 -05:00
wxGetApp ( ) . getBookmarkMgr ( ) . addRange ( re ) ;
wxGetApp ( ) . getBookmarkMgr ( ) . updateActiveList ( ) ;
}
2017-01-24 23:14:39 -05:00
void BookmarkView : : onRemoveRange ( wxCommandEvent & /* event */ ) {
2016-12-27 00:06:25 -05:00
if ( editingLabel ) {
return ;
}
TreeViewItem * curSel = itemToTVI ( m_treeView - > GetSelection ( ) ) ;
if ( curSel & & curSel - > type = = TreeViewItem : : TREEVIEW_ITEM_TYPE_RANGE ) {
ActionDialog : : showDialog ( new ActionDialogRemoveRange ( curSel - > rangeEnt ) ) ;
}
}
2017-01-24 23:14:39 -05:00
void BookmarkView : : onRenameRange ( wxCommandEvent & /* event */ ) {
2016-12-27 00:06:25 -05:00
TreeViewItem * curSel = itemToTVI ( m_treeView - > GetSelection ( ) ) ;
if ( ! curSel | | curSel - > type ! = TreeViewItem : : TREEVIEW_ITEM_TYPE_GROUP ) {
return ;
}
wxString stringVal = " " ;
stringVal = wxGetTextFromUser ( BOOKMARK_VIEW_STR_RENAME_GROUP , " New Group Name " , curSel - > groupName ) ;
std : : string newGroupName = stringVal . Trim ( ) . ToStdString ( ) ;
if ( newGroupName ! = " " ) {
wxGetApp ( ) . getBookmarkMgr ( ) . renameGroup ( curSel - > groupName , newGroupName ) ;
wxGetApp ( ) . getBookmarkMgr ( ) . updateBookmarks ( ) ;
}
}
2017-01-24 23:14:39 -05:00
void BookmarkView : : onActivateRange ( wxCommandEvent & /* event */ ) {
2016-12-27 00:06:25 -05:00
TreeViewItem * curSel = itemToTVI ( m_treeView - > GetSelection ( ) ) ;
if ( curSel & & curSel - > type = = TreeViewItem : : TREEVIEW_ITEM_TYPE_RANGE ) {
activateRange ( curSel - > rangeEnt ) ;
}
}
2017-01-24 23:14:39 -05:00
void BookmarkView : : onUpdateRange ( wxCommandEvent & /* event */ ) {
TreeViewItem * curSel = itemToTVI ( m_treeView - > GetSelection ( ) ) ;
if ( curSel & & curSel - > type = = TreeViewItem : : TREEVIEW_ITEM_TYPE_RANGE ) {
ActionDialog : : showDialog ( new ActionDialogUpdateRange ( curSel - > rangeEnt ) ) ;
}
}
2016-12-27 00:06:25 -05:00
2016-10-13 00:41:35 -04:00
void BookmarkView : : onTreeBeginDrag ( wxTreeEvent & event ) {
TreeViewItem * tvi = dynamic_cast < TreeViewItem * > ( m_treeView - > GetItemData ( event . GetItem ( ) ) ) ;
dragItem = nullptr ;
dragItemId = nullptr ;
2016-12-16 22:05:25 -05:00
SetCursor ( wxCURSOR_CROSS ) ;
2016-10-13 00:41:35 -04:00
if ( ! tvi ) {
event . Veto ( ) ;
return ;
}
bool bAllow = false ;
2016-11-14 23:52:50 -05:00
std : : wstring dragItemName ;
2016-10-13 00:41:35 -04:00
if ( tvi - > type = = TreeViewItem : : TREEVIEW_ITEM_TYPE_ACTIVE ) {
bAllow = true ;
2016-12-23 18:45:25 -05:00
dragItemName = BookmarkMgr : : getActiveDisplayName ( tvi - > demod ) ;
2016-12-16 22:05:25 -05:00
} else if ( tvi - > type = = TreeViewItem : : TREEVIEW_ITEM_TYPE_RECENT | | tvi - > type = = TreeViewItem : : TREEVIEW_ITEM_TYPE_BOOKMARK ) {
2016-10-13 00:41:35 -04:00
bAllow = true ;
2016-12-23 18:45:25 -05:00
dragItemName = BookmarkMgr : : getBookmarkEntryDisplayName ( tvi - > bookmarkEnt ) ;
2016-10-13 00:41:35 -04:00
}
if ( bAllow ) {
wxColour bgColor ( ThemeMgr : : mgr . currentTheme - > generalBackground ) ;
wxColour textColor ( ThemeMgr : : mgr . currentTheme - > text ) ;
m_treeView - > SetBackgroundColour ( textColor ) ;
m_treeView - > SetForegroundColour ( bgColor ) ;
2016-12-16 22:05:25 -05:00
// m_treeView->SetToolTip("Dragging " + dragItemName);
2016-10-13 00:41:35 -04:00
dragItem = tvi ;
dragItemId = event . GetItem ( ) ;
2016-12-16 22:05:25 -05:00
visualDragItem = new BookmarkViewVisualDragItem ( dragItemName ) ;
2016-10-13 00:41:35 -04:00
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 ( ) ;
2016-12-16 22:05:25 -05:00
SetCursor ( wxCURSOR_ARROW ) ;
if ( visualDragItem ! = nullptr ) {
visualDragItem - > Destroy ( ) ;
delete visualDragItem ;
visualDragItem = nullptr ;
}
2016-10-13 00:41:35 -04:00
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 ) {
2016-12-12 20:17:47 -05:00
doBookmarkActive ( BOOKMARK_VIEW_STR_UNNAMED , dragItem - > demod ) ;
2016-11-20 23:26:38 -05:00
} else if ( dragItem & & dragItem - > type = = TreeViewItem : : TREEVIEW_ITEM_TYPE_RECENT ) {
2016-12-12 20:17:47 -05:00
doBookmarkRecent ( BOOKMARK_VIEW_STR_UNNAMED , dragItem - > bookmarkEnt ) ;
} else if ( dragItem & & dragItem - > type = = TreeViewItem : : TREEVIEW_ITEM_TYPE_BOOKMARK ) {
doMoveBookmark ( dragItem - > bookmarkEnt , BOOKMARK_VIEW_STR_UNNAMED ) ;
2016-10-13 00:41:35 -04:00
}
}
return ;
}
if ( tvi - > type = = TreeViewItem : : TREEVIEW_ITEM_TYPE_GROUP ) {
if ( dragItem & & dragItem - > type = = TreeViewItem : : TREEVIEW_ITEM_TYPE_ACTIVE ) { // Active -> Group Item
2016-11-21 20:47:16 -05:00
doBookmarkActive ( tvi - > groupName , dragItem - > demod ) ;
2016-10-13 00:41:35 -04:00
} else if ( dragItem & & dragItem - > type = = TreeViewItem : : TREEVIEW_ITEM_TYPE_RECENT ) { // Recent -> Group Item
2016-11-21 20:47:16 -05:00
doBookmarkRecent ( tvi - > groupName , dragItem - > bookmarkEnt ) ;
2017-03-04 03:02:15 -05:00
m_treeView - > Delete ( dragItemId ) ;
2016-11-25 22:19:19 -05:00
} else if ( dragItem & & dragItem - > type = = TreeViewItem : : TREEVIEW_ITEM_TYPE_BOOKMARK ) { // Bookmark -> Group Item
doMoveBookmark ( dragItem - > bookmarkEnt , tvi - > groupName ) ;
2016-10-13 00:41:35 -04:00
}
} else if ( tvi - > type = = TreeViewItem : : TREEVIEW_ITEM_TYPE_BOOKMARK ) {
if ( dragItem & & dragItem - > type = = TreeViewItem : : TREEVIEW_ITEM_TYPE_ACTIVE ) { // Active -> Same Group
2016-11-21 20:47:16 -05:00
doBookmarkActive ( tvi - > groupName , dragItem - > demod ) ;
2016-10-13 00:41:35 -04:00
} else if ( dragItem & & dragItem - > type = = TreeViewItem : : TREEVIEW_ITEM_TYPE_RECENT ) { // Recent -> Same Group
2016-11-21 20:47:16 -05:00
doBookmarkRecent ( tvi - > groupName , dragItem - > bookmarkEnt ) ;
2017-03-04 03:02:15 -05:00
m_treeView - > Delete ( dragItemId ) ;
2016-11-25 22:19:19 -05:00
} else if ( dragItem & & dragItem - > type = = TreeViewItem : : TREEVIEW_ITEM_TYPE_BOOKMARK ) { // Bookmark -> Same Group
doMoveBookmark ( dragItem - > bookmarkEnt , tvi - > groupName ) ;
2016-10-13 00:41:35 -04:00
}
}
}
void BookmarkView : : onTreeItemGetTooltip ( wxTreeEvent & event ) {
event . Skip ( ) ;
}
2017-02-28 12:58:54 -05:00
void BookmarkView : : onEnterWindow ( wxMouseEvent & event ) {
mouseTracker . OnMouseEnterWindow ( event ) ;
# ifdef _WIN32
if ( wxGetApp ( ) . getAppFrame ( ) - > canFocus ( ) ) {
2017-03-01 16:13:41 -05:00
//make mousewheel work in the tree view.
m_treeView - > SetFocus ( ) ;
2017-02-28 12:58:54 -05:00
}
# endif
2017-03-01 16:13:41 -05:00
setStatusText ( " You can mouse-drag a bookmark entry from one category to the next..etc. TODO: add more Bookmarks descriptions " ) ;
2016-10-13 00:41:35 -04:00
}
2017-02-28 12:58:54 -05:00
void BookmarkView : : onLeaveWindow ( wxMouseEvent & event ) {
mouseTracker . OnMouseLeftWindow ( event ) ;
2016-10-13 00:41:35 -04:00
}
2016-12-15 21:53:51 -05:00
2016-12-16 22:05:25 -05:00
void BookmarkView : : onMotion ( wxMouseEvent & event ) {
2017-02-28 12:58:54 -05:00
mouseTracker . OnMouseMoved ( event ) ;
2016-12-16 22:05:25 -05:00
wxPoint pos = ClientToScreen ( event . GetPosition ( ) ) ;
pos + = wxPoint ( 30 , - 10 ) ;
if ( visualDragItem ! = nullptr ) {
visualDragItem - > SetPosition ( pos ) ;
}
2017-03-01 16:13:41 -05:00
2016-12-16 22:05:25 -05:00
event . Skip ( ) ;
}
2017-03-01 16:13:41 -05:00
void BookmarkView : : setStatusText ( std : : string statusText ) {
//make tooltips active on the tree view.
wxGetApp ( ) . getAppFrame ( ) - > setStatusText ( m_treeView , statusText ) ;
}
2016-12-15 21:53:51 -05:00
TreeViewItem * BookmarkView : : itemToTVI ( wxTreeItemId item ) {
TreeViewItem * tvi = nullptr ;
if ( item ! = nullptr ) {
tvi = dynamic_cast < TreeViewItem * > ( m_treeView - > GetItemData ( item ) ) ;
}
return tvi ;
}
2017-02-28 12:58:54 -05:00
void BookmarkView : : onSearchTextFocus ( wxMouseEvent & event ) {
mouseTracker . OnMouseMoved ( event ) ;
//apparently needed ???
m_searchText - > SetFocus ( ) ;
if ( m_searchText - > GetValue ( ) = = L " Search.. " ) {
//select the whole field, so that typing
//replaces the whole text by the new one right away.
m_searchText - > SetSelection ( - 1 , - 1 ) ;
}
else if ( ! m_searchText - > GetValue ( ) . Trim ( ) . empty ( ) ) {
//position at the end of the existing field, so we can append
//or truncate the existing field.
m_searchText - > SetInsertionPointEnd ( ) ;
}
else {
//empty field, restore displaying L"Search.."
m_searchText - > SetValue ( L " Search.. " ) ;
m_searchText - > SetSelection ( - 1 , - 1 ) ;
2016-12-26 21:56:19 -05:00
}
}
void BookmarkView : : onSearchText ( wxCommandEvent & event ) {
wstring searchText = m_searchText - > GetValue ( ) . Trim ( ) . Lower ( ) . ToStdWstring ( ) ;
2017-02-28 12:58:54 -05:00
searchKeywords . clear ( ) ;
2016-12-26 21:56:19 -05:00
2017-02-28 12:58:54 -05:00
if ( searchText . length ( ) ! = 0 ) {
2016-12-26 21:56:19 -05:00
std : : wstringstream searchTextLo ( searchText ) ;
wstring tmp ;
2016-12-27 00:06:25 -05:00
while ( std : : getline ( searchTextLo , tmp , L ' ' ) ) {
2016-12-26 21:56:19 -05:00
if ( tmp . length ( ) ! = 0 & & tmp . find ( L " search. " ) = = wstring : : npos ) {
searchKeywords . push_back ( tmp ) ;
2016-12-27 13:01:19 -05:00
// std::wcout << L"Keyword: " << tmp << '\n';
2016-12-26 21:56:19 -05:00
}
}
}
if ( searchKeywords . size ( ) ! = 0 & & ! m_clearSearchButton - > IsShown ( ) ) {
m_clearSearchButton - > Show ( ) ;
refreshLayout ( ) ;
} else if ( searchKeywords . size ( ) = = 0 & & m_clearSearchButton - > IsShown ( ) ) {
m_clearSearchButton - > Hide ( ) ;
refreshLayout ( ) ;
}
wxGetApp ( ) . getBookmarkMgr ( ) . updateActiveList ( ) ;
wxGetApp ( ) . getBookmarkMgr ( ) . updateBookmarks ( ) ;
}
2017-01-24 23:14:39 -05:00
void BookmarkView : : onClearSearch ( wxCommandEvent & /* event */ ) {
2016-12-27 13:01:19 -05:00
m_clearSearchButton - > Hide ( ) ;
2016-12-26 21:56:19 -05:00
m_searchText - > SetValue ( L " Search.. " ) ;
m_treeView - > SetFocus ( ) ;
2017-02-28 12:58:54 -05:00
searchKeywords . clear ( ) ;
2016-12-26 21:56:19 -05:00
wxGetApp ( ) . getBookmarkMgr ( ) . updateActiveList ( ) ;
wxGetApp ( ) . getBookmarkMgr ( ) . updateBookmarks ( ) ;
refreshLayout ( ) ;
}
2016-12-15 21:53:51 -05:00
2016-12-27 13:01:19 -05:00
void BookmarkView : : loadDefaultRanges ( ) {
2017-01-24 23:14:39 -05:00
2017-03-07 12:30:33 -05:00
wxGetApp ( ) . getBookmarkMgr ( ) . addRange ( std : : make_shared < BookmarkRangeEntry > ( L " 160 Meters " , 1900000 , 1800000 , 2000000 ) ) ;
wxGetApp ( ) . getBookmarkMgr ( ) . addRange ( std : : make_shared < BookmarkRangeEntry > ( L " 80 Meters " , 3750000 , 3500000 , 4000000 ) ) ;
wxGetApp ( ) . getBookmarkMgr ( ) . addRange ( std : : make_shared < BookmarkRangeEntry > ( L " 60 Meters " , 5368500 , 5332000 , 5405000 ) ) ;
wxGetApp ( ) . getBookmarkMgr ( ) . addRange ( std : : make_shared < BookmarkRangeEntry > ( L " 40 Meters " , 7150000 , 7000000 , 7300000 ) ) ;
wxGetApp ( ) . getBookmarkMgr ( ) . addRange ( std : : make_shared < BookmarkRangeEntry > ( L " 30 Meters " , 10125000 , 10100000 , 10150000 ) ) ;
wxGetApp ( ) . getBookmarkMgr ( ) . addRange ( std : : make_shared < BookmarkRangeEntry > ( L " 20 Meters " , 14175000 , 14000000 , 14350000 ) ) ;
wxGetApp ( ) . getBookmarkMgr ( ) . addRange ( std : : make_shared < BookmarkRangeEntry > ( L " 17 Meters " , 18068180 , 17044180 , 19092180 ) ) ;
wxGetApp ( ) . getBookmarkMgr ( ) . addRange ( std : : make_shared < BookmarkRangeEntry > ( L " 15 Meters " , 21225000 , 21000000 , 21450000 ) ) ;
wxGetApp ( ) . getBookmarkMgr ( ) . addRange ( std : : make_shared < BookmarkRangeEntry > ( L " 12 Meters " , 24940000 , 24890000 , 24990000 ) ) ;
wxGetApp ( ) . getBookmarkMgr ( ) . addRange ( std : : make_shared < BookmarkRangeEntry > ( L " 10 Meters " , 28850000 , 28000000 , 29700000 ) ) ;
2017-02-28 12:58:54 -05:00
}
BookmarkRangeEntryPtr BookmarkView : : makeActiveRangeEntry ( ) {
BookmarkRangeEntryPtr re ( new BookmarkRangeEntry ) ;
2017-01-24 23:14:39 -05:00
re - > freq = wxGetApp ( ) . getFrequency ( ) ;
re - > startFreq = wxGetApp ( ) . getAppFrame ( ) - > getViewCenterFreq ( ) - ( wxGetApp ( ) . getAppFrame ( ) - > getViewBandwidth ( ) / 2 ) ;
re - > endFreq = wxGetApp ( ) . getAppFrame ( ) - > getViewCenterFreq ( ) + ( wxGetApp ( ) . getAppFrame ( ) - > getViewBandwidth ( ) / 2 ) ;
return re ;
}
2017-03-02 16:10:17 -05:00
void BookmarkView : : SetTreeItemData ( const wxTreeItemId & item , wxTreeItemData * data ) {
TreeViewItem * itemData = itemToTVI ( item ) ;
if ( itemData ! = NULL ) {
2017-03-04 03:02:15 -05:00
//cleanup previous data, if any
2017-03-02 16:10:17 -05:00
delete itemData ;
}
m_treeView - > SetItemData ( item , data ) ;
}