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-2021 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 <bitmaps.h>
27#include <file_history.h>
28#include <kiface_base.h>
29#include <menus_helpers.h>
30#include <tool/action_manager.h>
31#include <tool/action_menu.h>
32#include <tool/tool_manager.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, selTool );
57 openRecentMenu->SetIcon( BITMAPS::recent );
58
59 recentFiles.UseMenu( openRecentMenu );
60 recentFiles.AddFilesToMenu();
61 }
62
63 // Ensure the title is up to date after changing language
64 openRecentMenu->SetTitle( _( "Open Recent" ) );
65 recentFiles.UpdateClearText( openRecentMenu, _( "Clear Recent Files" ) );
66
67 //-- File menu -------------------------------------------------------
68 //
69 ACTION_MENU* fileMenu = new ACTION_MENU( false, selTool );
70
71 fileMenu->Add( ACTIONS::doNew );
72 fileMenu->Add( ACTIONS::open );
73
74 wxMenuItem* item = fileMenu->Add( openRecentMenu->Clone() );
75
76 // Add the file menu condition here since it needs the item ID for the submenu
78 cond.Enable( FILE_HISTORY::FileHistoryNotEmpty( recentFiles ) );
79 RegisterUIUpdateHandler( item->GetId(), cond );
80
81 fileMenu->AppendSeparator();
82 fileMenu->Add( ACTIONS::save );
83 fileMenu->Add( ACTIONS::saveAs );
84
85 fileMenu->AppendSeparator();
86 fileMenu->Add( ACTIONS::print );
87
88 fileMenu->AppendSeparator();
89 fileMenu->AddQuitOrClose( &Kiface(), _( "Drawing Sheet Editor" ) );
90
91 //-- Edit menu -------------------------------------------------------
92 //
93 ACTION_MENU* editMenu = new ACTION_MENU( false, selTool );
94
95 editMenu->Add( ACTIONS::undo );
96 editMenu->Add( ACTIONS::redo );
97
98 editMenu->AppendSeparator();
99 editMenu->Add( ACTIONS::cut );
100 editMenu->Add( ACTIONS::copy );
101 editMenu->Add( ACTIONS::paste );
102 editMenu->Add( ACTIONS::doDelete );
103
104 //-- View menu -------------------------------------------------------
105 //
106 ACTION_MENU* viewMenu = new ACTION_MENU( false, selTool );
107
108 viewMenu->Add( ACTIONS::zoomInCenter );
109 viewMenu->Add( ACTIONS::zoomOutCenter );
110 viewMenu->Add( ACTIONS::zoomFitScreen );
111 viewMenu->Add( ACTIONS::zoomTool );
112 viewMenu->Add( ACTIONS::zoomRedraw );
113
114 viewMenu->AppendSeparator();
116
117 // Units submenu
118 ACTION_MENU* unitsSubMenu = new ACTION_MENU( false, selTool );
119 unitsSubMenu->SetTitle( _( "&Units" ) );
120 unitsSubMenu->SetIcon( BITMAPS::unit_mm );
122 unitsSubMenu->Add( ACTIONS::milsUnits, ACTION_MENU::CHECK );
124 viewMenu->Add( unitsSubMenu );
125
127
128 viewMenu->AppendSeparator();
129 viewMenu->Add( PL_ACTIONS::previewSettings );
130
131#ifdef __APPLE__
132 // Add a separator only on macOS because the OS adds menu items to the view menu after ours
133 viewMenu->AppendSeparator();
134#endif
135
136 //-- Place menu -------------------------------------------------------
137 //
138 ACTION_MENU* placeMenu = new ACTION_MENU( false, selTool );
139
140 placeMenu->Add( PL_ACTIONS::drawLine );
141 placeMenu->Add( PL_ACTIONS::drawRectangle );
142 placeMenu->Add( PL_ACTIONS::placeText );
143 placeMenu->Add( PL_ACTIONS::placeImage );
144
145 placeMenu->AppendSeparator();
147
148 //-- Inspector menu -------------------------------------------------------
149 //
150 ACTION_MENU* inspectorMenu = new ACTION_MENU( false, selTool );
151 inspectorMenu->Add( PL_ACTIONS::showInspector );
152
153 //-- Preferences menu --------------------------------------------------
154 //
155 ACTION_MENU* preferencesMenu = new ACTION_MENU( false, selTool );
156
157 // We can't use ACTIONS::showPreferences yet because wxWidgets moves this on
158 // Mac, and it needs the wxID_PREFERENCES id to find it.
159 preferencesMenu->Add( _( "Preferences..." ) + "\tCtrl+,",
160 _( "Show preferences for all open tools" ),
161 wxID_PREFERENCES,
163
164 // Language submenu
165 AddMenuLanguageList( preferencesMenu, selTool );
166
167 //-- Menubar -----------------------------------------------------------
168 //
169 menuBar->Append( fileMenu, _( "&File" ) );
170 menuBar->Append( editMenu, _( "&Edit" ) );
171 menuBar->Append( viewMenu, _( "&View" ) );
172 menuBar->Append( placeMenu, _( "&Place" ) );
173 menuBar->Append( inspectorMenu, _( "&Inspect" ) );
174 menuBar->Append( preferencesMenu, _( "P&references" ) );
175 AddStandardHelpMenu( menuBar );
176
177 SetMenuBar( menuBar );
178 delete oldMenuBar;
179}
KIFACE_BASE & Kiface()
Global KIFACE_BASE "get" accessor.
static TOOL_ACTION toggleGrid
Definition: actions.h:144
static TOOL_ACTION paste
Definition: actions.h:69
static TOOL_ACTION zoomRedraw
Definition: actions.h:93
static TOOL_ACTION millimetersUnits
Definition: actions.h:150
static TOOL_ACTION zoomOutCenter
Definition: actions.h:97
static TOOL_ACTION saveAs
Definition: actions.h:52
static TOOL_ACTION copy
Definition: actions.h:68
static TOOL_ACTION milsUnits
Definition: actions.h:149
static TOOL_ACTION open
Definition: actions.h:50
static TOOL_ACTION undo
Definition: actions.h:65
static TOOL_ACTION inchesUnits
Definition: actions.h:148
static TOOL_ACTION toggleCursorStyle
Definition: actions.h:105
static TOOL_ACTION doDelete
Definition: actions.h:73
static TOOL_ACTION save
Definition: actions.h:51
static TOOL_ACTION zoomFitScreen
Definition: actions.h:99
static TOOL_ACTION redo
Definition: actions.h:66
static TOOL_ACTION zoomTool
Definition: actions.h:102
static TOOL_ACTION print
Definition: actions.h:57
static TOOL_ACTION doNew
Definition: actions.h:47
static TOOL_ACTION zoomInCenter
Definition: actions.h:96
static TOOL_ACTION cut
Definition: actions.h:67
Defines the structure of a menu based on ACTIONs.
Definition: action_menu.h:49
void AddQuitOrClose(KIFACE_BASE *aKiface, wxString aAppname="")
Add either a standard Quit or Close item to the menu.
static constexpr bool CHECK
Definition: action_menu.h:189
ACTION_MENU * Clone() const
Create a deep, recursive copy of this ACTION_MENU.
void SetTitle(const wxString &aTitle) override
Set title for the menu.
Definition: action_menu.cpp:87
void SetIcon(BITMAPS aIcon)
Assign an icon for the entry.
Definition: action_menu.cpp:73
wxMenuItem * Add(const wxString &aLabel, int aId, BITMAPS aIcon)
Add a wxWidgets-style entry to the menu.
FILE_HISTORY & GetFileHistory()
Get the frame's main file history.
virtual void RegisterUIUpdateHandler(int aID, const ACTION_CONDITIONS &aConditions) override
Register a UI update handler for the control with ID aID.
void AddStandardHelpMenu(wxMenuBar *aMenuBar)
Adds the standard KiCad help menu to the menubar.
This class implements a file history object to store a list of files, that can then be added to a men...
Definition: file_history.h:43
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...
void UpdateClearText(wxMenu *aMenu, wxString aClearText)
Update the text displayed on the menu item that clears the entire menu.
void AddFilesToMenu() override
Add the files to all registered menus.
Definition: file_history.h:98
static TOOL_ACTION placeImage
Definition: pl_actions.h:59
static TOOL_ACTION drawRectangle
Definition: pl_actions.h:60
static TOOL_ACTION showInspector
Definition: pl_actions.h:72
static TOOL_ACTION previewSettings
Definition: pl_actions.h:73
static TOOL_ACTION placeText
Definition: pl_actions.h:58
static TOOL_ACTION appendImportedDrawingSheet
Definition: pl_actions.h:62
static TOOL_ACTION drawLine
Definition: pl_actions.h:61
void doReCreateMenuBar() override
TOOL_MANAGER * m_toolManager
Definition: tools_holder.h:170
Wrapper around a wxMenuBar object that prevents the accelerator table from being used.
Definition: wx_menubar.h:46
#define _(s)
void AddMenuLanguageList(ACTION_MENU *aMasterMenu, TOOL_INTERACTIVE *aControlTool)
Function AddMenuLanguageList creates a menu list for language choice, and add it as submenu to Master...
Macros and inline functions to create menus items in menubars or popup menus.
Functors that can be used to figure out how the action controls should be displayed in the UI and if ...
ACTION_CONDITIONS & Enable(const SELECTION_CONDITION &aCondition)