KiCad PCB EDA Suite
kicad/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) 2017 Jean-Pierre Charras, jp.charras at wanadoo.fr
5 * Copyright (C) 2009 Wayne Stambaugh <[email protected]>
6 * Copyright (C) 1992-2021 KiCad Developers, see AUTHORS.txt for contributors.
7 * Copyright (C) 2019 CERN
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version 2
12 * of the License, or (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, you may find one here:
21 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
22 * or you may search the http://www.gnu.org website for the version 2 license,
23 * or you may write to the Free Software Foundation, Inc.,
24 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
25 */
26
27#include <bitmaps.h>
28#include <filehistory.h>
29#include <kiplatform/policy.h>
30#include <menus_helpers.h>
31#include <paths.h>
32#include <policy_keys.h>
33#include <tool/action_manager.h>
34#include <tool/action_toolbar.h>
35#include <tool/tool_manager.h>
38#include "kicad_manager_frame.h"
39#include "pgm_kicad.h"
40#include "kicad_id.h"
41#include <widgets/wx_menubar.h>
42#include <wx/dir.h>
43
44
46{
48 // wxWidgets handles the Mac Application menu behind the scenes, but that means
49 // we always have to start from scratch with a new wxMenuBar.
50 wxMenuBar* oldMenuBar = GetMenuBar();
51 WX_MENUBAR* menuBar = new WX_MENUBAR();
52
53 //-- File menu -----------------------------------------------------------
54 //
55 ACTION_MENU* fileMenu = new ACTION_MENU( false, controlTool );
56 FILE_HISTORY& fileHistory = GetFileHistory();
57
58 fileHistory.SetClearText( _( "Clear Recent Projects" ) );
59
60 static ACTION_MENU* openRecentMenu;
61
62 // Create the menu if it does not exist. Adding a file to/from the history
63 // will automatically refresh the menu.
64 if( !openRecentMenu )
65 {
66 openRecentMenu = new ACTION_MENU( false, controlTool );
67 openRecentMenu->SetIcon( BITMAPS::recent );
68
69 fileHistory.UseMenu( openRecentMenu );
70 fileHistory.AddFilesToMenu();
71 }
72
73 // Ensure the title is up to date after changing language
74 openRecentMenu->SetTitle( _( "Open Recent" ) );
75
78
79 if( wxDir::Exists( PATHS::GetStockDemosPath() ) )
80 {
82 }
83
85
86 wxMenuItem* item = fileMenu->Add( openRecentMenu->Clone() );
87
88 // Add the file menu condition here since it needs the item ID for the submenu
90 cond.Enable( FILE_HISTORY::FileHistoryNotEmpty( fileHistory ) );
91 RegisterUIUpdateHandler( item->GetId(), cond );
92
93 fileMenu->AppendSeparator();
95
96 fileMenu->AppendSeparator();
97 fileMenu->Add( ACTIONS::saveAs );
98
99 fileMenu->AppendSeparator();
100
101 //Import Sub-menu
102 ACTION_MENU* importMenu = new ACTION_MENU( false, controlTool );
103 importMenu->SetTitle( _( "Import Non-KiCad Project..." ) );
104 importMenu->SetIcon( BITMAPS::import_project );
105
106 importMenu->Add( _( "CADSTAR Project..." ),
107 _( "Import CADSTAR Archive Schematic and PCB (*.csa, *.cpa)" ),
110
111 importMenu->Add( _( "EAGLE Project..." ),
112 _( "Import EAGLE CAD XML schematic and board" ),
115
116 fileMenu->Add( importMenu );
117
118 fileMenu->AppendSeparator();
119 fileMenu->Add( _( "&Archive Project..." ),
120 _( "Archive all needed project files into zip archive" ),
122 BITMAPS::zip );
123
124 fileMenu->Add( _( "&Unarchive Project..." ),
125 _( "Unarchive project files from zip archive" ),
128
129 fileMenu->AppendSeparator();
130 fileMenu->AddQuitOrClose( nullptr, "KiCad" );
131
132 //-- Edit menu -----------------------------------------------------------
133 //
134
135 ACTION_MENU* editMenu = new ACTION_MENU( false, controlTool );
136
137 /*
138 * While we don't presently use these, they need to be here so that cut/copy/paste work
139 * in things like search boxes in file open dialogs.
140 */
141 editMenu->Add( ACTIONS::cut );
142 editMenu->Add( ACTIONS::copy );
143 editMenu->Add( ACTIONS::paste );
144
145 //-- View menu -----------------------------------------------------------
146 //
147 ACTION_MENU* viewMenu = new ACTION_MENU( false, controlTool );
148
149 viewMenu->Add( ACTIONS::zoomRedraw );
150
151 viewMenu->AppendSeparator();
153 viewMenu->Add( _( "Browse Project Files" ),
154 _( "Open project directory in file browser" ),
157
158#ifdef __APPLE__
159 // Add a separator only on macOS because the OS adds menu items to the view menu after ours
160 viewMenu->AppendSeparator();
161#endif
162
163 //-- Tools menu -----------------------------------------------
164 //
165 ACTION_MENU* toolsMenu = new ACTION_MENU( false, controlTool );
166
171
172 toolsMenu->AppendSeparator();
177
178 wxMenuItem* pcmMenuItem = toolsMenu->Add( KICAD_MANAGER_ACTIONS::showPluginManager );
179
182 {
183 pcmMenuItem->Enable( false );
184 }
185
186 toolsMenu->AppendSeparator();
187 toolsMenu->Add( _( "Edit Local File..." ),
188 _( "Edit local file in text editor" ),
191
192 //-- Preferences menu -----------------------------------------------
193 //
194 ACTION_MENU* prefsMenu = new ACTION_MENU( false, controlTool );
195
196 prefsMenu->Add( ACTIONS::configurePaths );
197 prefsMenu->Add( ACTIONS::showSymbolLibTable );
199
200 // We can't use ACTIONS::showPreferences yet because wxWidgets moves this on
201 // Mac, and it needs the wxID_PREFERENCES id to find it.
202 prefsMenu->Add( _( "Preferences..." ) + "\tCtrl+,",
203 _( "Show preferences for all open tools" ),
204 wxID_PREFERENCES,
206
207 prefsMenu->AppendSeparator();
208 AddMenuLanguageList( prefsMenu, controlTool );
209
210
211 //-- Menubar -------------------------------------------------------------
212 //
213 menuBar->Append( fileMenu, _( "&File" ) );
214 menuBar->Append( editMenu, _( "&Edit" ) );
215 menuBar->Append( viewMenu, _( "&View" ) );
216 menuBar->Append( toolsMenu, _( "&Tools" ) );
217 menuBar->Append( prefsMenu, _( "&Preferences" ) );
218 AddStandardHelpMenu( menuBar );
219
220 SetMenuBar( menuBar );
221 delete oldMenuBar;
222}
223
224
229{
230 if( m_mainToolBar )
231 {
233 }
234 else
235 {
236 m_mainToolBar = new ACTION_TOOLBAR( this, ID_H_TOOLBAR, wxDefaultPosition, wxDefaultSize,
237 KICAD_AUI_TB_STYLE | wxAUI_TB_HORZ_LAYOUT );
239 }
240
241 // New
244
246 m_mainToolBar->AddTool( ID_SAVE_AND_ZIP_FILES, wxEmptyString,
248 _( "Archive all project files" ) );
249
250 m_mainToolBar->AddTool( ID_READ_ZIP_ARCHIVE, wxEmptyString,
252 _( "Unarchive project files from zip archive" ) );
253
256
258 m_mainToolBar->AddTool( ID_BROWSE_IN_FILE_EXPLORER, wxEmptyString,
260#ifdef __APPLE__
261 _( "Reveal project folder in Finder" ) );
262#else
263 _( "Open project directory in file explorer" ) );
264#endif
265
266 // Create m_mainToolBar
267 m_mainToolBar->Realize();
268}
wxBitmap KiScaledBitmap(BITMAPS aBitmap, wxWindow *aWindow, int aHeight, bool aQuantized)
Construct a wxBitmap from a memory record, scaling it if device DPI demands it.
Definition: bitmap.cpp:156
@ directory_browser
@ import_project
static TOOL_ACTION paste
Definition: actions.h:69
static TOOL_ACTION zoomRedraw
Definition: actions.h:92
static TOOL_ACTION saveAs
Definition: actions.h:52
static TOOL_ACTION copy
Definition: actions.h:68
static TOOL_ACTION showSymbolLibTable
Definition: actions.h:180
static TOOL_ACTION showFootprintLibTable
Definition: actions.h:181
static TOOL_ACTION cut
Definition: actions.h:67
static TOOL_ACTION configurePaths
Definition: actions.h:179
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.
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.
Define the structure of a toolbar with buttons that invoke ACTIONs.
void SetAuiManager(wxAuiManager *aManager)
Set the AUI manager that this toolbar belongs to.
void AddScaledSeparator(wxWindow *aWindow)
Add a separator that introduces space on either side to not squash the tools when scaled.
void ClearToolbar()
Clear the toolbar and remove all associated menus.
void Add(const TOOL_ACTION &aAction, bool aIsToggleEntry=false, bool aIsCancellable=false)
Add a TOOL_ACTION-based button to the toolbar.
static constexpr int KICAD_AUI_TB_STYLE
< Default style flags used for wxAUI toolbars.
wxAuiManager m_auimgr
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: filehistory.h:43
void SetClearText(wxString aClearText)
Set the text displayed on the menu item that clears the entire menu.
Definition: filehistory.h:123
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 AddFilesToMenu() override
Add the files to all registered menus.
Definition: filehistory.h:98
static TOOL_ACTION openDemoProject
static TOOL_ACTION editPCB
static TOOL_ACTION newProject
static TOOL_ACTION editSchematic
static TOOL_ACTION openTextEditor
static TOOL_ACTION openProject
static TOOL_ACTION closeProject
static TOOL_ACTION convertImage
static TOOL_ACTION editDrawingSheet
static TOOL_ACTION editFootprints
static TOOL_ACTION showPluginManager
static TOOL_ACTION showCalculator
static TOOL_ACTION viewGerbers
static TOOL_ACTION newFromTemplate
static TOOL_ACTION editSymbols
Handle actions in the kicad manager frame.
void RecreateBaseHToolbar()
(Re)Create the horizontal toolbar
void ReCreateMenuBar() override
Recreates the menu bar.
ACTION_TOOLBAR * m_mainToolBar
static wxString GetStockDemosPath()
Gets the stock (install) demos path.
Definition: paths.cpp:310
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)
@ ID_H_TOOLBAR
Definition: id.h:100
IDs used in KiCad main frame foe menuitems and tools.
@ ID_IMPORT_EAGLE_PROJECT
Definition: kicad_id.h:71
@ ID_READ_ZIP_ARCHIVE
Definition: kicad_id.h:69
@ ID_SAVE_AND_ZIP_FILES
Definition: kicad_id.h:68
@ ID_IMPORT_CADSTAR_ARCHIVE_PROJECT
Definition: kicad_id.h:72
@ ID_EDIT_LOCAL_FILE_IN_TEXT_EDITOR
Definition: kicad_id.h:66
@ ID_BROWSE_IN_FILE_EXPLORER
Definition: kicad_id.h:67
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.
STATE GetPolicyState(const wxString &aKey)
Definition: gtk/policy.cpp:25
#define POLICY_KEY_PCM
Definition: policy_keys.h:29
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)