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  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * as published by the Free Software Foundation; either version 2
11  * of the License, or (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, you may find one here:
20  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
21  * or you may search the http://www.gnu.org website for the version 2 license,
22  * or you may write to the Free Software Foundation, Inc.,
23  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
24  */
25 
26 #include <bitmaps.h>
27 #include <hotkeys_basic.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  _( "Import EAGLE Project..." ),
72  _( "Import EAGLE CAD XML schematic and board" ),
73  import_project_xpm, SELECTION_CONDITIONS::ShowAlways );
74 
75  fileMenu->AddSeparator();
76  fileMenu->AddItem( ID_SAVE_AND_ZIP_FILES,
77  _( "&Archive Project..." ),
78  _( "Archive all needed project files into zip archive" ),
80 
81  fileMenu->AddItem( ID_READ_ZIP_ARCHIVE,
82  _( "&Unarchive Project..." ),
83  _( "Unarchive project files from zip archive" ),
85 
86  fileMenu->AddSeparator();
87  // Don't use ACTIONS::quit; wxWidgets moves this on OSX and expects to find it via wxID_EXIT
88  fileMenu->AddItem( wxID_EXIT, _( "Quit" ), "", exit_xpm, SELECTION_CONDITIONS::ShowAlways );
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 
214 
215  KiScaledSeparator( m_launcher, this );
218 
219  KiScaledSeparator( m_launcher, this );
224 
225  // Create mlauncher
226  m_launcher->Realize();
227 }
228 
229 
231 {
236  m_launcher->Refresh();
237 }
238 
239 
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:161
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:162
void SetIcon(const BITMAP_OPAQUE *aIcon)
Function SetIcon() Assigns an icon for the entry.
Definition: action_menu.cpp:66
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()
static TOOL_ACTION editPCB
void SetTitle(const wxString &aTitle) override
Function SetTitle() Sets title for the menu.
Definition: action_menu.cpp:84
ACTION_TOOLBAR * m_launcher
void ReCreateMenuBar() override
Recreates the menu bar.
static TOOL_ACTION openProject
static TOOL_ACTION zoomRedraw
Definition: actions.h:85
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:160
void AddItem(const TOOL_ACTION &aAction, const SELECTION_CONDITION &aCondition, int aOrder=ANY_ORDER)
Function AddItem()
static TOOL_ACTION openTextEditor