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 The 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 fileMenu->AppendSeparator();
96
97 // Add the file menu condition here since it needs the item ID for the submenu
99 cond.Enable( FILE_HISTORY::FileHistoryNotEmpty( fileHistory ) );
100 RegisterUIUpdateHandler( item->GetId(), cond );
101
102 fileMenu->AppendSeparator();
104
105 fileMenu->AppendSeparator();
106 fileMenu->Add( ACTIONS::saveAs );
107
108 fileMenu->AppendSeparator();
109
110 //Import Sub-menu
111 ACTION_MENU* importMenu = new ACTION_MENU( false, controlTool );
112 importMenu->SetTitle( _( "Import Non-KiCad Project..." ) );
113 importMenu->SetIcon( BITMAPS::import_project );
114
115 importMenu->Add( _( "CADSTAR Project..." ),
116 _( "Import CADSTAR Archive Schematic and PCB (*.csa, *.cpa)" ),
118 BITMAPS::import_project );
119
120 importMenu->Add( _( "EAGLE Project..." ),
121 _( "Import EAGLE CAD XML schematic and board" ),
123 BITMAPS::import_project );
124
125 importMenu->Add( _( "EasyEDA (JLCEDA) Std Backup..." ),
126 _( "Import EasyEDA (JLCEDA) Standard schematic and board" ),
128 BITMAPS::import_project );
129
130 importMenu->Add( _( "EasyEDA (JLCEDA) Pro Project..." ),
131 _( "Import EasyEDA (JLCEDA) Professional schematic and board" ),
132 ID_IMPORT_EASYEDAPRO_PROJECT, BITMAPS::import_project );
133
134 fileMenu->Add( importMenu );
135
136 fileMenu->AppendSeparator();
137 fileMenu->Add( _( "&Archive Project..." ),
138 _( "Archive all needed project files into zip archive" ),
140 BITMAPS::zip );
141
142 fileMenu->Add( _( "&Unarchive Project..." ),
143 _( "Unarchive project files from zip archive" ),
145 BITMAPS::unzip );
146
147 fileMenu->AppendSeparator();
148 fileMenu->AddQuitOrClose( nullptr, wxS( "KiCad" ) );
149
150 //-- Edit menu -----------------------------------------------------------
151 //
152
153 ACTION_MENU* editMenu = new ACTION_MENU( false, controlTool );
154
155 /*
156 * While we don't presently use these, they need to be here so that cut/copy/paste work
157 * in things like search boxes in file open dialogs.
158 */
159 editMenu->Add( ACTIONS::cut );
160 editMenu->Add( ACTIONS::copy );
161 editMenu->Add( ACTIONS::paste );
162
163 //-- View menu -----------------------------------------------------------
164 //
165 ACTION_MENU* viewMenu = new ACTION_MENU( false, controlTool );
166
167 viewMenu->Add( ACTIONS::zoomRedraw );
168
169 viewMenu->AppendSeparator();
171 viewMenu->Add( _( "Browse Project Files" ),
172 _( "Open project directory in file browser" ),
174 BITMAPS::directory_browser );
175
176#ifdef __APPLE__
177 // Add a separator only on macOS because the OS adds menu items to the view menu after ours
178 viewMenu->AppendSeparator();
179#endif
180
181 //-- Tools menu -----------------------------------------------
182 //
183 ACTION_MENU* toolsMenu = new ACTION_MENU( false, controlTool );
184
189
190 toolsMenu->AppendSeparator();
195
196 wxMenuItem* pcmMenuItem = toolsMenu->Add( KICAD_MANAGER_ACTIONS::showPluginManager );
197
200 {
201 pcmMenuItem->Enable( false );
202 }
203
204 toolsMenu->AppendSeparator();
205 toolsMenu->Add( _( "Edit Local File..." ),
206 _( "Edit local file in text editor" ),
208 BITMAPS::editor );
209
210 //-- Preferences menu -----------------------------------------------
211 //
212 ACTION_MENU* prefsMenu = new ACTION_MENU( false, controlTool );
213
214 prefsMenu->Add( ACTIONS::configurePaths );
215 prefsMenu->Add( ACTIONS::showSymbolLibTable );
217 if( ADVANCED_CFG::GetCfg().m_EnableDesignBlocks )
219 prefsMenu->Add( ACTIONS::openPreferences );
220
221 prefsMenu->AppendSeparator();
222 AddMenuLanguageList( prefsMenu, controlTool );
223
224
225 //-- Menubar -------------------------------------------------------------
226 //
227 menuBar->Append( fileMenu, _( "&File" ) );
228 menuBar->Append( editMenu, _( "&Edit" ) );
229 menuBar->Append( viewMenu, _( "&View" ) );
230 menuBar->Append( toolsMenu, _( "&Tools" ) );
231 menuBar->Append( prefsMenu, _( "&Preferences" ) );
232 AddStandardHelpMenu( menuBar );
233
234 SetMenuBar( menuBar );
235 delete oldMenuBar;
236}
237
238
243{
244 if( m_mainToolBar )
245 {
247 }
248 else
249 {
250 m_mainToolBar = new ACTION_TOOLBAR( this, ID_H_TOOLBAR, wxDefaultPosition, wxDefaultSize,
251 KICAD_AUI_TB_STYLE | wxAUI_TB_VERTICAL );
253 }
254
255 // New
258
260 m_mainToolBar->AddTool( ID_SAVE_AND_ZIP_FILES, wxEmptyString,
261 KiBitmapBundle( BITMAPS::zip ),
262 KiDisabledBitmapBundle( BITMAPS::zip ),
263 wxITEM_NORMAL,
264 _( "Archive all project files" ),
265 wxEmptyString, nullptr );
266
267 m_mainToolBar->AddTool( ID_READ_ZIP_ARCHIVE, wxEmptyString,
268 KiBitmapBundle( BITMAPS::unzip ),
269 KiDisabledBitmapBundle( BITMAPS::unzip ),
270 wxITEM_NORMAL,
271 _( "Unarchive project files from zip archive" ),
272 wxEmptyString, nullptr );
273
276
278 m_mainToolBar->AddTool( ID_BROWSE_IN_FILE_EXPLORER, wxEmptyString,
279 KiBitmapBundle( BITMAPS::directory_browser ),
280#ifdef __APPLE__
281 _( "Reveal project folder in Finder" ) );
282#else
283 _( "Open project directory in file explorer" ) );
284#endif
285
286 // Create m_mainToolBar
288}
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
Define 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)
Create a menu list for language choice, and add it as submenu to MasterMenu.
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)
Add 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 openJobsetFile
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:398
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:97
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)