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.

327 lines
12 KiB

7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2018 Jean-Pierre Charras, jp.charras at wanadoo.fr
  5. * Copyright (C) 2009 Wayne Stambaugh <stambaughw@gmail.com>
  6. * Copyright (C) 1992-2022 KiCad Developers, see AUTHORS.txt for contributors.
  7. * Copyright (C) 2019 CERN
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public License
  11. * as published by the Free Software Foundation; either version 2
  12. * of the License, or (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, you may find one here:
  21. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  22. * or you may search the http://www.gnu.org website for the version 2 license,
  23. * or you may write to the Free Software Foundation, Inc.,
  24. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  25. */
  26. #include <bitmaps.h>
  27. #include <filehistory.h>
  28. #include <kiface_base.h>
  29. #include <menus_helpers.h>
  30. #include <schematic.h>
  31. #include <tool/action_manager.h>
  32. #include <tool/action_menu.h>
  33. #include <tool/tool_manager.h>
  34. #include <tools/ee_selection_tool.h>
  35. #include <tools/ee_actions.h>
  36. #include "eeschema_id.h"
  37. #include "sch_edit_frame.h"
  38. #include <widgets/wx_menubar.h>
  39. #include <advanced_config.h>
  40. void SCH_EDIT_FRAME::ReCreateMenuBar()
  41. {
  42. EE_SELECTION_TOOL* selTool = m_toolManager->GetTool<EE_SELECTION_TOOL>();
  43. // wxWidgets handles the Mac Application menu behind the scenes, but that means
  44. // we always have to start from scratch with a new wxMenuBar.
  45. wxMenuBar* oldMenuBar = GetMenuBar();
  46. WX_MENUBAR* menuBar = new WX_MENUBAR();
  47. //-- File menu -----------------------------------------------------------
  48. //
  49. ACTION_MENU* fileMenu = new ACTION_MENU( false, selTool );
  50. static ACTION_MENU* openRecentMenu;
  51. if( Kiface().IsSingle() ) // When not under a project mgr
  52. {
  53. FILE_HISTORY& fileHistory = GetFileHistory();
  54. // Add this menu to the list of menus managed by the file history
  55. // (the file history will be updated when adding/removing files in history)
  56. if( !openRecentMenu )
  57. {
  58. openRecentMenu = new ACTION_MENU( false, selTool );
  59. openRecentMenu->SetIcon( BITMAPS::recent );
  60. fileHistory.UseMenu( openRecentMenu );
  61. fileHistory.AddFilesToMenu( openRecentMenu );
  62. }
  63. // Ensure the title is up to date after changing language
  64. openRecentMenu->SetTitle( _( "Open Recent" ) );
  65. fileHistory.UpdateClearText( openRecentMenu, _( "Clear Recent Files" ) );
  66. fileMenu->Add( ACTIONS::doNew );
  67. fileMenu->Add( ACTIONS::open );
  68. wxMenuItem* item = fileMenu->Add( openRecentMenu->Clone() );
  69. // Add the file menu condition here since it needs the item ID for the submenu
  70. ACTION_CONDITIONS cond;
  71. cond.Enable( FILE_HISTORY::FileHistoryNotEmpty( fileHistory ) );
  72. RegisterUIUpdateHandler( item->GetId(), cond );
  73. fileMenu->AppendSeparator();
  74. }
  75. fileMenu->Add( ACTIONS::save );
  76. if( Kiface().IsSingle() )
  77. fileMenu->Add( ACTIONS::saveAs );
  78. else
  79. fileMenu->Add( EE_ACTIONS::saveCurrSheetCopyAs );
  80. fileMenu->Add( ACTIONS::revert );
  81. fileMenu->AppendSeparator();
  82. fileMenu->Add( _( "Insert Schematic Sheet Content..." ),
  83. _( "Append schematic sheet content from another project to the current sheet" ),
  84. ID_APPEND_PROJECT,
  85. BITMAPS::add_document );
  86. fileMenu->AppendSeparator();
  87. // Import submenu
  88. ACTION_MENU* submenuImport = new ACTION_MENU( false, selTool );
  89. submenuImport->SetTitle( _( "Import" ) );
  90. submenuImport->SetIcon( BITMAPS::import );
  91. submenuImport->Add( _( "Non-KiCad Schematic..." ),
  92. _( "Replace current schematic sheet with one imported from another application" ),
  93. ID_IMPORT_NON_KICAD_SCH,
  94. BITMAPS::import_document );
  95. submenuImport->Add( EE_ACTIONS::importFPAssignments, ACTION_MENU::NORMAL, _( "Footprint Assignments..." ) );
  96. fileMenu->Add( submenuImport );
  97. // Export submenu
  98. ACTION_MENU* submenuExport = new ACTION_MENU( false, selTool );
  99. submenuExport->SetTitle( _( "Export" ) );
  100. submenuExport->SetIcon( BITMAPS::export_file );
  101. submenuExport->Add( EE_ACTIONS::drawSheetOnClipboard, ACTION_MENU::NORMAL, _( "Drawing to Clipboard" ) );
  102. submenuExport->Add( EE_ACTIONS::exportNetlist, ACTION_MENU::NORMAL, _( "Netlist..." ) );
  103. submenuExport->Add( EE_ACTIONS::exportSymbolsToLibrary, ACTION_MENU::NORMAL,
  104. _( "Symbols to Library..." ) );
  105. submenuExport->Add( EE_ACTIONS::exportSymbolsToNewLibrary, ACTION_MENU::NORMAL,
  106. _( "Symbols to New Library..." ) );
  107. fileMenu->Add( submenuExport );
  108. fileMenu->AppendSeparator();
  109. fileMenu->Add( EE_ACTIONS::schematicSetup );
  110. fileMenu->AppendSeparator();
  111. fileMenu->Add( ACTIONS::pageSettings );
  112. fileMenu->Add( ACTIONS::print );
  113. fileMenu->Add( ACTIONS::plot );
  114. fileMenu->AppendSeparator();
  115. fileMenu->AddQuitOrClose( &Kiface(), _( "Schematic Editor" ) );
  116. //-- Edit menu -----------------------------------------------------------
  117. //
  118. ACTION_MENU* editMenu = new ACTION_MENU( false, selTool );
  119. editMenu->Add( ACTIONS::undo );
  120. editMenu->Add( ACTIONS::redo );
  121. editMenu->AppendSeparator();
  122. editMenu->Add( ACTIONS::cut );
  123. editMenu->Add( ACTIONS::copy );
  124. editMenu->Add( ACTIONS::paste );
  125. editMenu->Add( ACTIONS::pasteSpecial );
  126. editMenu->Add( ACTIONS::doDelete );
  127. editMenu->AppendSeparator();
  128. editMenu->Add( ACTIONS::selectAll );
  129. editMenu->AppendSeparator();
  130. editMenu->Add( ACTIONS::find );
  131. editMenu->Add( ACTIONS::findAndReplace );
  132. editMenu->AppendSeparator();
  133. editMenu->Add( ACTIONS::deleteTool );
  134. editMenu->Add( EE_ACTIONS::editTextAndGraphics );
  135. editMenu->Add( EE_ACTIONS::changeSymbols );
  136. editMenu->Add( EE_ACTIONS::editPageNumber );
  137. //-- View menu -----------------------------------------------------------
  138. //
  139. ACTION_MENU* viewMenu = new ACTION_MENU( false, selTool );
  140. viewMenu->Add( ACTIONS::showSymbolBrowser );
  141. viewMenu->Add( EE_ACTIONS::showHierarchy, ACTION_MENU::CHECK );
  142. viewMenu->Add( EE_ACTIONS::navigateBack );
  143. viewMenu->Add( EE_ACTIONS::navigateUp );
  144. viewMenu->Add( EE_ACTIONS::navigateForward );
  145. viewMenu->Add( EE_ACTIONS::navigatePrevious );
  146. viewMenu->Add( EE_ACTIONS::navigateNext );
  147. viewMenu->AppendSeparator();
  148. viewMenu->Add( ACTIONS::zoomInCenter );
  149. viewMenu->Add( ACTIONS::zoomOutCenter );
  150. viewMenu->Add( ACTIONS::zoomFitScreen );
  151. viewMenu->Add( ACTIONS::zoomFitObjects );
  152. viewMenu->Add( ACTIONS::zoomTool );
  153. viewMenu->Add( ACTIONS::zoomRedraw );
  154. viewMenu->AppendSeparator();
  155. viewMenu->Add( ACTIONS::toggleGrid, ACTION_MENU::CHECK );
  156. viewMenu->Add( ACTIONS::gridProperties );
  157. // Units submenu
  158. ACTION_MENU* unitsSubMenu = new ACTION_MENU( false, selTool );
  159. unitsSubMenu->SetTitle( _( "&Units" ) );
  160. unitsSubMenu->SetIcon( BITMAPS::unit_mm );
  161. unitsSubMenu->Add( ACTIONS::inchesUnits, ACTION_MENU::CHECK );
  162. unitsSubMenu->Add( ACTIONS::milsUnits, ACTION_MENU::CHECK );
  163. unitsSubMenu->Add( ACTIONS::millimetersUnits, ACTION_MENU::CHECK );
  164. viewMenu->Add( unitsSubMenu );
  165. viewMenu->Add( ACTIONS::toggleCursorStyle, ACTION_MENU::CHECK );
  166. viewMenu->AppendSeparator();
  167. viewMenu->Add( EE_ACTIONS::toggleHiddenPins, ACTION_MENU::CHECK );
  168. viewMenu->Add( EE_ACTIONS::toggleHiddenFields, ACTION_MENU::CHECK );
  169. viewMenu->Add( EE_ACTIONS::toggleERCErrors, ACTION_MENU::CHECK );
  170. viewMenu->Add( EE_ACTIONS::toggleERCWarnings, ACTION_MENU::CHECK );
  171. viewMenu->Add( EE_ACTIONS::toggleERCExclusions, ACTION_MENU::CHECK );
  172. #ifdef __APPLE__
  173. viewMenu->AppendSeparator();
  174. #endif
  175. //-- Place menu -----------------------------------------------------------
  176. //
  177. ACTION_MENU* placeMenu = new ACTION_MENU( false, selTool );
  178. placeMenu->Add( EE_ACTIONS::placeSymbol );
  179. placeMenu->Add( EE_ACTIONS::placePower );
  180. placeMenu->Add( EE_ACTIONS::drawWire );
  181. placeMenu->Add( EE_ACTIONS::drawBus );
  182. placeMenu->Add( EE_ACTIONS::placeBusWireEntry );
  183. placeMenu->Add( EE_ACTIONS::placeNoConnect );
  184. placeMenu->Add( EE_ACTIONS::placeJunction );
  185. placeMenu->Add( EE_ACTIONS::placeLabel );
  186. placeMenu->Add( EE_ACTIONS::placeClassLabel );
  187. placeMenu->Add( EE_ACTIONS::placeGlobalLabel );
  188. placeMenu->AppendSeparator();
  189. placeMenu->Add( EE_ACTIONS::placeHierLabel );
  190. placeMenu->Add( EE_ACTIONS::drawSheet );
  191. placeMenu->Add( EE_ACTIONS::importSheetPin );
  192. placeMenu->AppendSeparator();
  193. placeMenu->Add( EE_ACTIONS::placeSchematicText );
  194. placeMenu->Add( EE_ACTIONS::drawTextBox );
  195. placeMenu->Add( EE_ACTIONS::drawRectangle );
  196. placeMenu->Add( EE_ACTIONS::drawCircle );
  197. placeMenu->Add( EE_ACTIONS::drawArc );
  198. placeMenu->Add( EE_ACTIONS::drawLines );
  199. placeMenu->Add( EE_ACTIONS::placeImage );
  200. //-- Inspect menu -----------------------------------------------
  201. //
  202. ACTION_MENU* inspectMenu = new ACTION_MENU( false, selTool );
  203. inspectMenu->Add( EE_ACTIONS::runERC );
  204. inspectMenu->Add( ACTIONS::prevMarker );
  205. inspectMenu->Add( ACTIONS::nextMarker );
  206. inspectMenu->Add( ACTIONS::excludeMarker );
  207. #ifdef KICAD_SPICE
  208. inspectMenu->AppendSeparator();
  209. inspectMenu->Add( EE_ACTIONS::runSimulation );
  210. #endif
  211. //-- Tools menu -----------------------------------------------
  212. //
  213. ACTION_MENU* toolsMenu = new ACTION_MENU( false, selTool );
  214. wxMenuItem* update = toolsMenu->Add( ACTIONS::updatePcbFromSchematic );
  215. update->Enable( !Kiface().IsSingle() );
  216. update = toolsMenu->Add( ACTIONS::updateSchematicFromPcb );
  217. update->Enable( !Kiface().IsSingle() );
  218. toolsMenu->Add( EE_ACTIONS::showPcbNew );
  219. toolsMenu->AppendSeparator();
  220. toolsMenu->Add( ACTIONS::showSymbolEditor );
  221. toolsMenu->Add( EE_ACTIONS::updateSymbols );
  222. toolsMenu->AppendSeparator();
  223. toolsMenu->Add( EE_ACTIONS::rescueSymbols );
  224. toolsMenu->Add( EE_ACTIONS::remapSymbols );
  225. if( ADVANCED_CFG::GetCfg().m_ShowRepairSchematic )
  226. toolsMenu->Add( EE_ACTIONS::repairSchematic );
  227. toolsMenu->AppendSeparator();
  228. toolsMenu->Add( EE_ACTIONS::editSymbolFields );
  229. toolsMenu->Add( EE_ACTIONS::editSymbolLibraryLinks );
  230. toolsMenu->AppendSeparator();
  231. toolsMenu->Add( EE_ACTIONS::annotate );
  232. toolsMenu->AppendSeparator();
  233. toolsMenu->Add( EE_ACTIONS::assignFootprints );
  234. toolsMenu->Add( EE_ACTIONS::generateBOM );
  235. //-- Preferences menu -----------------------------------------------
  236. //
  237. ACTION_MENU* prefsMenu = new ACTION_MENU( false, selTool );
  238. prefsMenu->Add( ACTIONS::configurePaths );
  239. prefsMenu->Add( ACTIONS::showSymbolLibTable );
  240. // We can't use ACTIONS::showPreferences yet because wxWidgets moves this on
  241. // Mac, and it needs the wxID_PREFERENCES id to find it.
  242. prefsMenu->Add( _( "Preferences..." ) + "\tCtrl+,",
  243. _( "Show preferences for all open tools" ),
  244. wxID_PREFERENCES,
  245. BITMAPS::preference );
  246. prefsMenu->AppendSeparator();
  247. AddMenuLanguageList( prefsMenu, selTool );
  248. //-- Menubar -------------------------------------------------------------
  249. //
  250. menuBar->Append( fileMenu, _( "&File" ) );
  251. menuBar->Append( editMenu, _( "&Edit" ) );
  252. menuBar->Append( viewMenu, _( "&View" ) );
  253. menuBar->Append( placeMenu, _( "&Place" ) );
  254. menuBar->Append( inspectMenu, _( "&Inspect" ) );
  255. menuBar->Append( toolsMenu, _( "&Tools" ) );
  256. menuBar->Append( prefsMenu, _( "P&references" ) );
  257. AddStandardHelpMenu( menuBar );
  258. SetMenuBar( menuBar );
  259. delete oldMenuBar;
  260. }