kicad/pagelayout_editor/menubar.cpp

179 lines
7.2 KiB
C++

/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2016-2019 KiCad Developers, see AUTHORS.txt for contributors.
* Copyright (C) 2013 CERN
* @author Jean-Pierre Charras, jp.charras at wanadoo.fr
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, you may find one here:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* or you may search the http://www.gnu.org website for the version 2 license,
* or you may write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include <kiface_i.h>
#include <menus_helpers.h>
#include <pgm_base.h>
#include <tool/conditional_menu.h>
#include <tool/tool_manager.h>
#include <tool/selection.h>
#include <tools/pl_actions.h>
#include <tools/pl_selection_tool.h>
#include "hotkeys.h"
#include "pl_editor_frame.h"
#include "pl_editor_id.h"
void PL_EDITOR_FRAME::ReCreateMenuBar()
{
PL_SELECTION_TOOL* selTool = m_toolManager->GetTool<PL_SELECTION_TOOL>();
// wxWidgets handles the Mac Application menu behind the scenes, but that means
// we always have to start from scratch with a new wxMenuBar.
wxMenuBar* oldMenuBar = GetMenuBar();
wxMenuBar* menuBar = new wxMenuBar();
wxString msg;
static wxMenu* openRecentMenu; // Open Recent submenu,
// static to remember this menu
// Before deleting, remove the menus managed by m_fileHistory
// (the file history will be updated when adding/removing files in history
if( openRecentMenu )
Kiface().GetFileHistory().RemoveMenu( openRecentMenu );
// Recreate all menus:
// File Menu:
wxMenu* fileMenu = new wxMenu;
msg = AddHotkeyName( _( "&New" ), PlEditorHotkeysDescr, HK_NEW );
AddMenuItem( fileMenu, wxID_NEW, msg,
_( "Create new page layout design" ),
KiBitmap( new_page_layout_xpm ) );
msg = AddHotkeyName( _( "&Open..." ), PlEditorHotkeysDescr, HK_OPEN );
AddMenuItem( fileMenu, wxID_OPEN, msg,
_( "Open an existing page layout design file" ),
KiBitmap( open_page_layout_xpm ) );
openRecentMenu = new wxMenu();
Kiface().GetFileHistory().UseMenu( openRecentMenu );
Kiface().GetFileHistory().AddFilesToMenu();
AddMenuItem( fileMenu, openRecentMenu, wxID_ANY, _( "Open &Recent" ),
_( "Open recent page layout design file" ),
KiBitmap( recent_xpm ) );
fileMenu->AppendSeparator();
msg = AddHotkeyName( _( "&Save" ), PlEditorHotkeysDescr, HK_SAVE );
AddMenuItem( fileMenu, wxID_SAVE, msg,
_( "Save current page layout design file" ),
KiBitmap( save_xpm ) );
msg = AddHotkeyName( _( "Save &As..." ), PlEditorHotkeysDescr, HK_SAVEAS );
AddMenuItem( fileMenu, wxID_SAVEAS, msg,
_( "Save current page layout design file with a different name" ),
KiBitmap( save_as_xpm ) );
fileMenu->AppendSeparator();
msg = AddHotkeyName( _( "&Print..." ), PlEditorHotkeysDescr, HK_PRINT );
AddMenuItem( fileMenu, wxID_PRINT, msg, KiBitmap( print_button_xpm ) );
AddMenuItem( fileMenu, wxID_PREVIEW, _( "Print Pre&view..." ), KiBitmap( print_button_xpm ) );
fileMenu->AppendSeparator();
AddMenuItem( fileMenu, wxID_EXIT, _( "&Close" ),
_( "Close Page Layout Editor" ),
KiBitmap( exit_xpm ) );
// Edit Menu:
CONDITIONAL_MENU* editMenu = new CONDITIONAL_MENU( false, selTool );
auto enableUndoCondition = [ this ] ( const SELECTION& sel ) {
return GetScreen() && GetScreen()->GetUndoCommandCount() != 0;
};
auto enableRedoCondition = [ this ] ( const SELECTION& sel ) {
return GetScreen() && GetScreen()->GetRedoCommandCount() != 0;
};
editMenu->AddItem( ACTIONS::undo, enableUndoCondition );
editMenu->AddItem( ACTIONS::redo, enableRedoCondition );
editMenu->AddSeparator();
editMenu->AddItem( PL_ACTIONS::doDelete, SELECTION_CONDITIONS::MoreThan( 0 ) );
// View Menu:
CONDITIONAL_MENU* viewMenu = new CONDITIONAL_MENU( false, selTool );
auto whiteBackgroundCondition = [ this ] ( const SELECTION& aSel ) {
return GetDrawBgColor() == WHITE;
};
auto gridShownCondition = [ this ] ( const SELECTION& aSel ) {
return IsGridVisible();
};
auto fullCrosshairCondition = [ this ] ( const SELECTION& aSel ) {
return GetGalDisplayOptions().m_fullscreenCursor;
};
viewMenu->AddSeparator();
viewMenu->AddItem( ACTIONS::zoomInCenter, SELECTION_CONDITIONS::ShowAlways );
viewMenu->AddItem( ACTIONS::zoomOutCenter, SELECTION_CONDITIONS::ShowAlways );
viewMenu->AddItem( ACTIONS::zoomFitScreen, SELECTION_CONDITIONS::ShowAlways );
viewMenu->AddItem( ACTIONS::zoomTool, SELECTION_CONDITIONS::ShowAlways );
viewMenu->AddItem( ACTIONS::zoomRedraw, SELECTION_CONDITIONS::ShowAlways );
viewMenu->AddSeparator();
viewMenu->AddCheckItem( PL_ACTIONS::toggleBackground, whiteBackgroundCondition );
viewMenu->AddCheckItem( ACTIONS::toggleGrid, gridShownCondition );
viewMenu->AddCheckItem( ACTIONS::toggleCursorStyle, fullCrosshairCondition );
// Place Menu:
CONDITIONAL_MENU* placeMenu = new CONDITIONAL_MENU( false, selTool );
placeMenu->AddItem( PL_ACTIONS::drawLine, SELECTION_CONDITIONS::ShowAlways );
placeMenu->AddItem( PL_ACTIONS::drawRectangle, SELECTION_CONDITIONS::ShowAlways );
placeMenu->AddItem( PL_ACTIONS::placeText, SELECTION_CONDITIONS::ShowAlways );
placeMenu->AddItem( PL_ACTIONS::placeImage, SELECTION_CONDITIONS::ShowAlways );
placeMenu->AddSeparator();
placeMenu->AddItem( PL_ACTIONS::appendImportedWorksheet, SELECTION_CONDITIONS::ShowAlways );
// Menu for preferences
wxMenu* preferencesMenu = new wxMenu;
msg = AddHotkeyName( _( "&Preferences..." ), PlEditorHotkeysDescr, HK_PREFERENCES );
AddMenuItem( preferencesMenu, wxID_PREFERENCES, msg,
_( "Show preferences for all open tools" ),
KiBitmap( preference_xpm ) );
// Language submenu
Pgm().AddMenuLanguageList( preferencesMenu );
// Append menus to the menubar
menuBar->Append( fileMenu, _( "&File" ) );
menuBar->Append( editMenu, _( "&Edit" ) );
menuBar->Append( viewMenu, _( "&View" ) );
menuBar->Append( placeMenu, _( "&Place" ) );
menuBar->Append( preferencesMenu, _( "P&references" ) );
AddStandardHelpMenu( menuBar );
SetMenuBar( menuBar );
delete oldMenuBar;
}