You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

97 lines
2.7 KiB

  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2017-2019 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. #include <draw_frame.h>
  24. #include <tool/tool_menu.h>
  25. #include <tool/tool_interactive.h>
  26. #include <tool/action_menu.h>
  27. #include <tool/actions.h>
  28. #include <tool/zoom_menu.h>
  29. #include <tool/grid_menu.h>
  30. #include <tool/selection.h>
  31. TOOL_MENU::TOOL_MENU( TOOL_INTERACTIVE& aTool ) :
  32. m_menu( true, &aTool ),
  33. m_tool( aTool )
  34. {
  35. }
  36. TOOL_MENU::~TOOL_MENU()
  37. {
  38. }
  39. CONDITIONAL_MENU& TOOL_MENU::GetMenu()
  40. {
  41. return m_menu;
  42. }
  43. void TOOL_MENU::AddSubMenu( std::shared_ptr<ACTION_MENU> aSubMenu )
  44. {
  45. // store a copy of the menu (keeps a reference)
  46. m_subMenus.push_back( std::move( aSubMenu ) );
  47. }
  48. void TOOL_MENU::ShowContextMenu( SELECTION& aSelection )
  49. {
  50. m_menu.Evaluate( aSelection );
  51. m_menu.UpdateAll();
  52. m_menu.ClearDirty();
  53. m_tool.SetContextMenu( &m_menu, CMENU_NOW );
  54. }
  55. void TOOL_MENU::ShowContextMenu()
  56. {
  57. m_menu.SetDirty();
  58. m_tool.SetContextMenu( &m_menu, CMENU_NOW );
  59. }
  60. void TOOL_MENU::CloseContextMenu( OPT_TOOL_EVENT& evt )
  61. {
  62. }
  63. // This makes the factory functions a bit less verbose
  64. using S_C = SELECTION_CONDITIONS;
  65. void TOOL_MENU::AddStandardSubMenus( EDA_DRAW_FRAME* aFrame )
  66. {
  67. m_menu.AddItem( ACTIONS::zoomCenter, S_C::ShowAlways, 1000 );
  68. m_menu.AddItem( ACTIONS::zoomIn, S_C::ShowAlways, 1000 );
  69. m_menu.AddItem( ACTIONS::zoomOut, S_C::ShowAlways, 1000 );
  70. m_menu.AddItem( ACTIONS::zoomFitScreen, S_C::ShowAlways, 1000 );
  71. m_menu.AddSeparator(SELECTION_CONDITIONS::ShowAlways, 1000 );
  72. if( aFrame )
  73. {
  74. m_menu.AddMenu( createOwnSubMenu<ZOOM_MENU>( aFrame ).get(), S_C::ShowAlways, 1000 );
  75. m_menu.AddMenu( createOwnSubMenu<GRID_MENU>( aFrame ).get(), S_C::ShowAlways, 1000 );
  76. }
  77. }