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 <menus_helpers.h>
29 #include <tool/tool_manager.h>
30 #include <tool/action_toolbar.h>
33 #include "kicad_manager_frame.h"
34 #include "pgm_kicad.h"
35 #include "kicad_id.h"
36 
37 
39 {
41  // wxWidgets handles the Mac Application menu behind the scenes, but that means
42  // we always have to start from scratch with a new wxMenuBar.
43  wxMenuBar* oldMenuBar = GetMenuBar();
44  wxMenuBar* menuBar = new wxMenuBar();
45 
46  //-- File menu -----------------------------------------------------------
47  //
48  CONDITIONAL_MENU* fileMenu = new CONDITIONAL_MENU( false, controlTool );
49  static ACTION_MENU* openRecentMenu;
50 
51  // Before deleting, remove the menus managed by m_fileHistory
52  // (the file history will be updated when adding/removing files in history)
53  if( openRecentMenu )
54  PgmTop().GetFileHistory().RemoveMenu( openRecentMenu );
55 
56  openRecentMenu = new ACTION_MENU( false );
57  openRecentMenu->SetTool( controlTool );
58  openRecentMenu->SetTitle( _( "Open Recent" ) );
59  openRecentMenu->SetIcon( recent_xpm );
60 
61  PgmTop().GetFileHistory().UseMenu( openRecentMenu );
62  PgmTop().GetFileHistory().AddFilesToMenu( openRecentMenu );
63 
67  fileMenu->AddMenu( openRecentMenu, SELECTION_CONDITIONS::ShowAlways );
68 
69  fileMenu->AddSeparator();
71 
72  fileMenu->AddSeparator();
74  _( "Import EAGLE Project..." ),
75  _( "Import EAGLE CAD XML schematic and board" ),
76  import_project_xpm, SELECTION_CONDITIONS::ShowAlways );
77 
78  fileMenu->AddSeparator();
79  fileMenu->AddItem( ID_SAVE_AND_ZIP_FILES,
80  _( "&Archive Project..." ),
81  _( "Archive all needed project files into zip archive" ),
83 
84  fileMenu->AddItem( ID_READ_ZIP_ARCHIVE,
85  _( "&Unarchive Project..." ),
86  _( "Unarchive project files from zip archive" ),
88 
89  fileMenu->AddSeparator();
90  fileMenu->AddQuitOrClose( nullptr, "KiCad" );
91 
92  fileMenu->Resolve();
93 
94  //-- View menu -----------------------------------------------------------
95  //
96  CONDITIONAL_MENU* viewMenu = new CONDITIONAL_MENU( false, controlTool );
97 
99 
100  viewMenu->AddSeparator();
103  _( "Browse Project Files" ), _( "Open project directory in file browser" ),
104  directory_browser_xpm, SELECTION_CONDITIONS::ShowAlways );
105 
106 #ifdef __APPLE__
107  viewMenu->AddSeparator();
108 #endif
109 
110  viewMenu->Resolve();
111 
112  //-- Tools menu -----------------------------------------------
113  //
114  CONDITIONAL_MENU* toolsMenu = new CONDITIONAL_MENU( false, controlTool );
115 
120 
121  toolsMenu->AddSeparator();
126 
127  toolsMenu->AddSeparator();
129  _( "Edit Local File..." ), _( "Edit local file in text editor" ),
130  browse_files_xpm, SELECTION_CONDITIONS::ShowAlways );
131 
132  toolsMenu->Resolve();
133 
134  //-- Preferences menu -----------------------------------------------
135  //
136  CONDITIONAL_MENU* prefsMenu = new CONDITIONAL_MENU( false, controlTool );
137 
141  prefsMenu->AddItem( wxID_PREFERENCES,
142  _( "Preferences...\tCTRL+," ),
143  _( "Show preferences for all open tools" ),
144  preference_xpm, SELECTION_CONDITIONS::ShowAlways );
145 
146  prefsMenu->AddSeparator();
147  AddMenuLanguageList( prefsMenu, controlTool );
148 
149  prefsMenu->Resolve();
150 
151  //-- Menubar -------------------------------------------------------------
152  //
153  menuBar->Append( fileMenu, _( "&File" ) );
154  menuBar->Append( viewMenu, _( "&View" ) );
155  menuBar->Append( toolsMenu, _( "&Tools" ) );
156  menuBar->Append( prefsMenu, _( "&Preferences" ) );
157  AddStandardHelpMenu( menuBar );
158 
159  SetMenuBar( menuBar );
160  delete oldMenuBar;
161 }
162 
163 
168 {
169  if( m_mainToolBar )
170  m_mainToolBar->Clear();
171  else
172  m_mainToolBar = new ACTION_TOOLBAR( this, ID_H_TOOLBAR, wxDefaultPosition, wxDefaultSize,
173  KICAD_AUI_TB_STYLE | wxAUI_TB_HORZ_LAYOUT );
174 
175  // New
179 
181  m_mainToolBar->AddTool( ID_SAVE_AND_ZIP_FILES, wxEmptyString,
182  KiScaledBitmap( zip_xpm, this ),
183  _( "Archive all project files" ) );
184 
185  m_mainToolBar->AddTool( ID_READ_ZIP_ARCHIVE, wxEmptyString,
186  KiScaledBitmap( unzip_xpm, this ),
187  _( "Unarchive project files from zip archive" ) );
188 
191 
193  m_mainToolBar->AddTool( ID_BROWSE_IN_FILE_EXPLORER, wxEmptyString,
194  KiScaledBitmap( directory_browser_xpm, this ),
195 #ifdef __APPLE__
196  _( "Reveal project directory in Finder" ) );
197 #else
198  _( "Open project directory in file explorer" ) );
199 #endif
200 
201  // Create m_mainToolBar
202  m_mainToolBar->Realize();
203 }
204 
205 
207 {
208  if( m_launcher )
209  m_launcher->Clear();
210  else
211  m_launcher = new ACTION_TOOLBAR( this, ID_H_TOOLBAR, wxDefaultPosition, wxDefaultSize,
212  KICAD_AUI_TB_STYLE | wxAUI_TB_HORZ_LAYOUT );
213 
214  // Add tools. Note these KICAD_MANAGER_ACTIONS are defined with a bitmap
215  // suitable for menus. The icans will be changed later.
218 
219  KiScaledSeparator( m_launcher, this );
222 
223  KiScaledSeparator( m_launcher, this );
228 
229  // Now set big icons for these tools:
231  KiScaledBitmap( icon_eeschema_xpm, this ) );
233  KiScaledBitmap( icon_libedit_xpm, this ) );
235  KiScaledBitmap( icon_pcbnew_xpm, this ) );
237  KiScaledBitmap( icon_modedit_xpm, this ) );
239  KiScaledBitmap( icon_gerbview_xpm, this ) );
241  KiScaledBitmap( icon_bitmap2component_xpm, this ) );
243  KiScaledBitmap( icon_pcbcalculator_xpm, this ) );
245  KiScaledBitmap( icon_pagelayout_editor_xpm, this ) );
246 
247  // Create mlauncher
248  m_launcher->Realize();
249 
250  // And update the visual tools state:
251  SyncToolbars();
252 }
253 
254 
256 {
261  m_launcher->Refresh();
262 }
263 
264 
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:163
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:164
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 saveAs
Definition: actions.h:55
static TOOL_ACTION zoomRedraw
Definition: actions.h:87
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:162
void AddItem(const TOOL_ACTION &aAction, const SELECTION_CONDITION &aCondition, int aOrder=ANY_ORDER)
Function AddItem()
static TOOL_ACTION openTextEditor