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 <kiway.h>
32#include <local_history.h>
33#include <paths.h>
34#include <policy_keys.h>
35#include <tool/action_manager.h>
36#include <tool/action_toolbar.h>
37#include <tool/tool_manager.h>
38#include <tool/selection.h>
41#include "kicad_manager_frame.h"
42#include "pgm_kicad.h"
43#include "kicad_id.h"
44#include <widgets/wx_menubar.h>
45#include <wx/dir.h>
46#include <wx/utils.h>
47#include <local_history.h>
48
49
51{
53 // wxWidgets handles the Mac Application menu behind the scenes, but that means
54 // we always have to start from scratch with a new wxMenuBar.
55 wxMenuBar* oldMenuBar = GetMenuBar();
56 WX_MENUBAR* menuBar = new WX_MENUBAR();
57
58 //-- File menu -----------------------------------------------------------
59 //
60 ACTION_MENU* fileMenu = new ACTION_MENU( false, controlTool );
61 FILE_HISTORY& fileHistory = GetFileHistory();
62
63 fileHistory.SetClearText( _( "Clear Recent Projects" ) );
64
65 static ACTION_MENU* openRecentMenu;
66
67 // Create the menu if it does not exist. Adding a file to/from the history
68 // will automatically refresh the menu.
69 if( !openRecentMenu )
70 {
71 openRecentMenu = new ACTION_MENU( false, controlTool );
72 openRecentMenu->SetIcon( BITMAPS::recent );
73
74 fileHistory.UseMenu( openRecentMenu );
75 fileHistory.AddFilesToMenu();
76 }
77
78 // Ensure the title is up to date after changing language
79 openRecentMenu->SetTitle( _( "Open Recent" ) );
80
82
83 if( Pgm().GetCommonSettings() && Pgm().GetCommonSettings()->m_Git.enableGit )
85
86 if( wxDir::Exists( PATHS::GetStockDemosPath() ) )
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 wxMenuItem* restoreItem = fileMenu->Add( KICAD_MANAGER_ACTIONS::restoreLocalHistory );
107 ACTION_CONDITIONS historyCond;
108 historyCond.Enable( [&]( const SELECTION& )
109 {
111 && Kiway().LocalHistory().HistoryExists( Prj().GetProjectPath() );
112 } );
113 RegisterUIUpdateHandler( restoreItem->GetId(), historyCond );
114
115 fileMenu->AppendSeparator();
116 fileMenu->Add( ACTIONS::saveAs );
117
118 fileMenu->AppendSeparator();
119
120 //Import Sub-menu
121 ACTION_MENU* importMenu = new ACTION_MENU( false, controlTool );
122 importMenu->SetTitle( _( "Import Non-KiCad Project..." ) );
123 importMenu->SetIcon( BITMAPS::import_project );
124
125 importMenu->Add( _( "Altium Project..." ),
126 _( "Import Altium Schematic and PCB (*.PrjPcb)" ),
129 importMenu->Add( _( "CADSTAR Project..." ),
130 _( "Import CADSTAR Archive Schematic and PCB (*.csa, *.cpa)" ),
133
134 importMenu->Add( _( "EAGLE Project..." ),
135 _( "Import EAGLE CAD XML schematic and board" ),
138
139 importMenu->Add( _( "EasyEDA (JLCEDA) Std Backup..." ),
140 _( "Import EasyEDA (JLCEDA) Standard schematic and board" ),
143
144 importMenu->Add( _( "EasyEDA (JLCEDA) Pro Project..." ),
145 _( "Import EasyEDA (JLCEDA) Professional schematic and board" ),
147
148 fileMenu->Add( importMenu );
149
150 fileMenu->AppendSeparator();
153
154 fileMenu->AppendSeparator();
155 fileMenu->AddQuitOrClose( nullptr, wxS( "KiCad" ) );
156
157 //-- Edit menu -----------------------------------------------------------
158 //
159
160 ACTION_MENU* editMenu = new ACTION_MENU( false, controlTool );
161
162 /*
163 * While we don't presently use these, they need to be here so that cut/copy/paste work
164 * in things like search boxes in file open dialogs.
165 */
166 editMenu->Add( ACTIONS::cut );
167 editMenu->Add( ACTIONS::copy );
168 editMenu->Add( ACTIONS::paste );
169
170 wxString editCfgEnv;
171 if( wxGetEnv( wxS( "KICAD_EDIT_ADVANCED_CFG" ), &editCfgEnv ); editCfgEnv == wxS( "1" ) )
172 {
173 editMenu->Add( _( "Edit Advanced Config..." ),
174 _( "Edit advanced settings" ),
177 }
178
179 //-- View menu -----------------------------------------------------------
180 //
181 ACTION_MENU* viewMenu = new ACTION_MENU( false, controlTool );
182
183 ACTION_MENU* panelsMenu = new ACTION_MENU( false, controlTool );
184 panelsMenu->SetTitle( _( "Panels" ) );
186 viewMenu->Add( panelsMenu );
187
188 viewMenu->AppendSeparator();
189 viewMenu->Add( ACTIONS::zoomRedraw );
190
191 viewMenu->AppendSeparator();
194
195#ifdef __APPLE__
196 // Add a separator only on macOS because the OS adds menu items to the view menu after ours
197 viewMenu->AppendSeparator();
198#endif
199
200 //-- Tools menu -----------------------------------------------
201 //
202 ACTION_MENU* toolsMenu = new ACTION_MENU( false, controlTool );
203
208
209 toolsMenu->AppendSeparator();
214
215 wxMenuItem* pcmMenuItem = toolsMenu->Add( KICAD_MANAGER_ACTIONS::showPluginManager );
216
219 {
220 pcmMenuItem->Enable( false );
221 }
222
223 toolsMenu->AppendSeparator();
224 toolsMenu->Add( _( "Edit Local File..." ),
225 _( "Edit local file in text editor" ),
228
229 //-- Preferences menu -----------------------------------------------
230 //
231 ACTION_MENU* prefsMenu = new ACTION_MENU( false, controlTool );
232
233 prefsMenu->Add( ACTIONS::configurePaths );
234 prefsMenu->Add( ACTIONS::showSymbolLibTable );
237 prefsMenu->Add( ACTIONS::openPreferences );
238
239 prefsMenu->AppendSeparator();
240 AddMenuLanguageList( prefsMenu, controlTool );
241
242
243 //-- Menubar -------------------------------------------------------------
244 //
245 menuBar->Append( fileMenu, _( "&File" ) );
246 menuBar->Append( editMenu, _( "&Edit" ) );
247 menuBar->Append( viewMenu, _( "&View" ) );
248 menuBar->Append( toolsMenu, _( "&Tools" ) );
249 menuBar->Append( prefsMenu, _( "&Preferences" ) );
250 AddStandardHelpMenu( menuBar );
251
252 SetMenuBar( menuBar );
253 delete oldMenuBar;
254}
static TOOL_ACTION paste
Definition actions.h:80
static TOOL_ACTION zoomRedraw
Definition actions.h:131
static TOOL_ACTION saveAs
Definition actions.h:59
static TOOL_ACTION copy
Definition actions.h:78
static TOOL_ACTION showSymbolLibTable
Definition actions.h:283
static TOOL_ACTION openPreferences
Definition actions.h:281
static TOOL_ACTION showFootprintLibTable
Definition actions.h:284
static TOOL_ACTION showDesignBlockLibTable
Definition actions.h:285
static TOOL_ACTION cut
Definition actions.h:77
static TOOL_ACTION configurePaths
Definition actions.h:282
Define the structure of a menu based on ACTIONs.
Definition action_menu.h:47
void AddQuitOrClose(KIFACE_BASE *aKiface, wxString aAppname="")
Add either a standard Quit or Close item to the menu.
static constexpr bool CHECK
ACTION_MENU * Clone() const
Create a deep, recursive copy of this ACTION_MENU.
void SetTitle(const wxString &aTitle) override
Set title for the menu.
void SetIcon(BITMAPS aIcon)
Assign an icon for the entry.
wxMenuItem * Add(const wxString &aLabel, int aId, BITMAPS aIcon)
Add a wxWidgets-style entry to the menu.
void AddMenuLanguageList(ACTION_MENU *aMasterMenu, TOOL_INTERACTIVE *aControlTool)
Create a menu list for language choice, and add it as submenu to MasterMenu.
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...
void SetClearText(wxString aClearText)
Set the text displayed on the menu item that clears the entire menu.
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.
static TOOL_ACTION openDemoProject
static TOOL_ACTION unarchiveProject
static TOOL_ACTION restoreLocalHistory
static TOOL_ACTION newProject
static TOOL_ACTION showLocalHistory
static TOOL_ACTION editSchematic
static TOOL_ACTION openTextEditor
static TOOL_ACTION archiveProject
static TOOL_ACTION openProject
static TOOL_ACTION closeProject
static TOOL_ACTION convertImage
static TOOL_ACTION editDrawingSheet
static TOOL_ACTION openProjectDirectory
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 editSymbols
Handle actions in the kicad manager frame.
void doReCreateMenuBar() override
PROJECT & Prj() const
Return a reference to the PROJECT associated with this KIWAY.
KIWAY & Kiway() const
Return a reference to the KIWAY that this object has an opportunity to participate in.
LOCAL_HISTORY & LocalHistory()
Return the LOCAL_HISTORY associated with this KIWAY.
Definition kiway.h:404
bool HistoryExists(const wxString &aProjectPath)
Return true if history exists for the project.
static wxString GetStockDemosPath()
Gets the stock (install) demos path.
Definition paths.cpp:408
virtual COMMON_SETTINGS * GetCommonSettings() const
Definition pgm_base.cpp:537
TOOL_MANAGER * m_toolManager
Wrapper around a wxMenuBar object that prevents the accelerator table from being used.
Definition wx_menubar.h:47
#define _(s)
@ ID_EDIT_ADVANCED_CFG
Definition kicad_id.h:38
@ ID_IMPORT_EAGLE_PROJECT
Definition kicad_id.h:40
@ ID_IMPORT_EASYEDAPRO_PROJECT
Definition kicad_id.h:42
@ ID_IMPORT_CADSTAR_ARCHIVE_PROJECT
Definition kicad_id.h:39
@ ID_EDIT_LOCAL_FILE_IN_TEXT_EDITOR
Definition kicad_id.h:37
@ ID_IMPORT_EASYEDA_PROJECT
Definition kicad_id.h:41
@ ID_IMPORT_ALTIUM_PROJECT
Definition kicad_id.h:43
PBOOL GetPolicyBool(const wxString &aKey)
PGM_BASE & Pgm()
The global program "get" accessor.
Definition pgm_base.cpp:946
#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)