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( _( "gEDA / Lepton EDA Project..." ),
150 _( "Import gEDA or Lepton EDA schematic and PCB layout" ),
153
154 importMenu->Add( _( "DipTrace Project..." ),
155 _( "Import DipTrace schematic and PCB (*.dch, *.dip)" ),
158
159 fileMenu->Add( importMenu );
160
161 fileMenu->AppendSeparator();
164
165 fileMenu->AppendSeparator();
166 fileMenu->AddQuitOrClose( nullptr, wxS( "KiCad" ) );
167
168 //-- Edit menu -----------------------------------------------------------
169 //
170
171 ACTION_MENU* editMenu = new ACTION_MENU( false, controlTool );
172
173 /*
174 * While we don't presently use these, they need to be here so that cut/copy/paste work
175 * in things like search boxes in file open dialogs.
176 */
177 editMenu->Add( ACTIONS::cut );
178 editMenu->Add( ACTIONS::copy );
179 editMenu->Add( ACTIONS::paste );
180
181 wxString editCfgEnv;
182 if( wxGetEnv( wxS( "KICAD_EDIT_ADVANCED_CFG" ), &editCfgEnv ); editCfgEnv == wxS( "1" ) )
183 {
184 editMenu->Add( _( "Edit Advanced Config..." ),
185 _( "Edit advanced settings" ),
188 }
189
190 //-- View menu -----------------------------------------------------------
191 //
192 ACTION_MENU* viewMenu = new ACTION_MENU( false, controlTool );
193
194 ACTION_MENU* panelsMenu = new ACTION_MENU( false, controlTool );
195 panelsMenu->SetTitle( _( "Panels" ) );
197 viewMenu->Add( panelsMenu );
198
199 viewMenu->AppendSeparator();
200 viewMenu->Add( ACTIONS::zoomRedraw );
201
202 viewMenu->AppendSeparator();
205
206#ifdef __APPLE__
207 // Add a separator only on macOS because the OS adds menu items to the view menu after ours
208 viewMenu->AppendSeparator();
209#endif
210
211 //-- Tools menu -----------------------------------------------
212 //
213 ACTION_MENU* toolsMenu = new ACTION_MENU( false, controlTool );
214
219
220 toolsMenu->AppendSeparator();
225
226 wxMenuItem* pcmMenuItem = toolsMenu->Add( KICAD_MANAGER_ACTIONS::showPluginManager );
227
230 {
231 pcmMenuItem->Enable( false );
232 }
233
234 toolsMenu->AppendSeparator();
235 toolsMenu->Add( _( "Compare Project Branches..." ),
236 _( "Review the file changes between two git refs in the "
237 "current project" ),
240
241 toolsMenu->Add( _( "Edit Local File..." ),
242 _( "Edit local file in text editor" ),
245
246 //-- Preferences menu -----------------------------------------------
247 //
248 ACTION_MENU* prefsMenu = new ACTION_MENU( false, controlTool );
249
250 prefsMenu->Add( ACTIONS::configurePaths );
251 prefsMenu->Add( ACTIONS::showSymbolLibTable );
254 prefsMenu->Add( ACTIONS::openPreferences );
255
256 prefsMenu->AppendSeparator();
257 AddMenuLanguageList( prefsMenu, controlTool );
258
259
260 //-- Menubar -------------------------------------------------------------
261 //
262 menuBar->Append( fileMenu, _( "&File" ) );
263 menuBar->Append( editMenu, _( "&Edit" ) );
264 menuBar->Append( viewMenu, _( "&View" ) );
265 menuBar->Append( toolsMenu, _( "&Tools" ) );
266 menuBar->Append( prefsMenu, _( "&Preferences" ) );
267 AddStandardHelpMenu( menuBar );
268
269 SetMenuBar( menuBar );
270 delete oldMenuBar;
271}
@ 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:278
static TOOL_ACTION openPreferences
Definition actions.h:276
static TOOL_ACTION showFootprintLibTable
Definition actions.h:279
static TOOL_ACTION showDesignBlockLibTable
Definition actions.h:280
static TOOL_ACTION cut
Definition actions.h:73
static TOOL_ACTION configurePaths
Definition actions.h:277
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.
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:528
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:42
@ 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: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_EASYEDA_PROJECT
Definition kicad_id.h:37
@ ID_IMPORT_ALTIUM_PROJECT
Definition kicad_id.h:39
@ ID_COMPARE_PROJECT_BRANCHES
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: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)