34#include <wx/clipbrd.h>
36#include <wx/filedlg.h>
37#include <wx/filename.h>
40#include <wx/wfstream.h>
41#include <wx/wupdlock.h>
54 if(
const int row = aEvent.GetRow(); row >= 0 && row < m_grid->GetNumberRows() )
58 _(
"Copy the reference for this embedded file" ) );
59 menu.AppendSeparator();
77 if( wxTheClipboard->Open() )
79 wxTheClipboard->SetData(
new wxTextDataObject( cellValue ) );
80 wxTheClipboard->Close();
95 std::vector<const EMBEDDED_FILES*> aInheritedFiles ) :
103 for(
auto& [
name, file] :
m_files->EmbeddedFileMap() )
105 EMBEDDED_FILES::EMBEDDED_FILE* newFile = new EMBEDDED_FILES::EMBEDDED_FILE( *file );
106 m_localFiles->AddFile( newFile );
111 for( auto& [name, file] : inheritedFiles->EmbeddedFileMap() )
113 if( m_localFiles->HasFile( name ) )
116 EMBEDDED_FILES::EMBEDDED_FILE* newFile = new EMBEDDED_FILES::EMBEDDED_FILE( *file );
117 m_localFiles->AddFile( newFile );
118 m_inheritedFileNames.insert( name );
124 m_filesGridSizer->Detach( m_files_grid );
125 m_filesGridSizer->Add( m_files_grid, 5, wxEXPAND, 5 );
127 m_buttonsSizer->Detach( m_browse_button );
128 m_buttonsSizer->Prepend( m_browse_button, 0, wxALIGN_CENTER_VERTICAL|wxRIGHT, 5 );
130 m_buttonsSizer->Detach( m_export );
131 m_buttonsSizer->Add( m_export, 0, wxALIGN_CENTER_VERTICAL|wxRIGHT, 5 );
137 m_files_grid->SetMargins( 0 - wxSYS_VSCROLL_X, 0 );
138 m_files_grid->EnableAlternateRowColors();
141 m_files_grid->SetupColumnAutosizer( 1 );
143 m_localFiles->SetFileAddedCallback(
146 for(
int ii = 0; ii < m_files_grid->GetNumberRows(); ii++ )
148 if( m_files_grid->GetCellValue( ii, 1 ) == file->
GetLink() )
150 m_files_grid->DeleteRows( ii );
155 m_files_grid->AppendRows( 1 );
156 int ii = m_files_grid->GetNumberRows() - 1;
157 m_files_grid->SetCellValue( ii, 0, file->
name );
158 m_files_grid->SetCellValue( ii, 1, file->
GetLink() );
197 std::optional<bool> deleteReferences;
204 if( parent->Type() ==
PCB_T )
206 return IsOK( m_parent,
_(
"Deleted embedded files are also referenced in some footprints.\n"
207 "Delete from footprints as well?" ) );
211 return IsOK( m_parent,
_(
"Deleted embedded files are also referenced in some symbols.\n"
212 "Delete from symbols as well?" ) );
216 wxFAIL_MSG( wxT(
"Unexpected embedded files owner" ) );
220 for(
const auto& [
name, file] :
m_files->EmbeddedFileMap() )
224 m_files->RunOnNestedEmbeddedFiles(
229 if( !deleteReferences.has_value() )
230 deleteReferences = confirmDelete();
232 if( deleteReferences.value() )
238 if( deleteReferences.has_value() && deleteReferences.value() ==
false )
244 std::vector<EMBEDDED_FILES::EMBEDDED_FILE*> files;
247 files.push_back( file );
266 wxWindowUpdateLocker updateLock(
this );
275 for(
int ii = 0; ii <
m_files_grid->GetNumberRows(); ii++ )
291 std::set<KIFONT::OUTLINE_FONT*>
fonts =
m_files->GetFonts();
299 wxLogTrace( wxT(
"KICAD_EMBED" ), wxString::Format(
"Could not embed font %s",
300 font->GetFileName() ) );
308 col_pos = std::max( std::min( col_pos,
m_files_grid->GetNumberCols() - 1 ), 0 );
309 row_pos = std::max( std::min( row_pos,
m_files_grid->GetNumberRows() - 1 ), 0 );
312 for(
int ii = 0; ii <
m_files_grid->GetNumberRows(); ++ii )
326 wxFileName fileName( aFile );
327 wxString
name = fileName.GetFullName();
331 wxString msg = wxString::Format(
_(
"File '%s' already exists." ),
name );
333 KIDIALOG errorDlg( m_parent, msg,
_(
"Confirmation" ), wxOK | wxCANCEL | wxICON_WARNING );
334 errorDlg.SetOKLabel(
_(
"Overwrite" ) );
339 for(
int ii = 0; ii <
m_files_grid->GetNumberRows(); ii++ )
353 wxString msg = wxString::Format(
_(
"Failed to add file '%s'." ),
name );
355 KIDIALOG errorDlg( m_parent, msg,
_(
"Error" ), wxOK | wxICON_ERROR );
367 wxFileDialog fileDialog(
this,
_(
"Select a file to embed" ), wxEmptyString, wxEmptyString,
368 _(
"All Files" ) + wxT(
" (*.*)|*.*" ),
369 wxFD_OPEN | wxFD_FILE_MUST_EXIST | wxFD_MULTIPLE );
371 if( fileDialog.ShowModal() == wxID_OK )
374 fileDialog.GetPaths( paths );
376 for(
const wxString&
path : paths )
384 wxString
name = aFileName;
391 wxString msg =
_(
"Embedded files inherited from a parent symbol cannot be removed." );
397 int row = std::max( 0,
m_files_grid->GetGridCursorRow() );
399 for(
int ii = 0; ii <
m_files_grid->GetNumberRows(); ii++ )
406 if( row < m_files_grid->GetNumberRows() )
433 wxDirDialog dirDialog(
this,
_(
"Select a directory to export files" ) );
435 if( dirDialog.ShowModal() != wxID_OK )
438 wxString
path = dirDialog.GetPath();
444 if( fileName.FileExists() )
446 wxString msg = wxString::Format(
_(
"File '%s' already exists." ), fileName.GetFullName() );
448 KIDIALOG errorDlg( m_parent, msg,
_(
"Confirmation" ), wxOK | wxCANCEL | wxICON_WARNING );
456 bool skip_file =
false;
460 if( !fileName.IsDirWritable() )
463 wxString msg = wxString::Format(
_(
"Directory '%s' is not writable." ), fileName.GetFullName() );
465 wxString msg = wxString::Format(
_(
"Folder '%s' is not writable." ), fileName.GetPath() );
468 KIDIALOG errorDlg( m_parent, msg,
_(
"Error" ), wxYES_NO | wxCANCEL | wxICON_ERROR );
469 errorDlg.SetYesNoCancelLabels(
_(
"Retry" ),
_(
"Skip" ),
_(
"Cancel" ) );
473 if(
result == wxID_CANCEL )
477 else if(
result == wxID_NO )
493 wxFFileOutputStream out( fileName.GetFullPath() );
497 wxString msg = wxString::Format(
_(
"Failed to open file '%s'." ), fileName.GetFullName() );
499 KIDIALOG errorDlg( m_parent, msg,
_(
"Error" ), wxOK | wxICON_ERROR );
508 wxString msg = wxString::Format(
_(
"Failed to write file '%s'." ), fileName.GetFullName() );
510 KIDIALOG errorDlg( m_parent, msg,
_(
"Error" ), wxOK | wxICON_ERROR );
wxBitmapBundle KiBitmapBundle(BITMAPS aBitmap, int aMinHeight)
A base class for most all the KiCad significant classes used in schematics and boards.
@ EMBEDDED_FILES_GRID_TRICKS_COPY_FILENAME
EMBEDDED_FILES_GRID_TRICKS(WX_GRID *aGrid)
void doPopupSelection(wxCommandEvent &event) override
void showPopupMenu(wxMenu &menu, wxGridEvent &aEvent) override
void RemoveFile(const wxString &name, bool aErase=true)
Remove a file from the collection and frees the memory.
bool HasFile(const wxString &name) const
GRID_TRICKS(WX_GRID *aGrid)
virtual void doPopupSelection(wxCommandEvent &event)
virtual void showPopupMenu(wxMenu &menu, wxGridEvent &aEvent)
WX_GRID * m_grid
I don't own the grid, but he owns me.
Helper class to create more flexible dialogs, including 'do not show again' checkbox handling.
void DoNotShowCheckbox(wxString file, int line)
Shows the 'do not show again' checkbox.
bool SetOKCancelLabels(const ButtonLabel &ok, const ButtonLabel &cancel) override
Class OUTLINE_FONT implements outline font drawing.
wxCheckBox * m_cbEmbedFonts
PANEL_EMBEDDED_FILES_BASE(wxWindow *parent, wxWindowID id=wxID_ANY, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxSize(-1,-1), long style=wxTAB_TRAVERSAL, const wxString &name=wxEmptyString)
PANEL_EMBEDDED_FILES(wxWindow *aParent, EMBEDDED_FILES *aFiles, int aFlags=0, std::vector< const EMBEDDED_FILES * > aInheritedFiles={})
bool RemoveEmbeddedFile(const wxString &aFileName)
std::set< wxString > m_inheritedFileNames
void onFontEmbedClick(wxCommandEvent &event) override
void onAddEmbeddedFiles(wxCommandEvent &event) override
std::vector< const EMBEDDED_FILES * > m_inheritedFiles
void onDeleteEmbeddedFile(wxCommandEvent &event) override
~PANEL_EMBEDDED_FILES() override
bool TransferDataToWindow() override
EMBEDDED_FILES * m_localFiles
void onExportFiles(wxCommandEvent &event) override
EMBEDDED_FILES::EMBEDDED_FILE * AddEmbeddedFile(const wxString &aFileName)
bool TransferDataFromWindow() override
bool IsOK(wxWindow *aParent, const wxString &aMessage)
Display a yes/no dialog with aMessage and returns the user response.
void DisplayErrorMessage(wxWindow *aParent, const wxString &aText, const wxString &aExtraInfo)
Display an error message with aMessage.
This file is part of the common library.
static const std::string KiCadUriPrefix
std::vector< char > decompressedData
wxString result
Test unit parsing edge cases and error handling.