KiCad PCB EDA Suite
pagelayout_editor/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) 2016 KiCad Developers, see AUTHORS.txt for contributors.
5  * Copyright (C) 2013 CERN
6  * @author Jean-Pierre Charras, jp.charras at wanadoo.fr
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 
32 #include <kiface_i.h>
33 #include <menus_helpers.h>
34 #include <pgm_base.h>
35 
36 #include "hotkeys.h"
37 #include "pl_editor_frame.h"
38 #include "pl_editor_id.h"
39 
40 
42 {
43  // Create and try to get the current menubar
44  wxMenuBar* menuBar = GetMenuBar();
45 
46  if( !menuBar )
47  menuBar = new wxMenuBar();
48 
49  // Delete all existing menus so they can be rebuilt.
50  // This allows language changes of the menu text on the fly.
51  menuBar->Freeze();
52 
53  while( menuBar->GetMenuCount() )
54  delete menuBar->Remove( 0 );
55 
56  // Recreate all menus:
57 
58  // Menu File:
59  wxMenu* fileMenu = new wxMenu;
60 
61  // Load
62  AddMenuItem( fileMenu, wxID_NEW,
63  _( "&New Page Layout Design" ),
64  wxEmptyString, KiBitmap( new_generic_xpm ) );
65  AddMenuItem( fileMenu, wxID_OPEN,
66  _( "Load Page Layout &File" ),
67  wxEmptyString, KiBitmap( pagelayout_load_xpm ) );
69  _( "Load &Default Page Layout" ),
70  wxEmptyString, KiBitmap( pagelayout_load_xpm ) );
71 
72  // Recent gerber files
73  static wxMenu* openRecentMenu;
74 
75  // Add this menu to list menu managed by m_fileHistory
76  // (the file history will be updated when adding/removing files in history
77  if( openRecentMenu )
78  Kiface().GetFileHistory().RemoveMenu( openRecentMenu );
79 
80  openRecentMenu = new wxMenu();
81 
82  Kiface().GetFileHistory().UseMenu( openRecentMenu );
83  Kiface().GetFileHistory().AddFilesToMenu();
84 
85  AddMenuItem( fileMenu, openRecentMenu,
86  wxID_ANY, _( "Open &Recent Page Layout File" ),
87  wxEmptyString, KiBitmap( recent_xpm ) );
88 
89  fileMenu->AppendSeparator();
90  // Save current sheet
91  AddMenuItem( fileMenu, wxID_SAVE,
92  _( "&Save Page Layout Design" ),
93  wxEmptyString, KiBitmap( save_xpm ) );
94 
95  // Save current sheet as
96  AddMenuItem( fileMenu, wxID_SAVEAS,
97  _( "Save Page Layout Design &As" ),
98  wxEmptyString, KiBitmap( save_as_xpm ) );
99 
100  // Print
101  fileMenu->AppendSeparator();
102  AddMenuItem( fileMenu, wxID_PRINT, _( "&Print" ),
103  wxEmptyString, KiBitmap( print_button_xpm ) );
104  AddMenuItem( fileMenu, wxID_PREVIEW, _( "Print Pre&view" ),
105  wxEmptyString, KiBitmap( print_button_xpm ) );
106 
107  // Separator
108  fileMenu->AppendSeparator();
109 
110  // Exit
111  AddMenuItem( fileMenu, wxID_EXIT,
112  _( "&Close" ),
113  _( "&Close Page Layout Editor" ),
114  KiBitmap( exit_xpm ) );
115 
116  // Menu for preferences
117  wxMenu* preferencesMenu = new wxMenu;
118 
119  AddMenuItem( preferencesMenu,
121  GetDrawBgColor() == WHITE ?
122  _( "&Background Black" ) : _( "&Background White" ),
123  wxEmptyString, KiBitmap( palette_xpm ) );
124 
125  AddMenuItem( preferencesMenu,
127  IsGridVisible() ? _( "Hide &Grid" ) : _( "Show &Grid" ),
128  wxEmptyString, KiBitmap( grid_xpm ) );
129 
130  // Text editor selection
131  AddMenuItem( preferencesMenu,
133  _( "&Text Editor" ),
134  _( "Select your preferred text editor" ),
135  KiBitmap( editor_xpm ) );
136 
137  // Language submenu
138  Pgm().AddMenuLanguageList( preferencesMenu );
139 
140  // Icons options submenu
141  AddMenuIconsOptions( preferencesMenu );
142 
143  // Hotkey submenu
144  AddHotkeyConfigMenu( preferencesMenu );
145 
146  // Menu Help
147  wxMenu* helpMenu = new wxMenu;
148 
149  // Contents
150  AddMenuItem( helpMenu,
151  wxID_HELP,
152  _( "Page Layout Editor &Manual" ),
153  _( "Open the Page Layout Editor Manual" ),
154  KiBitmap( online_help_xpm ) );
155 
156  AddMenuItem( helpMenu,
157  wxID_INDEX,
158  _( "&Getting Started in KiCad" ),
159  _( "Open \"Getting Started in KiCad\" guide for beginners" ),
160  KiBitmap( help_xpm ) );
161 
163  _( "&List Hotkeys" ),
164  _( "Displays the current hotkeys list and corresponding commands" ),
165  KiBitmap( hotkeys_xpm ) );
166 
167  helpMenu->AppendSeparator();
169  _( "Get &Involved" ),
170  _( "Contribute to KiCad (opens a web browser)" ),
171  KiBitmap( info_xpm ) );
172 
173  // Separator
174  helpMenu->AppendSeparator();
175 
176  // About Kicad
177  AddMenuItem( helpMenu,
178  wxID_ABOUT,
179  _( "&About Kicad" ),
180  _( "About KiCad" ),
181  KiBitmap( about_xpm ) );
182 
183  // Append menus to the menubar
184  menuBar->Append( fileMenu, _( "&File" ) );
185  menuBar->Append( preferencesMenu, _( "&Preferences" ) );
186  menuBar->Append( helpMenu, _( "&Help" ) );
187 
188  menuBar->Thaw();
189 
190  // Associate the menu bar with the frame, if no previous menubar
191  if( GetMenuBar() == NULL )
192  SetMenuBar( menuBar );
193  else
194  menuBar->Refresh();
195 }
wxMenuItem * AddMenuItem(wxMenu *aMenu, int aId, const wxString &aText, const wxBitmap &aImage, wxItemKind aType=wxITEM_NORMAL)
Function AddMenuItem is an inline helper function to create and insert a menu item with an icon into ...
Definition: bitmap.cpp:55
void ReCreateMenuBar() override
Function ReCreateMenuBar Creates recreates the menu bar.
PGM_BASE & Pgm()
The global Program "get" accessor.
Definition: kicad.cpp:65
KIFACE_I & Kiface()
Global KIFACE_I "get" accessor.
Definition: kicad.cpp:52
virtual bool IsGridVisible() const
Function IsGridVisible() , virtual.
Definition: draw_frame.h:429
wxBitmap KiBitmap(BITMAP_DEF aBitmap)
Function KiBitmap constructs a wxBitmap from a memory record, held in a BITMAP_DEF.
Definition: bitmap.cpp:36
virtual COLOR4D GetDrawBgColor() const
Definition: draw_frame.h:286
wxFileHistory & GetFileHistory()
Definition: kiface_i.h:123
void AddHotkeyConfigMenu(wxMenu *aMenu)
void AddMenuIconsOptions(wxMenu *MasterMenu)
Function AddMenuIconsOptions creates a menu list for icons in menu and icon sizes choice...
Definition: basicframe.cpp:673
see class PGM_BASE
Definition: colors.h:49
VTBL_ENTRY void AddMenuLanguageList(wxMenu *MasterMenu)
Function AddMenuLanguageList creates a menu list for language choice, and add it as submenu to Master...
Definition: pgm_base.cpp:822