KiCad PCB EDA Suite
Loading...
Searching...
No Matches
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-2023 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 <advanced_config.h>
28#include <bitmaps.h>
29#include <file_history.h>
30#include <kiplatform/policy.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( ADVANCED_CFG::GetCfg().m_EnableGit )
80 {
82 }
83
84 if( wxDir::Exists( PATHS::GetStockDemosPath() ) )
85 {
87 }
88
90
91 wxMenuItem* item = fileMenu->Add( openRecentMenu->Clone() );
92
93 // Add the file menu condition here since it needs the item ID for the submenu
95 cond.Enable( FILE_HISTORY::FileHistoryNotEmpty( fileHistory ) );
96 RegisterUIUpdateHandler( item->GetId(), cond );
97
98 fileMenu->AppendSeparator();
100
101 fileMenu->AppendSeparator();
102 fileMenu->Add( ACTIONS::saveAs );
103
104 fileMenu->AppendSeparator();
105
106 //Import Sub-menu
107 ACTION_MENU* importMenu = new ACTION_MENU( false, controlTool );
108 importMenu->SetTitle( _( "Import Non-KiCad Project..." ) );
109 importMenu->SetIcon( BITMAPS::import_project );
110
111 importMenu->Add( _( "CADSTAR Project..." ),
112 _( "Import CADSTAR Archive Schematic and PCB (*.csa, *.cpa)" ),
114 BITMAPS::import_project );
115
116 importMenu->Add( _( "EAGLE Project..." ),
117 _( "Import EAGLE CAD XML schematic and board" ),
119 BITMAPS::import_project );
120
121 importMenu->Add( _( "EasyEDA (JLCEDA) Std Backup..." ),
122 _( "Import EasyEDA (JLCEDA) Standard schematic and board" ),
124 BITMAPS::import_project );
125
126 importMenu->Add( _( "EasyEDA (JLCEDA) Pro Project..." ),
127 _( "Import EasyEDA (JLCEDA) Professional schematic and board" ),
128 ID_IMPORT_EASYEDAPRO_PROJECT, BITMAPS::import_project );
129
130 fileMenu->Add( importMenu );
131
132 fileMenu->AppendSeparator();
133 fileMenu->Add( _( "&Archive Project..." ),
134 _( "Archive all needed project files into zip archive" ),
136 BITMAPS::zip );
137
138 fileMenu->Add( _( "&Unarchive Project..." ),
139 _( "Unarchive project files from zip archive" ),
141 BITMAPS::unzip );
142
143 fileMenu->AppendSeparator();
144 fileMenu->AddQuitOrClose( nullptr, wxS( "KiCad" ) );
145
146 //-- Edit menu -----------------------------------------------------------
147 //
148
149 ACTION_MENU* editMenu = new ACTION_MENU( false, controlTool );
150
151 /*
152 * While we don't presently use these, they need to be here so that cut/copy/paste work
153 * in things like search boxes in file open dialogs.
154 */
155 editMenu->Add( ACTIONS::cut );
156 editMenu->Add( ACTIONS::copy );
157 editMenu->Add( ACTIONS::paste );
158
159 //-- View menu -----------------------------------------------------------
160 //
161 ACTION_MENU* viewMenu = new ACTION_MENU( false, controlTool );
162
163 viewMenu->Add( ACTIONS::zoomRedraw );
164
165 viewMenu->AppendSeparator();
167 viewMenu->Add( _( "Browse Project Files" ),
168 _( "Open project directory in file browser" ),
170 BITMAPS::directory_browser );
171
172#ifdef __APPLE__
173 // Add a separator only on macOS because the OS adds menu items to the view menu after ours
174 viewMenu->AppendSeparator();
175#endif
176
177 //-- Tools menu -----------------------------------------------
178 //
179 ACTION_MENU* toolsMenu = new ACTION_MENU( false, controlTool );
180
185
186 toolsMenu->AppendSeparator();
191
192 wxMenuItem* pcmMenuItem = toolsMenu->Add( KICAD_MANAGER_ACTIONS::showPluginManager );
193
196 {
197 pcmMenuItem->Enable( false );
198 }
199
200 toolsMenu->AppendSeparator();
201 toolsMenu->Add( _( "Edit Local File..." ),
202 _( "Edit local file in text editor" ),
204 BITMAPS::editor );
205
206 //-- Preferences menu -----------------------------------------------
207 //
208 ACTION_MENU* prefsMenu = new ACTION_MENU( false, controlTool );
209
210 prefsMenu->Add( ACTIONS::configurePaths );
211 prefsMenu->Add( ACTIONS::showSymbolLibTable );
213 prefsMenu->Add( ACTIONS::openPreferences );
214
215 prefsMenu->AppendSeparator();
216 AddMenuLanguageList( prefsMenu, controlTool );
217
218
219 //-- Menubar -------------------------------------------------------------
220 //
221 menuBar->Append( fileMenu, _( "&File" ) );
222 menuBar->Append( editMenu, _( "&Edit" ) );
223 menuBar->Append( viewMenu, _( "&View" ) );
224 menuBar->Append( toolsMenu, _( "&Tools" ) );
225 menuBar->Append( prefsMenu, _( "&Preferences" ) );
226 AddStandardHelpMenu( menuBar );
227
228 SetMenuBar( menuBar );
229 delete oldMenuBar;
230}
231
232
237{
238 if( m_mainToolBar )
239 {
241 }
242 else
243 {
244 m_mainToolBar = new ACTION_TOOLBAR( this, ID_H_TOOLBAR, wxDefaultPosition, wxDefaultSize,
245 KICAD_AUI_TB_STYLE | wxAUI_TB_HORZ_LAYOUT );
247 }
248
249 // New
252
254 m_mainToolBar->AddTool( ID_SAVE_AND_ZIP_FILES, wxEmptyString,
255 KiBitmapBundle( BITMAPS::zip ),
256 KiDisabledBitmapBundle( BITMAPS::zip ),
257 wxITEM_NORMAL,
258 _( "Archive all project files" ),
259 wxEmptyString, nullptr );
260
261 m_mainToolBar->AddTool( ID_READ_ZIP_ARCHIVE, wxEmptyString,
262 KiBitmapBundle( BITMAPS::unzip ),
263 KiDisabledBitmapBundle( BITMAPS::unzip ),
264 wxITEM_NORMAL,
265 _( "Unarchive project files from zip archive" ),
266 wxEmptyString, nullptr );
267
270
272 m_mainToolBar->AddTool( ID_BROWSE_IN_FILE_EXPLORER, wxEmptyString,
273 KiBitmapBundle( BITMAPS::directory_browser ),
274#ifdef __APPLE__
275 _( "Reveal project folder in Finder" ) );
276#else
277 _( "Open project directory in file explorer" ) );
278#endif
279
280 // Create m_mainToolBar
282}
wxBitmapBundle KiBitmapBundle(BITMAPS aBitmap)
Definition: bitmap.cpp:110
wxBitmapBundle KiDisabledBitmapBundle(BITMAPS aBitmap)
Definition: bitmap.cpp:116
static TOOL_ACTION paste
Definition: actions.h:70
static TOOL_ACTION zoomRedraw
Definition: actions.h:114
static TOOL_ACTION saveAs
Definition: actions.h:52
static TOOL_ACTION copy
Definition: actions.h:69
static TOOL_ACTION showSymbolLibTable
Definition: actions.h:213
static TOOL_ACTION openPreferences
Definition: actions.h:211
static TOOL_ACTION showFootprintLibTable
Definition: actions.h:214
static TOOL_ACTION cut
Definition: actions.h:68
static TOOL_ACTION configurePaths
Definition: actions.h:212
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:92
void SetIcon(BITMAPS aIcon)
Assign an icon for the entry.
Definition: action_menu.cpp:78
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.
bool KiRealize()
Use this over Realize() to avoid a rendering glitch with fixed orientation toolbars.
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 const ADVANCED_CFG & GetCfg()
Get the singleton instance's config, which is shared by all consumers.
static constexpr int KICAD_AUI_TB_STYLE
< Default style flags used for wxAUI toolbars.
void AddMenuLanguageList(ACTION_MENU *aMasterMenu, TOOL_INTERACTIVE *aControlTool)
Function AddMenuLanguageList creates a menu list for language choice, and add it as submenu to Master...
void SetMenuBar(wxMenuBar *menu_bar) override
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: file_history.h:43
void SetClearText(wxString aClearText)
Set the text displayed on the menu item that clears the entire menu.
Definition: file_history.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: file_history.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 newFromRepository
static TOOL_ACTION newFromTemplate
static TOOL_ACTION editSymbols
Handle actions in the kicad manager frame.
void RecreateBaseHToolbar()
(Re)Create the horizontal toolbar
ACTION_TOOLBAR * m_mainToolBar
void doReCreateMenuBar() override
static wxString GetStockDemosPath()
Gets the stock (install) demos path.
Definition: paths.cpp:344
TOOL_MANAGER * m_toolManager
Definition: tools_holder.h:167
Wrapper around a wxMenuBar object that prevents the accelerator table from being used.
Definition: wx_menubar.h:47
#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:72
@ ID_IMPORT_EASYEDAPRO_PROJECT
Definition: kicad_id.h:74
@ 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:71
@ ID_EDIT_LOCAL_FILE_IN_TEXT_EDITOR
Definition: kicad_id.h:66
@ ID_IMPORT_EASYEDA_PROJECT
Definition: kicad_id.h:73
@ ID_BROWSE_IN_FILE_EXPLORER
Definition: kicad_id.h:67
PBOOL GetPolicyBool(const wxString &aKey)
Definition: gtk/policy.cpp:26
#define POLICY_KEY_PCM
Definition: policy_keys.h:31
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)