KiCad PCB EDA Suite
pagelayout_editor/menubar.cpp
Go to the documentation of this file.
1 /*
2  * This program source code file is part of KiCad, a free EDA CAD application.
3  *
4  * Copyright (C) 2016-2019 KiCad Developers, see AUTHORS.txt for contributors.
5  * Copyright (C) 2013 CERN
6  * @author Jean-Pierre Charras, jp.charras at wanadoo.fr
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * as published by the Free Software Foundation; either version 2
11  * of the License, or (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, you may find one here:
20  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
21  * or you may search the http://www.gnu.org website for the version 2 license,
22  * or you may write to the Free Software Foundation, Inc.,
23  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
24  */
25 
26 #include <kiface_i.h>
27 #include <menus_helpers.h>
28 #include <pgm_base.h>
29 #include <tool/conditional_menu.h>
30 #include <tool/tool_manager.h>
31 #include <tool/selection.h>
32 #include <tools/pl_actions.h>
34 #include "pl_editor_frame.h"
35 #include "pl_editor_id.h"
36 
37 
39 {
41  // wxWidgets handles the Mac Application menu behind the scenes, but that means
42  // we always have to start from scratch with a new wxMenuBar.
43  wxMenuBar* oldMenuBar = GetMenuBar();
44  wxMenuBar* menuBar = new wxMenuBar();
45 
46  auto modifiedDocumentCondition = [ this ] ( const SELECTION& sel ) {
47  return GetScreen() && GetScreen()->IsModify();
48  };
49 
50  static ACTION_MENU* openRecentMenu; // Open Recent submenu, static to remember this menu
51 
52  // Before deleting, remove the menus managed by m_fileHistory
53  // (the file history will be updated when adding/removing files in history
54  if( openRecentMenu )
55  Kiface().GetFileHistory().RemoveMenu( openRecentMenu );
56 
57  //-- File menu -------------------------------------------------------
58  //
59  CONDITIONAL_MENU* fileMenu = new CONDITIONAL_MENU( false, selTool );
60 
61  openRecentMenu = new ACTION_MENU( false );
62  openRecentMenu->SetTool( selTool );
63  openRecentMenu->SetTitle( _( "Open Recent" ) );
64  openRecentMenu->SetIcon( recent_xpm );
65 
66  Kiface().GetFileHistory().UseMenu( openRecentMenu );
67  Kiface().GetFileHistory().AddFilesToMenu();
68 
71  fileMenu->AddMenu( openRecentMenu, SELECTION_CONDITIONS::ShowAlways );
72 
73  fileMenu->AddSeparator();
74  fileMenu->AddItem( ACTIONS::save, modifiedDocumentCondition );
76 
77  fileMenu->AddSeparator();
80 
81  fileMenu->AppendSeparator();
82  // Don't use ACTIONS::quit; wxWidgets moves this on OSX and expects to find it via wxID_EXIT
83  fileMenu->AddItem( wxID_EXIT, _( "Quit" ), "", exit_xpm, SELECTION_CONDITIONS::ShowAlways );
84 
85  fileMenu->Resolve();
86 
87  //-- Edit menu -------------------------------------------------------
88  //
89  CONDITIONAL_MENU* editMenu = new CONDITIONAL_MENU( false, selTool );
90 
91  auto enableUndoCondition = [ this ] ( const SELECTION& sel ) {
92  return GetScreen() && GetScreen()->GetUndoCommandCount() != 0;
93  };
94  auto enableRedoCondition = [ this ] ( const SELECTION& sel ) {
95  return GetScreen() && GetScreen()->GetRedoCommandCount() != 0;
96  };
97  auto idleCondition = [] ( const SELECTION& sel ) {
98  return !sel.Front() || sel.Front()->GetEditFlags() == 0;
99  };
100 
101  editMenu->AddItem( ACTIONS::undo, enableUndoCondition );
102  editMenu->AddItem( ACTIONS::redo, enableRedoCondition );
103 
104  editMenu->AddSeparator();
107  editMenu->AddItem( ACTIONS::paste, idleCondition );
109 
110  editMenu->Resolve();
111 
112  //-- View menu -------------------------------------------------------
113  //
114  CONDITIONAL_MENU* viewMenu = new CONDITIONAL_MENU( false, selTool );
115 
116  auto whiteBackgroundCondition = [ this ] ( const SELECTION& aSel ) {
117  return GetDrawBgColor() == WHITE;
118  };
119  auto gridShownCondition = [ this ] ( const SELECTION& aSel ) {
120  return IsGridVisible();
121  };
122  auto fullCrosshairCondition = [ this ] ( const SELECTION& aSel ) {
124  };
125 
126  viewMenu->AddSeparator();
132 
133  viewMenu->AddSeparator();
134  viewMenu->AddCheckItem( PL_ACTIONS::toggleBackground, whiteBackgroundCondition );
135  viewMenu->AddCheckItem( ACTIONS::toggleGrid, gridShownCondition );
136  viewMenu->AddCheckItem( ACTIONS::toggleCursorStyle, fullCrosshairCondition );
137 
138  viewMenu->Resolve();
139 
140  //-- Inspector menu -------------------------------------------------------
141  //
142  CONDITIONAL_MENU* inspectorMenu = new CONDITIONAL_MENU( false, selTool );
144  inspectorMenu->Resolve();
145 
146  //-- Place menu -------------------------------------------------------
147  //
148  CONDITIONAL_MENU* placeMenu = new CONDITIONAL_MENU( false, selTool );
149 
154 
155  placeMenu->AddSeparator();
157 
158  placeMenu->Resolve();
159 
160  //-- Preferences menu --------------------------------------------------
161  //
162  CONDITIONAL_MENU* preferencesMenu = new CONDITIONAL_MENU( false, selTool );
163 
164  preferencesMenu->AddItem( wxID_PREFERENCES,
165  _( "Preferences...\tCTRL+," ),
166  _( "Show preferences for all open tools" ),
167  preference_xpm, SELECTION_CONDITIONS::ShowAlways );
168 
169  // Language submenu
170  AddMenuLanguageList( preferencesMenu, selTool );
171 
172  //-- Menubar -----------------------------------------------------------
173  //
174  menuBar->Append( fileMenu, _( "&File" ) );
175  menuBar->Append( editMenu, _( "&Edit" ) );
176  menuBar->Append( viewMenu, _( "&View" ) );
177  menuBar->Append( inspectorMenu, _( "&Inspect" ) );
178  menuBar->Append( placeMenu, _( "&Place" ) );
179  menuBar->Append( preferencesMenu, _( "P&references" ) );
180  AddStandardHelpMenu( menuBar );
181 
182  SetMenuBar( menuBar );
183  delete oldMenuBar;
184 }
static bool ShowAlways(const SELECTION &aSelection)
Function ShowAlways The default condition function (always returns true).
void AddMenu(ACTION_MENU *aMenu, const SELECTION_CONDITION &aCondition=SELECTION_CONDITIONS::ShowAlways, int aOrder=ANY_ORDER)
Function AddMenu()
static TOOL_ACTION showInspector
Definition: pl_actions.h:76
static TOOL_ACTION zoomInCenter
Definition: actions.h:88
KIGFX::GAL_DISPLAY_OPTIONS & GetGalDisplayOptions()
Return a reference to the gal rendering options used by GAL for rendering.
static TOOL_ACTION pageSettings
Definition: actions.h:59
Class ACTION_MENU.
Definition: action_menu.h:43
static TOOL_ACTION doDelete
Definition: actions.h:73
static TOOL_ACTION drawLine
Definition: pl_actions.h:66
static SELECTION_CONDITION MoreThan(int aNumber)
Function MoreThan Creates a functor that tests if the number of selected items is greater than the va...
static TOOL_ACTION zoomTool
Definition: actions.h:93
static TOOL_ACTION placeImage
Definition: pl_actions.h:64
void ReCreateMenuBar() override
Recreates the menu bar.
virtual bool IsGridVisible() const
void AddMenuLanguageList(CONDITIONAL_MENU *aMasterMenu, TOOL_INTERACTIVE *aControlTool)
Function AddMenuLanguageList creates a menu list for language choice, and add it as submenu to Master...
int GetUndoCommandCount() const
Definition: base_screen.h:201
static TOOL_ACTION zoomFitScreen
Definition: actions.h:91
void AddCheckItem(const TOOL_ACTION &aAction, const SELECTION_CONDITION &aCondition, int aOrder=ANY_ORDER)
Function AddCheckItem()
static TOOL_ACTION placeText
Definition: pl_actions.h:63
static TOOL_ACTION print
Definition: actions.h:60
KIFACE_I & Kiface()
Global KIFACE_I "get" accessor.
Definition: kicad.cpp:51
static TOOL_ACTION zoomOutCenter
Definition: actions.h:89
void SetTool(TOOL_INTERACTIVE *aTool)
Function SetTool() Sets a tool that is the creator of the menu.
static TOOL_ACTION copy
Definition: actions.h:70
static TOOL_ACTION toggleGrid
Definition: actions.h:130
static TOOL_ACTION open
Definition: actions.h:53
static TOOL_ACTION save
Definition: actions.h:54
static TOOL_ACTION doNew
Definition: actions.h:47
void SetIcon(const BITMAP_OPAQUE *aIcon)
Function SetIcon() Assigns an icon for the entry.
Definition: action_menu.cpp:66
void AddStandardHelpMenu(wxMenuBar *aMenuBar)
Adds the standard KiCad help menu to the menubar.
static TOOL_ACTION cut
Definition: actions.h:69
PL_EDITOR_SCREEN * GetScreen() const override
Return a pointer to a BASE_SCREEN or one of its derivatives.
bool IsModify() const
Definition: base_screen.h:228
static TOOL_ACTION drawRectangle
Definition: pl_actions.h:65
#define _(s)
void Resolve()
Function Resolve()
void AddSeparator(int aOrder=ANY_ORDER)
Function AddSeparator()
static TOOL_ACTION toggleBackground
Definition: pl_actions.h:75
static TOOL_ACTION redo
Definition: actions.h:68
void SetTitle(const wxString &aTitle) override
Function SetTitle() Sets title for the menu.
Definition: action_menu.cpp:84
see class PGM_BASE
static TOOL_ACTION saveAs
Definition: actions.h:55
static TOOL_ACTION zoomRedraw
Definition: actions.h:85
FILE_HISTORY & GetFileHistory()
Definition: kiface_i.h:123
static TOOL_ACTION appendImportedWorksheet
Definition: pl_actions.h:67
Definition: colors.h:49
virtual COLOR4D GetDrawBgColor() const
static TOOL_ACTION undo
Definition: actions.h:67
static TOOL_ACTION toggleCursorStyle
Definition: actions.h:96
TOOL_MANAGER * m_toolManager
int GetRedoCommandCount() const
Definition: base_screen.h:206
void AddItem(const TOOL_ACTION &aAction, const SELECTION_CONDITION &aCondition, int aOrder=ANY_ORDER)
Function AddItem()
bool m_fullscreenCursor
Fullscreen crosshair or small cross
static TOOL_ACTION paste
Definition: actions.h:71