KiCad PCB EDA Suite
tool_menu.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) 2017 KiCad Developers, see CHANGELOG.txt for contributors.
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, you may find one here:
18  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
19  * or you may search the http://www.gnu.org website for the version 2 license,
20  * or you may write to the Free Software Foundation, Inc.,
21  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22  */
23 
24 #include <draw_frame.h>
25 
26 #include <tool/tool_menu.h>
27 #include <tool/tool_interactive.h>
28 
29 #include <tool/context_menu.h>
30 
31 #include <tool/actions.h>
32 #include <tool/zoom_menu.h>
33 #include <tool/grid_menu.h>
34 #include <tool/selection.h>
35 
36 
38  m_menu( &aTool ),
39  m_tool( aTool )
40 {
41 }
42 
43 
45 {
46 }
47 
48 
50 {
51  return m_menu;
52 }
53 
54 
55 void TOOL_MENU::AddSubMenu( std::shared_ptr<CONTEXT_MENU> aSubMenu )
56 {
57  // store a copy of the menu (keeps a reference)
58  m_subMenus.push_back( std::move( aSubMenu ) );
59 }
60 
61 
63 {
64  m_contextMenu = std::unique_ptr<CONTEXT_MENU>(
65  m_menu.Generate( aSelection ) );
66 
67  if( m_contextMenu->GetMenuItemCount() > 0 )
68  {
70  }
71 }
72 
73 
75 {
76  SELECTION dummySelection;
77 
78  ShowContextMenu( dummySelection );
79 }
80 
81 
83 {
84  // m_contextMenu can be null here, that's OK
85  if( evt->Parameter<CONTEXT_MENU*>() == m_contextMenu.get() )
86  {
87  m_contextMenu = nullptr;
88  }
89 }
90 
91 
92 // This makes the factory functions a bit less verbose
94 
96 {
101 
103 
104  m_menu.AddMenu( createOwnSubMenu<ZOOM_MENU>( &aFrame ).get(), false, S_C::ShowAlways, 1000 );
105  m_menu.AddMenu( createOwnSubMenu<GRID_MENU>( &aFrame ).get(), false, S_C::ShowAlways, 1000 );
106 }
static bool ShowAlways(const SELECTION &aSelection)
Function ShowAlways The default condition function (always returns true).
TOOL_INTERACTIVE & m_tool
The tool that owns this menu.
Definition: tool_menu.h:165
void ShowContextMenu()
Function ShowContextMenu.
Definition: tool_menu.cpp:74
~TOOL_MENU()
Destructor, also destructs any submenus created with TOOL_MENU::CreateSubMenu().
Definition: tool_menu.cpp:44
Class CONTEXT_MENU.
Definition: context_menu.h:44
void AddSeparator(const SELECTION_CONDITION &aCondition=SELECTION_CONDITIONS::ShowAlways, int aOrder=ANY_ORDER)
Function AddSeparator()
CONDITIONAL_MENU & GetMenu()
Function GetMenu.
Definition: tool_menu.cpp:49
void AddSubMenu(std::shared_ptr< CONTEXT_MENU > aSubMenu)
Function CreateSubMenu.
Definition: tool_menu.cpp:55
static TOOL_ACTION zoomFitScreen
Definition: actions.h:56
Class that groups generic conditions for selected items.
Class EDA_DRAW_FRAME is the base class for create windows for drawing purpose.
Definition: draw_frame.h:53
CONDITIONAL_MENU m_menu
The conditional model of the menu displayed by the tool.
Definition: tool_menu.h:155
void AddStandardSubMenus(EDA_DRAW_FRAME &aFrame)
Function CreateBasicMenu.
Definition: tool_menu.cpp:95
void SetContextMenu(CONTEXT_MENU *aMenu, CONTEXT_MENU_TRIGGER aTrigger=CMENU_BUTTON)
Function SetContextMenu()
void CloseContextMenu(OPT_TOOL_EVENT &evt)
Function CloseContextMenu.
Definition: tool_menu.cpp:82
void AddMenu(CONTEXT_MENU *aMenu, bool aExpand=false, const SELECTION_CONDITION &aCondition=SELECTION_CONDITIONS::ShowAlways, int aOrder=ANY_ORDER)
Function AddMenu()
static TOOL_ACTION zoomCenter
Definition: actions.h:55
void AddItem(const TOOL_ACTION &aAction, const SELECTION_CONDITION &aCondition=SELECTION_CONDITIONS::ShowAlways, int aOrder=ANY_ORDER)
Function AddItem()
CONTEXT_MENU * Generate(SELECTION &aSelection)
Function Generate()
std::unique_ptr< CONTEXT_MENU > m_contextMenu
The actual menu displayed by the tool.
Definition: tool_menu.h:160
TOOL_MENU(TOOL_INTERACTIVE &aTool)
Function TOOL_MENU.
Definition: tool_menu.cpp:37
std::vector< std::shared_ptr< CONTEXT_MENU > > m_subMenus
Lifetime-managing container of submenus.
Definition: tool_menu.h:170
static TOOL_ACTION zoomIn
Definition: actions.h:51
static TOOL_ACTION zoomOut
Definition: actions.h:52