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 <filehistory.h>
27 #include <kiface_i.h>
28 #include <menus_helpers.h>
29 #include <pgm_base.h>
30 #include <tool/action_menu.h>
31 #include <tool/tool_manager.h>
32 #include <tool/selection.h>
33 #include <widgets/wx_menubar.h>
34 
35 #include "pl_editor_frame.h"
36 #include "pl_editor_id.h"
37 #include "tools/pl_actions.h"
39 
40 
42 {
44  // wxWidgets handles the Mac Application menu behind the scenes, but that means
45  // we always have to start from scratch with a new wxMenuBar.
46  wxMenuBar* oldMenuBar = GetMenuBar();
47  WX_MENUBAR* menuBar = new WX_MENUBAR();
48 
49  static ACTION_MENU* openRecentMenu; // Open Recent submenu, static to remember this menu
50  FILE_HISTORY& recentFiles = GetFileHistory();
51 
52  // Create the menu if it does not exist. Adding a file to/from the history
53  // will automatically refresh the menu.
54  if( !openRecentMenu )
55  {
56  openRecentMenu = new ACTION_MENU( false );
57  openRecentMenu->SetTool( selTool );
58  openRecentMenu->SetTitle( _( "Open Recent" ) );
59  openRecentMenu->SetIcon( recent_xpm );
60 
61  recentFiles.UseMenu( openRecentMenu );
62  recentFiles.AddFilesToMenu();
63  }
64 
65  //-- File menu -------------------------------------------------------
66  //
67  ACTION_MENU* fileMenu = new ACTION_MENU( false, selTool );
68 
69  fileMenu->Add( ACTIONS::doNew );
70  fileMenu->Add( ACTIONS::open );
71 
72  wxMenuItem* item = fileMenu->Add( openRecentMenu );
73 
74  // Add the file menu condition here since it needs the item ID for the submenu
75  ACTION_CONDITIONS cond;
76  cond.Enable( FILE_HISTORY::FileHistoryNotEmpty( recentFiles ) );
77  RegisterUIUpdateHandler( item->GetId(), cond );
78 
79  fileMenu->AppendSeparator();
80  fileMenu->Add( ACTIONS::save );
81  fileMenu->Add( ACTIONS::saveAs );
82 
83  fileMenu->AppendSeparator();
84  fileMenu->Add( ACTIONS::print );
85 
86  fileMenu->AppendSeparator();
87  fileMenu->AddQuitOrClose( &Kiface(), _( "Page Layout Editor" ) );
88 
89  //-- Edit menu -------------------------------------------------------
90  //
91  ACTION_MENU* editMenu = new ACTION_MENU( false, selTool );
92 
93  editMenu->Add( ACTIONS::undo );
94  editMenu->Add( ACTIONS::redo );
95 
96  editMenu->AppendSeparator();
97  editMenu->Add( ACTIONS::cut );
98  editMenu->Add( ACTIONS::copy );
99  editMenu->Add( ACTIONS::paste );
100  editMenu->Add( ACTIONS::doDelete );
101 
102  //-- View menu -------------------------------------------------------
103  //
104  ACTION_MENU* viewMenu = new ACTION_MENU( false, selTool );
105 
106  viewMenu->Add( ACTIONS::zoomInCenter );
107  viewMenu->Add( ACTIONS::zoomOutCenter );
108  viewMenu->Add( ACTIONS::zoomFitScreen );
109  viewMenu->Add( ACTIONS::zoomTool );
110  viewMenu->Add( ACTIONS::zoomRedraw );
111 
112  viewMenu->AppendSeparator();
114 
115  // Units submenu
116  ACTION_MENU* unitsSubMenu = new ACTION_MENU( false, selTool );
117  unitsSubMenu->SetTitle( _( "&Units" ) );
118  unitsSubMenu->SetIcon( unit_mm_xpm );
119  unitsSubMenu->Add( ACTIONS::inchesUnits, ACTION_MENU::CHECK );
120  unitsSubMenu->Add( ACTIONS::milsUnits, ACTION_MENU::CHECK );
122  viewMenu->Add( unitsSubMenu );
123 
125 
126  viewMenu->AppendSeparator();
127  viewMenu->Add( PL_ACTIONS::previewSettings );
128 
129 #ifdef __APPLE__
130  // Add a separator only on macOS because the OS adds menu items to the view menu after ours
131  viewMenu->AppendSeparator();
132 #endif
133 
134  //-- Place menu -------------------------------------------------------
135  //
136  ACTION_MENU* placeMenu = new ACTION_MENU( false, selTool );
137 
138  placeMenu->Add( PL_ACTIONS::drawLine );
139  placeMenu->Add( PL_ACTIONS::drawRectangle );
140  placeMenu->Add( PL_ACTIONS::placeText );
141  placeMenu->Add( PL_ACTIONS::placeImage );
142 
143  placeMenu->AppendSeparator();
145 
146  //-- Inspector menu -------------------------------------------------------
147  //
148  ACTION_MENU* inspectorMenu = new ACTION_MENU( false, selTool );
149  inspectorMenu->Add( PL_ACTIONS::showInspector );
150 
151 
152  //-- Preferences menu --------------------------------------------------
153  //
154  ACTION_MENU* preferencesMenu = new ACTION_MENU( false, selTool );
155 
156  preferencesMenu->Add( _( "Preferences...\tCTRL+," ),
157  _( "Show preferences for all open tools" ),
158  wxID_PREFERENCES,
159  preference_xpm );
160 
161  // Language submenu
162  AddMenuLanguageList( preferencesMenu, selTool );
163 
164  //-- Menubar -----------------------------------------------------------
165  //
166  menuBar->Append( fileMenu, _( "&File" ) );
167  menuBar->Append( editMenu, _( "&Edit" ) );
168  menuBar->Append( viewMenu, _( "&View" ) );
169  menuBar->Append( placeMenu, _( "&Place" ) );
170  menuBar->Append( inspectorMenu, _( "&Inspect" ) );
171  menuBar->Append( preferencesMenu, _( "P&references" ) );
172  AddStandardHelpMenu( menuBar );
173 
174  SetMenuBar( menuBar );
175  delete oldMenuBar;
176 }
void AddFilesToMenu() override
Add the files to all registered menus.
Definition: filehistory.h:98
wxMenuItem * Add(const wxString &aLabel, int aId, const BITMAP_OPAQUE *aIcon)
Adds a wxWidgets-style entry to the menu.
static TOOL_ACTION showInspector
Definition: pl_actions.h:78
static TOOL_ACTION zoomInCenter
Definition: actions.h:91
Defines the structure of a menu based on ACTIONs.
Definition: action_menu.h:43
static TOOL_ACTION doDelete
Definition: actions.h:75
static TOOL_ACTION drawLine
Definition: pl_actions.h:67
static TOOL_ACTION zoomTool
Definition: actions.h:97
static TOOL_ACTION placeImage
Definition: pl_actions.h:65
void ReCreateMenuBar() override
Recreates the menu bar.
static TOOL_ACTION zoomFitScreen
Definition: actions.h:94
static TOOL_ACTION millimetersUnits
Definition: actions.h:144
virtual void RegisterUIUpdateHandler(int aID, const ACTION_CONDITIONS &aConditions) override
Register a UI update handler for the control with ID aID.
static TOOL_ACTION placeText
Definition: pl_actions.h:64
static TOOL_ACTION print
Definition: actions.h:60
Wrapper around a wxMenuBar object that prevents the accelerator table from being used.
Definition: wx_menubar.h:45
This class implements a file history object to store a list of files, that can then be added to a men...
Definition: filehistory.h:42
static TOOL_ACTION zoomOutCenter
Definition: actions.h:92
const BITMAP_OPAQUE recent_xpm[1]
Definition: recent.cpp:68
void SetTool(TOOL_INTERACTIVE *aTool)
Sets a tool that is the creator of the menu.
ACTION_CONDITIONS & Enable(const SELECTION_CONDITION &aCondition)
static TOOL_ACTION copy
Definition: actions.h:70
static TOOL_ACTION toggleGrid
Definition: actions.h:138
static TOOL_ACTION open
Definition: actions.h:53
static TOOL_ACTION inchesUnits
Definition: actions.h:142
static TOOL_ACTION save
Definition: actions.h:54
static TOOL_ACTION doNew
Definition: actions.h:47
void SetIcon(const BITMAP_OPAQUE *aIcon)
Assigns an icon for the entry.
Definition: action_menu.cpp:71
KIFACE_I & Kiface()
Global KIFACE_I "get" accessor.
void AddStandardHelpMenu(wxMenuBar *aMenuBar)
Adds the standard KiCad help menu to the menubar.
static TOOL_ACTION previewSettings
Definition: pl_actions.h:79
static TOOL_ACTION cut
Definition: actions.h:69
static TOOL_ACTION drawRectangle
Definition: pl_actions.h:66
void AddMenuLanguageList(ACTION_MENU *aMasterMenu, TOOL_INTERACTIVE *aControlTool)
Function AddMenuLanguageList creates a menu list for language choice, and add it as submenu to Master...
static TOOL_ACTION milsUnits
Definition: actions.h:143
const BITMAP_OPAQUE unit_mm_xpm[1]
Definition: unit_mm.cpp:26
static TOOL_ACTION redo
Definition: actions.h:68
static constexpr bool CHECK
Definition: action_menu.h:162
TOOL_MANAGER * m_toolManager
Definition: tools_holder.h:48
void SetTitle(const wxString &aTitle) override
Sets title for the menu.
Definition: action_menu.cpp:89
see class PGM_BASE
FILE_HISTORY & GetFileHistory()
Get the frame's main file history.
static SELECTION_CONDITION FileHistoryNotEmpty(const FILE_HISTORY &aHistory)
Create a SELECTION_CONDITION that can be used to enable a menu item when the file history has items i...
static TOOL_ACTION saveAs
Definition: actions.h:55
void AddQuitOrClose(KIFACE_I *aKiface, wxString aAppname="")
Adds either a standard Quit or Close item to the menu.
#define _(s)
Definition: 3d_actions.cpp:33
static TOOL_ACTION zoomRedraw
Definition: actions.h:88
Functors that can be used to figure out how the action controls should be displayed in the UI and if ...
static TOOL_ACTION appendImportedWorksheet
Definition: pl_actions.h:68
static TOOL_ACTION undo
Definition: actions.h:67
static TOOL_ACTION toggleCursorStyle
Definition: actions.h:100
const BITMAP_OPAQUE preference_xpm[1]
Definition: preference.cpp:53
static TOOL_ACTION paste
Definition: actions.h:71