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-2020 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 <tool/action_manager.h>
31 #include <tool/action_toolbar.h>
32 #include <tool/tool_manager.h>
35 #include "kicad_manager_frame.h"
36 #include "pgm_kicad.h"
37 #include "kicad_id.h"
38 #include <widgets/wx_menubar.h>
39 
40 
42 {
44  // wxWidgets handles the Mac Application menu behind the scenes, but that means
45  // we always have to start from scratch with a new wxMenuBar.
46  wxMenuBar* oldMenuBar = GetMenuBar();
47  WX_MENUBAR* menuBar = new WX_MENUBAR();
48 
49  //-- File menu -----------------------------------------------------------
50  //
51  ACTION_MENU* fileMenu = new ACTION_MENU( false, controlTool );
52  FILE_HISTORY& fileHistory = GetFileHistory();
53 
54  fileHistory.SetClearText( _( "Clear Recent Projects" ) );
55 
56  static ACTION_MENU* openRecentMenu;
57 
58  // Create the menu if it does not exist. Adding a file to/from the history
59  // will automatically refresh the menu.
60  if( !openRecentMenu )
61  {
62  openRecentMenu = new ACTION_MENU( false, controlTool );
63  openRecentMenu->SetTitle( _( "Open Recent" ) );
64  openRecentMenu->SetIcon( recent_xpm );
65 
66  fileHistory.UseMenu( openRecentMenu );
67  fileHistory.AddFilesToMenu();
68  }
69 
73 
74  wxMenuItem* item = fileMenu->Add( openRecentMenu );
75 
76  // Add the file menu condition here since it needs the item ID for the submenu
77  ACTION_CONDITIONS cond;
78  cond.Enable( FILE_HISTORY::FileHistoryNotEmpty( fileHistory ) );
79  RegisterUIUpdateHandler( item->GetId(), cond );
80 
82 
83  fileMenu->AppendSeparator();
84  fileMenu->Add( ACTIONS::saveAs );
85 
86  fileMenu->AppendSeparator();
87 
88  //Import Sub-menu
89  ACTION_MENU* importMenu = new ACTION_MENU( false, controlTool );
90  importMenu->SetTitle( _( "Import Non-KiCad Project..." ) );
91  importMenu->SetIcon( import_project_xpm );
92 
93  importMenu->Add( _( "Import CADSTAR Project..." ),
94  _( "Import CADSTAR Archive Schematic and PCB (*.csa, *.cpa)" ),
97 
98  importMenu->Add( _( "Import EAGLE Project..." ),
99  _( "Import EAGLE CAD XML schematic and board" ),
102 
103  fileMenu->Add( importMenu );
104 
105  fileMenu->AppendSeparator();
106  fileMenu->Add( _( "&Archive Project..." ),
107  _( "Archive all needed project files into zip archive" ),
109  zip_xpm );
110 
111  fileMenu->Add( _( "&Unarchive Project..." ),
112  _( "Unarchive project files from zip archive" ),
114  unzip_xpm );
115 
116  fileMenu->AppendSeparator();
117  fileMenu->AddQuitOrClose( nullptr, "KiCad" );
118 
119  //-- View menu -----------------------------------------------------------
120  //
121  ACTION_MENU* viewMenu = new ACTION_MENU( false, controlTool );
122 
123  viewMenu->Add( ACTIONS::zoomRedraw );
124 
125  viewMenu->AppendSeparator();
127  viewMenu->Add( _( "Browse Project Files" ),
128  _( "Open project directory in file browser" ),
131 
132 #ifdef __APPLE__
133  // Add a separator only on macOS because the OS adds menu items to the view menu after ours
134  viewMenu->AppendSeparator();
135 #endif
136 
137  //-- Tools menu -----------------------------------------------
138  //
139  ACTION_MENU* toolsMenu = new ACTION_MENU( false, controlTool );
140 
143  toolsMenu->Add( KICAD_MANAGER_ACTIONS::editPCB );
145 
146  toolsMenu->AppendSeparator();
151 
152  toolsMenu->AppendSeparator();
153  toolsMenu->Add( _( "Edit Local File..." ),
154  _( "Edit local file in text editor" ),
157 
158  //-- Preferences menu -----------------------------------------------
159  //
160  ACTION_MENU* prefsMenu = new ACTION_MENU( false, controlTool );
161 
162  prefsMenu->Add( ACTIONS::configurePaths );
163  prefsMenu->Add( ACTIONS::showSymbolLibTable );
164  prefsMenu->Add( ACTIONS::showFootprintLibTable );
165  prefsMenu->Add( _( "Preferences...\tCTRL+," ),
166  _( "Show preferences for all open tools" ),
167  wxID_PREFERENCES,
168  preference_xpm );
169 
170  prefsMenu->AppendSeparator();
171  AddMenuLanguageList( prefsMenu, controlTool );
172 
173 
174  //-- Menubar -------------------------------------------------------------
175  //
176  menuBar->Append( fileMenu, _( "&File" ) );
177  menuBar->Append( viewMenu, _( "&View" ) );
178  menuBar->Append( toolsMenu, _( "&Tools" ) );
179  menuBar->Append( prefsMenu, _( "&Preferences" ) );
180  AddStandardHelpMenu( menuBar );
181 
182  SetMenuBar( menuBar );
183  delete oldMenuBar;
184 }
185 
186 
191 {
192  if( m_mainToolBar )
193  {
195  }
196  else
197  {
198  m_mainToolBar = new ACTION_TOOLBAR( this, ID_H_TOOLBAR, wxDefaultPosition, wxDefaultSize,
199  KICAD_AUI_TB_STYLE | wxAUI_TB_HORZ_LAYOUT );
201  }
202 
203  // New
207 
209  m_mainToolBar->AddTool( ID_SAVE_AND_ZIP_FILES, wxEmptyString,
210  KiScaledBitmap( zip_xpm, this ),
211  _( "Archive all project files" ) );
212 
213  m_mainToolBar->AddTool( ID_READ_ZIP_ARCHIVE, wxEmptyString,
214  KiScaledBitmap( unzip_xpm, this ),
215  _( "Unarchive project files from zip archive" ) );
216 
219 
221  m_mainToolBar->AddTool( ID_BROWSE_IN_FILE_EXPLORER, wxEmptyString,
223 #ifdef __APPLE__
224  _( "Reveal project folder in Finder" ) );
225 #else
226  _( "Open project directory in file explorer" ) );
227 #endif
228 
229  // Create m_mainToolBar
230  m_mainToolBar->Realize();
231 }
232 
233 
235 {
236  if( m_launcher )
237  {
238  m_launcher->Clear();
239  }
240  else
241  {
242  m_launcher = new ACTION_TOOLBAR( this, ID_H_TOOLBAR, wxDefaultPosition, wxDefaultSize,
243  KICAD_AUI_TB_STYLE | wxAUI_TB_HORZ_LAYOUT );
245  }
246 
247  // Add tools. Note these KICAD_MANAGER_ACTIONS are defined with a bitmap
248  // suitable for menus. The icans will be changed later.
251 
255 
261 
262  // Now set big icons for these tools:
266  KiScaledBitmap( icon_libedit_xpm, this ) );
268  KiScaledBitmap( icon_pcbnew_xpm, this ) );
270  KiScaledBitmap( icon_modedit_xpm, this ) );
279 
280  // Create mlauncher
281  m_launcher->Realize();
282 }
const BITMAP_OPAQUE browse_files_xpm[1]
void AddFilesToMenu() override
Add the files to all registered menus.
Definition: filehistory.h:98
static TOOL_ACTION newProject
wxMenuItem * Add(const wxString &aLabel, int aId, const BITMAP_OPAQUE *aIcon)
Adds a wxWidgets-style entry to the menu.
IDs used in KiCad main frame foe menuitems and tools.
ACTION_TOOLBAR.
Defines the structure of a menu based on ACTIONs.
Definition: action_menu.h:43
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
void Add(const TOOL_ACTION &aAction, bool aIsToggleEntry=false, bool aIsCancellable=false)
Adds a TOOL_ACTION-based button to the toolbar.
const BITMAP_OPAQUE directory_browser_xpm[1]
const BITMAP_OPAQUE zip_xpm[1]
Definition: zip.cpp:60
static TOOL_ACTION viewGerbers
const BITMAP_OPAQUE icon_pcbcalculator_xpm[1]
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:173
static TOOL_ACTION newFromTemplate
const BITMAP_OPAQUE icon_bitmap2component_xpm[1]
void SetAuiManager(wxAuiManager *aManager)
Set the AUI manager that this toolbar belongs to.
KICAD_MANAGER_CONTROL.
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
wxBitmap KiScaledBitmap(BITMAP_DEF aBitmap, wxWindow *aWindow)
Construct a wxBitmap from a memory record, scaling it if device DPI demands it.
Definition: bitmap.cpp:118
static TOOL_ACTION convertImage
const BITMAP_OPAQUE recent_xpm[1]
Definition: recent.cpp:68
static TOOL_ACTION closeProject
ACTION_CONDITIONS & Enable(const SELECTION_CONDITION &aCondition)
const BITMAP_OPAQUE icon_eeschema_xpm[1]
static TOOL_ACTION editSchematic
static TOOL_ACTION showFootprintLibTable
Definition: actions.h:174
const BITMAP_OPAQUE icon_pagelayout_editor_xpm[1]
void SetIcon(const BITMAP_OPAQUE *aIcon)
Assigns an icon for the entry.
Definition: action_menu.cpp:71
void AddStandardHelpMenu(wxMenuBar *aMenuBar)
Adds the standard KiCad help menu to the menubar.
static TOOL_ACTION editFootprints
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...
static TOOL_ACTION editWorksheet
const BITMAP_OPAQUE icon_gerbview_xpm[1]
const BITMAP_OPAQUE import_project_xpm[1]
const BITMAP_OPAQUE icon_modedit_xpm[1]
const BITMAP_OPAQUE icon_libedit_xpm[1]
static TOOL_ACTION editPCB
TOOL_MANAGER * m_toolManager
Definition: tools_holder.h:48
void SetTitle(const wxString &aTitle) override
Sets title for the menu.
Definition: action_menu.cpp:89
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...
ACTION_TOOLBAR * m_launcher
void ReCreateMenuBar() override
Recreates the menu bar.
static TOOL_ACTION openProject
static TOOL_ACTION saveAs
Definition: actions.h:55
void AddQuitOrClose(KIFACE_I *aKiface, wxString aAppname="")
Adds either a standard Quit or Close item to the menu.
#define _(s)
Definition: 3d_actions.cpp:33
static TOOL_ACTION zoomRedraw
Definition: actions.h:88
Functors that can be used to figure out how the action controls should be displayed in the UI and if ...
void SetToolBitmap(const TOOL_ACTION &aAction, const wxBitmap &aBitmap)
Updates the bitmap of a particular tool.
static constexpr int KICAD_AUI_TB_STYLE
Default style flags used for wxAUI toolbars
const BITMAP_OPAQUE icon_pcbnew_xpm[1]
Definition: icon_pcbnew.cpp:49
ACTION_TOOLBAR * m_mainToolBar
const BITMAP_OPAQUE preference_xpm[1]
Definition: preference.cpp:53
static TOOL_ACTION editSymbols
static TOOL_ACTION configurePaths
Definition: actions.h:172
static TOOL_ACTION openTextEditor
const BITMAP_OPAQUE unzip_xpm[1]
Definition: unzip.cpp:61
void ClearToolbar()
Clear the toolbar and remove all associated menus.