kicad/kicad/menubar.cpp

265 lines
11 KiB
C++
Raw Normal View History

/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2017 Jean-Pierre Charras, jp.charras at wanadoo.fr
* Copyright (C) 2009 Wayne Stambaugh <stambaughw@verizon.net>
* Copyright (C) 1992-2019 KiCad Developers, see AUTHORS.txt for contributors.
2019-08-14 08:28:07 +00:00
* Copyright (C) 2019 CERN
*
* 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
*/
2016-02-24 21:36:52 +00:00
#include <bitmaps.h>
#include <filehistory.h>
2016-02-24 21:36:52 +00:00
#include <menus_helpers.h>
#include <tool/tool_manager.h>
2019-06-09 21:57:23 +00:00
#include <tool/action_toolbar.h>
#include <tools/kicad_manager_control.h>
#include <tools/kicad_manager_actions.h>
2019-06-09 10:10:19 +00:00
#include "kicad_manager_frame.h"
2016-02-24 21:36:52 +00:00
#include "pgm_kicad.h"
#include "kicad_id.h"
2016-02-24 21:36:52 +00:00
2011-04-17 13:54:17 +00:00
void KICAD_MANAGER_FRAME::ReCreateMenuBar()
2008-11-02 22:53:38 +00:00
{
KICAD_MANAGER_CONTROL* controlTool = m_toolManager->GetTool<KICAD_MANAGER_CONTROL>();
// wxWidgets handles the Mac Application menu behind the scenes, but that means
// we always have to start from scratch with a new wxMenuBar.
wxMenuBar* oldMenuBar = GetMenuBar();
wxMenuBar* menuBar = new wxMenuBar();
//-- File menu -----------------------------------------------------------
//
CONDITIONAL_MENU* fileMenu = new CONDITIONAL_MENU( false, controlTool );
FILE_HISTORY& fileHistory = PgmTop().GetFileHistory();
static FILE_HISTORY_MENU* openRecentMenu;
// Create the menu if it does not exist. Adding a file to/from the history
// will automatically refresh the menu.
if( !openRecentMenu )
{
openRecentMenu = new FILE_HISTORY_MENU( fileHistory, _( "Clear Recent Projects" ) );
openRecentMenu->SetTool( controlTool );
openRecentMenu->SetTitle( _( "Open Recent" ) );
openRecentMenu->SetIcon( recent_xpm );
}
fileMenu->AddItem( KICAD_MANAGER_ACTIONS::newProject, SELECTION_CONDITIONS::ShowAlways );
fileMenu->AddItem( KICAD_MANAGER_ACTIONS::newFromTemplate, SELECTION_CONDITIONS::ShowAlways );
fileMenu->AddItem( KICAD_MANAGER_ACTIONS::openProject, SELECTION_CONDITIONS::ShowAlways );
fileMenu->AddMenu( openRecentMenu,
FILE_HISTORY::FileHistoryNotEmpty( fileHistory ) );
fileMenu->AddSeparator();
fileMenu->AddItem( ACTIONS::saveAs, SELECTION_CONDITIONS::ShowAlways );
fileMenu->AddSeparator();
fileMenu->AddItem( ID_IMPORT_EAGLE_PROJECT,
_( "Import EAGLE Project..." ),
_( "Import EAGLE CAD XML schematic and board" ),
import_project_xpm, SELECTION_CONDITIONS::ShowAlways );
fileMenu->AddSeparator();
fileMenu->AddItem( ID_SAVE_AND_ZIP_FILES,
_( "&Archive Project..." ),
_( "Archive all needed project files into zip archive" ),
zip_xpm, SELECTION_CONDITIONS::ShowAlways );
fileMenu->AddItem( ID_READ_ZIP_ARCHIVE,
_( "&Unarchive Project..." ),
_( "Unarchive project files from zip archive" ),
unzip_xpm, SELECTION_CONDITIONS::ShowAlways );
fileMenu->AddSeparator();
2019-08-18 16:38:42 +00:00
fileMenu->AddQuitOrClose( nullptr, "KiCad" );
fileMenu->Resolve();
//-- View menu -----------------------------------------------------------
//
CONDITIONAL_MENU* viewMenu = new CONDITIONAL_MENU( false, controlTool );
viewMenu->AddItem( ACTIONS::zoomRedraw, SELECTION_CONDITIONS::ShowAlways );
viewMenu->AddSeparator();
viewMenu->AddItem( KICAD_MANAGER_ACTIONS::openTextEditor, SELECTION_CONDITIONS::ShowAlways );
viewMenu->AddItem( ID_BROWSE_IN_FILE_EXPLORER,
_( "Browse Project Files" ), _( "Open project directory in file browser" ),
directory_browser_xpm, SELECTION_CONDITIONS::ShowAlways );
2017-09-06 14:54:15 +00:00
2018-02-22 17:50:32 +00:00
#ifdef __APPLE__
viewMenu->AddSeparator();
2018-02-22 17:50:32 +00:00
#endif
viewMenu->Resolve();
//-- Tools menu -----------------------------------------------
//
CONDITIONAL_MENU* toolsMenu = new CONDITIONAL_MENU( false, controlTool );
toolsMenu->AddItem( KICAD_MANAGER_ACTIONS::editSchematic, SELECTION_CONDITIONS::ShowAlways );
toolsMenu->AddItem( KICAD_MANAGER_ACTIONS::editSymbols, SELECTION_CONDITIONS::ShowAlways );
toolsMenu->AddItem( KICAD_MANAGER_ACTIONS::editPCB, SELECTION_CONDITIONS::ShowAlways );
toolsMenu->AddItem( KICAD_MANAGER_ACTIONS::editFootprints, SELECTION_CONDITIONS::ShowAlways );
toolsMenu->AddSeparator();
toolsMenu->AddItem( KICAD_MANAGER_ACTIONS::viewGerbers, SELECTION_CONDITIONS::ShowAlways );
toolsMenu->AddItem( KICAD_MANAGER_ACTIONS::convertImage, SELECTION_CONDITIONS::ShowAlways );
toolsMenu->AddItem( KICAD_MANAGER_ACTIONS::showCalculator, SELECTION_CONDITIONS::ShowAlways );
toolsMenu->AddItem( KICAD_MANAGER_ACTIONS::editWorksheet, SELECTION_CONDITIONS::ShowAlways );
toolsMenu->AddSeparator();
toolsMenu->AddItem( ID_EDIT_LOCAL_FILE_IN_TEXT_EDITOR,
_( "Edit Local File..." ), _( "Edit local file in text editor" ),
browse_files_xpm, SELECTION_CONDITIONS::ShowAlways );
toolsMenu->Resolve();
//-- Preferences menu -----------------------------------------------
//
CONDITIONAL_MENU* prefsMenu = new CONDITIONAL_MENU( false, controlTool );
prefsMenu->AddItem( ACTIONS::configurePaths, SELECTION_CONDITIONS::ShowAlways );
prefsMenu->AddItem( ACTIONS::showSymbolLibTable, SELECTION_CONDITIONS::ShowAlways );
prefsMenu->AddItem( ACTIONS::showFootprintLibTable, SELECTION_CONDITIONS::ShowAlways );
prefsMenu->AddItem( wxID_PREFERENCES,
2019-06-09 21:57:23 +00:00
_( "Preferences...\tCTRL+," ),
_( "Show preferences for all open tools" ),
preference_xpm, SELECTION_CONDITIONS::ShowAlways );
prefsMenu->AddSeparator();
AddMenuLanguageList( prefsMenu, controlTool );
prefsMenu->Resolve();
//-- Menubar -------------------------------------------------------------
//
menuBar->Append( fileMenu, _( "&File" ) );
2017-09-06 14:54:15 +00:00
menuBar->Append( viewMenu, _( "&View" ) );
menuBar->Append( toolsMenu, _( "&Tools" ) );
menuBar->Append( prefsMenu, _( "&Preferences" ) );
AddStandardHelpMenu( menuBar );
SetMenuBar( menuBar );
delete oldMenuBar;
}
2008-11-02 22:53:38 +00:00
/**
2010-02-14 14:59:43 +00:00
* @brief (Re)Create the horizontal toolbar
2008-11-02 22:53:38 +00:00
*/
2011-04-17 13:54:17 +00:00
void KICAD_MANAGER_FRAME::RecreateBaseHToolbar()
{
if( m_mainToolBar )
m_mainToolBar->Clear();
else
m_mainToolBar = new ACTION_TOOLBAR( this, ID_H_TOOLBAR, wxDefaultPosition, wxDefaultSize,
KICAD_AUI_TB_STYLE | wxAUI_TB_HORZ_LAYOUT );
// New
m_mainToolBar->Add( KICAD_MANAGER_ACTIONS::newProject );
m_mainToolBar->Add( KICAD_MANAGER_ACTIONS::newFromTemplate );
m_mainToolBar->Add( KICAD_MANAGER_ACTIONS::openProject );
2008-11-02 22:53:38 +00:00
KiScaledSeparator( m_mainToolBar, this );
m_mainToolBar->AddTool( ID_SAVE_AND_ZIP_FILES, wxEmptyString,
KiScaledBitmap( zip_xpm, this ),
_( "Archive all project files" ) );
2008-11-02 22:53:38 +00:00
2017-09-06 14:54:15 +00:00
m_mainToolBar->AddTool( ID_READ_ZIP_ARCHIVE, wxEmptyString,
KiScaledBitmap( unzip_xpm, this ),
2017-09-06 14:54:15 +00:00
_( "Unarchive project files from zip archive" ) );
KiScaledSeparator( m_mainToolBar, this );
m_mainToolBar->Add( ACTIONS::zoomRedraw );
2008-11-02 22:53:38 +00:00
KiScaledSeparator( m_mainToolBar, this );
m_mainToolBar->AddTool( ID_BROWSE_IN_FILE_EXPLORER, wxEmptyString,
KiScaledBitmap( directory_browser_xpm, this ),
#ifdef __APPLE__
_( "Reveal project directory in Finder" ) );
#else
_( "Open project directory in file explorer" ) );
#endif
// Create m_mainToolBar
m_mainToolBar->Realize();
2008-11-02 22:53:38 +00:00
}
void KICAD_MANAGER_FRAME::RecreateLauncher()
{
if( m_launcher )
m_launcher->Clear();
else
m_launcher = new ACTION_TOOLBAR( this, ID_H_TOOLBAR, wxDefaultPosition, wxDefaultSize,
KICAD_AUI_TB_STYLE | wxAUI_TB_HORZ_LAYOUT );
// Add tools. Note these KICAD_MANAGER_ACTIONS are defined with a bitmap
// suitable for menus. The icans will be changed later.
m_launcher->Add( KICAD_MANAGER_ACTIONS::editSchematic );
m_launcher->Add( KICAD_MANAGER_ACTIONS::editSymbols );
KiScaledSeparator( m_launcher, this );
m_launcher->Add( KICAD_MANAGER_ACTIONS::editPCB );
m_launcher->Add( KICAD_MANAGER_ACTIONS::editFootprints );
KiScaledSeparator( m_launcher, this );
m_launcher->Add( KICAD_MANAGER_ACTIONS::viewGerbers );
m_launcher->Add( KICAD_MANAGER_ACTIONS::convertImage );
m_launcher->Add( KICAD_MANAGER_ACTIONS::showCalculator );
m_launcher->Add( KICAD_MANAGER_ACTIONS::editWorksheet );
// Now set big icons for these tools:
m_launcher->SetToolBitmap( KICAD_MANAGER_ACTIONS::editSchematic,
KiScaledBitmap( icon_eeschema_xpm, this ) );
m_launcher->SetToolBitmap( KICAD_MANAGER_ACTIONS::editSymbols,
KiScaledBitmap( icon_libedit_xpm, this ) );
m_launcher->SetToolBitmap( KICAD_MANAGER_ACTIONS::editPCB,
KiScaledBitmap( icon_pcbnew_xpm, this ) );
m_launcher->SetToolBitmap( KICAD_MANAGER_ACTIONS::editFootprints,
KiScaledBitmap( icon_modedit_xpm, this ) );
m_launcher->SetToolBitmap( KICAD_MANAGER_ACTIONS::viewGerbers,
KiScaledBitmap( icon_gerbview_xpm, this ) );
m_launcher->SetToolBitmap( KICAD_MANAGER_ACTIONS::convertImage,
KiScaledBitmap( icon_bitmap2component_xpm, this ) );
m_launcher->SetToolBitmap( KICAD_MANAGER_ACTIONS::showCalculator,
KiScaledBitmap( icon_pcbcalculator_xpm, this ) );
m_launcher->SetToolBitmap( KICAD_MANAGER_ACTIONS::editWorksheet,
KiScaledBitmap( icon_pagelayout_editor_xpm, this ) );
// Create mlauncher
m_launcher->Realize();
// And update the visual tools state:
SyncToolbars();
}
void KICAD_MANAGER_FRAME::SyncToolbars()
{
m_launcher->Toggle( KICAD_MANAGER_ACTIONS::editSchematic, m_active_project );
m_launcher->Toggle( KICAD_MANAGER_ACTIONS::editSymbols, m_active_project );
m_launcher->Toggle( KICAD_MANAGER_ACTIONS::editPCB, m_active_project );
m_launcher->Toggle( KICAD_MANAGER_ACTIONS::editFootprints, m_active_project );
m_launcher->Refresh();
}