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 <stambaughw@verizon.net>
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->SetTitle( _( "Open Recent" ) );
66  openRecentMenu->SetIcon( BITMAPS::recent );
67 
68  fileHistory.UseMenu( openRecentMenu );
69  fileHistory.AddFilesToMenu();
70  }
71 
74 
75  if( wxDir::Exists( PATHS::GetStockDemosPath() ) )
76  {
78  }
79 
81 
82  wxMenuItem* item = fileMenu->Add( openRecentMenu );
83 
84  // Add the file menu condition here since it needs the item ID for the submenu
85  ACTION_CONDITIONS cond;
86  cond.Enable( FILE_HISTORY::FileHistoryNotEmpty( fileHistory ) );
87  RegisterUIUpdateHandler( item->GetId(), cond );
88 
89  fileMenu->AppendSeparator();
91 
92  fileMenu->AppendSeparator();
93  fileMenu->Add( ACTIONS::saveAs );
94 
95  fileMenu->AppendSeparator();
96 
97  //Import Sub-menu
98  ACTION_MENU* importMenu = new ACTION_MENU( false, controlTool );
99  importMenu->SetTitle( _( "Import Non-KiCad Project..." ) );
100  importMenu->SetIcon( BITMAPS::import_project );
101 
102  importMenu->Add( _( "CADSTAR Project..." ),
103  _( "Import CADSTAR Archive Schematic and PCB (*.csa, *.cpa)" ),
106 
107  importMenu->Add( _( "EAGLE Project..." ),
108  _( "Import EAGLE CAD XML schematic and board" ),
111 
112  fileMenu->Add( importMenu );
113 
114  fileMenu->AppendSeparator();
115  fileMenu->Add( _( "&Archive Project..." ),
116  _( "Archive all needed project files into zip archive" ),
118  BITMAPS::zip );
119 
120  fileMenu->Add( _( "&Unarchive Project..." ),
121  _( "Unarchive project files from zip archive" ),
123  BITMAPS::unzip );
124 
125  fileMenu->AppendSeparator();
126  fileMenu->AddQuitOrClose( nullptr, "KiCad" );
127 
128  //-- View menu -----------------------------------------------------------
129  //
130  ACTION_MENU* viewMenu = new ACTION_MENU( false, controlTool );
131 
132  viewMenu->Add( ACTIONS::zoomRedraw );
133 
134  viewMenu->AppendSeparator();
136  viewMenu->Add( _( "Browse Project Files" ),
137  _( "Open project directory in file browser" ),
140 
141 #ifdef __APPLE__
142  // Add a separator only on macOS because the OS adds menu items to the view menu after ours
143  viewMenu->AppendSeparator();
144 #endif
145 
146  //-- Tools menu -----------------------------------------------
147  //
148  ACTION_MENU* toolsMenu = new ACTION_MENU( false, controlTool );
149 
152  toolsMenu->Add( KICAD_MANAGER_ACTIONS::editPCB );
154 
155  toolsMenu->AppendSeparator();
160 #ifdef PCM
161  toolsMenu->Add( KICAD_MANAGER_ACTIONS::showPluginManager );
162 #endif
163 
164  toolsMenu->AppendSeparator();
165  toolsMenu->Add( _( "Edit Local File..." ),
166  _( "Edit local file in text editor" ),
168  BITMAPS::editor );
169 
170  //-- Preferences menu -----------------------------------------------
171  //
172  ACTION_MENU* prefsMenu = new ACTION_MENU( false, controlTool );
173 
174  prefsMenu->Add( ACTIONS::configurePaths );
175  prefsMenu->Add( ACTIONS::showSymbolLibTable );
176  prefsMenu->Add( ACTIONS::showFootprintLibTable );
177 
178  // We can't use ACTIONS::showPreferences yet because wxWidgets moves this on
179  // Mac, and it needs the wxID_PREFERENCES id to find it.
180  prefsMenu->Add( _( "Preferences..." ) + "\tCtrl+,",
181  _( "Show preferences for all open tools" ),
182  wxID_PREFERENCES,
184 
185  prefsMenu->AppendSeparator();
186  AddMenuLanguageList( prefsMenu, controlTool );
187 
188 
189  //-- Menubar -------------------------------------------------------------
190  //
191  menuBar->Append( fileMenu, _( "&File" ) );
192  menuBar->Append( viewMenu, _( "&View" ) );
193  menuBar->Append( toolsMenu, _( "&Tools" ) );
194  menuBar->Append( prefsMenu, _( "&Preferences" ) );
195  AddStandardHelpMenu( menuBar );
196 
197  SetMenuBar( menuBar );
198  delete oldMenuBar;
199 }
200 
201 
206 {
207  if( m_mainToolBar )
208  {
210  }
211  else
212  {
213  m_mainToolBar = new ACTION_TOOLBAR( this, ID_H_TOOLBAR, wxDefaultPosition, wxDefaultSize,
214  KICAD_AUI_TB_STYLE | wxAUI_TB_HORZ_LAYOUT );
216  }
217 
218  // New
221 
223  m_mainToolBar->AddTool( ID_SAVE_AND_ZIP_FILES, wxEmptyString,
224  KiScaledBitmap( BITMAPS::zip, this ),
225  _( "Archive all project files" ) );
226 
227  m_mainToolBar->AddTool( ID_READ_ZIP_ARCHIVE, wxEmptyString,
229  _( "Unarchive project files from zip archive" ) );
230 
233 
235  m_mainToolBar->AddTool( ID_BROWSE_IN_FILE_EXPLORER, wxEmptyString,
237 #ifdef __APPLE__
238  _( "Reveal project folder in Finder" ) );
239 #else
240  _( "Open project directory in file explorer" ) );
241 #endif
242 
243  // Create m_mainToolBar
244  m_mainToolBar->Realize();
245 }
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:174
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:175
void AddStandardHelpMenu(wxMenuBar *aMenuBar)
Adds the standard KiCad help menu to the menubar.
static TOOL_ACTION editFootprints
#define _(s)
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:252
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:173
static TOOL_ACTION openTextEditor
static TOOL_ACTION editDrawingSheet
void ClearToolbar()
Clear the toolbar and remove all associated menus.