From 0263408aef4819a5987ac11aeac51e4678b870c5 Mon Sep 17 00:00:00 2001 From: "Zane U. Ji" Date: Wed, 15 Aug 2012 21:43:31 +0800 Subject: [PATCH] Supported navigation between documents with keyboard --- src/mynotebook.cpp | 25 +++++++++++++++++++++++++ src/mynotebook.h | 1 + src/xmlcopyeditor.cpp | 17 +++++++++++------ src/xmlcopyeditor.h | 4 ++++ 4 files changed, 41 insertions(+), 6 deletions(-) diff --git a/src/mynotebook.cpp b/src/mynotebook.cpp index 04ea8bd..796efd6 100755 --- a/src/mynotebook.cpp +++ b/src/mynotebook.cpp @@ -27,6 +27,7 @@ BEGIN_EVENT_TABLE ( MyNotebook, wxAuiNotebook ) EVT_RIGHT_DOWN ( MyNotebook::OnRightDown ) EVT_MENU ( ID_MENU_CLOSE, MyNotebook::OnMenuClose ) EVT_MENU ( ID_MENU_CLOSE_ALL, MyNotebook::OnMenuCloseAll ) + //EVT_KEY_DOWN ( MyNotebook::OnKeyDown ) END_EVENT_TABLE() MyNotebook::MyNotebook ( @@ -37,6 +38,9 @@ MyNotebook::MyNotebook ( int style ) : wxAuiNotebook ( parent, id, position, size, style ) { rightClickPage = -1; + + wxApp::GetInstance()->Connect ( wxEVT_KEY_DOWN, + wxKeyEventHandler ( MyNotebook::OnKeyDown ), NULL, this ); } void MyNotebook::OnLeftDown ( wxMouseEvent& event ) @@ -104,3 +108,24 @@ void MyNotebook::OnMenuCloseAll ( wxCommandEvent& WXUNUSED ( event ) ) wxCommandEvent e; frame->OnCloseAll ( e ); } + +void MyNotebook::OnKeyDown ( wxKeyEvent &event ) +{ +#if defined __WXGTK__ + if ( event.m_keyCode != WXK_TAB || !event.m_altDown ) +#elif defined __WXOSX__ + if ( event.m_uniChar != ',' || !event.m_controlDown ) +#else + if ( event.m_keyCode != WXK_TAB || !event.m_controlDown ) +#endif + { + event.Skip(); + return; + } + + AdvanceSelection ( !event.m_shiftDown ); + + XmlDoc *doc = ( XmlDoc * ) GetCurrentPage(); + if ( doc != NULL ) + doc->SetFocus(); +} diff --git a/src/mynotebook.h b/src/mynotebook.h index 347392e..b245c79 100755 --- a/src/mynotebook.h +++ b/src/mynotebook.h @@ -43,6 +43,7 @@ class MyNotebook : public wxAuiNotebook void OnRightDown ( wxMouseEvent& event ); void OnMenuClose ( wxCommandEvent& event ); void OnMenuCloseAll ( wxCommandEvent& event ); + void OnKeyDown ( wxKeyEvent &event ); private: int rightClickPage; DECLARE_EVENT_TABLE() diff --git a/src/xmlcopyeditor.cpp b/src/xmlcopyeditor.cpp index 4b7195b..4d0068f 100755 --- a/src/xmlcopyeditor.cpp +++ b/src/xmlcopyeditor.cpp @@ -592,18 +592,18 @@ MyFrame::MyFrame ( mainBook ( 0 ), restoreFocusToNotebook ( false ) { +#ifdef __WXDEBUG__ + wxLog::SetActiveTarget ( &logTarget ); + wxLog::SetLogLevel ( wxLOG_Max ); +#endif + manager.SetManagedWindow ( this ); lastPos = 0; htmlReport = NULL; lastDoc = NULL; - wxString defaultFont = -#ifdef __WXMSW__ - _T ( "Arial" ); -#else - _T ( "Bitstream Vera Sans" ); -#endif + wxString defaultFont = wxSystemSettings::GetFont ( wxSYS_SYSTEM_FONT ).GetFaceName(); bool findMatchCase; @@ -850,6 +850,7 @@ MyFrame::MyFrame ( long style = wxAUI_NB_TOP | wxAUI_NB_TAB_SPLIT | wxAUI_NB_TAB_MOVE | + wxAUI_NB_SCROLL_BUTTONS | wxAUI_NB_WINDOWLIST_BUTTON | wxAUI_NB_CLOSE_ON_ALL_TABS | wxNO_BORDER; @@ -987,6 +988,10 @@ MyFrame::MyFrame ( MyFrame::~MyFrame() { +#ifdef __WXDEBUG__ + wxLog::SetActiveTarget ( NULL ); +#endif + std::vector::iterator it; for ( it = tempFileVector.begin(); it != tempFileVector.end(); it++ ) wxRemoveFile ( *it ); diff --git a/src/xmlcopyeditor.h b/src/xmlcopyeditor.h index 8997d62..b3ae5c7 100755 --- a/src/xmlcopyeditor.h +++ b/src/xmlcopyeditor.h @@ -345,7 +345,11 @@ class MyFrame : public wxFrame wxLocale& myLocale; bool singleInstanceCheck; int lang, lastPos; +#ifdef __WXDEBUG__ + wxLogStderr logTarget; +#else wxLogNull logTarget; +#endif std::auto_ptr htmlPrinting; std::auto_ptr findDialog; std::auto_ptr helpController;