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-2019 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 <hotkeys_basic.h>
29 #include <menus_helpers.h>
30 #include <tool/tool_manager.h>
31 #include <tool/action_toolbar.h>
34 #include "kicad_manager_frame.h"
35 #include "pgm_kicad.h"
36 #include "kicad_id.h"
37 
38 
40 {
42  // wxWidgets handles the Mac Application menu behind the scenes, but that means
43  // we always have to start from scratch with a new wxMenuBar.
44  wxMenuBar* oldMenuBar = GetMenuBar();
45  wxMenuBar* menuBar = new wxMenuBar();
46 
47  //-- File menu -----------------------------------------------------------
48  //
49  CONDITIONAL_MENU* fileMenu = new CONDITIONAL_MENU( false, controlTool );
50  static ACTION_MENU* openRecentMenu;
51 
52  // Before deleting, remove the menus managed by m_fileHistory
53  // (the file history will be updated when adding/removing files in history)
54  if( openRecentMenu )
55  PgmTop().GetFileHistory().RemoveMenu( openRecentMenu );
56 
57  openRecentMenu = new ACTION_MENU( false );
58  openRecentMenu->SetTool( controlTool );
59  openRecentMenu->SetTitle( _( "Open Recent" ) );
60  openRecentMenu->SetIcon( recent_xpm );
61 
62  PgmTop().GetFileHistory().UseMenu( openRecentMenu );
63  PgmTop().GetFileHistory().AddFilesToMenu( openRecentMenu );
64 
68  fileMenu->AddMenu( openRecentMenu, SELECTION_CONDITIONS::ShowAlways );
69 
70  fileMenu->AddSeparator();
72  _( "Import EAGLE Project..." ),
73  _( "Import EAGLE CAD XML schematic and board" ),
74  import_project_xpm, SELECTION_CONDITIONS::ShowAlways );
75 
76  fileMenu->AddSeparator();
77  fileMenu->AddItem( ID_SAVE_AND_ZIP_FILES,
78  _( "&Archive Project..." ),
79  _( "Archive all needed project files into zip archive" ),
81 
82  fileMenu->AddItem( ID_READ_ZIP_ARCHIVE,
83  _( "&Unarchive Project..." ),
84  _( "Unarchive project files from zip archive" ),
86 
87  fileMenu->AddSeparator();
88  fileMenu->AddQuitOrClose( nullptr, _( "KiCad" ) );
89 
90  fileMenu->Resolve();
91 
92  //-- View menu -----------------------------------------------------------
93  //
94  CONDITIONAL_MENU* viewMenu = new CONDITIONAL_MENU( false, controlTool );
95 
97 
98  viewMenu->AddSeparator();
101  _( "Browse Project Files" ), _( "Open project directory in file browser" ),
102  directory_browser_xpm, SELECTION_CONDITIONS::ShowAlways );
103 
104 #ifdef __APPLE__
105  viewMenu->AddSeparator();
106 #endif
107 
108  viewMenu->Resolve();
109 
110  //-- Tools menu -----------------------------------------------
111  //
112  CONDITIONAL_MENU* toolsMenu = new CONDITIONAL_MENU( false, controlTool );
113 
118 
119  toolsMenu->AddSeparator();
124 
125  toolsMenu->AddSeparator();
127  _( "Edit Local File..." ), _( "Edit local file in text editor" ),
128  browse_files_xpm, SELECTION_CONDITIONS::ShowAlways );
129 
130  toolsMenu->Resolve();
131 
132  //-- Preferences menu -----------------------------------------------
133  //
134  CONDITIONAL_MENU* prefsMenu = new CONDITIONAL_MENU( false, controlTool );
135 
139  prefsMenu->AddItem( wxID_PREFERENCES,
140  _( "Preferences...\tCTRL+," ),
141  _( "Show preferences for all open tools" ),
142  preference_xpm, SELECTION_CONDITIONS::ShowAlways );
143 
144  prefsMenu->AddSeparator();
145  AddMenuLanguageList( prefsMenu, controlTool );
146 
147  prefsMenu->Resolve();
148 
149  //-- Menubar -------------------------------------------------------------
150  //
151  menuBar->Append( fileMenu, _( "&File" ) );
152  menuBar->Append( viewMenu, _( "&View" ) );
153  menuBar->Append( toolsMenu, _( "&Tools" ) );
154  menuBar->Append( prefsMenu, _( "&Preferences" ) );
155  AddStandardHelpMenu( menuBar );
156 
157  SetMenuBar( menuBar );
158  delete oldMenuBar;
159 }
160 
161 
166 {
167  if( m_mainToolBar )
168  m_mainToolBar->Clear();
169  else
170  m_mainToolBar = new ACTION_TOOLBAR( this, ID_H_TOOLBAR, wxDefaultPosition, wxDefaultSize,
171  KICAD_AUI_TB_STYLE | wxAUI_TB_HORZ_LAYOUT );
172 
173  // New
177 
179  m_mainToolBar->AddTool( ID_SAVE_AND_ZIP_FILES, wxEmptyString,
180  KiScaledBitmap( zip_xpm, this ),
181  _( "Archive all project files" ) );
182 
183  m_mainToolBar->AddTool( ID_READ_ZIP_ARCHIVE, wxEmptyString,
184  KiScaledBitmap( unzip_xpm, this ),
185  _( "Unarchive project files from zip archive" ) );
186 
189 
191  m_mainToolBar->AddTool( ID_BROWSE_IN_FILE_EXPLORER, wxEmptyString,
192  KiScaledBitmap( directory_browser_xpm, this ),
193 #ifdef __APPLE__
194  _( "Reveal project directory in Finder" ) );
195 #else
196  _( "Open project directory in file explorer" ) );
197 #endif
198 
199  // Create m_mainToolBar
200  m_mainToolBar->Realize();
201 }
202 
203 
205 {
206  if( m_launcher )
207  m_launcher->Clear();
208  else
209  m_launcher = new ACTION_TOOLBAR( this, ID_H_TOOLBAR, wxDefaultPosition, wxDefaultSize,
210  KICAD_AUI_TB_STYLE | wxAUI_TB_HORZ_LAYOUT );
211 
212  // Add tools. Note these KICAD_MANAGER_ACTIONS are defined with a bitmap
213  // suitable for menus. The icans will be changed later.
216 
217  KiScaledSeparator( m_launcher, this );
220 
221  KiScaledSeparator( m_launcher, this );
226 
227  // Now set big icons for these tools:
229  KiScaledBitmap( icon_eeschema_xpm, this ) );
231  KiScaledBitmap( icon_libedit_xpm, this ) );
233  KiScaledBitmap( icon_pcbnew_xpm, this ) );
235  KiScaledBitmap( icon_modedit_xpm, this ) );
237  KiScaledBitmap( icon_gerbview_xpm, this ) );
239  KiScaledBitmap( icon_bitmap2component_xpm, this ) );
241  KiScaledBitmap( icon_pcbcalculator_xpm, this ) );
243  KiScaledBitmap( icon_pagelayout_editor_xpm, this ) );
244 
245  // Create mlauncher
246  m_launcher->Realize();
247 
248  // And update the visual tools state:
249  SyncToolbars();
250 }
251 
252 
254 {
259  m_launcher->Refresh();
260 }
261 
262 
static bool ShowAlways(const SELECTION &aSelection)
Function ShowAlways The default condition function (always returns true).
static TOOL_ACTION newProject
void AddMenu(ACTION_MENU *aMenu, const SELECTION_CONDITION &aCondition=SELECTION_CONDITIONS::ShowAlways, int aOrder=ANY_ORDER)
Function AddMenu()
IDs used in KiCad main frame foe menuitems and tools.
Class ACTION_TOOLBAR.
FILE_HISTORY & GetFileHistory()
Definition: pgm_kicad.h:57
Class ACTION_MENU.
Definition: action_menu.h:43
static TOOL_ACTION showCalculator
void AddMenuLanguageList(CONDITIONAL_MENU *aMasterMenu, TOOL_INTERACTIVE *aControlTool)
Function AddMenuLanguageList creates a menu list for language choice, and add it as submenu to Master...
void Add(const TOOL_ACTION &aAction, bool aIsToggleEntry=false)
Function Add() Adds a TOOL_ACTION-based button to the toolbar.
static TOOL_ACTION viewGerbers
static TOOL_ACTION showSymbolLibTable
Definition: actions.h:162
static TOOL_ACTION newFromTemplate
Class KICAD_MANAGER_CONTROL.
wxBitmap KiScaledBitmap(BITMAP_DEF aBitmap, EDA_BASE_FRAME *aWindow)
Construct a wxBitmap from a memory record, scaling it if device DPI demands it.
Definition: bitmap.cpp:116
static TOOL_ACTION convertImage
void SetTool(TOOL_INTERACTIVE *aTool)
Function SetTool() Sets a tool that is the creator of the menu.
static TOOL_ACTION editSchematic
static TOOL_ACTION showFootprintLibTable
Definition: actions.h:163
void SetIcon(const BITMAP_OPAQUE *aIcon)
Function SetIcon() Assigns an icon for the entry.
Definition: action_menu.cpp:68
void AddStandardHelpMenu(wxMenuBar *aMenuBar)
Adds the standard KiCad help menu to the menubar.
static TOOL_ACTION editFootprints
void RecreateBaseHToolbar()
(Re)Create the horizontal toolbar
static TOOL_ACTION editWorksheet
#define _(s)
void Resolve()
Function Resolve()
void SyncToolbars() override
Update the toolbars (mostly settings/check buttons/checkboxes) with the current controller state.
PGM_KICAD & PgmTop()
Definition: kicad.cpp:71
void AddSeparator(int aOrder=ANY_ORDER)
Function AddSeparator()
void AddQuitOrClose(KIFACE_I *aKiface, wxString aAppname="")
Functions AddQuitOrClose()
static TOOL_ACTION editPCB
void SetTitle(const wxString &aTitle) override
Function SetTitle() Sets title for the menu.
Definition: action_menu.cpp:86
ACTION_TOOLBAR * m_launcher
void ReCreateMenuBar() override
Recreates the menu bar.
static TOOL_ACTION openProject
static TOOL_ACTION zoomRedraw
Definition: actions.h:86
void SetToolBitmap(const TOOL_ACTION &aAction, const wxBitmap &aBitmap)
Function SetToolBitmap() Updates the bitmap of a particular tool.
void Toggle(const TOOL_ACTION &aAction, bool aState)
Applies the default toggle action.
void KiScaledSeparator(wxAuiToolBar *aToolbar, EDA_BASE_FRAME *aWindow)
Add a separator to the given toolbar scaled the same way as KiScaledBitmap.
Definition: bitmap.cpp:167
static constexpr int KICAD_AUI_TB_STYLE
Default style flags used for wxAUI toolbars
TOOL_MANAGER * m_toolManager
ACTION_TOOLBAR * m_mainToolBar
static TOOL_ACTION editSymbols
static TOOL_ACTION configurePaths
Definition: actions.h:161
void AddItem(const TOOL_ACTION &aAction, const SELECTION_CONDITION &aCondition, int aOrder=ANY_ORDER)
Function AddItem()
static TOOL_ACTION openTextEditor