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  wxString msg;
44  static wxMenu* openRecentMenu; // Open Recent submenu,
45  // static to remember this menu
46 
47  // Create and try to get the current menubar
48  wxMenuBar* menuBar = GetMenuBar();
49 
50  if( !menuBar )
51  menuBar = new wxMenuBar();
52 
53  // Delete all existing menus so they can be rebuilt.
54  // This allows language changes of the menu text on the fly.
55  menuBar->Freeze();
56 
57  // Before deleting, remove the menus managed by m_fileHistory
58  // (the file history will be updated when adding/removing files in history
59  if( openRecentMenu )
60  Kiface().GetFileHistory().RemoveMenu( openRecentMenu );
61 
62  // Delete all existing menus
63  while( menuBar->GetMenuCount() )
64  delete menuBar->Remove( 0 );
65 
66  // Recreate all menus:
67 
68  // File Menu:
69  wxMenu* fileMenu = new wxMenu;
70 
71  msg = AddHotkeyName( _( "&New" ), PlEditorHokeysDescr, HK_NEW );
72  AddMenuItem( fileMenu, wxID_NEW, msg,
73  _( "Create new page layout design" ),
74  KiBitmap( new_generic_xpm ) );
75 
76  msg = AddHotkeyName( _( "&Open..." ), PlEditorHokeysDescr, HK_OPEN );
77  AddMenuItem( fileMenu, wxID_OPEN, msg,
78  _( "Open an existing page layout design file" ),
79  KiBitmap( pagelayout_load_xpm ) );
80 
81  openRecentMenu = new wxMenu();
82  Kiface().GetFileHistory().UseMenu( openRecentMenu );
83  Kiface().GetFileHistory().AddFilesToMenu();
84  AddMenuItem( fileMenu, openRecentMenu,
85  wxID_ANY,
86  _( "Open &Recent" ),
87  _( "Open recent page layout design file" ),
88  KiBitmap( recent_xpm ) );
89 
90  fileMenu->AppendSeparator();
91 
92  msg = AddHotkeyName( _( "&Save" ), PlEditorHokeysDescr, HK_SAVE );
93  AddMenuItem( fileMenu, wxID_SAVE, msg,
94  _( "Save current page layout design file" ),
95  KiBitmap( save_xpm ) );
96 
97  msg = AddHotkeyName( _( "Save &As" ), PlEditorHokeysDescr, HK_SAVEAS );
98  AddMenuItem( fileMenu, wxID_SAVEAS, msg,
99  _( "Save current page layout design file with a different name" ),
100  KiBitmap( save_as_xpm ) );
101 
102  fileMenu->AppendSeparator();
103 
104  msg = AddHotkeyName( _( "&Print..." ), PlEditorHokeysDescr, HK_PRINT );
105  AddMenuItem( fileMenu, wxID_PRINT, msg,
106  wxEmptyString, KiBitmap( print_button_xpm ) );
107 
108  AddMenuItem( fileMenu, wxID_PREVIEW, _( "Print Pre&view..." ),
109  wxEmptyString, KiBitmap( print_button_xpm ) );
110 
111  fileMenu->AppendSeparator();
112 
113  AddMenuItem( fileMenu, wxID_EXIT, _( "&Close" ),
114  _( "Close Page Layout Editor" ), KiBitmap( exit_xpm ) );
115 
116 
117  // Edit Menu:
118  wxMenu* editMenu = new wxMenu;
119 
120  msg = AddHotkeyName( _( "Undo" ), PlEditorHokeysDescr, HK_UNDO );
121  AddMenuItem( editMenu, wxID_UNDO, msg, wxEmptyString, KiBitmap( undo_xpm ) );
122 
123  msg = AddHotkeyName( _( "Redo" ), PlEditorHokeysDescr, HK_REDO );
124  AddMenuItem( editMenu, wxID_REDO, msg, wxEmptyString, KiBitmap( redo_xpm ) );
125 
126  editMenu->AppendSeparator();
127 
128  AddMenuItem( editMenu, wxID_CUT, _( "Delete" ), wxEmptyString, KiBitmap( delete_xpm ) );
129 
130 
131  // View Menu:
132  wxMenu* viewMenu = new wxMenu;
133 
134  msg = AddHotkeyName( _( "Zoom in" ), PlEditorHokeysDescr, HK_ZOOM_IN );
135  AddMenuItem( viewMenu, ID_ZOOM_IN, msg, wxEmptyString, KiBitmap( zoom_in_xpm ) );
136 
137  msg = AddHotkeyName( _( "Zoom out" ), PlEditorHokeysDescr, HK_ZOOM_OUT );
138  AddMenuItem( viewMenu, ID_ZOOM_OUT, msg, wxEmptyString, KiBitmap( zoom_out_xpm ) );
139 
140  msg = AddHotkeyName( _( "Zoom all" ), PlEditorHokeysDescr, HK_ZOOM_AUTO );
141  AddMenuItem( viewMenu, ID_ZOOM_PAGE, msg, wxEmptyString, KiBitmap( zoom_fit_in_page_xpm ) );
142 
143  msg = AddHotkeyName( _( "Zoom to selection" ), PlEditorHokeysDescr, HK_ZOOM_SELECTION );
144  AddMenuItem( viewMenu, ID_ZOOM_SELECTION, msg, wxEmptyString, KiBitmap( zoom_area_xpm ) );
145 
146  viewMenu->AppendSeparator();
147 
148  msg = AddHotkeyName( _( "Redraw view" ), PlEditorHokeysDescr, HK_ZOOM_REDRAW );
149  AddMenuItem( viewMenu, ID_ZOOM_REDRAW, msg, wxEmptyString, KiBitmap( zoom_redraw_xpm ) );
150 
151 
152  // Place Menu:
153  wxMenu* placeMenu = new wxMenu;
154 
155  AddMenuItem( placeMenu, ID_POPUP_ITEM_ADD_LINE, _( "&Line..." ),
156  wxEmptyString, KiBitmap( add_dashed_line_xpm ) );
157 
158  AddMenuItem( placeMenu, ID_POPUP_ITEM_ADD_RECT, _( "&Rectangle..." ),
159  wxEmptyString, KiBitmap( add_rectangle_xpm ) );
160 
161  AddMenuItem( placeMenu, ID_POPUP_ITEM_ADD_TEXT, _( "&Text..." ),
162  wxEmptyString, KiBitmap( text_xpm ) );
163 
164  AddMenuItem( placeMenu, ID_POPUP_ITEM_ADD_BITMAP, _( "&Bitmap..." ),
165  wxEmptyString, KiBitmap( image_xpm ) );
166 
167  placeMenu->AppendSeparator();
168 
169  AddMenuItem( placeMenu, ID_APPEND_DESCR_FILE, _( "&Append Existing Page Layout Design File..." ),
170  _( "Append an existing page layout design file to current file" ),
171  KiBitmap( pagelayout_load_xpm ) );
172 
173 
174  // Menu for preferences
175  wxMenu* preferencesMenu = new wxMenu;
176 
177  AddMenuItem( preferencesMenu,
179  GetDrawBgColor() == WHITE ?
180  _( "&Background Black" ) : _( "&Background White" ),
181  wxEmptyString, KiBitmap( palette_xpm ) );
182 
183  AddMenuItem( preferencesMenu,
185  IsGridVisible() ? _( "Hide &Grid" ) : _( "Show &Grid" ),
186  wxEmptyString, KiBitmap( grid_xpm ) );
187 
188  // Text editor selection
189  AddMenuItem( preferencesMenu,
191  _( "&Text Editor" ),
192  _( "Select your preferred text editor" ),
193  KiBitmap( editor_xpm ) );
194 
195  // Language submenu
196  Pgm().AddMenuLanguageList( preferencesMenu );
197 
198  // Icons options submenu
199  AddMenuIconsOptions( preferencesMenu );
200 
201  // Hotkey submenu
202  AddHotkeyConfigMenu( preferencesMenu );
203 
204  // Menu Help
205  wxMenu* helpMenu = new wxMenu;
206 
207  // Contents
208  AddMenuItem( helpMenu,
209  wxID_HELP,
210  _( "Page Layout Editor &Manual" ),
211  _( "Open the Page Layout Editor Manual" ),
212  KiBitmap( online_help_xpm ) );
213 
214  AddMenuItem( helpMenu,
215  wxID_INDEX,
216  _( "&Getting Started in KiCad" ),
217  _( "Open \"Getting Started in KiCad\" guide for beginners" ),
218  KiBitmap( help_xpm ) );
219 
220  msg = AddHotkeyName( _( "&List Hotkeys" ), PlEditorHokeysDescr, HK_HELP );
222  _( "Displays the current hotkeys list and corresponding commands" ),
223  KiBitmap( hotkeys_xpm ) );
224 
225  helpMenu->AppendSeparator();
227  _( "Get &Involved" ),
228  _( "Contribute to KiCad (opens a web browser)" ),
229  KiBitmap( info_xpm ) );
230 
231  // Separator
232  helpMenu->AppendSeparator();
233 
234  // About Kicad
235  AddMenuItem( helpMenu,
236  wxID_ABOUT,
237  _( "&About Kicad" ),
238  _( "About KiCad" ),
239  KiBitmap( about_xpm ) );
240 
241  // Append menus to the menubar
242  menuBar->Append( fileMenu, _( "&File" ) );
243  menuBar->Append( editMenu, _( "&Edit" ) );
244  menuBar->Append( viewMenu, _( "&View" ) );
245  menuBar->Append( placeMenu, _( "&Place" ) );
246  menuBar->Append( preferencesMenu, _( "P&references" ) );
247  menuBar->Append( helpMenu, _( "&Help" ) );
248 
249  menuBar->Thaw();
250 
251  // Associate the menu bar with the frame, if no previous menubar
252  if( GetMenuBar() == NULL )
253  SetMenuBar( menuBar );
254  else
255  menuBar->Refresh();
256 }
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.
Definition: id.h:232
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:481
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:324
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:692
wxString AddHotkeyName(const wxString &aText, EDA_HOTKEY **aList, int aCommandId, HOTKEY_ACTION_TYPE aShortCutType)
Function AddHotkeyName Add the key name from the Command id value ( m_Idcommand member value) ...
see class PGM_BASE
struct EDA_HOTKEY_CONFIG PlEditorHokeysDescr[]
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:824
static const char * text_xpm[]