KiCad PCB EDA Suite
cvpcb/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) 2004 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
5  * Copyright (C) 2004-2019 KiCad Developers, see AUTHORS.txt for contributors.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, you may find one here:
19  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20  * or you may search the http://www.gnu.org website for the version 2 license,
21  * or you may write to the Free Software Foundation, Inc.,
22  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23  */
24 
25 #include <bitmaps.h>
26 #include <menus_helpers.h>
27 #include <tool/actions.h>
28 #include <tool/common_control.h>
29 #include <tool/conditional_menu.h>
30 #include <tool/tool_manager.h>
31 
32 #include <cvpcb_mainframe.h>
33 #include <tools/cvpcb_actions.h>
34 #include <widgets/wx_menubar.h>
35 
36 
38 {
40  // wxWidgets handles the Mac Application menu behind the scenes, but that means
41  // we always have to start from scratch with a new wxMenuBar.
42  wxMenuBar* oldMenuBar = GetMenuBar();
43  WX_MENUBAR* menuBar = new WX_MENUBAR();
44 
45  //-- File menu -----------------------------------------------------------
46  //
47  CONDITIONAL_MENU* fileMenu = new CONDITIONAL_MENU( false, tool );
48 
49  auto enableSaveCondition = [ this ] ( const SELECTION& sel )
50  {
51  return IsContentModified();
52  };
53 
54  fileMenu->AddItem( CVPCB_ACTIONS::saveAssociations, enableSaveCondition );
55  fileMenu->AddSeparator();
56  fileMenu->AddClose( _( "Assign Footprints" ) );
57 
58  fileMenu->Resolve();
59 
60  //-- Preferences menu -----------------------------------------------
61  //
62  CONDITIONAL_MENU* editMenu = new CONDITIONAL_MENU( false, tool );
63 
64  auto enableUndoCondition = [ this ] ( const SELECTION& sel )
65  {
66  return m_undoList.size() > 0;
67  };
68  auto enableRedoCondition = [ this ] ( const SELECTION& sel )
69  {
70  return m_redoList.size() > 0;
71  };
72 
73  editMenu->AddItem( ACTIONS::undo, enableUndoCondition );
74  editMenu->AddItem( ACTIONS::redo, enableRedoCondition );
75  editMenu->AddSeparator();
79 
80  editMenu->Resolve();
81 
82  //-- Preferences menu -----------------------------------------------
83  //
84  CONDITIONAL_MENU* prefsMenu = new CONDITIONAL_MENU( false, tool );
85 
88  prefsMenu->AddItem( wxID_PREFERENCES,
89  _( "Preferences...\tCTRL+," ),
90  _( "Show preferences for all open tools" ),
92  prefsMenu->AddSeparator();
94 
95  prefsMenu->AddSeparator();
96  AddMenuLanguageList( prefsMenu, tool );
97 
98  prefsMenu->Resolve();
99 
100  //-- Menubar -------------------------------------------------------------
101  //
102  menuBar->Append( fileMenu, _( "&File" ) );
103  menuBar->Append( editMenu, _( "&Edit" ) );
104  menuBar->Append( prefsMenu, _( "&Preferences" ) );
105  AddStandardHelpMenu( menuBar );
106 
107  SetMenuBar( menuBar );
108  delete oldMenuBar;
109 }
static bool ShowAlways(const SELECTION &aSelection)
Function ShowAlways The default condition function (always returns true).
static TOOL_ACTION showEquFileTable
Definition: cvpcb_actions.h:60
Wrapper around a wxMenuBar object that prevents the accelerator table from being used.
Definition: wx_menubar.h:45
bool IsContentModified() override
Get if the current associations have been modified but not saved.
static TOOL_ACTION copy
Definition: actions.h:70
static TOOL_ACTION showFootprintLibTable
Definition: actions.h:168
void AddStandardHelpMenu(wxMenuBar *aMenuBar)
Adds the standard KiCad help menu to the menubar.
static TOOL_ACTION cut
Definition: actions.h:69
void ReCreateMenuBar() override
Recreates the menu bar.
CVPCB_UNDO_REDO_LIST m_undoList
static TOOL_ACTION saveAssociations
Management actions.
Definition: cvpcb_actions.h:59
COMMON_CONTROL.
void Resolve()
Function Resolve()
void AddSeparator(int aOrder=ANY_ORDER)
Function AddSeparator()
static TOOL_ACTION redo
Definition: actions.h:68
void AddClose(wxString aAppname="")
Function AddClose()
TOOL_MANAGER * m_toolManager
Definition: tools_holder.h:48
void AddMenuLanguageList(CONDITIONAL_MENU *aMasterMenu, TOOL_INTERACTIVE *aControlTool)
Function AddMenuLanguageList creates a menu list for language choice, and add it as submenu to Master...
#define _(s)
Definition: 3d_actions.cpp:33
CVPCB_UNDO_REDO_LIST m_redoList
static TOOL_ACTION undo
Definition: actions.h:67
const BITMAP_OPAQUE preference_xpm[1]
Definition: preference.cpp:66
static TOOL_ACTION configurePaths
Definition: actions.h:166
void AddItem(const TOOL_ACTION &aAction, const SELECTION_CONDITION &aCondition, int aOrder=ANY_ORDER)
Function AddItem()
static TOOL_ACTION paste
Definition: actions.h:71