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( ADVANCED_CFG::GetCfg().m_EnableJobset )
85 {
87 }
88
89 if( wxDir::Exists( PATHS::GetStockDemosPath() ) )
90 {
92 }
93
95
96 wxMenuItem* item = fileMenu->Add( openRecentMenu->Clone() );
97
98 // Add the file menu condition here since it needs the item ID for the submenu
100 cond.Enable( FILE_HISTORY::FileHistoryNotEmpty( fileHistory ) );
101 RegisterUIUpdateHandler( item->GetId(), cond );
102
103 fileMenu->AppendSeparator();
105
106 fileMenu->AppendSeparator();
107 fileMenu->Add( ACTIONS::saveAs );
108
109 fileMenu->AppendSeparator();
110
111 //Import Sub-menu
112 ACTION_MENU* importMenu = new ACTION_MENU( false, controlTool );
113 importMenu->SetTitle( _( "Import Non-KiCad Project..." ) );
114 importMenu->SetIcon( BITMAPS::import_project );
115
116 importMenu->Add( _( "CADSTAR Project..." ),
117 _( "Import CADSTAR Archive Schematic and PCB (*.csa, *.cpa)" ),
119 BITMAPS::import_project );
120
121 importMenu->Add( _( "EAGLE Project..." ),
122 _( "Import EAGLE CAD XML schematic and board" ),
124 BITMAPS::import_project );
125
126 importMenu->Add( _( "EasyEDA (JLCEDA) Std Backup..." ),
127 _( "Import EasyEDA (JLCEDA) Standard schematic and board" ),
129 BITMAPS::import_project );
130
131 importMenu->Add( _( "EasyEDA (JLCEDA) Pro Project..." ),
132 _( "Import EasyEDA (JLCEDA) Professional schematic and board" ),
133 ID_IMPORT_EASYEDAPRO_PROJECT, BITMAPS::import_project );
134
135 fileMenu->Add( importMenu );
136
137 fileMenu->AppendSeparator();
138 fileMenu->Add( _( "&Archive Project..." ),
139 _( "Archive all needed project files into zip archive" ),
141 BITMAPS::zip );
142
143 fileMenu->Add( _( "&Unarchive Project..." ),
144 _( "Unarchive project files from zip archive" ),
146 BITMAPS::unzip );
147
148 fileMenu->AppendSeparator();
149 fileMenu->AddQuitOrClose( nullptr, wxS( "KiCad" ) );
150
151 //-- Edit menu -----------------------------------------------------------
152 //
153
154 ACTION_MENU* editMenu = new ACTION_MENU( false, controlTool );
155
156 /*
157 * While we don't presently use these, they need to be here so that cut/copy/paste work
158 * in things like search boxes in file open dialogs.
159 */
160 editMenu->Add( ACTIONS::cut );
161 editMenu->Add( ACTIONS::copy );
162 editMenu->Add( ACTIONS::paste );
163
164 //-- View menu -----------------------------------------------------------
165 //
166 ACTION_MENU* viewMenu = new ACTION_MENU( false, controlTool );
167
168 viewMenu->Add( ACTIONS::zoomRedraw );
169
170 viewMenu->AppendSeparator();
172 viewMenu->Add( _( "Browse Project Files" ),
173 _( "Open project directory in file browser" ),
175 BITMAPS::directory_browser );
176
177#ifdef __APPLE__
178 // Add a separator only on macOS because the OS adds menu items to the view menu after ours
179 viewMenu->AppendSeparator();
180#endif
181
182 //-- Tools menu -----------------------------------------------
183 //
184 ACTION_MENU* toolsMenu = new ACTION_MENU( false, controlTool );
185
190
191 toolsMenu->AppendSeparator();
196
197 wxMenuItem* pcmMenuItem = toolsMenu->Add( KICAD_MANAGER_ACTIONS::showPluginManager );
198
201 {
202 pcmMenuItem->Enable( false );
203 }
204
205 toolsMenu->AppendSeparator();
206 toolsMenu->Add( _( "Edit Local File..." ),
207 _( "Edit local file in text editor" ),
209 BITMAPS::editor );
210
211 //-- Preferences menu -----------------------------------------------
212 //
213 ACTION_MENU* prefsMenu = new ACTION_MENU( false, controlTool );
214
215 prefsMenu->Add( ACTIONS::configurePaths );
216 prefsMenu->Add( ACTIONS::showSymbolLibTable );
218 if( ADVANCED_CFG::GetCfg().m_EnableDesignBlocks )
220 prefsMenu->Add( ACTIONS::openPreferences );
221
222 prefsMenu->AppendSeparator();
223 AddMenuLanguageList( prefsMenu, controlTool );
224
225
226 //-- Menubar -------------------------------------------------------------
227 //
228 menuBar->Append( fileMenu, _( "&File" ) );
229 menuBar->Append( editMenu, _( "&Edit" ) );
230 menuBar->Append( viewMenu, _( "&View" ) );
231 menuBar->Append( toolsMenu, _( "&Tools" ) );
232 menuBar->Append( prefsMenu, _( "&Preferences" ) );
233 AddStandardHelpMenu( menuBar );
234
235 SetMenuBar( menuBar );
236 delete oldMenuBar;
237}
238
239
244{
245 if( m_mainToolBar )
246 {
248 }
249 else
250 {
251 m_mainToolBar = new ACTION_TOOLBAR( this, ID_H_TOOLBAR, wxDefaultPosition, wxDefaultSize,
252 KICAD_AUI_TB_STYLE | wxAUI_TB_VERTICAL );
254 }
255
256 // New
259
261 m_mainToolBar->AddTool( ID_SAVE_AND_ZIP_FILES, wxEmptyString,
262 KiBitmapBundle( BITMAPS::zip ),
263 KiDisabledBitmapBundle( BITMAPS::zip ),
264 wxITEM_NORMAL,
265 _( "Archive all project files" ),
266 wxEmptyString, nullptr );
267
268 m_mainToolBar->AddTool( ID_READ_ZIP_ARCHIVE, wxEmptyString,
269 KiBitmapBundle( BITMAPS::unzip ),
270 KiDisabledBitmapBundle( BITMAPS::unzip ),
271 wxITEM_NORMAL,
272 _( "Unarchive project files from zip archive" ),
273 wxEmptyString, nullptr );
274
277
279 m_mainToolBar->AddTool( ID_BROWSE_IN_FILE_EXPLORER, wxEmptyString,
280 KiBitmapBundle( BITMAPS::directory_browser ),
281#ifdef __APPLE__
282 _( "Reveal project folder in Finder" ) );
283#else
284 _( "Open project directory in file explorer" ) );
285#endif
286
287 // Create m_mainToolBar
289}
wxBitmapBundle KiBitmapBundle(BITMAPS aBitmap)
Definition: bitmap.cpp:110
wxBitmapBundle KiDisabledBitmapBundle(BITMAPS aBitmap)
Definition: bitmap.cpp:116
static TOOL_ACTION paste
Definition: actions.h:73
static TOOL_ACTION zoomRedraw
Definition: actions.h:124
static TOOL_ACTION saveAs
Definition: actions.h:52
static TOOL_ACTION copy
Definition: actions.h:71
static TOOL_ACTION showSymbolLibTable
Definition: actions.h:229
static TOOL_ACTION openPreferences
Definition: actions.h:227
static TOOL_ACTION showFootprintLibTable
Definition: actions.h:230
static TOOL_ACTION showDesignBlockLibTable
Definition: actions.h:231
static TOOL_ACTION cut
Definition: actions.h:70
static TOOL_ACTION configurePaths
Definition: actions.h:228
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 newJobsetFile
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 RecreateBaseLeftToolbar()
(Re)Create the left vertical toolbar
ACTION_TOOLBAR * m_mainToolBar
void doReCreateMenuBar() override
static wxString GetStockDemosPath()
Gets the stock (install) demos path.
Definition: paths.cpp:354
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:99
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: unix/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)