mirror of
https://gitlab.com/kicad/code/kicad.git
synced 2025-04-19 18:31:40 +00:00
Move project manager actions to the tool framework
This commit is contained in:
parent
ea2f8a63c1
commit
29c62e9d9a
@ -57,7 +57,7 @@ void KICAD_MANAGER_FRAME::OnClearFileHistory( wxCommandEvent& aEvent )
|
||||
}
|
||||
|
||||
|
||||
void KICAD_MANAGER_FRAME::OnUnarchiveFiles( wxCommandEvent& event )
|
||||
void KICAD_MANAGER_FRAME::UnarchiveFiles()
|
||||
{
|
||||
wxFileName fn = Prj().GetProjectFullName();
|
||||
|
||||
@ -104,31 +104,3 @@ void KICAD_MANAGER_FRAME::OnUnarchiveFiles( wxCommandEvent& event )
|
||||
RefreshProjectTree();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void KICAD_MANAGER_FRAME::OnArchiveFiles( wxCommandEvent& event )
|
||||
{
|
||||
wxFileName fileName = GetProjectFileName();
|
||||
|
||||
fileName.SetExt( FILEEXT::ArchiveFileExtension );
|
||||
|
||||
wxFileDialog dlg( this, _( "Archive Project Files" ),
|
||||
fileName.GetPath(), fileName.GetFullName(),
|
||||
FILEEXT::ZipFileWildcard(), wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
|
||||
|
||||
if( dlg.ShowModal() == wxID_CANCEL )
|
||||
return;
|
||||
|
||||
wxFileName zipFile = dlg.GetPath();
|
||||
|
||||
wxString currdirname = fileName.GetPathWithSep();
|
||||
wxDir dir( currdirname );
|
||||
|
||||
if( !dir.IsOpened() ) // wxWidgets display a error message on issue.
|
||||
return;
|
||||
|
||||
STATUSBAR_REPORTER reporter( GetStatusBar(), 1 );
|
||||
PROJECT_ARCHIVER archiver;
|
||||
|
||||
archiver.Archive( currdirname, zipFile.GetFullPath(), reporter, true, true );
|
||||
}
|
||||
|
@ -64,9 +64,6 @@ enum id_kicad_frm {
|
||||
ID_PROJECT_RENAME,
|
||||
|
||||
ID_EDIT_LOCAL_FILE_IN_TEXT_EDITOR,
|
||||
ID_BROWSE_IN_FILE_EXPLORER,
|
||||
ID_SAVE_AND_ZIP_FILES,
|
||||
ID_READ_ZIP_ARCHIVE,
|
||||
ID_INIT_WATCHED_PATHS,
|
||||
ID_IMPORT_CADSTAR_ARCHIVE_PROJECT,
|
||||
ID_IMPORT_EAGLE_PROJECT,
|
||||
|
@ -100,9 +100,6 @@ BEGIN_EVENT_TABLE( KICAD_MANAGER_FRAME, EDA_BASE_FRAME )
|
||||
// Menu events
|
||||
EVT_MENU( wxID_EXIT, KICAD_MANAGER_FRAME::OnExit )
|
||||
EVT_MENU( ID_EDIT_LOCAL_FILE_IN_TEXT_EDITOR, KICAD_MANAGER_FRAME::OnOpenFileInTextEditor )
|
||||
EVT_MENU( ID_BROWSE_IN_FILE_EXPLORER, KICAD_MANAGER_FRAME::OnBrowseInFileExplorer )
|
||||
EVT_MENU( ID_SAVE_AND_ZIP_FILES, KICAD_MANAGER_FRAME::OnArchiveFiles )
|
||||
EVT_MENU( ID_READ_ZIP_ARCHIVE, KICAD_MANAGER_FRAME::OnUnarchiveFiles )
|
||||
EVT_MENU( ID_IMPORT_CADSTAR_ARCHIVE_PROJECT, KICAD_MANAGER_FRAME::OnImportCadstarArchiveFiles )
|
||||
EVT_MENU( ID_IMPORT_EAGLE_PROJECT, KICAD_MANAGER_FRAME::OnImportEagleFiles )
|
||||
EVT_MENU( ID_IMPORT_EASYEDA_PROJECT, KICAD_MANAGER_FRAME::OnImportEasyEdaFiles )
|
||||
@ -437,6 +434,7 @@ void KICAD_MANAGER_FRAME::setupUIConditions()
|
||||
|
||||
manager->SetConditions( ACTIONS::saveAs, activeProjectCond );
|
||||
manager->SetConditions( KICAD_MANAGER_ACTIONS::closeProject, activeProjectCond );
|
||||
manager->SetConditions( KICAD_MANAGER_ACTIONS::archiveProject, activeProjectCond );
|
||||
manager->SetConditions( KICAD_MANAGER_ACTIONS::newJobsetFile, activeProjectCond );
|
||||
manager->SetConditions( KICAD_MANAGER_ACTIONS::openJobsetFile, activeProjectCond );
|
||||
|
||||
@ -446,9 +444,6 @@ void KICAD_MANAGER_FRAME::setupUIConditions()
|
||||
manager->SetConditions( ACTIONS::copy, ENABLE( SELECTION_CONDITIONS::ShowNever ) );
|
||||
manager->SetConditions( ACTIONS::paste, ENABLE( SELECTION_CONDITIONS::ShowNever ) );
|
||||
|
||||
// TODO: Switch this to an action
|
||||
RegisterUIUpdateHandler( ID_SAVE_AND_ZIP_FILES, activeProjectCond );
|
||||
|
||||
#undef ENABLE
|
||||
}
|
||||
|
||||
@ -958,13 +953,6 @@ void KICAD_MANAGER_FRAME::OnOpenFileInTextEditor( wxCommandEvent& event )
|
||||
}
|
||||
|
||||
|
||||
void KICAD_MANAGER_FRAME::OnBrowseInFileExplorer( wxCommandEvent& event )
|
||||
{
|
||||
// open project directory in host OS's file explorer
|
||||
LaunchExternal( Prj().GetProjectPath() );
|
||||
}
|
||||
|
||||
|
||||
void KICAD_MANAGER_FRAME::RefreshProjectTree()
|
||||
{
|
||||
m_leftWin->ReCreateTreePrj();
|
||||
|
@ -54,11 +54,9 @@ public:
|
||||
void doCloseWindow() override;
|
||||
void OnSize( wxSizeEvent& event ) override;
|
||||
|
||||
void OnArchiveFiles( wxCommandEvent& event );
|
||||
void OnUnarchiveFiles( wxCommandEvent& event );
|
||||
void UnarchiveFiles();
|
||||
|
||||
void OnOpenFileInTextEditor( wxCommandEvent& event );
|
||||
void OnBrowseInFileExplorer( wxCommandEvent& event );
|
||||
|
||||
void OnFileHistory( wxCommandEvent& event );
|
||||
void OnClearFileHistory( wxCommandEvent& aEvent );
|
||||
|
@ -138,15 +138,8 @@ void KICAD_MANAGER_FRAME::doReCreateMenuBar()
|
||||
fileMenu->Add( importMenu );
|
||||
|
||||
fileMenu->AppendSeparator();
|
||||
fileMenu->Add( _( "&Archive Project..." ),
|
||||
_( "Archive all needed project files into zip archive" ),
|
||||
ID_SAVE_AND_ZIP_FILES,
|
||||
BITMAPS::zip );
|
||||
|
||||
fileMenu->Add( _( "&Unarchive Project..." ),
|
||||
_( "Unarchive project files from zip archive" ),
|
||||
ID_READ_ZIP_ARCHIVE,
|
||||
BITMAPS::unzip );
|
||||
fileMenu->Add( KICAD_MANAGER_ACTIONS::archiveProject );
|
||||
fileMenu->Add( KICAD_MANAGER_ACTIONS::unarchiveProject );
|
||||
|
||||
fileMenu->AppendSeparator();
|
||||
fileMenu->AddQuitOrClose( nullptr, wxS( "KiCad" ) );
|
||||
@ -172,10 +165,7 @@ void KICAD_MANAGER_FRAME::doReCreateMenuBar()
|
||||
|
||||
viewMenu->AppendSeparator();
|
||||
viewMenu->Add( KICAD_MANAGER_ACTIONS::openTextEditor );
|
||||
viewMenu->Add( _( "Browse Project Files" ),
|
||||
_( "Open project directory in file browser" ),
|
||||
ID_BROWSE_IN_FILE_EXPLORER,
|
||||
BITMAPS::directory_browser );
|
||||
viewMenu->Add( KICAD_MANAGER_ACTIONS::openProjectDirectory );
|
||||
|
||||
#ifdef __APPLE__
|
||||
// Add a separator only on macOS because the OS adds menu items to the view menu after ours
|
||||
@ -248,35 +238,15 @@ std::optional<TOOLBAR_CONFIGURATION> KICAD_MANAGER_FRAME::DefaultLeftToolbarConf
|
||||
config.AppendAction( KICAD_MANAGER_ACTIONS::newProject )
|
||||
.AppendAction( KICAD_MANAGER_ACTIONS::openProject );
|
||||
|
||||
config.AppendSeparator();
|
||||
/* TODO (ISM): Toolize this:
|
||||
m_tbTopMain->AddTool( ID_SAVE_AND_ZIP_FILES, wxEmptyString,
|
||||
KiBitmapBundle( BITMAPS::zip ),
|
||||
KiDisabledBitmapBundle( BITMAPS::zip ),
|
||||
wxITEM_NORMAL,
|
||||
_( "Archive all project files" ),
|
||||
wxEmptyString, nullptr );
|
||||
config.AppendSeparator()
|
||||
.AppendAction( KICAD_MANAGER_ACTIONS::archiveProject )
|
||||
.AppendAction( KICAD_MANAGER_ACTIONS::unarchiveProject );
|
||||
|
||||
m_tbTopMain->AddTool( ID_READ_ZIP_ARCHIVE, wxEmptyString,
|
||||
KiBitmapBundle( BITMAPS::unzip ),
|
||||
KiDisabledBitmapBundle( BITMAPS::unzip ),
|
||||
wxITEM_NORMAL,
|
||||
_( "Unarchive project files from zip archive" ),
|
||||
wxEmptyString, nullptr );
|
||||
*/
|
||||
config.AppendSeparator()
|
||||
.AppendAction( ACTIONS::zoomRedraw );
|
||||
|
||||
config.AppendSeparator();
|
||||
/* TODO (ISM): Toolize this:
|
||||
m_tbTopMain->AddTool( ID_BROWSE_IN_FILE_EXPLORER, wxEmptyString,
|
||||
KiBitmapBundle( BITMAPS::directory_browser ),
|
||||
#ifdef __APPLE__
|
||||
_( "Reveal project folder in Finder" ) );
|
||||
#else
|
||||
_( "Open project directory in file explorer" ) );
|
||||
#endif
|
||||
*/
|
||||
config.AppendSeparator()
|
||||
.AppendAction( KICAD_MANAGER_ACTIONS::openProjectDirectory );
|
||||
|
||||
// clang-format on
|
||||
return config;
|
||||
|
@ -214,3 +214,26 @@ TOOL_ACTION KICAD_MANAGER_ACTIONS::editOtherPCB( TOOL_ACTION_ARGS()
|
||||
.Name( "kicad.Control.editOtherPCB" )
|
||||
.Scope( AS_GLOBAL )
|
||||
.Parameter<wxString*>( nullptr ) ); // Default to no filename
|
||||
|
||||
TOOL_ACTION KICAD_MANAGER_ACTIONS::archiveProject( TOOL_ACTION_ARGS()
|
||||
.Name( "kicad.Control.archiveProject" )
|
||||
.Scope( AS_GLOBAL )
|
||||
.FriendlyName( _( "Archive all project files" ) )
|
||||
.Icon( BITMAPS::zip ) );
|
||||
|
||||
TOOL_ACTION KICAD_MANAGER_ACTIONS::unarchiveProject( TOOL_ACTION_ARGS()
|
||||
.Name( "kicad.Control.unarchiveProject" )
|
||||
.Scope( AS_GLOBAL )
|
||||
.FriendlyName( _( "Unarchive project files from zip archive" ) )
|
||||
.Icon( BITMAPS::unzip ) );
|
||||
|
||||
TOOL_ACTION KICAD_MANAGER_ACTIONS::openProjectDirectory( TOOL_ACTION_ARGS()
|
||||
.Name( "kicad.Control.OpenProjectDirectory" )
|
||||
.Scope( AS_GLOBAL )
|
||||
.FriendlyName( _( "Browse Project Files" ) )
|
||||
#ifdef __APPLE__
|
||||
.Tooltip( _( "Reveal project folder in Finder" ) )
|
||||
#else
|
||||
.Tooltip( _( "Open project directory in file explorer" ) )
|
||||
#endif
|
||||
.Icon( BITMAPS::directory_browser ) );
|
||||
|
@ -55,6 +55,10 @@ public:
|
||||
|
||||
static TOOL_ACTION editOtherSch;
|
||||
static TOOL_ACTION editOtherPCB;
|
||||
|
||||
static TOOL_ACTION archiveProject;
|
||||
static TOOL_ACTION unarchiveProject;
|
||||
static TOOL_ACTION openProjectDirectory;
|
||||
};
|
||||
|
||||
|
||||
|
@ -48,6 +48,8 @@
|
||||
#include <wx/filedlg.h>
|
||||
#include <design_block_lib_table.h>
|
||||
#include "dialog_pcm.h"
|
||||
#include <project/project_archiver.h>
|
||||
#include <launch_ext.h>
|
||||
|
||||
#include "widgets/filedlg_new_project.h"
|
||||
|
||||
@ -454,6 +456,51 @@ int KICAD_MANAGER_CONTROL::LoadProject( const TOOL_EVENT& aEvent )
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int KICAD_MANAGER_CONTROL::ArchiveProject( const TOOL_EVENT& aEvent )
|
||||
{
|
||||
wxFileName fileName = m_frame->GetProjectFileName();
|
||||
|
||||
fileName.SetExt( FILEEXT::ArchiveFileExtension );
|
||||
|
||||
wxFileDialog dlg( m_frame, _( "Archive Project Files" ),
|
||||
fileName.GetPath(), fileName.GetFullName(),
|
||||
FILEEXT::ZipFileWildcard(), wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
|
||||
|
||||
if( dlg.ShowModal() == wxID_CANCEL )
|
||||
return 0;
|
||||
|
||||
wxFileName zipFile = dlg.GetPath();
|
||||
|
||||
wxString currdirname = fileName.GetPathWithSep();
|
||||
wxDir dir( currdirname );
|
||||
|
||||
if( !dir.IsOpened() ) // wxWidgets display a error message on issue.
|
||||
return 0;
|
||||
|
||||
STATUSBAR_REPORTER reporter( m_frame->GetStatusBar(), 1 );
|
||||
PROJECT_ARCHIVER archiver;
|
||||
|
||||
archiver.Archive( currdirname, zipFile.GetFullPath(), reporter, true, true );
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int KICAD_MANAGER_CONTROL::UnarchiveProject( const TOOL_EVENT& aEvent )
|
||||
{
|
||||
m_frame->UnarchiveFiles();
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int KICAD_MANAGER_CONTROL::ExploreProject( const TOOL_EVENT& aEvent )
|
||||
{
|
||||
// Open project directory in host OS's file explorer
|
||||
LaunchExternal( Prj().GetProjectPath() );
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int KICAD_MANAGER_CONTROL::ViewDroppedViewers( const TOOL_EVENT& aEvent )
|
||||
{
|
||||
if( aEvent.Parameter<wxString*>() )
|
||||
@ -1017,6 +1064,10 @@ void KICAD_MANAGER_CONTROL::setTransitions()
|
||||
Go( &KICAD_MANAGER_CONTROL::LoadProject, KICAD_MANAGER_ACTIONS::loadProject.MakeEvent() );
|
||||
Go( &KICAD_MANAGER_CONTROL::ViewDroppedViewers, KICAD_MANAGER_ACTIONS::viewDroppedGerbers.MakeEvent() );
|
||||
|
||||
Go( &KICAD_MANAGER_CONTROL::ArchiveProject, KICAD_MANAGER_ACTIONS::archiveProject.MakeEvent() );
|
||||
Go( &KICAD_MANAGER_CONTROL::UnarchiveProject, KICAD_MANAGER_ACTIONS::unarchiveProject.MakeEvent() );
|
||||
Go( &KICAD_MANAGER_CONTROL::ExploreProject, KICAD_MANAGER_ACTIONS::openProjectDirectory.MakeEvent() );
|
||||
|
||||
Go( &KICAD_MANAGER_CONTROL::Refresh, ACTIONS::zoomRedraw.MakeEvent() );
|
||||
Go( &KICAD_MANAGER_CONTROL::UpdateMenu, ACTIONS::updateMenu.MakeEvent() );
|
||||
|
||||
|
@ -55,6 +55,10 @@ public:
|
||||
int SaveProjectAs( const TOOL_EVENT& aEvent );
|
||||
int LoadProject( const TOOL_EVENT& aEvent );
|
||||
|
||||
int ArchiveProject( const TOOL_EVENT& aEvent );
|
||||
int UnarchiveProject( const TOOL_EVENT& aEvent );
|
||||
int ExploreProject( const TOOL_EVENT& aEvent );
|
||||
|
||||
/**
|
||||
* @brief Imports a non kicad project from a sch/pcb dropped file.
|
||||
* No error is displayed if the project can not be imported.
|
||||
|
Loading…
Reference in New Issue
Block a user