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" ), PlEditorHotkeysDescr, 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..." ), PlEditorHotkeysDescr, 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, wxID_ANY, _( "Open &Recent" ),
76  _( "Open recent page layout design file" ),
77  KiBitmap( recent_xpm ) );
78 
79  fileMenu->AppendSeparator();
80 
81  msg = AddHotkeyName( _( "&Save" ), PlEditorHotkeysDescr, HK_SAVE );
82  AddMenuItem( fileMenu, wxID_SAVE, msg,
83  _( "Save current page layout design file" ),
84  KiBitmap( save_xpm ) );
85 
86  msg = AddHotkeyName( _( "Save &As..." ), PlEditorHotkeysDescr, HK_SAVEAS );
87  AddMenuItem( fileMenu, wxID_SAVEAS, msg,
88  _( "Save current page layout design file with a different name" ),
89  KiBitmap( save_as_xpm ) );
90 
91  fileMenu->AppendSeparator();
92 
93  msg = AddHotkeyName( _( "&Print..." ), PlEditorHotkeysDescr, HK_PRINT );
94  AddMenuItem( fileMenu, wxID_PRINT, msg, KiBitmap( print_button_xpm ) );
95 
96  AddMenuItem( fileMenu, wxID_PREVIEW, _( "Print Pre&view..." ), KiBitmap( print_button_xpm ) );
97 
98  fileMenu->AppendSeparator();
99 
100  AddMenuItem( fileMenu, wxID_EXIT, _( "&Close" ),
101  _( "Close Page Layout Editor" ),
102  KiBitmap( exit_xpm ) );
103 
104 
105  // Edit Menu:
106  wxMenu* editMenu = new wxMenu;
107 
108  msg = AddHotkeyName( _( "Undo" ), PlEditorHotkeysDescr, HK_UNDO );
109  AddMenuItem( editMenu, wxID_UNDO, msg, wxEmptyString, KiBitmap( undo_xpm ) );
110 
111  msg = AddHotkeyName( _( "Redo" ), PlEditorHotkeysDescr, HK_REDO );
112  AddMenuItem( editMenu, wxID_REDO, msg, wxEmptyString, KiBitmap( redo_xpm ) );
113 
114  editMenu->AppendSeparator();
115 
116  msg = AddHotkeyName( _( "Delete" ), PlEditorHotkeysDescr, HK_DELETE_ITEM );
117  AddMenuItem( editMenu, wxID_DELETE, msg, wxEmptyString, KiBitmap( delete_xpm ) );
118 
119 
120  // View Menu:
121  wxMenu* viewMenu = new wxMenu;
122 
123  msg = AddHotkeyName( _( "Zoom In" ), PlEditorHotkeysDescr, HK_ZOOM_IN, IS_ACCELERATOR );
124  AddMenuItem( viewMenu, ID_ZOOM_IN, msg, wxEmptyString, KiBitmap( zoom_in_xpm ) );
125 
126  msg = AddHotkeyName( _( "Zoom Out" ), PlEditorHotkeysDescr, HK_ZOOM_OUT, IS_ACCELERATOR );
127  AddMenuItem( viewMenu, ID_ZOOM_OUT, msg, wxEmptyString, KiBitmap( zoom_out_xpm ) );
128 
129  msg = AddHotkeyName( _( "Zoom to Fit" ), PlEditorHotkeysDescr, HK_ZOOM_AUTO );
130  AddMenuItem( viewMenu, ID_ZOOM_PAGE, msg, wxEmptyString, KiBitmap( zoom_fit_in_page_xpm ) );
131 
132  msg = AddHotkeyName( _( "Zoom to Selection" ), PlEditorHotkeysDescr, HK_ZOOM_SELECTION );
133  AddMenuItem( viewMenu, ID_ZOOM_SELECTION, msg, wxEmptyString, KiBitmap( zoom_area_xpm ), wxITEM_CHECK );
134 
135  viewMenu->AppendSeparator();
136 
138  GetDrawBgColor() == WHITE ? _( "&Background Black" ) : _( "&Background White" ),
139  wxEmptyString, KiBitmap( palette_xpm ) );
140 
141  AddMenuItem( viewMenu, ID_MENU_GRID_ONOFF,
142  IsGridVisible() ? _( "Hide &Grid" ) : _( "Show &Grid" ),
143  wxEmptyString, KiBitmap( grid_xpm ) );
144 
145  viewMenu->AppendSeparator();
146 
147  msg = AddHotkeyName( _( "Redraw View" ), PlEditorHotkeysDescr, HK_ZOOM_REDRAW );
148  AddMenuItem( viewMenu, ID_ZOOM_REDRAW, msg, wxEmptyString, KiBitmap( zoom_redraw_xpm ) );
149 
150 
151  // Place Menu:
152  wxMenu* placeMenu = new wxMenu;
153 
154  AddMenuItem( placeMenu, ID_POPUP_ITEM_ADD_LINE, _( "&Line..." ),
155  wxEmptyString, KiBitmap( add_dashed_line_xpm ) );
156 
157  AddMenuItem( placeMenu, ID_POPUP_ITEM_ADD_RECT, _( "&Rectangle..." ),
158  wxEmptyString, KiBitmap( add_rectangle_xpm ) );
159 
160  AddMenuItem( placeMenu, ID_POPUP_ITEM_ADD_TEXT, _( "&Text..." ),
161  wxEmptyString, KiBitmap( text_xpm ) );
162 
163  AddMenuItem( placeMenu, ID_POPUP_ITEM_ADD_BITMAP, _( "&Bitmap..." ),
164  wxEmptyString, KiBitmap( image_xpm ) );
165 
166  placeMenu->AppendSeparator();
167 
168  AddMenuItem( placeMenu, ID_APPEND_DESCR_FILE, _( "&Append Existing Page Layout Design File..." ),
169  _( "Append an existing page layout design file to current file" ),
170  KiBitmap( pagelayout_load_xpm ) );
171 
172 
173  // Menu for preferences
174  wxMenu* preferencesMenu = new wxMenu;
175 
176  msg = AddHotkeyName( _( "&Preferences..." ), PlEditorHotkeysDescr, HK_PREFERENCES );
177  AddMenuItem( preferencesMenu, wxID_PREFERENCES, msg,
178  _( "Show preferences for all open tools" ),
179  KiBitmap( preference_xpm ) );
180 
181  // Language submenu
182  Pgm().AddMenuLanguageList( preferencesMenu );
183 
184  // Menu Help
185  wxMenu* helpMenu = new wxMenu;
186 
187  // Contents
188  AddMenuItem( helpMenu, wxID_HELP, _( "Page Layout Editor &Manual" ),
189  _( "Open the Page Layout Editor Manual" ),
190  KiBitmap( online_help_xpm ) );
191 
192  AddMenuItem( helpMenu, wxID_INDEX, _( "&Getting Started in KiCad" ),
193  _( "Open \"Getting Started in KiCad\" guide for beginners" ),
194  KiBitmap( help_xpm ) );
195 
196  msg = AddHotkeyName( _( "&List Hotkeys" ), PlEditorHotkeysDescr, HK_HELP );
198  _( "Displays the current hotkeys list and corresponding commands" ),
199  KiBitmap( hotkeys_xpm ) );
200 
201  helpMenu->AppendSeparator();
202  AddMenuItem( helpMenu, ID_HELP_GET_INVOLVED, _( "Get &Involved" ),
203  _( "Contribute to KiCad (opens a web browser)" ),
204  KiBitmap( info_xpm ) );
205 
206  // Separator
207  helpMenu->AppendSeparator();
208 
209  // About Kicad
210  AddMenuItem( helpMenu, wxID_ABOUT, _( "&About KiCad" ), wxEmptyString, KiBitmap( about_xpm ) );
211 
212  // Append menus to the menubar
213  menuBar->Append( fileMenu, _( "&File" ) );
214  menuBar->Append( editMenu, _( "&Edit" ) );
215  menuBar->Append( viewMenu, _( "&View" ) );
216  menuBar->Append( placeMenu, _( "&Place" ) );
217  menuBar->Append( preferencesMenu, _( "P&references" ) );
218  menuBar->Append( helpMenu, _( "&Help" ) );
219 
220  SetMenuBar( menuBar );
221  delete oldMenuBar;
222 }
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:251
void ReCreateMenuBar() override
Recreates the menu bar.
virtual bool IsGridVisible() const
Definition: draw_frame.h:533
Definition: id.h:235
PGM_BASE & Pgm()
The global Program "get" accessor.
Definition: kicad.cpp:66
KIFACE_I & Kiface()
Global KIFACE_I "get" accessor.
Definition: kicad.cpp:52
wxBitmap KiBitmap(BITMAP_DEF aBitmap)
Construct a wxBitmap from a memory record, held in a BITMAP_DEF.
Definition: bitmap.cpp:79
struct EDA_HOTKEY_CONFIG PlEditorHotkeysDescr[]
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
FILE_HISTORY & GetFileHistory()
Definition: kiface_i.h:123
Definition: colors.h:49
virtual COLOR4D GetDrawBgColor() const
Definition: draw_frame.h:386
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:815
static const char * text_xpm[]