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