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, see <https://www.gnu.org/licenses/>.
21 */
22
24#include <advanced_config.h>
25#include <bitmaps.h>
26#include <file_history.h>
27#include <kiplatform/policy.h>
28#include <kiway.h>
29#include <local_history.h>
30#include <paths.h>
31#include <policy_keys.h>
32#include <tool/action_manager.h>
33#include <tool/action_toolbar.h>
34#include <tool/tool_manager.h>
35#include <tool/selection.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#include <wx/utils.h>
44#include <local_history.h>
45
46
48{
50 // wxWidgets handles the Mac Application menu behind the scenes, but that means
51 // we always have to start from scratch with a new wxMenuBar.
52 wxMenuBar* oldMenuBar = GetMenuBar();
53 WX_MENUBAR* menuBar = new WX_MENUBAR();
54
55 //-- File menu -----------------------------------------------------------
56 //
57 ACTION_MENU* fileMenu = new ACTION_MENU( false, controlTool );
58 FILE_HISTORY& fileHistory = GetFileHistory();
59
60 fileHistory.SetClearText( _( "Clear Recent Projects" ) );
61
62 static ACTION_MENU* openRecentMenu;
63
64 // Create the menu if it does not exist. Adding a file to/from the history
65 // will automatically refresh the menu.
66 if( !openRecentMenu )
67 {
68 openRecentMenu = new ACTION_MENU( false, controlTool );
69 openRecentMenu->SetIcon( BITMAPS::recent );
70
71 fileHistory.UseMenu( openRecentMenu );
72 fileHistory.AddFilesToMenu();
73 }
74
75 // Ensure the title is up to date after changing language
76 openRecentMenu->SetTitle( _( "Open Recent" ) );
77
79
80 if( Pgm().GetCommonSettings() && Pgm().GetCommonSettings()->m_Git.enableGit )
82
83 if( wxDir::Exists( PATHS::GetStockDemosPath() ) )
85
87
88 wxMenuItem* item = fileMenu->Add( openRecentMenu->Clone() );
89
90 fileMenu->AppendSeparator();
93
94 // Add the file menu condition here since it needs the item ID for the submenu
96 cond.Enable( FILE_HISTORY::FileHistoryNotEmpty( fileHistory ) );
97 RegisterUIUpdateHandler( item->GetId(), cond );
98
99 fileMenu->AppendSeparator();
101
102 fileMenu->AppendSeparator();
103 wxMenuItem* restoreItem = fileMenu->Add( KICAD_MANAGER_ACTIONS::restoreLocalHistory );
104 ACTION_CONDITIONS historyCond;
105 historyCond.Enable( [&]( const SELECTION& )
106 {
108 && Kiway().LocalHistory().HistoryExists( Prj().GetProjectPath() );
109 } );
110 RegisterUIUpdateHandler( restoreItem->GetId(), historyCond );
111
112 fileMenu->AppendSeparator();
113 fileMenu->Add( ACTIONS::saveAs );
114
115 fileMenu->AppendSeparator();
116
117 //Import Sub-menu
118 ACTION_MENU* importMenu = new ACTION_MENU( false, controlTool );
119 importMenu->SetTitle( _( "Import Non-KiCad Project..." ) );
120 importMenu->SetIcon( BITMAPS::import_project );
121
122 importMenu->Add( _( "Altium Project..." ),
123 _( "Import Altium Schematic and PCB (*.PrjPcb)" ),
126 importMenu->Add( _( "CADSTAR Project..." ),
127 _( "Import CADSTAR Archive Schematic and PCB (*.csa, *.cpa)" ),
130
131 importMenu->Add( _( "EAGLE Project..." ),
132 _( "Import EAGLE CAD XML schematic and board" ),
135
136 importMenu->Add( _( "EasyEDA (JLCEDA) Std Backup..." ),
137 _( "Import EasyEDA (JLCEDA) Standard schematic and board" ),
140
141 importMenu->Add( _( "EasyEDA (JLCEDA) Pro Project..." ),
142 _( "Import EasyEDA (JLCEDA) Professional schematic and board" ),
144
145 importMenu->Add( _( "PADS Project..." ),
146 _( "Import PADS Logic schematic and PADS ASCII PCB (*.asc, *.txt)" ),
148
149 importMenu->Add( _( "P-CAD Project..." ),
150 _( "Import P-CAD ASCII schematic and board" ),
152
153 importMenu->Add( _( "gEDA / Lepton EDA Project..." ),
154 _( "Import gEDA or Lepton EDA schematic and PCB layout" ),
157
158 importMenu->Add( _( "DipTrace Project..." ),
159 _( "Import DipTrace schematic and PCB (*.dch, *.dip)" ),
162
163 importMenu->Add( _( "OrCAD Project..." ),
164 _( "Import OrCAD schematic (*.dsn) and optional Allegro board (*.brd)" ),
167
168 fileMenu->Add( importMenu );
169
170 fileMenu->AppendSeparator();
173
174 fileMenu->AppendSeparator();
175 fileMenu->AddQuitOrClose( nullptr, wxS( "KiCad" ) );
176
177 //-- Edit menu -----------------------------------------------------------
178 //
179
180 ACTION_MENU* editMenu = new ACTION_MENU( false, controlTool );
181
182 /*
183 * While we don't presently use these, they need to be here so that cut/copy/paste work
184 * in things like search boxes in file open dialogs.
185 */
186 editMenu->Add( ACTIONS::cut );
187 editMenu->Add( ACTIONS::copy );
188 editMenu->Add( ACTIONS::paste );
189
190 wxString editCfgEnv;
191 if( wxGetEnv( wxS( "KICAD_EDIT_ADVANCED_CFG" ), &editCfgEnv ); editCfgEnv == wxS( "1" ) )
192 {
193 editMenu->Add( _( "Edit Advanced Config..." ),
194 _( "Edit advanced settings" ),
197 }
198
199 //-- View menu -----------------------------------------------------------
200 //
201 ACTION_MENU* viewMenu = new ACTION_MENU( false, controlTool );
202
203 ACTION_MENU* panelsMenu = new ACTION_MENU( false, controlTool );
204 panelsMenu->SetTitle( _( "Panels" ) );
206 viewMenu->Add( panelsMenu );
207
208 viewMenu->AppendSeparator();
209 viewMenu->Add( ACTIONS::zoomRedraw );
210
211 viewMenu->AppendSeparator();
214
215#ifdef __APPLE__
216 // Add a separator only on macOS because the OS adds menu items to the view menu after ours
217 viewMenu->AppendSeparator();
218#endif
219
220 //-- Tools menu -----------------------------------------------
221 //
222 ACTION_MENU* toolsMenu = new ACTION_MENU( false, controlTool );
223
228
229 toolsMenu->AppendSeparator();
234
235 wxMenuItem* pcmMenuItem = toolsMenu->Add( KICAD_MANAGER_ACTIONS::showPluginManager );
236
239 {
240 pcmMenuItem->Enable( false );
241 }
242
243 toolsMenu->AppendSeparator();
244 toolsMenu->Add( _( "Compare Project Branches..." ),
245 _( "Review the file changes between two git refs in the "
246 "current project" ),
249
250 toolsMenu->Add( _( "Edit Local File..." ),
251 _( "Edit local file in text editor" ),
254
255 //-- Preferences menu -----------------------------------------------
256 //
257 ACTION_MENU* prefsMenu = new ACTION_MENU( false, controlTool );
258
259 prefsMenu->Add( ACTIONS::configurePaths );
260 prefsMenu->Add( ACTIONS::showSymbolLibTable );
263 prefsMenu->Add( ACTIONS::openPreferences );
264
265 prefsMenu->AppendSeparator();
266 AddMenuLanguageList( prefsMenu, controlTool );
267
268
269 //-- Menubar -------------------------------------------------------------
270 //
271 menuBar->Append( fileMenu, _( "&File" ) );
272 menuBar->Append( editMenu, _( "&Edit" ) );
273 menuBar->Append( viewMenu, _( "&View" ) );
274 menuBar->Append( toolsMenu, _( "&Tools" ) );
275 menuBar->Append( prefsMenu, _( "&Preferences" ) );
276 AddStandardHelpMenu( menuBar );
277
278 SetMenuBar( menuBar );
279 delete oldMenuBar;
280}
@ change_entry_orient
static TOOL_ACTION paste
Definition actions.h:76
static TOOL_ACTION zoomRedraw
Definition actions.h:128
static TOOL_ACTION saveAs
Definition actions.h:55
static TOOL_ACTION copy
Definition actions.h:74
static TOOL_ACTION showSymbolLibTable
Definition actions.h:280
static TOOL_ACTION openPreferences
Definition actions.h:278
static TOOL_ACTION showFootprintLibTable
Definition actions.h:281
static TOOL_ACTION showDesignBlockLibTable
Definition actions.h:282
static TOOL_ACTION cut
Definition actions.h:73
static TOOL_ACTION configurePaths
Definition actions.h:279
Define the structure of a menu based on ACTIONs.
Definition action_menu.h:43
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.
bool AutosaveUsesLocalHistory() const
The backup format is the single switch that selects the autosave mechanism: the incremental format re...
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:422
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:449
virtual COMMON_SETTINGS * GetCommonSettings() const
Definition pgm_base.cpp:562
TOOL_MANAGER * m_toolManager
Wrapper around a wxMenuBar object that prevents the accelerator table from being used.
Definition wx_menubar.h:43
#define _(s)
@ ID_EDIT_ADVANCED_CFG
Definition kicad_id.h:34
@ ID_IMPORT_DIPTRACE_PROJECT
Definition kicad_id.h:43
@ ID_IMPORT_EAGLE_PROJECT
Definition kicad_id.h:36
@ ID_IMPORT_EASYEDAPRO_PROJECT
Definition kicad_id.h:38
@ ID_IMPORT_PADS_PROJECT
Definition kicad_id.h:40
@ ID_IMPORT_GEDA_PROJECT
Definition kicad_id.h:42
@ ID_IMPORT_PCAD_PROJECT
Definition kicad_id.h:41
@ ID_IMPORT_CADSTAR_ARCHIVE_PROJECT
Definition kicad_id.h:35
@ ID_EDIT_LOCAL_FILE_IN_TEXT_EDITOR
Definition kicad_id.h:33
@ ID_IMPORT_ORCAD_PROJECT
Definition kicad_id.h:44
@ ID_IMPORT_EASYEDA_PROJECT
Definition kicad_id.h:37
@ ID_IMPORT_ALTIUM_PROJECT
Definition kicad_id.h:39
@ ID_COMPARE_PROJECT_BRANCHES
Definition kicad_id.h:45
PBOOL GetPolicyBool(const wxString &aKey)
PGM_BASE & Pgm()
The global program "get" accessor.
#define POLICY_KEY_PCM
Definition policy_keys.h:27
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)