KiCad PCB EDA Suite
Loading...
Searching...
No Matches
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-2021 KiCad Developers, see AUTHORS.txt for contributors.
5 * Copyright (C) 2013-2019 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
26#include <bitmaps.h>
27#include <file_history.h>
28#include <kiface_base.h>
29#include <menus_helpers.h>
30#include <tool/action_manager.h>
31#include <tool/action_menu.h>
32#include <tool/tool_manager.h>
33#include <widgets/wx_menubar.h>
34
35#include "pl_editor_frame.h"
36#include "pl_editor_id.h"
37#include "tools/pl_actions.h"
39
40
42{
44 // wxWidgets handles the Mac Application menu behind the scenes, but that means
45 // we always have to start from scratch with a new wxMenuBar.
46 wxMenuBar* oldMenuBar = GetMenuBar();
47 WX_MENUBAR* menuBar = new WX_MENUBAR();
48
49 static ACTION_MENU* openRecentMenu; // Open Recent submenu, static to remember this menu
50 FILE_HISTORY& recentFiles = GetFileHistory();
51
52 // Create the menu if it does not exist. Adding a file to/from the history
53 // will automatically refresh the menu.
54 if( !openRecentMenu )
55 {
56 openRecentMenu = new ACTION_MENU( false, selTool );
57 openRecentMenu->SetIcon( BITMAPS::recent );
58
59 recentFiles.UseMenu( openRecentMenu );
60 recentFiles.AddFilesToMenu();
61 }
62
63 // Ensure the title is up to date after changing language
64 openRecentMenu->SetTitle( _( "Open Recent" ) );
65 recentFiles.UpdateClearText( openRecentMenu, _( "Clear Recent Files" ) );
66
67 //-- File menu -------------------------------------------------------
68 //
69 ACTION_MENU* fileMenu = new ACTION_MENU( false, selTool );
70
71 fileMenu->Add( ACTIONS::doNew );
72 fileMenu->Add( ACTIONS::open );
73
74 wxMenuItem* item = fileMenu->Add( openRecentMenu->Clone() );
75
76 // Add the file menu condition here since it needs the item ID for the submenu
78 cond.Enable( FILE_HISTORY::FileHistoryNotEmpty( recentFiles ) );
79 RegisterUIUpdateHandler( item->GetId(), cond );
80
81 fileMenu->AppendSeparator();
82 fileMenu->Add( ACTIONS::save );
83 fileMenu->Add( ACTIONS::saveAs );
84
85 fileMenu->AppendSeparator();
86 fileMenu->Add( ACTIONS::print );
87
88 fileMenu->AppendSeparator();
89 fileMenu->AddClose( _( "Drawing Sheet Editor" ) );
90 fileMenu->AddQuit( _( "Drawing Sheet Editor" ) );
91
92 //-- Edit menu -------------------------------------------------------
93 //
94 ACTION_MENU* editMenu = new ACTION_MENU( false, selTool );
95
96 editMenu->Add( ACTIONS::undo );
97 editMenu->Add( ACTIONS::redo );
98
99 editMenu->AppendSeparator();
100 editMenu->Add( ACTIONS::cut );
101 editMenu->Add( ACTIONS::copy );
102 editMenu->Add( ACTIONS::paste );
103 editMenu->Add( ACTIONS::doDelete );
104
105 //-- View menu -------------------------------------------------------
106 //
107 ACTION_MENU* viewMenu = new ACTION_MENU( false, selTool );
108
109 viewMenu->Add( ACTIONS::zoomInCenter );
110 viewMenu->Add( ACTIONS::zoomOutCenter );
111 viewMenu->Add( ACTIONS::zoomFitScreen );
112 viewMenu->Add( ACTIONS::zoomTool );
113 viewMenu->Add( ACTIONS::zoomRedraw );
114
115 viewMenu->AppendSeparator();
116 viewMenu->Add( PL_ACTIONS::previewSettings );
117
118#ifdef __APPLE__
119 // Add a separator only on macOS because the OS adds menu items to the view menu after ours
120 viewMenu->AppendSeparator();
121#endif
122
123 //-- Place menu -------------------------------------------------------
124 //
125 ACTION_MENU* placeMenu = new ACTION_MENU( false, selTool );
126
127 placeMenu->Add( PL_ACTIONS::drawLine );
128 placeMenu->Add( PL_ACTIONS::drawRectangle );
129 placeMenu->Add( PL_ACTIONS::placeText );
130 placeMenu->Add( PL_ACTIONS::placeImage );
131
132 placeMenu->AppendSeparator();
134
135 //-- Inspector menu -------------------------------------------------------
136 //
137 ACTION_MENU* inspectorMenu = new ACTION_MENU( false, selTool );
138 inspectorMenu->Add( PL_ACTIONS::showInspector );
139
140 //-- Preferences menu --------------------------------------------------
141 //
142 ACTION_MENU* preferencesMenu = new ACTION_MENU( false, selTool );
143
144 preferencesMenu->Add( ACTIONS::openPreferences );
145
146 // Language submenu
147 AddMenuLanguageList( preferencesMenu, selTool );
148
149 //-- Menubar -----------------------------------------------------------
150 //
151 menuBar->Append( fileMenu, _( "&File" ) );
152 menuBar->Append( editMenu, _( "&Edit" ) );
153 menuBar->Append( viewMenu, _( "&View" ) );
154 menuBar->Append( placeMenu, _( "&Place" ) );
155 menuBar->Append( inspectorMenu, _( "&Inspect" ) );
156 menuBar->Append( preferencesMenu, _( "P&references" ) );
157 AddStandardHelpMenu( menuBar );
158
159 SetMenuBar( menuBar );
160 delete oldMenuBar;
161}
static TOOL_ACTION paste
Definition: actions.h:69
static TOOL_ACTION zoomRedraw
Definition: actions.h:94
static TOOL_ACTION zoomOutCenter
Definition: actions.h:98
static TOOL_ACTION saveAs
Definition: actions.h:52
static TOOL_ACTION copy
Definition: actions.h:68
static TOOL_ACTION openPreferences
Definition: actions.h:187
static TOOL_ACTION open
Definition: actions.h:50
static TOOL_ACTION undo
Definition: actions.h:65
static TOOL_ACTION doDelete
Definition: actions.h:74
static TOOL_ACTION save
Definition: actions.h:51
static TOOL_ACTION zoomFitScreen
Definition: actions.h:100
static TOOL_ACTION redo
Definition: actions.h:66
static TOOL_ACTION zoomTool
Definition: actions.h:103
static TOOL_ACTION print
Definition: actions.h:57
static TOOL_ACTION doNew
Definition: actions.h:47
static TOOL_ACTION zoomInCenter
Definition: actions.h:97
static TOOL_ACTION cut
Definition: actions.h:67
Defines the structure of a menu based on ACTIONs.
Definition: action_menu.h:49
void AddClose(const wxString &aAppname="")
Add a standard close item to the menu with the accelerator key CTRL-W.
void AddQuit(const wxString &aAppname="")
Add a standard Quit item to the menu.
ACTION_MENU * Clone() const
Create a deep, recursive copy of this ACTION_MENU.
void SetTitle(const wxString &aTitle) override
Set title for the menu.
Definition: action_menu.cpp:87
void SetIcon(BITMAPS aIcon)
Assign an icon for the entry.
Definition: action_menu.cpp:73
wxMenuItem * Add(const wxString &aLabel, int aId, BITMAPS aIcon)
Add a wxWidgets-style entry to the menu.
void SetMenuBar(wxMenuBar *menu_bar) override
FILE_HISTORY & GetFileHistory()
Get the frame's main file history.
virtual void RegisterUIUpdateHandler(int aID, const ACTION_CONDITIONS &aConditions) override
Register a UI update handler for the control with ID aID.
void AddStandardHelpMenu(wxMenuBar *aMenuBar)
Adds the standard KiCad help menu to the menubar.
This class implements a file history object to store a list of files, that can then be added to a men...
Definition: file_history.h:43
static SELECTION_CONDITION FileHistoryNotEmpty(const FILE_HISTORY &aHistory)
Create a SELECTION_CONDITION that can be used to enable a menu item when the file history has items i...
void UpdateClearText(wxMenu *aMenu, wxString aClearText)
Update the text displayed on the menu item that clears the entire menu.
void AddFilesToMenu() override
Add the files to all registered menus.
Definition: file_history.h:98
static TOOL_ACTION placeImage
Definition: pl_actions.h:59
static TOOL_ACTION drawRectangle
Definition: pl_actions.h:60
static TOOL_ACTION showInspector
Definition: pl_actions.h:72
static TOOL_ACTION previewSettings
Definition: pl_actions.h:73
static TOOL_ACTION placeText
Definition: pl_actions.h:58
static TOOL_ACTION appendImportedDrawingSheet
Definition: pl_actions.h:62
static TOOL_ACTION drawLine
Definition: pl_actions.h:61
void doReCreateMenuBar() override
TOOL_MANAGER * m_toolManager
Definition: tools_holder.h:165
Wrapper around a wxMenuBar object that prevents the accelerator table from being used.
Definition: wx_menubar.h:46
#define _(s)
void AddMenuLanguageList(ACTION_MENU *aMasterMenu, TOOL_INTERACTIVE *aControlTool)
Function AddMenuLanguageList creates a menu list for language choice, and add it as submenu to Master...
Macros and inline functions to create menus items in menubars or popup menus.
Functors that can be used to figure out how the action controls should be displayed in the UI and if ...
ACTION_CONDITIONS & Enable(const SELECTION_CONDITION &aCondition)