From c258ad7e3c5744618264b38e29e364731b7369f2 Mon Sep 17 00:00:00 2001 From: Ian McInerney Date: Fri, 2 Aug 2019 10:35:26 +0200 Subject: [PATCH] pleditor: Fix menubar actions and display * Move the preview settings to view and make the menu item work * Fix bug with preferences menu not displaying on GTK * Implement quit command and make it similar to the other programs Fixes: lp:1832139 * https://bugs.launchpad.net/kicad/+bug/1832139 --- pagelayout_editor/menubar.cpp | 20 ++++++++++++++++--- pagelayout_editor/pl_editor_frame.cpp | 20 +++++++++++++++++-- pagelayout_editor/pl_editor_frame.h | 13 +++++++++++- pagelayout_editor/tools/pl_editor_control.cpp | 8 -------- pagelayout_editor/tools/pl_editor_control.h | 1 - 5 files changed, 47 insertions(+), 15 deletions(-) diff --git a/pagelayout_editor/menubar.cpp b/pagelayout_editor/menubar.cpp index 865794f897..f1c3ec9c4e 100644 --- a/pagelayout_editor/menubar.cpp +++ b/pagelayout_editor/menubar.cpp @@ -75,12 +75,21 @@ void PL_EDITOR_FRAME::ReCreateMenuBar() fileMenu->AddItem( ACTIONS::saveAs, SELECTION_CONDITIONS::ShowAlways ); fileMenu->AddSeparator(); - fileMenu->AddItem( ACTIONS::pageSettings, SELECTION_CONDITIONS::ShowAlways ); fileMenu->AddItem( ACTIONS::print, SELECTION_CONDITIONS::ShowAlways ); fileMenu->AddSeparator(); - // Don't use ACTIONS::quit; wxWidgets moves this on OSX and expects to find it via wxID_EXIT - fileMenu->AddItem( wxID_EXIT, _( "Quit" ), "", exit_xpm, SELECTION_CONDITIONS::ShowAlways ); + + if( Kiface().IsSingle() ) + { + // Don't use ACTIONS::quit; wxWidgets moves this on OSX and expects to find it via wxID_EXIT + fileMenu->AddItem( wxID_EXIT, _( "Quit" ), "", exit_xpm, + SELECTION_CONDITIONS::ShowAlways ); + } + else + { + fileMenu->AddItem( wxID_CLOSE, _( "Close" ), "", exit_xpm, + SELECTION_CONDITIONS::ShowAlways ); + } fileMenu->Resolve(); @@ -135,6 +144,9 @@ void PL_EDITOR_FRAME::ReCreateMenuBar() viewMenu->AddCheckItem( ACTIONS::toggleGrid, gridShownCondition ); viewMenu->AddCheckItem( ACTIONS::toggleCursorStyle, fullCrosshairCondition ); + viewMenu->AddSeparator(); + viewMenu->AddItem( PL_ACTIONS::previewSettings, SELECTION_CONDITIONS::ShowAlways ); + viewMenu->Resolve(); //-- Inspector menu ------------------------------------------------------- @@ -169,6 +181,8 @@ void PL_EDITOR_FRAME::ReCreateMenuBar() // Language submenu AddMenuLanguageList( preferencesMenu, selTool ); + preferencesMenu->Resolve(); + //-- Menubar ----------------------------------------------------------- // menuBar->Append( fileMenu, _( "&File" ) ); diff --git a/pagelayout_editor/pl_editor_frame.cpp b/pagelayout_editor/pl_editor_frame.cpp index 0454863d24..25d8f8ae2d 100644 --- a/pagelayout_editor/pl_editor_frame.cpp +++ b/pagelayout_editor/pl_editor_frame.cpp @@ -57,6 +57,9 @@ BEGIN_EVENT_TABLE( PL_EDITOR_FRAME, EDA_DRAW_FRAME ) EVT_CLOSE( PL_EDITOR_FRAME::OnCloseWindow ) + EVT_MENU( wxID_CLOSE, PL_EDITOR_FRAME::OnExit ) + EVT_MENU( wxID_EXIT, PL_EDITOR_FRAME::OnExit ) + EVT_MENU( wxID_FILE, PL_EDITOR_FRAME::Files_io ) EVT_MENU_RANGE( ID_FILE1, ID_FILEMAX, PL_EDITOR_FRAME::OnFileHistory ) @@ -177,6 +180,9 @@ PL_EDITOR_FRAME::PL_EDITOR_FRAME( KIWAY* aKiway, wxWindow* aParent ) : m_auimgr.Update(); + // Add the exit key handler + InitExitKey(); + wxPoint originCoord = ReturnCoordOriginCorner(); SetGridOrigin( originCoord ); @@ -237,7 +243,17 @@ bool PL_EDITOR_FRAME::OpenProjectFiles( const std::vector& aFileSet, i } -void PL_EDITOR_FRAME::OnCloseWindow( wxCloseEvent& Event ) +void PL_EDITOR_FRAME::OnExit( wxCommandEvent& aEvent ) +{ + if( aEvent.GetId() == wxID_EXIT ) + Kiway().OnKiCadExit(); + + if( aEvent.GetId() == wxID_CLOSE || Kiface().IsSingle() ) + Close( false ); +} + + +void PL_EDITOR_FRAME::OnCloseWindow( wxCloseEvent& aEvent ) { if( GetScreen()->IsModify() ) { @@ -247,7 +263,7 @@ void PL_EDITOR_FRAME::OnCloseWindow( wxCloseEvent& Event ) if( !HandleUnsavedChanges( this, wxString::Format( msg, filename.GetFullName() ), [&]()->bool { return saveCurrentPageLayout(); } ) ) { - Event.Veto(); + aEvent.Veto(); return; } } diff --git a/pagelayout_editor/pl_editor_frame.h b/pagelayout_editor/pl_editor_frame.h index cded428970..66a10ec3de 100644 --- a/pagelayout_editor/pl_editor_frame.h +++ b/pagelayout_editor/pl_editor_frame.h @@ -98,7 +98,18 @@ public: */ bool InsertPageLayoutDescrFile( const wxString& aFullFileName ); - void OnCloseWindow( wxCloseEvent& Event ); + + /* + * Function OnExit + * Event handler for the wxID_EXIT and wxID_CLOSE events + */ + void OnExit( wxCommandEvent& aEvent ); + + /* + * Function OnCloseWindow + * Event handler for the close event + */ + void OnCloseWindow( wxCloseEvent& aEvent ); // The Tool Framework initalization void setupTools(); diff --git a/pagelayout_editor/tools/pl_editor_control.cpp b/pagelayout_editor/tools/pl_editor_control.cpp index 6ad14e54b0..7937737853 100644 --- a/pagelayout_editor/tools/pl_editor_control.cpp +++ b/pagelayout_editor/tools/pl_editor_control.cpp @@ -117,13 +117,6 @@ int PL_EDITOR_CONTROL::Plot( const TOOL_EVENT& aEvent ) } -int PL_EDITOR_CONTROL::Quit( const TOOL_EVENT& aEvent ) -{ - m_frame->Close( false ); - return 0; -} - - int PL_EDITOR_CONTROL::ToggleBackgroundColor( const TOOL_EVENT& aEvent ) { m_frame->SetDrawBgColor( m_frame->GetDrawBgColor() == WHITE ? BLACK : WHITE ); @@ -185,7 +178,6 @@ void PL_EDITOR_CONTROL::setTransitions() Go( &PL_EDITOR_CONTROL::SaveAs, ACTIONS::saveAs.MakeEvent() ); Go( &PL_EDITOR_CONTROL::Print, ACTIONS::print.MakeEvent() ); Go( &PL_EDITOR_CONTROL::Plot, ACTIONS::plot.MakeEvent() ); - Go( &PL_EDITOR_CONTROL::Quit, ACTIONS::quit.MakeEvent() ); Go( &PL_EDITOR_CONTROL::PageSetup, PL_ACTIONS::previewSettings.MakeEvent() ); Go( &PL_EDITOR_CONTROL::ToggleBackgroundColor, PL_ACTIONS::toggleBackground.MakeEvent() ); diff --git a/pagelayout_editor/tools/pl_editor_control.h b/pagelayout_editor/tools/pl_editor_control.h index a3ee62f470..c9c7e9cec6 100644 --- a/pagelayout_editor/tools/pl_editor_control.h +++ b/pagelayout_editor/tools/pl_editor_control.h @@ -58,7 +58,6 @@ public: int PageSetup( const TOOL_EVENT& aEvent ); int Print( const TOOL_EVENT& aEvent ); int Plot( const TOOL_EVENT& aEvent ); - int Quit( const TOOL_EVENT& aEvent ); int ToggleBackgroundColor( const TOOL_EVENT& aEvent ); int ShowInspector( const TOOL_EVENT& aEvent );