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-2021 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 <paths.h>
31 #include <tool/action_manager.h>
32 #include <tool/action_toolbar.h>
33 #include <tool/tool_manager.h>
34 #include <tools/kicad_manager_control.h>
35 #include <tools/kicad_manager_actions.h>
36 #include "kicad_manager_frame.h"
37 #include "pgm_kicad.h"
38 #include "kicad_id.h"
39 #include <widgets/wx_menubar.h>
40 #include <wx/dir.h>
41
42
ReCreateMenuBar()43 void KICAD_MANAGER_FRAME::ReCreateMenuBar()
44 {
45 KICAD_MANAGER_CONTROL* controlTool = m_toolManager->GetTool<KICAD_MANAGER_CONTROL>();
46 // wxWidgets handles the Mac Application menu behind the scenes, but that means
47 // we always have to start from scratch with a new wxMenuBar.
48 wxMenuBar* oldMenuBar = GetMenuBar();
49 WX_MENUBAR* menuBar = new WX_MENUBAR();
50
51 //-- File menu -----------------------------------------------------------
52 //
53 ACTION_MENU* fileMenu = new ACTION_MENU( false, controlTool );
54 FILE_HISTORY& fileHistory = GetFileHistory();
55
56 fileHistory.SetClearText( _( "Clear Recent Projects" ) );
57
58 static ACTION_MENU* openRecentMenu;
59
60 // Create the menu if it does not exist. Adding a file to/from the history
61 // will automatically refresh the menu.
62 if( !openRecentMenu )
63 {
64 openRecentMenu = new ACTION_MENU( false, controlTool );
65 openRecentMenu->SetTitle( _( "Open Recent" ) );
66 openRecentMenu->SetIcon( BITMAPS::recent );
67
68 fileHistory.UseMenu( openRecentMenu );
69 fileHistory.AddFilesToMenu();
70 }
71
72 fileMenu->Add( KICAD_MANAGER_ACTIONS::newProject );
73 fileMenu->Add( KICAD_MANAGER_ACTIONS::newFromTemplate );
74
75 if( wxDir::Exists( PATHS::GetStockDemosPath() ) )
76 {
77 fileMenu->Add( KICAD_MANAGER_ACTIONS::openDemoProject );
78 }
79
80 fileMenu->Add( KICAD_MANAGER_ACTIONS::openProject );
81
82 wxMenuItem* item = fileMenu->Add( openRecentMenu );
83
84 // Add the file menu condition here since it needs the item ID for the submenu
85 ACTION_CONDITIONS cond;
86 cond.Enable( FILE_HISTORY::FileHistoryNotEmpty( fileHistory ) );
87 RegisterUIUpdateHandler( item->GetId(), cond );
88
89 fileMenu->AppendSeparator();
90 fileMenu->Add( KICAD_MANAGER_ACTIONS::closeProject );
91
92 fileMenu->AppendSeparator();
93 fileMenu->Add( ACTIONS::saveAs );
94
95 fileMenu->AppendSeparator();
96
97 //Import Sub-menu
98 ACTION_MENU* importMenu = new ACTION_MENU( false, controlTool );
99 importMenu->SetTitle( _( "Import Non-KiCad Project..." ) );
100 importMenu->SetIcon( BITMAPS::import_project );
101
102 importMenu->Add( _( "CADSTAR Project..." ),
103 _( "Import CADSTAR Archive Schematic and PCB (*.csa, *.cpa)" ),
104 ID_IMPORT_CADSTAR_ARCHIVE_PROJECT,
105 BITMAPS::import_project );
106
107 importMenu->Add( _( "EAGLE Project..." ),
108 _( "Import EAGLE CAD XML schematic and board" ),
109 ID_IMPORT_EAGLE_PROJECT,
110 BITMAPS::import_project );
111
112 fileMenu->Add( importMenu );
113
114 fileMenu->AppendSeparator();
115 fileMenu->Add( _( "&Archive Project..." ),
116 _( "Archive all needed project files into zip archive" ),
117 ID_SAVE_AND_ZIP_FILES,
118 BITMAPS::zip );
119
120 fileMenu->Add( _( "&Unarchive Project..." ),
121 _( "Unarchive project files from zip archive" ),
122 ID_READ_ZIP_ARCHIVE,
123 BITMAPS::unzip );
124
125 fileMenu->AppendSeparator();
126 fileMenu->AddQuitOrClose( nullptr, "KiCad" );
127
128 //-- View menu -----------------------------------------------------------
129 //
130 ACTION_MENU* viewMenu = new ACTION_MENU( false, controlTool );
131
132 viewMenu->Add( ACTIONS::zoomRedraw );
133
134 viewMenu->AppendSeparator();
135 viewMenu->Add( KICAD_MANAGER_ACTIONS::openTextEditor );
136 viewMenu->Add( _( "Browse Project Files" ),
137 _( "Open project directory in file browser" ),
138 ID_BROWSE_IN_FILE_EXPLORER,
139 BITMAPS::directory_browser );
140
141 #ifdef __APPLE__
142 // Add a separator only on macOS because the OS adds menu items to the view menu after ours
143 viewMenu->AppendSeparator();
144 #endif
145
146 //-- Tools menu -----------------------------------------------
147 //
148 ACTION_MENU* toolsMenu = new ACTION_MENU( false, controlTool );
149
150 toolsMenu->Add( KICAD_MANAGER_ACTIONS::editSchematic );
151 toolsMenu->Add( KICAD_MANAGER_ACTIONS::editSymbols );
152 toolsMenu->Add( KICAD_MANAGER_ACTIONS::editPCB );
153 toolsMenu->Add( KICAD_MANAGER_ACTIONS::editFootprints );
154
155 toolsMenu->AppendSeparator();
156 toolsMenu->Add( KICAD_MANAGER_ACTIONS::viewGerbers );
157 toolsMenu->Add( KICAD_MANAGER_ACTIONS::convertImage );
158 toolsMenu->Add( KICAD_MANAGER_ACTIONS::showCalculator );
159 toolsMenu->Add( KICAD_MANAGER_ACTIONS::editDrawingSheet );
160 #ifdef PCM
161 toolsMenu->Add( KICAD_MANAGER_ACTIONS::showPluginManager );
162 #endif
163
164 toolsMenu->AppendSeparator();
165 toolsMenu->Add( _( "Edit Local File..." ),
166 _( "Edit local file in text editor" ),
167 ID_EDIT_LOCAL_FILE_IN_TEXT_EDITOR,
168 BITMAPS::editor );
169
170 //-- Preferences menu -----------------------------------------------
171 //
172 ACTION_MENU* prefsMenu = new ACTION_MENU( false, controlTool );
173
174 prefsMenu->Add( ACTIONS::configurePaths );
175 prefsMenu->Add( ACTIONS::showSymbolLibTable );
176 prefsMenu->Add( ACTIONS::showFootprintLibTable );
177
178 // We can't use ACTIONS::showPreferences yet because wxWidgets moves this on
179 // Mac, and it needs the wxID_PREFERENCES id to find it.
180 prefsMenu->Add( _( "Preferences..." ) + "\tCtrl+,",
181 _( "Show preferences for all open tools" ),
182 wxID_PREFERENCES,
183 BITMAPS::preference );
184
185 prefsMenu->AppendSeparator();
186 AddMenuLanguageList( prefsMenu, controlTool );
187
188
189 //-- Menubar -------------------------------------------------------------
190 //
191 menuBar->Append( fileMenu, _( "&File" ) );
192 menuBar->Append( viewMenu, _( "&View" ) );
193 menuBar->Append( toolsMenu, _( "&Tools" ) );
194 menuBar->Append( prefsMenu, _( "&Preferences" ) );
195 AddStandardHelpMenu( menuBar );
196
197 SetMenuBar( menuBar );
198 delete oldMenuBar;
199 }
200
201
202 /**
203 * @brief (Re)Create the horizontal toolbar
204 */
RecreateBaseHToolbar()205 void KICAD_MANAGER_FRAME::RecreateBaseHToolbar()
206 {
207 if( m_mainToolBar )
208 {
209 m_mainToolBar->ClearToolbar();
210 }
211 else
212 {
213 m_mainToolBar = new ACTION_TOOLBAR( this, ID_H_TOOLBAR, wxDefaultPosition, wxDefaultSize,
214 KICAD_AUI_TB_STYLE | wxAUI_TB_HORZ_LAYOUT );
215 m_mainToolBar->SetAuiManager( &m_auimgr );
216 }
217
218 // New
219 m_mainToolBar->Add( KICAD_MANAGER_ACTIONS::newProject );
220 m_mainToolBar->Add( KICAD_MANAGER_ACTIONS::openProject );
221
222 m_mainToolBar->AddScaledSeparator( this );
223 m_mainToolBar->AddTool( ID_SAVE_AND_ZIP_FILES, wxEmptyString,
224 KiScaledBitmap( BITMAPS::zip, this ),
225 _( "Archive all project files" ) );
226
227 m_mainToolBar->AddTool( ID_READ_ZIP_ARCHIVE, wxEmptyString,
228 KiScaledBitmap( BITMAPS::unzip, this ),
229 _( "Unarchive project files from zip archive" ) );
230
231 m_mainToolBar->AddScaledSeparator( this );
232 m_mainToolBar->Add( ACTIONS::zoomRedraw );
233
234 m_mainToolBar->AddScaledSeparator( this );
235 m_mainToolBar->AddTool( ID_BROWSE_IN_FILE_EXPLORER, wxEmptyString,
236 KiScaledBitmap( BITMAPS::directory_browser, this ),
237 #ifdef __APPLE__
238 _( "Reveal project folder in Finder" ) );
239 #else
240 _( "Open project directory in file explorer" ) );
241 #endif
242
243 // Create m_mainToolBar
244 m_mainToolBar->Realize();
245 }
246