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 <tool/action_manager.h>
30#include <tool/action_menu.h>
31#include <tool/tool_manager.h>
32#include <widgets/wx_menubar.h>
33
34#include "pl_editor_frame.h"
35#include "pl_editor_id.h"
36#include "tools/pl_actions.h"
38
39
41{
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 WX_MENUBAR* menuBar = new WX_MENUBAR();
47
48 static ACTION_MENU* openRecentMenu; // Open Recent submenu, static to remember this menu
49 FILE_HISTORY& recentFiles = GetFileHistory();
50
51 // Create the menu if it does not exist. Adding a file to/from the history
52 // will automatically refresh the menu.
53 if( !openRecentMenu )
54 {
55 openRecentMenu = new ACTION_MENU( false, selTool );
56 openRecentMenu->SetIcon( BITMAPS::recent );
57
58 recentFiles.UseMenu( openRecentMenu );
59 recentFiles.AddFilesToMenu();
60 }
61
62 // Ensure the title is up to date after changing language
63 openRecentMenu->SetTitle( _( "Open Recent" ) );
64 recentFiles.UpdateClearText( openRecentMenu, _( "Clear Recent Files" ) );
65
66 //-- File menu -------------------------------------------------------
67 //
68 ACTION_MENU* fileMenu = new ACTION_MENU( false, selTool );
69
70 fileMenu->Add( ACTIONS::doNew );
71 fileMenu->Add( ACTIONS::open );
72
73 wxMenuItem* item = fileMenu->Add( openRecentMenu->Clone() );
74
75 // Add the file menu condition here since it needs the item ID for the submenu
77 cond.Enable( FILE_HISTORY::FileHistoryNotEmpty( recentFiles ) );
78 RegisterUIUpdateHandler( item->GetId(), cond );
79
80 fileMenu->AppendSeparator();
81 fileMenu->Add( ACTIONS::save );
82 fileMenu->Add( ACTIONS::saveAs );
83
84 fileMenu->AppendSeparator();
85 fileMenu->Add( ACTIONS::print );
86
87 fileMenu->AppendSeparator();
88 fileMenu->AddClose( _( "Drawing Sheet Editor" ) );
89 fileMenu->AddQuit( _( "Drawing Sheet Editor" ) );
90
91 //-- Edit menu -------------------------------------------------------
92 //
93 ACTION_MENU* editMenu = new ACTION_MENU( false, selTool );
94
95 editMenu->Add( ACTIONS::undo );
96 editMenu->Add( ACTIONS::redo );
97
98 editMenu->AppendSeparator();
99 editMenu->Add( ACTIONS::cut );
100 editMenu->Add( ACTIONS::copy );
101 editMenu->Add( ACTIONS::paste );
102 editMenu->Add( ACTIONS::doDelete );
103
104 //-- View menu -------------------------------------------------------
105 //
106 ACTION_MENU* viewMenu = new ACTION_MENU( false, selTool );
107
108 viewMenu->Add( ACTIONS::zoomInCenter );
109 viewMenu->Add( ACTIONS::zoomOutCenter );
110 viewMenu->Add( ACTIONS::zoomFitScreen );
111 viewMenu->Add( ACTIONS::zoomTool );
112 viewMenu->Add( ACTIONS::zoomRedraw );
113
114 viewMenu->AppendSeparator();
115 viewMenu->Add( PL_ACTIONS::previewSettings );
116
117#ifdef __APPLE__
118 // Add a separator only on macOS because the OS adds menu items to the view menu after ours
119 viewMenu->AppendSeparator();
120#endif
121
122 //-- Place menu -------------------------------------------------------
123 //
124 ACTION_MENU* placeMenu = new ACTION_MENU( false, selTool );
125
126 placeMenu->Add( PL_ACTIONS::drawLine );
127 placeMenu->Add( PL_ACTIONS::drawRectangle );
128 placeMenu->Add( PL_ACTIONS::placeText );
129 placeMenu->Add( PL_ACTIONS::placeImage );
130
131 placeMenu->AppendSeparator();
133
134 //-- Inspector menu -------------------------------------------------------
135 //
136 ACTION_MENU* inspectorMenu = new ACTION_MENU( false, selTool );
137 inspectorMenu->Add( PL_ACTIONS::showInspector );
138
139 //-- Preferences menu --------------------------------------------------
140 //
141 ACTION_MENU* preferencesMenu = new ACTION_MENU( false, selTool );
142
143 preferencesMenu->Add( ACTIONS::openPreferences );
144
145 // Language submenu
146 AddMenuLanguageList( preferencesMenu, selTool );
147
148 //-- Menubar -----------------------------------------------------------
149 //
150 menuBar->Append( fileMenu, _( "&File" ) );
151 menuBar->Append( editMenu, _( "&Edit" ) );
152 menuBar->Append( viewMenu, _( "&View" ) );
153 menuBar->Append( placeMenu, _( "&Place" ) );
154 menuBar->Append( inspectorMenu, _( "&Inspect" ) );
155 menuBar->Append( preferencesMenu, _( "P&references" ) );
156 AddStandardHelpMenu( menuBar );
157
158 SetMenuBar( menuBar );
159 delete oldMenuBar;
160}
static TOOL_ACTION paste
Definition: actions.h:70
static TOOL_ACTION zoomRedraw
Definition: actions.h:114
static TOOL_ACTION zoomOutCenter
Definition: actions.h:118
static TOOL_ACTION saveAs
Definition: actions.h:52
static TOOL_ACTION copy
Definition: actions.h:69
static TOOL_ACTION openPreferences
Definition: actions.h:211
static TOOL_ACTION open
Definition: actions.h:50
static TOOL_ACTION undo
Definition: actions.h:66
static TOOL_ACTION doDelete
Definition: actions.h:75
static TOOL_ACTION save
Definition: actions.h:51
static TOOL_ACTION zoomFitScreen
Definition: actions.h:124
static TOOL_ACTION redo
Definition: actions.h:67
static TOOL_ACTION zoomTool
Definition: actions.h:127
static TOOL_ACTION print
Definition: actions.h:57
static TOOL_ACTION doNew
Definition: actions.h:47
static TOOL_ACTION zoomInCenter
Definition: actions.h:117
static TOOL_ACTION cut
Definition: actions.h:68
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:92
void SetIcon(BITMAPS aIcon)
Assign an icon for the entry.
Definition: action_menu.cpp:78
wxMenuItem * Add(const wxString &aLabel, int aId, BITMAPS aIcon)
Add a wxWidgets-style entry to the menu.
void AddMenuLanguageList(ACTION_MENU *aMasterMenu, TOOL_INTERACTIVE *aControlTool)
Function AddMenuLanguageList creates a menu list for language choice, and add it as submenu to Master...
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:167
Wrapper around a wxMenuBar object that prevents the accelerator table from being used.
Definition: wx_menubar.h:47
#define _(s)
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)