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 <filehistory.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 #include <widgets/wx_menubar.h>
38 
39 
41 {
43  // wxWidgets handles the Mac Application menu behind the scenes, but that means
44  // we always have to start from scratch with a new wxMenuBar.
45  wxMenuBar* oldMenuBar = GetMenuBar();
46  WX_MENUBAR* menuBar = new WX_MENUBAR();
47 
48  //-- File menu -----------------------------------------------------------
49  //
50  CONDITIONAL_MENU* fileMenu = new CONDITIONAL_MENU( false, controlTool );
51  FILE_HISTORY& fileHistory = GetFileHistory();
52 
53  fileHistory.SetClearText( _( "Clear Recent Projects" ) );
54 
55  static ACTION_MENU* openRecentMenu;
56 
57  // Create the menu if it does not exist. Adding a file to/from the history
58  // will automatically refresh the menu.
59  if( !openRecentMenu )
60  {
61  openRecentMenu = new ACTION_MENU( false );
62  openRecentMenu->SetTool( controlTool );
63  openRecentMenu->SetTitle( _( "Open Recent" ) );
64  openRecentMenu->SetIcon( recent_xpm );
65 
66  fileHistory.UseMenu( openRecentMenu );
67  fileHistory.AddFilesToMenu();
68  }
69 
73  fileMenu->AddMenu( openRecentMenu,
74  FILE_HISTORY::FileHistoryNotEmpty( fileHistory ) );
75 
76  fileMenu->AddSeparator();
78 
79  fileMenu->AddSeparator();
81  _( "Import EAGLE Project..." ),
82  _( "Import EAGLE CAD XML schematic and board" ),
84 
85  fileMenu->AddSeparator();
86  fileMenu->AddItem( ID_SAVE_AND_ZIP_FILES,
87  _( "&Archive Project..." ),
88  _( "Archive all needed project files into zip archive" ),
90 
91  fileMenu->AddItem( ID_READ_ZIP_ARCHIVE,
92  _( "&Unarchive Project..." ),
93  _( "Unarchive project files from zip archive" ),
95 
96  fileMenu->AddSeparator();
97  fileMenu->AddQuitOrClose( nullptr, "KiCad" );
98 
99  fileMenu->Resolve();
100 
101  //-- View menu -----------------------------------------------------------
102  //
103  CONDITIONAL_MENU* viewMenu = new CONDITIONAL_MENU( false, controlTool );
104 
106 
107  viewMenu->AddSeparator();
110  _( "Browse Project Files" ), _( "Open project directory in file browser" ),
112 
113 #ifdef __APPLE__
114  viewMenu->AddSeparator();
115 #endif
116 
117  viewMenu->Resolve();
118 
119  //-- Tools menu -----------------------------------------------
120  //
121  CONDITIONAL_MENU* toolsMenu = new CONDITIONAL_MENU( false, controlTool );
122 
127 
128  toolsMenu->AddSeparator();
133 
134  toolsMenu->AddSeparator();
136  _( "Edit Local File..." ), _( "Edit local file in text editor" ),
138 
139  toolsMenu->Resolve();
140 
141  //-- Preferences menu -----------------------------------------------
142  //
143  CONDITIONAL_MENU* prefsMenu = new CONDITIONAL_MENU( false, controlTool );
144 
148  prefsMenu->AddItem( wxID_PREFERENCES,
149  _( "Preferences...\tCTRL+," ),
150  _( "Show preferences for all open tools" ),
152 
153  prefsMenu->AddSeparator();
154  AddMenuLanguageList( prefsMenu, controlTool );
155 
156  prefsMenu->Resolve();
157 
158  //-- Menubar -------------------------------------------------------------
159  //
160  menuBar->Append( fileMenu, _( "&File" ) );
161  menuBar->Append( viewMenu, _( "&View" ) );
162  menuBar->Append( toolsMenu, _( "&Tools" ) );
163  menuBar->Append( prefsMenu, _( "&Preferences" ) );
164  AddStandardHelpMenu( menuBar );
165 
166  SetMenuBar( menuBar );
167  delete oldMenuBar;
168 }
169 
170 
175 {
176  if( m_mainToolBar )
178  else
179  m_mainToolBar = new ACTION_TOOLBAR( this, ID_H_TOOLBAR, wxDefaultPosition, wxDefaultSize,
180  KICAD_AUI_TB_STYLE | wxAUI_TB_HORZ_LAYOUT );
181 
182  // New
186 
188  m_mainToolBar->AddTool( ID_SAVE_AND_ZIP_FILES, wxEmptyString,
189  KiScaledBitmap( zip_xpm, this ),
190  _( "Archive all project files" ) );
191 
192  m_mainToolBar->AddTool( ID_READ_ZIP_ARCHIVE, wxEmptyString,
193  KiScaledBitmap( unzip_xpm, this ),
194  _( "Unarchive project files from zip archive" ) );
195 
198 
200  m_mainToolBar->AddTool( ID_BROWSE_IN_FILE_EXPLORER, wxEmptyString,
202 #ifdef __APPLE__
203  _( "Reveal project folder in Finder" ) );
204 #else
205  _( "Open project directory in file explorer" ) );
206 #endif
207 
208  // Create m_mainToolBar
209  m_mainToolBar->Realize();
210 }
211 
212 
214 {
215  if( m_launcher )
216  m_launcher->Clear();
217  else
218  m_launcher = new ACTION_TOOLBAR( this, ID_H_TOOLBAR, wxDefaultPosition, wxDefaultSize,
219  KICAD_AUI_TB_STYLE | wxAUI_TB_HORZ_LAYOUT );
220 
221  // Add tools. Note these KICAD_MANAGER_ACTIONS are defined with a bitmap
222  // suitable for menus. The icans will be changed later.
225 
229 
235 
236  // Now set big icons for these tools:
240  KiScaledBitmap( icon_libedit_xpm, this ) );
242  KiScaledBitmap( icon_pcbnew_xpm, this ) );
244  KiScaledBitmap( icon_modedit_xpm, this ) );
253 
254  // Create mlauncher
255  m_launcher->Realize();
256 
257  // And update the visual tools state:
258  SyncToolbars();
259 }
260 
261 
263 {
268  m_launcher->Refresh();
269 }
270 
271 
const BITMAP_OPAQUE browse_files_xpm[1]
void AddFilesToMenu() override
Add the files to all registered menus.
Definition: filehistory.h:98
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.
ACTION_TOOLBAR.
ACTION_MENU.
Definition: action_menu.h:44
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)
Function Add() 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]
static TOOL_ACTION showSymbolLibTable
Definition: actions.h:167
static TOOL_ACTION newFromTemplate
const BITMAP_OPAQUE icon_bitmap2component_xpm[1]
KICAD_MANAGER_CONTROL.
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:116
static TOOL_ACTION convertImage
const BITMAP_OPAQUE recent_xpm[1]
Definition: recent.cpp:68
void SetTool(TOOL_INTERACTIVE *aTool)
Function SetTool() Sets a tool that is the creator of the menu.
const BITMAP_OPAQUE icon_eeschema_xpm[1]
static TOOL_ACTION editSchematic
static TOOL_ACTION showFootprintLibTable
Definition: actions.h:168
const BITMAP_OPAQUE icon_pagelayout_editor_xpm[1]
void SetIcon(const BITMAP_OPAQUE *aIcon)
Function SetIcon() Assigns an icon for the entry.
Definition: action_menu.cpp:70
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
void Resolve()
Function Resolve()
const BITMAP_OPAQUE icon_gerbview_xpm[1]
void SyncToolbars() override
Update the toolbars (mostly settings/check buttons/checkboxes) with the current controller state.
const BITMAP_OPAQUE import_project_xpm[1]
const BITMAP_OPAQUE icon_modedit_xpm[1]
void AddSeparator(int aOrder=ANY_ORDER)
Function AddSeparator()
void AddQuitOrClose(KIFACE_I *aKiface, wxString aAppname="")
Functions AddQuitOrClose()
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
Function SetTitle() Sets title for the menu.
Definition: action_menu.cpp:88
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
void AddMenuLanguageList(CONDITIONAL_MENU *aMasterMenu, TOOL_INTERACTIVE *aControlTool)
Function AddMenuLanguageList creates a menu list for language choice, and add it as submenu to Master...
static TOOL_ACTION saveAs
Definition: actions.h:55
#define _(s)
Definition: 3d_actions.cpp:33
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.
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:66
static TOOL_ACTION editSymbols
static TOOL_ACTION configurePaths
Definition: actions.h:166
void AddItem(const TOOL_ACTION &aAction, const SELECTION_CONDITION &aCondition, int aOrder=ANY_ORDER)
Function AddItem()
static TOOL_ACTION openTextEditor
const BITMAP_OPAQUE unzip_xpm[1]
Definition: unzip.cpp:61
void ClearToolbar()
Clear the toolbar and remove all associated menus.