2017-01-11 17:22:53 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2020-12-27 00:41:04 +00:00
|
|
|
* Copyright (C) 2017-2020 KiCad Developers, see AUTHORS.txt for contributors.
|
2017-01-11 17:22:53 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, you may find one here:
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 2 license,
|
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef TOOLS_TOOL_MENU__H_
|
|
|
|
#define TOOLS_TOOL_MENU__H_
|
|
|
|
|
2017-02-28 03:04:44 +00:00
|
|
|
#include <tool/conditional_menu.h>
|
|
|
|
#include <tool/tool_event.h>
|
2017-01-11 17:22:53 +00:00
|
|
|
|
|
|
|
#include <vector>
|
|
|
|
#include <memory>
|
|
|
|
|
2019-05-14 11:14:00 +00:00
|
|
|
class ACTION_MENU;
|
2017-01-11 17:22:53 +00:00
|
|
|
|
|
|
|
/**
|
2020-12-27 00:41:04 +00:00
|
|
|
* Manage a #CONDITIONAL_MENU and some number of CONTEXT_MENUs as sub-menus.
|
2017-01-11 17:22:53 +00:00
|
|
|
*
|
2020-12-27 00:41:04 +00:00
|
|
|
* Each "top-level" interactive tool can have one of these, and other tools can contribute
|
|
|
|
* #CONTEXT_MENUS to it. There are also helper functions for adding common sets of menu
|
|
|
|
* items, for example zoom and grid controls.
|
2017-01-11 17:22:53 +00:00
|
|
|
*/
|
|
|
|
class TOOL_MENU
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
/**
|
2020-12-27 00:41:04 +00:00
|
|
|
* Construct a new TOOL_MENU for a specific tool.
|
2017-01-11 17:22:53 +00:00
|
|
|
*
|
2020-12-27 00:41:04 +00:00
|
|
|
* This menu will be empty - it's up to the caller to add the relevant items. This can be
|
|
|
|
* done directly, using the reference returned by TOOL_MENU::GetMenu(), or the helpers for
|
|
|
|
* common command sets can be used, or a combination of the two.
|
2017-01-11 17:22:53 +00:00
|
|
|
*/
|
|
|
|
TOOL_MENU( TOOL_INTERACTIVE& aTool );
|
|
|
|
|
|
|
|
/**
|
2020-12-27 00:41:04 +00:00
|
|
|
* Destruct any submenus created with TOOL_MENU::CreateSubMenu().
|
2017-01-11 17:22:53 +00:00
|
|
|
*/
|
|
|
|
~TOOL_MENU();
|
|
|
|
|
|
|
|
/**
|
2020-12-27 00:41:04 +00:00
|
|
|
* @return reference to the CONDITIONAL_MENU model, which can be used by tools to add
|
|
|
|
* their own commands to the menu.
|
2017-01-11 17:22:53 +00:00
|
|
|
*/
|
|
|
|
CONDITIONAL_MENU& GetMenu();
|
|
|
|
|
|
|
|
/**
|
2020-12-27 00:41:04 +00:00
|
|
|
* Store a submenu of this menu model. This can be shared with other menu models.
|
2017-01-11 17:22:53 +00:00
|
|
|
*
|
2020-12-27 00:41:04 +00:00
|
|
|
* It is the callers responsibility to add the submenu to m_menu (via GetMenu() ) in the
|
|
|
|
* right way, as well as to set the tool with SetTool(), since it's not a given that the
|
|
|
|
* menu's tool is the tool that directly owns this #TOOL_MENU.
|
2017-01-11 17:22:53 +00:00
|
|
|
*
|
|
|
|
* @param aSubMenu: a sub menu to add
|
|
|
|
*/
|
2019-05-14 11:14:00 +00:00
|
|
|
void AddSubMenu( std::shared_ptr<ACTION_MENU> aSubMenu );
|
2017-01-11 17:22:53 +00:00
|
|
|
|
2018-11-13 13:30:56 +00:00
|
|
|
/**
|
|
|
|
* @return the list of submenus from this menu
|
|
|
|
*/
|
|
|
|
std::vector<std::shared_ptr<ACTION_MENU> >& GetSubMenus()
|
|
|
|
{
|
|
|
|
return m_subMenus;
|
|
|
|
}
|
|
|
|
|
2017-01-11 17:22:53 +00:00
|
|
|
/**
|
2020-12-27 00:41:04 +00:00
|
|
|
* Helper function to set and immediately show a #CONDITIONAL_MENU in concert with the
|
|
|
|
* given #SELECTION
|
2017-01-11 17:22:53 +00:00
|
|
|
*
|
2020-12-27 00:41:04 +00:00
|
|
|
* You don't have to use this function, if the caller has a different way to show the
|
|
|
|
* menu, it can create one from the reference returned by TOOL_MENU::GetMenu(), but it
|
|
|
|
* will have to be managed externally to this class.
|
2017-01-11 17:22:53 +00:00
|
|
|
*/
|
|
|
|
void ShowContextMenu( SELECTION& aSelection );
|
|
|
|
|
|
|
|
/**
|
2020-12-27 00:41:04 +00:00
|
|
|
* Helper function to show a context menu without any selection for tools that can't
|
|
|
|
* make selections.
|
2017-01-11 17:22:53 +00:00
|
|
|
*/
|
|
|
|
void ShowContextMenu();
|
|
|
|
|
|
|
|
private:
|
|
|
|
/**
|
2020-12-27 00:41:04 +00:00
|
|
|
* The conditional menu displayed by the tool.
|
2017-01-11 17:22:53 +00:00
|
|
|
*/
|
|
|
|
CONDITIONAL_MENU m_menu;
|
|
|
|
|
|
|
|
/**
|
2020-12-27 00:41:04 +00:00
|
|
|
* The tool that owns this menu.
|
2017-01-11 17:22:53 +00:00
|
|
|
*/
|
|
|
|
TOOL_INTERACTIVE& m_tool;
|
|
|
|
|
|
|
|
/**
|
2020-12-27 00:41:04 +00:00
|
|
|
* Lifetime-managing container of submenus.
|
2017-01-11 17:22:53 +00:00
|
|
|
*/
|
2019-05-14 11:14:00 +00:00
|
|
|
std::vector<std::shared_ptr<ACTION_MENU> > m_subMenus;
|
2017-01-11 17:22:53 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // TOOLS_TOOL_MENU__H_
|