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#include <wx/utils.h>
44
45
47{
49 // wxWidgets handles the Mac Application menu behind the scenes, but that means
50 // we always have to start from scratch with a new wxMenuBar.
51 wxMenuBar* oldMenuBar = GetMenuBar();
52 WX_MENUBAR* menuBar = new WX_MENUBAR();
53
54 //-- File menu -----------------------------------------------------------
55 //
56 ACTION_MENU* fileMenu = new ACTION_MENU( false, controlTool );
57 FILE_HISTORY& fileHistory = GetFileHistory();
58
59 fileHistory.SetClearText( _( "Clear Recent Projects" ) );
60
61 static ACTION_MENU* openRecentMenu;
62
63 // Create the menu if it does not exist. Adding a file to/from the history
64 // will automatically refresh the menu.
65 if( !openRecentMenu )
66 {
67 openRecentMenu = new ACTION_MENU( false, controlTool );
68 openRecentMenu->SetIcon( BITMAPS::recent );
69
70 fileHistory.UseMenu( openRecentMenu );
71 fileHistory.AddFilesToMenu();
72 }
73
74 // Ensure the title is up to date after changing language
75 openRecentMenu->SetTitle( _( "Open Recent" ) );
76
78
79 if( Pgm().GetCommonSettings() && Pgm().GetCommonSettings()->m_Git.enableGit )
81
82 if( wxDir::Exists( PATHS::GetStockDemosPath() ) )
84
86
87 wxMenuItem* item = fileMenu->Add( openRecentMenu->Clone() );
88
89 fileMenu->AppendSeparator();
92
93 // Add the file menu condition here since it needs the item ID for the submenu
95 cond.Enable( FILE_HISTORY::FileHistoryNotEmpty( fileHistory ) );
96 RegisterUIUpdateHandler( item->GetId(), cond );
97
98 fileMenu->AppendSeparator();
100
101 fileMenu->AppendSeparator();
102 fileMenu->Add( ACTIONS::saveAs );
103
104 fileMenu->AppendSeparator();
105
106 //Import Sub-menu
107 ACTION_MENU* importMenu = new ACTION_MENU( false, controlTool );
108 importMenu->SetTitle( _( "Import Non-KiCad Project..." ) );
109 importMenu->SetIcon( BITMAPS::import_project );
110
111 importMenu->Add( _( "Altium Project..." ),
112 _( "Import Altium Schematic and PCB (*.PrjPcb)" ),
115 importMenu->Add( _( "CADSTAR Project..." ),
116 _( "Import CADSTAR Archive Schematic and PCB (*.csa, *.cpa)" ),
119
120 importMenu->Add( _( "EAGLE Project..." ),
121 _( "Import EAGLE CAD XML schematic and board" ),
124
125 importMenu->Add( _( "EasyEDA (JLCEDA) Std Backup..." ),
126 _( "Import EasyEDA (JLCEDA) Standard schematic and board" ),
129
130 importMenu->Add( _( "EasyEDA (JLCEDA) Pro Project..." ),
131 _( "Import EasyEDA (JLCEDA) Professional schematic and board" ),
133
134 fileMenu->Add( importMenu );
135
136 fileMenu->AppendSeparator();
139
140 fileMenu->AppendSeparator();
141 fileMenu->AddQuitOrClose( nullptr, wxS( "KiCad" ) );
142
143 //-- Edit menu -----------------------------------------------------------
144 //
145
146 ACTION_MENU* editMenu = new ACTION_MENU( false, controlTool );
147
148 /*
149 * While we don't presently use these, they need to be here so that cut/copy/paste work
150 * in things like search boxes in file open dialogs.
151 */
152 editMenu->Add( ACTIONS::cut );
153 editMenu->Add( ACTIONS::copy );
154 editMenu->Add( ACTIONS::paste );
155
156 wxString editCfgEnv;
157 if( wxGetEnv( wxS( "KICAD_EDIT_ADVANCED_CFG" ), &editCfgEnv ); editCfgEnv == wxS( "1" ) )
158 {
159 editMenu->Add( _( "Edit Advanced Config..." ),
160 _( "Edit advanced settings" ),
163 }
164
165 //-- View menu -----------------------------------------------------------
166 //
167 ACTION_MENU* viewMenu = new ACTION_MENU( false, controlTool );
168
169 viewMenu->Add( ACTIONS::zoomRedraw );
170
171 viewMenu->AppendSeparator();
174
175#ifdef __APPLE__
176 // Add a separator only on macOS because the OS adds menu items to the view menu after ours
177 viewMenu->AppendSeparator();
178#endif
179
180 //-- Tools menu -----------------------------------------------
181 //
182 ACTION_MENU* toolsMenu = new ACTION_MENU( false, controlTool );
183
188
189 toolsMenu->AppendSeparator();
194
195 wxMenuItem* pcmMenuItem = toolsMenu->Add( KICAD_MANAGER_ACTIONS::showPluginManager );
196
199 {
200 pcmMenuItem->Enable( false );
201 }
202
203 toolsMenu->AppendSeparator();
204 toolsMenu->Add( _( "Edit Local File..." ),
205 _( "Edit local file in text editor" ),
208
209 //-- Preferences menu -----------------------------------------------
210 //
211 ACTION_MENU* prefsMenu = new ACTION_MENU( false, controlTool );
212
213 prefsMenu->Add( ACTIONS::configurePaths );
214 prefsMenu->Add( ACTIONS::showSymbolLibTable );
217 prefsMenu->Add( ACTIONS::openPreferences );
218
219 prefsMenu->AppendSeparator();
220 AddMenuLanguageList( prefsMenu, controlTool );
221
222
223 //-- Menubar -------------------------------------------------------------
224 //
225 menuBar->Append( fileMenu, _( "&File" ) );
226 menuBar->Append( editMenu, _( "&Edit" ) );
227 menuBar->Append( viewMenu, _( "&View" ) );
228 menuBar->Append( toolsMenu, _( "&Tools" ) );
229 menuBar->Append( prefsMenu, _( "&Preferences" ) );
230 AddStandardHelpMenu( menuBar );
231
232 SetMenuBar( menuBar );
233 delete oldMenuBar;
234}
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.
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 newProject
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
static wxString GetStockDemosPath()
Gets the stock (install) demos path.
Definition paths.cpp:408
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:913
#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)