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.

160 lines
5.7 KiB

  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, you may find one here:
  20. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  21. * or you may search the http://www.gnu.org website for the version 2 license,
  22. * or you may write to the Free Software Foundation, Inc.,
  23. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  24. */
  25. #include <bitmaps.h>
  26. #include <file_history.h>
  27. #include <kiface_base.h>
  28. #include <tool/action_manager.h>
  29. #include <tool/action_menu.h>
  30. #include <tool/tool_manager.h>
  31. #include <widgets/wx_menubar.h>
  32. #include "pl_editor_frame.h"
  33. #include "pl_editor_id.h"
  34. #include "tools/pl_actions.h"
  35. #include "tools/pl_selection_tool.h"
  36. void PL_EDITOR_FRAME::doReCreateMenuBar()
  37. {
  38. PL_SELECTION_TOOL* selTool = m_toolManager->GetTool<PL_SELECTION_TOOL>();
  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. static ACTION_MENU* openRecentMenu; // Open Recent submenu, static to remember this menu
  44. FILE_HISTORY& recentFiles = GetFileHistory();
  45. // Create the menu if it does not exist. Adding a file to/from the history
  46. // will automatically refresh the menu.
  47. if( !openRecentMenu )
  48. {
  49. openRecentMenu = new ACTION_MENU( false, selTool );
  50. openRecentMenu->SetIcon( BITMAPS::recent );
  51. recentFiles.UseMenu( openRecentMenu );
  52. recentFiles.AddFilesToMenu();
  53. }
  54. // Ensure the title is up to date after changing language
  55. openRecentMenu->SetTitle( _( "Open Recent" ) );
  56. recentFiles.UpdateClearText( openRecentMenu, _( "Clear Recent Files" ) );
  57. //-- File menu -------------------------------------------------------
  58. //
  59. ACTION_MENU* fileMenu = new ACTION_MENU( false, selTool );
  60. fileMenu->Add( ACTIONS::doNew );
  61. fileMenu->Add( ACTIONS::open );
  62. wxMenuItem* item = fileMenu->Add( openRecentMenu->Clone() );
  63. // Add the file menu condition here since it needs the item ID for the submenu
  64. ACTION_CONDITIONS cond;
  65. cond.Enable( FILE_HISTORY::FileHistoryNotEmpty( recentFiles ) );
  66. RegisterUIUpdateHandler( item->GetId(), cond );
  67. fileMenu->AppendSeparator();
  68. fileMenu->Add( ACTIONS::save );
  69. fileMenu->Add( ACTIONS::saveAs );
  70. fileMenu->AppendSeparator();
  71. fileMenu->Add( ACTIONS::print );
  72. fileMenu->AppendSeparator();
  73. fileMenu->AddClose( _( "Drawing Sheet Editor" ) );
  74. fileMenu->AddQuit( _( "Drawing Sheet Editor" ) );
  75. //-- Edit menu -------------------------------------------------------
  76. //
  77. ACTION_MENU* editMenu = new ACTION_MENU( false, selTool );
  78. editMenu->Add( ACTIONS::undo );
  79. editMenu->Add( ACTIONS::redo );
  80. editMenu->AppendSeparator();
  81. editMenu->Add( ACTIONS::cut );
  82. editMenu->Add( ACTIONS::copy );
  83. editMenu->Add( ACTIONS::paste );
  84. editMenu->Add( ACTIONS::doDelete );
  85. //-- View menu -------------------------------------------------------
  86. //
  87. ACTION_MENU* viewMenu = new ACTION_MENU( false, selTool );
  88. viewMenu->Add( ACTIONS::zoomInCenter );
  89. viewMenu->Add( ACTIONS::zoomOutCenter );
  90. viewMenu->Add( ACTIONS::zoomFitScreen );
  91. viewMenu->Add( ACTIONS::zoomTool );
  92. viewMenu->Add( ACTIONS::zoomRedraw );
  93. viewMenu->AppendSeparator();
  94. viewMenu->Add( PL_ACTIONS::previewSettings );
  95. #ifdef __APPLE__
  96. // Add a separator only on macOS because the OS adds menu items to the view menu after ours
  97. viewMenu->AppendSeparator();
  98. #endif
  99. //-- Place menu -------------------------------------------------------
  100. //
  101. ACTION_MENU* placeMenu = new ACTION_MENU( false, selTool );
  102. placeMenu->Add( PL_ACTIONS::drawLine );
  103. placeMenu->Add( PL_ACTIONS::drawRectangle );
  104. placeMenu->Add( PL_ACTIONS::placeText );
  105. placeMenu->Add( PL_ACTIONS::placeImage );
  106. placeMenu->AppendSeparator();
  107. placeMenu->Add( PL_ACTIONS::appendImportedDrawingSheet );
  108. //-- Inspector menu -------------------------------------------------------
  109. //
  110. ACTION_MENU* inspectorMenu = new ACTION_MENU( false, selTool );
  111. inspectorMenu->Add( PL_ACTIONS::showInspector );
  112. //-- Preferences menu --------------------------------------------------
  113. //
  114. ACTION_MENU* preferencesMenu = new ACTION_MENU( false, selTool );
  115. preferencesMenu->Add( ACTIONS::openPreferences );
  116. // Language submenu
  117. AddMenuLanguageList( preferencesMenu, selTool );
  118. //-- Menubar -----------------------------------------------------------
  119. //
  120. menuBar->Append( fileMenu, _( "&File" ) );
  121. menuBar->Append( editMenu, _( "&Edit" ) );
  122. menuBar->Append( viewMenu, _( "&View" ) );
  123. menuBar->Append( placeMenu, _( "&Place" ) );
  124. menuBar->Append( inspectorMenu, _( "&Inspect" ) );
  125. menuBar->Append( preferencesMenu, _( "P&references" ) );
  126. AddStandardHelpMenu( menuBar );
  127. SetMenuBar( menuBar );
  128. delete oldMenuBar;
  129. }