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-2018 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  // 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  wxMenuBar* menuBar = new wxMenuBar();
47 
48  wxString msg;
49  static wxMenu* openRecentMenu; // Open Recent submenu,
50  // static to remember this menu
51 
52  // Before deleting, remove the menus managed by m_fileHistory
53  // (the file history will be updated when adding/removing files in history
54  if( openRecentMenu )
55  Kiface().GetFileHistory().RemoveMenu( openRecentMenu );
56 
57  // Recreate all menus:
58 
59  // File Menu:
60  wxMenu* fileMenu = new wxMenu;
61 
62  msg = AddHotkeyName( _( "&New" ), PlEditorHokeysDescr, HK_NEW );
63  AddMenuItem( fileMenu, wxID_NEW, msg,
64  _( "Create new page layout design" ),
65  KiBitmap( new_page_layout_xpm ) );
66 
67  msg = AddHotkeyName( _( "&Open..." ), PlEditorHokeysDescr, HK_OPEN );
68  AddMenuItem( fileMenu, wxID_OPEN, msg,
69  _( "Open an existing page layout design file" ),
70  KiBitmap( open_page_layout_xpm ) );
71 
72  openRecentMenu = new wxMenu();
73  Kiface().GetFileHistory().UseMenu( openRecentMenu );
74  Kiface().GetFileHistory().AddFilesToMenu();
75  AddMenuItem( fileMenu, openRecentMenu,
76  wxID_ANY,
77  _( "Open &Recent" ),
78  _( "Open recent page layout design file" ),
79  KiBitmap( recent_xpm ) );
80 
81  fileMenu->AppendSeparator();
82 
83  msg = AddHotkeyName( _( "&Save" ), PlEditorHokeysDescr, HK_SAVE );
84  AddMenuItem( fileMenu, wxID_SAVE, msg,
85  _( "Save current page layout design file" ),
86  KiBitmap( save_xpm ) );
87 
88  msg = AddHotkeyName( _( "Save &As..." ), PlEditorHokeysDescr, HK_SAVEAS );
89  AddMenuItem( fileMenu, wxID_SAVEAS, msg,
90  _( "Save current page layout design file with a different name" ),
91  KiBitmap( save_as_xpm ) );
92 
93  fileMenu->AppendSeparator();
94 
95  msg = AddHotkeyName( _( "&Print..." ), PlEditorHokeysDescr, HK_PRINT );
96  AddMenuItem( fileMenu, wxID_PRINT, msg,
97  wxEmptyString, KiBitmap( print_button_xpm ) );
98 
99  AddMenuItem( fileMenu, wxID_PREVIEW, _( "Print Pre&view..." ),
100  wxEmptyString, KiBitmap( print_button_xpm ) );
101 
102  fileMenu->AppendSeparator();
103 
104  AddMenuItem( fileMenu, wxID_EXIT, _( "&Close" ),
105  _( "Close Page Layout Editor" ), KiBitmap( exit_xpm ) );
106 
107 
108  // Edit Menu:
109  wxMenu* editMenu = new wxMenu;
110 
111  msg = AddHotkeyName( _( "Undo" ), PlEditorHokeysDescr, HK_UNDO );
112  AddMenuItem( editMenu, wxID_UNDO, msg, wxEmptyString, KiBitmap( undo_xpm ) );
113 
114  msg = AddHotkeyName( _( "Redo" ), PlEditorHokeysDescr, HK_REDO );
115  AddMenuItem( editMenu, wxID_REDO, msg, wxEmptyString, KiBitmap( redo_xpm ) );
116 
117  editMenu->AppendSeparator();
118 
119  AddMenuItem( editMenu, wxID_CUT, _( "Delete" ), wxEmptyString, KiBitmap( delete_xpm ) );
120 
121 
122  // View Menu:
123  wxMenu* viewMenu = new wxMenu;
124 
125  msg = AddHotkeyName( _( "Zoom In" ), PlEditorHokeysDescr, HK_ZOOM_IN, IS_ACCELERATOR );
126  AddMenuItem( viewMenu, ID_ZOOM_IN, msg, wxEmptyString, KiBitmap( zoom_in_xpm ) );
127 
128  msg = AddHotkeyName( _( "Zoom Out" ), PlEditorHokeysDescr, HK_ZOOM_OUT, IS_ACCELERATOR );
129  AddMenuItem( viewMenu, ID_ZOOM_OUT, msg, wxEmptyString, KiBitmap( zoom_out_xpm ) );
130 
131  msg = AddHotkeyName( _( "Zoom to Fit" ), PlEditorHokeysDescr, HK_ZOOM_AUTO );
132  AddMenuItem( viewMenu, ID_ZOOM_PAGE, msg, wxEmptyString, KiBitmap( zoom_fit_in_page_xpm ) );
133 
134  msg = AddHotkeyName( _( "Zoom to Selection" ), PlEditorHokeysDescr, HK_ZOOM_SELECTION );
135  AddMenuItem( viewMenu, ID_MENU_ZOOM_SELECTION, msg, wxEmptyString, KiBitmap( zoom_area_xpm ) );
136 
137  viewMenu->AppendSeparator();
138 
139  msg = AddHotkeyName( _( "Redraw View" ), PlEditorHokeysDescr, HK_ZOOM_REDRAW );
140  AddMenuItem( viewMenu, ID_ZOOM_REDRAW, msg, wxEmptyString, KiBitmap( zoom_redraw_xpm ) );
141 
142 
143  // Place Menu:
144  wxMenu* placeMenu = new wxMenu;
145 
146  AddMenuItem( placeMenu, ID_POPUP_ITEM_ADD_LINE, _( "&Line..." ),
147  wxEmptyString, KiBitmap( add_dashed_line_xpm ) );
148 
149  AddMenuItem( placeMenu, ID_POPUP_ITEM_ADD_RECT, _( "&Rectangle..." ),
150  wxEmptyString, KiBitmap( add_rectangle_xpm ) );
151 
152  AddMenuItem( placeMenu, ID_POPUP_ITEM_ADD_TEXT, _( "&Text..." ),
153  wxEmptyString, KiBitmap( text_xpm ) );
154 
155  AddMenuItem( placeMenu, ID_POPUP_ITEM_ADD_BITMAP, _( "&Bitmap..." ),
156  wxEmptyString, KiBitmap( image_xpm ) );
157 
158  placeMenu->AppendSeparator();
159 
160  AddMenuItem( placeMenu, ID_APPEND_DESCR_FILE, _( "&Append Existing Page Layout Design File..." ),
161  _( "Append an existing page layout design file to current file" ),
162  KiBitmap( pagelayout_load_xpm ) );
163 
164 
165  // Menu for preferences
166  wxMenu* preferencesMenu = new wxMenu;
167 
168  AddMenuItem( preferencesMenu,
170  GetDrawBgColor() == WHITE ?
171  _( "&Background Black" ) : _( "&Background White" ),
172  wxEmptyString, KiBitmap( palette_xpm ) );
173 
174  AddMenuItem( preferencesMenu,
176  IsGridVisible() ? _( "Hide &Grid" ) : _( "Show &Grid" ),
177  wxEmptyString, KiBitmap( grid_xpm ) );
178 
179  // Text editor selection
180  AddMenuItem( preferencesMenu,
182  _( "Set &Text Editor..." ),
183  _( "Select your preferred text editor" ),
184  KiBitmap( editor_xpm ) );
185 
186  // Language submenu
187  Pgm().AddMenuLanguageList( preferencesMenu );
188 
189  // Icons options submenu
190  AddMenuIconsOptions( preferencesMenu );
191 
192  // Hotkey submenu
193  AddHotkeyConfigMenu( preferencesMenu );
194 
195  // Menu Help
196  wxMenu* helpMenu = new wxMenu;
197 
198  // Contents
199  AddMenuItem( helpMenu,
200  wxID_HELP,
201  _( "Page Layout Editor &Manual" ),
202  _( "Open the Page Layout Editor Manual" ),
203  KiBitmap( online_help_xpm ) );
204 
205  AddMenuItem( helpMenu,
206  wxID_INDEX,
207  _( "&Getting Started in KiCad" ),
208  _( "Open \"Getting Started in KiCad\" guide for beginners" ),
209  KiBitmap( help_xpm ) );
210 
211  msg = AddHotkeyName( _( "&List Hotkeys" ), PlEditorHokeysDescr, HK_HELP );
213  _( "Displays the current hotkeys list and corresponding commands" ),
214  KiBitmap( hotkeys_xpm ) );
215 
216  helpMenu->AppendSeparator();
218  _( "Get &Involved" ),
219  _( "Contribute to KiCad (opens a web browser)" ),
220  KiBitmap( info_xpm ) );
221 
222  // Separator
223  helpMenu->AppendSeparator();
224 
225  // About Kicad
226  AddMenuItem( helpMenu,
227  wxID_ABOUT,
228  _( "&About KiCad" ),
229  _( "About KiCad" ),
230  KiBitmap( about_xpm ) );
231 
232  // Append menus to the menubar
233  menuBar->Append( fileMenu, _( "&File" ) );
234  menuBar->Append( editMenu, _( "&Edit" ) );
235  menuBar->Append( viewMenu, _( "&View" ) );
236  menuBar->Append( placeMenu, _( "&Place" ) );
237  menuBar->Append( preferencesMenu, _( "P&references" ) );
238  menuBar->Append( helpMenu, _( "&Help" ) );
239 
240  SetMenuBar( menuBar );
241  delete oldMenuBar;
242 }
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:174
void ReCreateMenuBar() override
Function ReCreateMenuBar Creates recreates the menu bar.
Definition: id.h:242
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:498
wxBitmap KiBitmap(BITMAP_DEF aBitmap)
Function KiBitmap constructs a wxBitmap from a memory record, held in a BITMAP_DEF.
Definition: bitmap.cpp:78
virtual COLOR4D GetDrawBgColor() const
Definition: draw_frame.h:338
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...
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:831
static const char * text_xpm[]