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-2019 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();
79 
80  fileMenu->AddSeparator();
81  fileMenu->AddQuitOrClose( &Kiface(), _( "Page Layout Editor" ) );
82 
83  fileMenu->Resolve();
84 
85  //-- Edit menu -------------------------------------------------------
86  //
87  CONDITIONAL_MENU* editMenu = new CONDITIONAL_MENU( false, selTool );
88 
89  auto enableUndoCondition = [ this ] ( const SELECTION& sel ) {
90  return GetScreen() && GetScreen()->GetUndoCommandCount() != 0;
91  };
92  auto enableRedoCondition = [ this ] ( const SELECTION& sel ) {
93  return GetScreen() && GetScreen()->GetRedoCommandCount() != 0;
94  };
95  auto idleCondition = [] ( const SELECTION& sel ) {
96  return !sel.Front() || sel.Front()->GetEditFlags() == 0;
97  };
98 
99  editMenu->AddItem( ACTIONS::undo, enableUndoCondition );
100  editMenu->AddItem( ACTIONS::redo, enableRedoCondition );
101 
102  editMenu->AddSeparator();
105  editMenu->AddItem( ACTIONS::paste, idleCondition );
107 
108  editMenu->Resolve();
109 
110  //-- View menu -------------------------------------------------------
111  //
112  CONDITIONAL_MENU* viewMenu = new CONDITIONAL_MENU( false, selTool );
113 
114  auto whiteBackgroundCondition = [ this ] ( const SELECTION& aSel ) {
115  return GetDrawBgColor() == WHITE;
116  };
117  auto gridShownCondition = [ this ] ( const SELECTION& aSel ) {
118  return IsGridVisible();
119  };
120  auto fullCrosshairCondition = [ this ] ( const SELECTION& aSel ) {
122  };
123 
124  viewMenu->AddSeparator();
130 
131  viewMenu->AddSeparator();
132  viewMenu->AddCheckItem( PL_ACTIONS::toggleBackground, whiteBackgroundCondition );
133  viewMenu->AddCheckItem( ACTIONS::toggleGrid, gridShownCondition );
134  viewMenu->AddCheckItem( ACTIONS::toggleCursorStyle, fullCrosshairCondition );
135 
136  viewMenu->AddSeparator();
138 
139 #ifdef __APPLE__
140  viewMenu->AddSeparator();
141 #endif
142 
143  viewMenu->Resolve();
144 
145  //-- Place menu -------------------------------------------------------
146  //
147  CONDITIONAL_MENU* placeMenu = new CONDITIONAL_MENU( false, selTool );
148 
153 
154  placeMenu->AddSeparator();
156 
157  placeMenu->Resolve();
158 
159  //-- Inspector menu -------------------------------------------------------
160  //
161  CONDITIONAL_MENU* inspectorMenu = new CONDITIONAL_MENU( false, selTool );
163 
164  inspectorMenu->Resolve();
165 
166  //-- Preferences menu --------------------------------------------------
167  //
168  CONDITIONAL_MENU* preferencesMenu = new CONDITIONAL_MENU( false, selTool );
169 
170  preferencesMenu->AddItem( wxID_PREFERENCES,
171  _( "Preferences...\tCTRL+," ),
172  _( "Show preferences for all open tools" ),
173  preference_xpm, SELECTION_CONDITIONS::ShowAlways );
174 
175  // Language submenu
176  AddMenuLanguageList( preferencesMenu, selTool );
177 
178  preferencesMenu->Resolve();
179 
180  //-- Menubar -----------------------------------------------------------
181  //
182  menuBar->Append( fileMenu, _( "&File" ) );
183  menuBar->Append( editMenu, _( "&Edit" ) );
184  menuBar->Append( viewMenu, _( "&View" ) );
185  menuBar->Append( placeMenu, _( "&Place" ) );
186  menuBar->Append( inspectorMenu, _( "&Inspect" ) );
187  menuBar->Append( preferencesMenu, _( "P&references" ) );
188  AddStandardHelpMenu( menuBar );
189 
190  SetMenuBar( menuBar );
191  delete oldMenuBar;
192 }
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:90
KIGFX::GAL_DISPLAY_OPTIONS & GetGalDisplayOptions()
Return a reference to the gal rendering options used by GAL for rendering.
Class ACTION_MENU.
Definition: action_menu.h:43
static TOOL_ACTION doDelete
Definition: actions.h:74
static TOOL_ACTION drawLine
Definition: pl_actions.h:67
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:95
static TOOL_ACTION placeImage
Definition: pl_actions.h:65
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:93
void AddCheckItem(const TOOL_ACTION &aAction, const SELECTION_CONDITION &aCondition, int aOrder=ANY_ORDER)
Function AddCheckItem()
static TOOL_ACTION placeText
Definition: pl_actions.h:64
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:91
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:132
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:68
void AddStandardHelpMenu(wxMenuBar *aMenuBar)
Adds the standard KiCad help menu to the menubar.
static TOOL_ACTION previewSettings
Definition: pl_actions.h:77
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:66
#define _(s)
void Resolve()
Function Resolve()
void AddSeparator(int aOrder=ANY_ORDER)
Function AddSeparator()
static TOOL_ACTION toggleBackground
Definition: pl_actions.h:75
void AddQuitOrClose(KIFACE_I *aKiface, wxString aAppname="")
Functions AddQuitOrClose()
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:86
see class PGM_BASE
static TOOL_ACTION saveAs
Definition: actions.h:55
static TOOL_ACTION zoomRedraw
Definition: actions.h:87
FILE_HISTORY & GetFileHistory()
Definition: kiface_i.h:123
static TOOL_ACTION appendImportedWorksheet
Definition: pl_actions.h:68
Definition: colors.h:49
virtual COLOR4D GetDrawBgColor() const
static TOOL_ACTION undo
Definition: actions.h:67
static TOOL_ACTION toggleCursorStyle
Definition: actions.h:98
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