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, wxID_ANY, _( "Open &Recent" ),
76  _( "Open recent page layout design file" ),
77  KiBitmap( recent_xpm ) );
78 
79  fileMenu->AppendSeparator();
80 
81  msg = AddHotkeyName( _( "&Save" ), PlEditorHokeysDescr, 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..." ), PlEditorHokeysDescr, 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..." ), PlEditorHokeysDescr, 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" ), PlEditorHokeysDescr, HK_UNDO );
109  AddMenuItem( editMenu, wxID_UNDO, msg, wxEmptyString, KiBitmap( undo_xpm ) );
110 
111  msg = AddHotkeyName( _( "Redo" ), PlEditorHokeysDescr, HK_REDO );
112  AddMenuItem( editMenu, wxID_REDO, msg, wxEmptyString, KiBitmap( redo_xpm ) );
113 
114  editMenu->AppendSeparator();
115 
116  AddMenuItem( editMenu, wxID_CUT, _( "Delete" ), wxEmptyString, KiBitmap( delete_xpm ) );
117 
118 
119  // View Menu:
120  wxMenu* viewMenu = new wxMenu;
121 
122  msg = AddHotkeyName( _( "Zoom In" ), PlEditorHokeysDescr, HK_ZOOM_IN, IS_ACCELERATOR );
123  AddMenuItem( viewMenu, ID_ZOOM_IN, msg, wxEmptyString, KiBitmap( zoom_in_xpm ) );
124 
125  msg = AddHotkeyName( _( "Zoom Out" ), PlEditorHokeysDescr, HK_ZOOM_OUT, IS_ACCELERATOR );
126  AddMenuItem( viewMenu, ID_ZOOM_OUT, msg, wxEmptyString, KiBitmap( zoom_out_xpm ) );
127 
128  msg = AddHotkeyName( _( "Zoom to Fit" ), PlEditorHokeysDescr, HK_ZOOM_AUTO );
129  AddMenuItem( viewMenu, ID_ZOOM_PAGE, msg, wxEmptyString, KiBitmap( zoom_fit_in_page_xpm ) );
130 
131  msg = AddHotkeyName( _( "Zoom to Selection" ), PlEditorHokeysDescr, HK_ZOOM_SELECTION );
132  AddMenuItem( viewMenu, ID_MENU_ZOOM_SELECTION, msg, wxEmptyString, KiBitmap( zoom_area_xpm ) );
133 
134  viewMenu->AppendSeparator();
135 
137  GetDrawBgColor() == WHITE ? _( "&Background Black" ) : _( "&Background White" ),
138  wxEmptyString, KiBitmap( palette_xpm ) );
139 
140  AddMenuItem( viewMenu, ID_MENU_GRID_ONOFF,
141  IsGridVisible() ? _( "Hide &Grid" ) : _( "Show &Grid" ),
142  wxEmptyString, KiBitmap( grid_xpm ) );
143 
144  viewMenu->AppendSeparator();
145 
146  msg = AddHotkeyName( _( "Redraw View" ), PlEditorHokeysDescr, HK_ZOOM_REDRAW );
147  AddMenuItem( viewMenu, ID_ZOOM_REDRAW, msg, wxEmptyString, KiBitmap( zoom_redraw_xpm ) );
148 
149 
150  // Place Menu:
151  wxMenu* placeMenu = new wxMenu;
152 
153  AddMenuItem( placeMenu, ID_POPUP_ITEM_ADD_LINE, _( "&Line..." ),
154  wxEmptyString, KiBitmap( add_dashed_line_xpm ) );
155 
156  AddMenuItem( placeMenu, ID_POPUP_ITEM_ADD_RECT, _( "&Rectangle..." ),
157  wxEmptyString, KiBitmap( add_rectangle_xpm ) );
158 
159  AddMenuItem( placeMenu, ID_POPUP_ITEM_ADD_TEXT, _( "&Text..." ),
160  wxEmptyString, KiBitmap( text_xpm ) );
161 
162  AddMenuItem( placeMenu, ID_POPUP_ITEM_ADD_BITMAP, _( "&Bitmap..." ),
163  wxEmptyString, KiBitmap( image_xpm ) );
164 
165  placeMenu->AppendSeparator();
166 
167  AddMenuItem( placeMenu, ID_APPEND_DESCR_FILE, _( "&Append Existing Page Layout Design File..." ),
168  _( "Append an existing page layout design file to current file" ),
169  KiBitmap( pagelayout_load_xpm ) );
170 
171 
172  // Menu for preferences
173  wxMenu* preferencesMenu = new wxMenu;
174 
175  AddMenuItem( preferencesMenu, wxID_PREFERENCES, _( "&Preferences..." ),
176  _( "Show preferences for all open tools" ),
177  KiBitmap( preference_xpm ) );
178 
179  // Language submenu
180  Pgm().AddMenuLanguageList( preferencesMenu );
181 
182  // Menu Help
183  wxMenu* helpMenu = new wxMenu;
184 
185  // Contents
186  AddMenuItem( helpMenu, wxID_HELP, _( "Page Layout Editor &Manual" ),
187  _( "Open the Page Layout Editor Manual" ),
188  KiBitmap( online_help_xpm ) );
189 
190  AddMenuItem( helpMenu, wxID_INDEX, _( "&Getting Started in KiCad" ),
191  _( "Open \"Getting Started in KiCad\" guide for beginners" ),
192  KiBitmap( help_xpm ) );
193 
194  msg = AddHotkeyName( _( "&List Hotkeys" ), PlEditorHokeysDescr, HK_HELP );
196  _( "Displays the current hotkeys list and corresponding commands" ),
197  KiBitmap( hotkeys_xpm ) );
198 
199  helpMenu->AppendSeparator();
200  AddMenuItem( helpMenu, ID_HELP_GET_INVOLVED, _( "Get &Involved" ),
201  _( "Contribute to KiCad (opens a web browser)" ),
202  KiBitmap( info_xpm ) );
203 
204  // Separator
205  helpMenu->AppendSeparator();
206 
207  // About Kicad
208  AddMenuItem( helpMenu, wxID_ABOUT, _( "&About KiCad" ), wxEmptyString, KiBitmap( about_xpm ) );
209 
210  // Append menus to the menubar
211  menuBar->Append( fileMenu, _( "&File" ) );
212  menuBar->Append( editMenu, _( "&Edit" ) );
213  menuBar->Append( viewMenu, _( "&View" ) );
214  menuBar->Append( placeMenu, _( "&Place" ) );
215  menuBar->Append( preferencesMenu, _( "P&references" ) );
216  menuBar->Append( helpMenu, _( "&Help" ) );
217 
218  SetMenuBar( menuBar );
219  delete oldMenuBar;
220 }
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:223
void ReCreateMenuBar() override
Function ReCreateMenuBar Creates recreates the menu bar.
Definition: id.h:241
PGM_BASE & Pgm()
The global Program "get" accessor.
Definition: kicad.cpp:66
KIFACE_I & Kiface()
Global KIFACE_I "get" accessor.
Definition: kicad.cpp:52
virtual bool IsGridVisible() const
Definition: draw_frame.h:528
wxBitmap KiBitmap(BITMAP_DEF aBitmap)
Construct a wxBitmap from a memory record, held in a BITMAP_DEF.
Definition: bitmap.cpp:79
virtual COLOR4D GetDrawBgColor() const
Definition: draw_frame.h:375
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
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:800
static const char * text_xpm[]