KiCad PCB EDA Suite
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 (C) 1992-2021 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 <bitmaps.h>
28 #include <filehistory.h>
29 #include <menus_helpers.h>
30 #include <paths.h>
31 #include <tool/action_manager.h>
32 #include <tool/action_toolbar.h>
33 #include <tool/tool_manager.h>
36 #include "kicad_manager_frame.h"
37 #include "pgm_kicad.h"
38 #include "kicad_id.h"
39 #include <widgets/wx_menubar.h>
40 #include <wx/dir.h>
41 
42 
44 {
46  // wxWidgets handles the Mac Application menu behind the scenes, but that means
47  // we always have to start from scratch with a new wxMenuBar.
48  wxMenuBar* oldMenuBar = GetMenuBar();
49  WX_MENUBAR* menuBar = new WX_MENUBAR();
50 
51  //-- File menu -----------------------------------------------------------
52  //
53  ACTION_MENU* fileMenu = new ACTION_MENU( false, controlTool );
54  FILE_HISTORY& fileHistory = GetFileHistory();
55 
56  fileHistory.SetClearText( _( "Clear Recent Projects" ) );
57 
58  static ACTION_MENU* openRecentMenu;
59 
60  // Create the menu if it does not exist. Adding a file to/from the history
61  // will automatically refresh the menu.
62  if( !openRecentMenu )
63  {
64  openRecentMenu = new ACTION_MENU( false, controlTool );
65  openRecentMenu->SetIcon( BITMAPS::recent );
66 
67  fileHistory.UseMenu( openRecentMenu );
68  fileHistory.AddFilesToMenu();
69  }
70 
71  // Ensure the title is up to date after changing language
72  openRecentMenu->SetTitle( _( "Open Recent" ) );
73 
76 
77  if( wxDir::Exists( PATHS::GetStockDemosPath() ) )
78  {
80  }
81 
83 
84  wxMenuItem* item = fileMenu->Add( openRecentMenu->Clone() );
85 
86  // Add the file menu condition here since it needs the item ID for the submenu
87  ACTION_CONDITIONS cond;
88  cond.Enable( FILE_HISTORY::FileHistoryNotEmpty( fileHistory ) );
89  RegisterUIUpdateHandler( item->GetId(), cond );
90 
91  fileMenu->AppendSeparator();
93 
94  fileMenu->AppendSeparator();
95  fileMenu->Add( ACTIONS::saveAs );
96 
97  fileMenu->AppendSeparator();
98 
99  //Import Sub-menu
100  ACTION_MENU* importMenu = new ACTION_MENU( false, controlTool );
101  importMenu->SetTitle( _( "Import Non-KiCad Project..." ) );
102  importMenu->SetIcon( BITMAPS::import_project );
103 
104  importMenu->Add( _( "CADSTAR Project..." ),
105  _( "Import CADSTAR Archive Schematic and PCB (*.csa, *.cpa)" ),
108 
109  importMenu->Add( _( "EAGLE Project..." ),
110  _( "Import EAGLE CAD XML schematic and board" ),
113 
114  fileMenu->Add( importMenu );
115 
116  fileMenu->AppendSeparator();
117  fileMenu->Add( _( "&Archive Project..." ),
118  _( "Archive all needed project files into zip archive" ),
120  BITMAPS::zip );
121 
122  fileMenu->Add( _( "&Unarchive Project..." ),
123  _( "Unarchive project files from zip archive" ),
125  BITMAPS::unzip );
126 
127  fileMenu->AppendSeparator();
128  fileMenu->AddQuitOrClose( nullptr, wxT( "KiCad" ) );
129 
130  //-- View menu -----------------------------------------------------------
131  //
132  ACTION_MENU* viewMenu = new ACTION_MENU( false, controlTool );
133 
134  viewMenu->Add( ACTIONS::zoomRedraw );
135 
136  viewMenu->AppendSeparator();
138  viewMenu->Add( _( "Browse Project Files" ),
139  _( "Open project directory in file browser" ),
142 
143 #ifdef __APPLE__
144  // Add a separator only on macOS because the OS adds menu items to the view menu after ours
145  viewMenu->AppendSeparator();
146 #endif
147 
148  //-- Tools menu -----------------------------------------------
149  //
150  ACTION_MENU* toolsMenu = new ACTION_MENU( false, controlTool );
151 
154  toolsMenu->Add( KICAD_MANAGER_ACTIONS::editPCB );
156 
157  toolsMenu->AppendSeparator();
162 #ifdef PCM
163  toolsMenu->Add( KICAD_MANAGER_ACTIONS::showPluginManager );
164 #endif
165 
166  toolsMenu->AppendSeparator();
167  toolsMenu->Add( _( "Edit Local File..." ),
168  _( "Edit local file in text editor" ),
170  BITMAPS::editor );
171 
172  //-- Preferences menu -----------------------------------------------
173  //
174  ACTION_MENU* prefsMenu = new ACTION_MENU( false, controlTool );
175 
176  prefsMenu->Add( ACTIONS::configurePaths );
177  prefsMenu->Add( ACTIONS::showSymbolLibTable );
178  prefsMenu->Add( ACTIONS::showFootprintLibTable );
179 
180  // We can't use ACTIONS::showPreferences yet because wxWidgets moves this on
181  // Mac, and it needs the wxID_PREFERENCES id to find it.
182  prefsMenu->Add( _( "Preferences..." ) + "\tCtrl+,",
183  _( "Show preferences for all open tools" ),
184  wxID_PREFERENCES,
186 
187  prefsMenu->AppendSeparator();
188  AddMenuLanguageList( prefsMenu, controlTool );
189 
190 
191  //-- Menubar -------------------------------------------------------------
192  //
193  menuBar->Append( fileMenu, _( "&File" ) );
194  menuBar->Append( viewMenu, _( "&View" ) );
195  menuBar->Append( toolsMenu, _( "&Tools" ) );
196  menuBar->Append( prefsMenu, _( "&Preferences" ) );
197  AddStandardHelpMenu( menuBar );
198 
199  SetMenuBar( menuBar );
200  delete oldMenuBar;
201 }
202 
203 
208 {
209  if( m_mainToolBar )
210  {
212  }
213  else
214  {
215  m_mainToolBar = new ACTION_TOOLBAR( this, ID_H_TOOLBAR, wxDefaultPosition, wxDefaultSize,
216  KICAD_AUI_TB_STYLE | wxAUI_TB_HORZ_LAYOUT );
218  }
219 
220  // New
223 
225  m_mainToolBar->AddTool( ID_SAVE_AND_ZIP_FILES, wxEmptyString,
226  KiScaledBitmap( BITMAPS::zip, this ),
227  _( "Archive all project files" ) );
228 
229  m_mainToolBar->AddTool( ID_READ_ZIP_ARCHIVE, wxEmptyString,
231  _( "Unarchive project files from zip archive" ) );
232 
235 
237  m_mainToolBar->AddTool( ID_BROWSE_IN_FILE_EXPLORER, wxEmptyString,
239 #ifdef __APPLE__
240  _( "Reveal project folder in Finder" ) );
241 #else
242  _( "Open project directory in file explorer" ) );
243 #endif
244 
245  // Create m_mainToolBar
246  m_mainToolBar->Realize();
247 }
void AddFilesToMenu() override
Add the files to all registered menus.
Definition: filehistory.h:98
static TOOL_ACTION newProject
IDs used in KiCad main frame foe menuitems and tools.
Define the structure of a toolbar with buttons that invoke ACTIONs.
Defines the structure of a menu based on ACTIONs.
Definition: action_menu.h:48
void SetIcon(BITMAPS aIcon)
Assign an icon for the entry.
Definition: action_menu.cpp:73
void AddScaledSeparator(wxWindow *aWindow)
Add a separator that introduces space on either side to not squash the tools when scaled.
static TOOL_ACTION showCalculator
void SetClearText(wxString aClearText)
Set the text displayed on the menu item that clears the entire menu.
Definition: filehistory.h:123
static TOOL_ACTION openDemoProject
void Add(const TOOL_ACTION &aAction, bool aIsToggleEntry=false, bool aIsCancellable=false)
Add a TOOL_ACTION-based button to the toolbar.
static TOOL_ACTION viewGerbers
virtual void RegisterUIUpdateHandler(int aID, const ACTION_CONDITIONS &aConditions) override
Register a UI update handler for the control with ID aID.
static TOOL_ACTION showSymbolLibTable
Definition: actions.h:175
static TOOL_ACTION newFromTemplate
void SetAuiManager(wxAuiManager *aManager)
Set the AUI manager that this toolbar belongs to.
Handle actions in the kicad manager frame.
wxAuiManager m_auimgr
Wrapper around a wxMenuBar object that prevents the accelerator table from being used.
Definition: wx_menubar.h:45
This class implements a file history object to store a list of files, that can then be added to a men...
Definition: filehistory.h:42
static TOOL_ACTION convertImage
static TOOL_ACTION closeProject
ACTION_CONDITIONS & Enable(const SELECTION_CONDITION &aCondition)
static TOOL_ACTION editSchematic
static TOOL_ACTION showFootprintLibTable
Definition: actions.h:176
void AddStandardHelpMenu(wxMenuBar *aMenuBar)
Adds the standard KiCad help menu to the menubar.
static TOOL_ACTION editFootprints
#define _(s)
ACTION_MENU * Clone() const
Create a deep, recursive copy of this ACTION_MENU.
void RecreateBaseHToolbar()
(Re)Create the horizontal toolbar
void AddMenuLanguageList(ACTION_MENU *aMasterMenu, TOOL_INTERACTIVE *aControlTool)
Function AddMenuLanguageList creates a menu list for language choice, and add it as submenu to Master...
wxBitmap KiScaledBitmap(BITMAPS aBitmap, wxWindow *aWindow, int aHeight, bool aQuantized)
Construct a wxBitmap from a memory record, scaling it if device DPI demands it.
Definition: bitmap.cpp:148
static TOOL_ACTION editPCB
TOOL_MANAGER * m_toolManager
Definition: tools_holder.h:158
void SetTitle(const wxString &aTitle) override
Set title for the menu.
Definition: action_menu.cpp:87
FILE_HISTORY & GetFileHistory()
Get the frame's main file history.
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 ReCreateMenuBar() override
Recreates the menu bar.
static TOOL_ACTION openProject
static TOOL_ACTION saveAs
Definition: actions.h:52
static TOOL_ACTION zoomRedraw
Definition: actions.h:90
static wxString GetStockDemosPath()
Gets the stock (install) demos path.
Definition: paths.cpp:302
Functors that can be used to figure out how the action controls should be displayed in the UI and if ...
wxMenuItem * Add(const wxString &aLabel, int aId, BITMAPS aIcon)
Add a wxWidgets-style entry to the menu.
static constexpr int KICAD_AUI_TB_STYLE
< Default style flags used for wxAUI toolbars.
void AddQuitOrClose(KIFACE_BASE *aKiface, wxString aAppname="")
Add either a standard Quit or Close item to the menu.
ACTION_TOOLBAR * m_mainToolBar
static TOOL_ACTION editSymbols
static TOOL_ACTION configurePaths
Definition: actions.h:174
static TOOL_ACTION openTextEditor
static TOOL_ACTION editDrawingSheet
void ClearToolbar()
Clear the toolbar and remove all associated menus.