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
28#include <advanced_config.h>
29#include <bitmaps.h>
30#include <file_history.h>
31#include <kiplatform/policy.h>
32#include <kiway.h>
33#include <local_history.h>
34#include <paths.h>
35#include <policy_keys.h>
36#include <tool/action_manager.h>
37#include <tool/action_toolbar.h>
38#include <tool/tool_manager.h>
39#include <tool/selection.h>
42#include "kicad_manager_frame.h"
43#include "pgm_kicad.h"
44#include "kicad_id.h"
45#include <widgets/wx_menubar.h>
46#include <wx/dir.h>
47#include <wx/utils.h>
48#include <local_history.h>
49
50
52{
54 // wxWidgets handles the Mac Application menu behind the scenes, but that means
55 // we always have to start from scratch with a new wxMenuBar.
56 wxMenuBar* oldMenuBar = GetMenuBar();
57 WX_MENUBAR* menuBar = new WX_MENUBAR();
58
59 //-- File menu -----------------------------------------------------------
60 //
61 ACTION_MENU* fileMenu = new ACTION_MENU( false, controlTool );
62 FILE_HISTORY& fileHistory = GetFileHistory();
63
64 fileHistory.SetClearText( _( "Clear Recent Projects" ) );
65
66 static ACTION_MENU* openRecentMenu;
67
68 // Create the menu if it does not exist. Adding a file to/from the history
69 // will automatically refresh the menu.
70 if( !openRecentMenu )
71 {
72 openRecentMenu = new ACTION_MENU( false, controlTool );
73 openRecentMenu->SetIcon( BITMAPS::recent );
74
75 fileHistory.UseMenu( openRecentMenu );
76 fileHistory.AddFilesToMenu();
77 }
78
79 // Ensure the title is up to date after changing language
80 openRecentMenu->SetTitle( _( "Open Recent" ) );
81
83
84 if( Pgm().GetCommonSettings() && Pgm().GetCommonSettings()->m_Git.enableGit )
86
87 if( wxDir::Exists( PATHS::GetStockDemosPath() ) )
89
91
92 wxMenuItem* item = fileMenu->Add( openRecentMenu->Clone() );
93
94 fileMenu->AppendSeparator();
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 wxMenuItem* restoreItem = fileMenu->Add( KICAD_MANAGER_ACTIONS::restoreLocalHistory );
108 ACTION_CONDITIONS historyCond;
109 historyCond.Enable( [&]( const SELECTION& )
110 {
112 && Kiway().LocalHistory().HistoryExists( Prj().GetProjectPath() );
113 } );
114 RegisterUIUpdateHandler( restoreItem->GetId(), historyCond );
115
116 fileMenu->AppendSeparator();
117 fileMenu->Add( ACTIONS::saveAs );
118
119 fileMenu->AppendSeparator();
120
121 //Import Sub-menu
122 ACTION_MENU* importMenu = new ACTION_MENU( false, controlTool );
123 importMenu->SetTitle( _( "Import Non-KiCad Project..." ) );
124 importMenu->SetIcon( BITMAPS::import_project );
125
126 importMenu->Add( _( "Altium Project..." ),
127 _( "Import Altium Schematic and PCB (*.PrjPcb)" ),
130 importMenu->Add( _( "CADSTAR Project..." ),
131 _( "Import CADSTAR Archive Schematic and PCB (*.csa, *.cpa)" ),
134
135 importMenu->Add( _( "EAGLE Project..." ),
136 _( "Import EAGLE CAD XML schematic and board" ),
139
140 importMenu->Add( _( "EasyEDA (JLCEDA) Std Backup..." ),
141 _( "Import EasyEDA (JLCEDA) Standard schematic and board" ),
144
145 importMenu->Add( _( "EasyEDA (JLCEDA) Pro Project..." ),
146 _( "Import EasyEDA (JLCEDA) Professional schematic and board" ),
148
149 importMenu->Add( _( "PADS Project..." ),
150 _( "Import PADS Logic schematic and PADS ASCII PCB (*.asc, *.txt)" ),
152
153 importMenu->Add( _( "gEDA / Lepton EDA Project..." ),
154 _( "Import gEDA or Lepton EDA schematic and PCB layout" ),
157
158 fileMenu->Add( importMenu );
159
160 fileMenu->AppendSeparator();
163
164 fileMenu->AppendSeparator();
165 fileMenu->AddQuitOrClose( nullptr, wxS( "KiCad" ) );
166
167 //-- Edit menu -----------------------------------------------------------
168 //
169
170 ACTION_MENU* editMenu = new ACTION_MENU( false, controlTool );
171
172 /*
173 * While we don't presently use these, they need to be here so that cut/copy/paste work
174 * in things like search boxes in file open dialogs.
175 */
176 editMenu->Add( ACTIONS::cut );
177 editMenu->Add( ACTIONS::copy );
178 editMenu->Add( ACTIONS::paste );
179
180 wxString editCfgEnv;
181 if( wxGetEnv( wxS( "KICAD_EDIT_ADVANCED_CFG" ), &editCfgEnv ); editCfgEnv == wxS( "1" ) )
182 {
183 editMenu->Add( _( "Edit Advanced Config..." ),
184 _( "Edit advanced settings" ),
187 }
188
189 //-- View menu -----------------------------------------------------------
190 //
191 ACTION_MENU* viewMenu = new ACTION_MENU( false, controlTool );
192
193 ACTION_MENU* panelsMenu = new ACTION_MENU( false, controlTool );
194 panelsMenu->SetTitle( _( "Panels" ) );
196 viewMenu->Add( panelsMenu );
197
198 viewMenu->AppendSeparator();
199 viewMenu->Add( ACTIONS::zoomRedraw );
200
201 viewMenu->AppendSeparator();
204
205#ifdef __APPLE__
206 // Add a separator only on macOS because the OS adds menu items to the view menu after ours
207 viewMenu->AppendSeparator();
208#endif
209
210 //-- Tools menu -----------------------------------------------
211 //
212 ACTION_MENU* toolsMenu = new ACTION_MENU( false, controlTool );
213
218
219 toolsMenu->AppendSeparator();
224
225 wxMenuItem* pcmMenuItem = toolsMenu->Add( KICAD_MANAGER_ACTIONS::showPluginManager );
226
229 {
230 pcmMenuItem->Enable( false );
231 }
232
233 toolsMenu->AppendSeparator();
234 toolsMenu->Add( _( "Edit Local File..." ),
235 _( "Edit local file in text editor" ),
238
239 //-- Preferences menu -----------------------------------------------
240 //
241 ACTION_MENU* prefsMenu = new ACTION_MENU( false, controlTool );
242
243 prefsMenu->Add( ACTIONS::configurePaths );
244 prefsMenu->Add( ACTIONS::showSymbolLibTable );
247 prefsMenu->Add( ACTIONS::openPreferences );
248
249 prefsMenu->AppendSeparator();
250 AddMenuLanguageList( prefsMenu, controlTool );
251
252
253 //-- Menubar -------------------------------------------------------------
254 //
255 menuBar->Append( fileMenu, _( "&File" ) );
256 menuBar->Append( editMenu, _( "&Edit" ) );
257 menuBar->Append( viewMenu, _( "&View" ) );
258 menuBar->Append( toolsMenu, _( "&Tools" ) );
259 menuBar->Append( prefsMenu, _( "&Preferences" ) );
260 AddStandardHelpMenu( menuBar );
261
262 SetMenuBar( menuBar );
263 delete oldMenuBar;
264}
static TOOL_ACTION paste
Definition actions.h:80
static TOOL_ACTION zoomRedraw
Definition actions.h:132
static TOOL_ACTION saveAs
Definition actions.h:59
static TOOL_ACTION copy
Definition actions.h:78
static TOOL_ACTION showSymbolLibTable
Definition actions.h:282
static TOOL_ACTION openPreferences
Definition actions.h:280
static TOOL_ACTION showFootprintLibTable
Definition actions.h:283
static TOOL_ACTION showDesignBlockLibTable
Definition actions.h:284
static TOOL_ACTION cut
Definition actions.h:77
static TOOL_ACTION configurePaths
Definition actions.h:281
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:407
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:439
virtual COMMON_SETTINGS * GetCommonSettings() const
Definition pgm_base.cpp:541
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_PADS_PROJECT
Definition kicad_id.h:44
@ ID_IMPORT_GEDA_PROJECT
Definition kicad_id.h:45
@ 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.
#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)