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();
101 for(
auto& [
name, file] :
m_files->EmbeddedFileMap() )
103 EMBEDDED_FILES::EMBEDDED_FILE* newFile = new EMBEDDED_FILES::EMBEDDED_FILE( *file );
104 m_localFiles->AddFile( newFile );
109 m_filesGridSizer->Detach( m_files_grid );
110 m_filesGridSizer->Add( m_files_grid, 5, wxEXPAND, 5 );
112 m_buttonsSizer->Detach( m_browse_button );
113 m_buttonsSizer->Prepend( m_browse_button, 0, wxALIGN_CENTER_VERTICAL|wxRIGHT, 5 );
115 m_buttonsSizer->Detach( m_export );
116 m_buttonsSizer->Add( m_export, 0, wxALIGN_CENTER_VERTICAL|wxRIGHT, 5 );
131 for(
int ii = 0; ii <
m_files_grid->GetNumberRows(); ii++ )
181 std::optional<bool> deleteReferences;
188 if( parent->Type() ==
PCB_T )
190 return IsOK( m_parent,
_(
"Deleted embedded files are also referenced in some footprints.\n"
191 "Delete from footprints as well?" ) );
195 return IsOK( m_parent,
_(
"Deleted embedded files are also referenced in some symbols.\n"
196 "Delete from symbols as well?" ) );
200 wxFAIL_MSG( wxT(
"Unexpected embedded files owner" ) );
204 for(
const auto& [
name, file] :
m_files->EmbeddedFileMap() )
208 m_files->RunOnNestedEmbeddedFiles(
213 if( !deleteReferences.has_value() )
214 deleteReferences = confirmDelete();
216 if( deleteReferences.value() )
222 if( deleteReferences.has_value() && deleteReferences.value() ==
false )
228 std::vector<EMBEDDED_FILES::EMBEDDED_FILE*> files;
231 files.push_back( file );
247 wxWindowUpdateLocker updateLock(
this );
256 for(
int ii = 0; ii <
m_files_grid->GetNumberRows(); ii++ )
272 std::set<KIFONT::OUTLINE_FONT*>
fonts =
m_files->GetFonts();
280 wxLogTrace( wxT(
"KICAD_EMBED" ), wxString::Format(
"Could not embed font %s",
281 font->GetFileName() ) );
289 col_pos = std::max( std::min( col_pos,
m_files_grid->GetNumberCols() - 1 ), 0 );
290 row_pos = std::max( std::min( row_pos,
m_files_grid->GetNumberRows() - 1 ), 0 );
293 for(
int ii = 0; ii <
m_files_grid->GetNumberRows(); ++ii )
307 wxFileName fileName( aFile );
308 wxString
name = fileName.GetFullName();
312 wxString msg = wxString::Format(
_(
"File '%s' already exists." ),
name );
314 KIDIALOG errorDlg( m_parent, msg,
_(
"Confirmation" ), wxOK | wxCANCEL | wxICON_WARNING );
315 errorDlg.SetOKLabel(
_(
"Overwrite" ) );
320 for(
int ii = 0; ii <
m_files_grid->GetNumberRows(); ii++ )
334 wxString msg = wxString::Format(
_(
"Failed to add file '%s'." ),
name );
336 KIDIALOG errorDlg( m_parent, msg,
_(
"Error" ), wxOK | wxICON_ERROR );
348 wxFileDialog fileDialog(
this,
_(
"Select a file to embed" ), wxEmptyString, wxEmptyString,
349 _(
"All Files" ) + wxT(
" (*.*)|*.*" ),
350 wxFD_OPEN | wxFD_FILE_MUST_EXIST | wxFD_MULTIPLE );
352 if( fileDialog.ShowModal() == wxID_OK )
355 fileDialog.GetPaths( paths );
357 for(
const wxString&
path : paths )
365 wxString
name = aFileName;
370 int row = std::max( 0,
m_files_grid->GetGridCursorRow() );
372 for(
int ii = 0; ii <
m_files_grid->GetNumberRows(); ii++ )
379 if( row < m_files_grid->GetNumberRows() )
407 wxDirDialog dirDialog(
this,
_(
"Select a directory to export files" ) );
409 if( dirDialog.ShowModal() != wxID_OK )
412 wxString
path = dirDialog.GetPath();
418 if( fileName.FileExists() )
420 wxString msg = wxString::Format(
_(
"File '%s' already exists." ), fileName.GetFullName() );
422 KIDIALOG errorDlg( m_parent, msg,
_(
"Confirmation" ), wxOK | wxCANCEL | wxICON_WARNING );
430 bool skip_file =
false;
434 if( !fileName.IsDirWritable() )
437 wxString msg = wxString::Format(
_(
"Directory '%s' is not writable." ), fileName.GetFullName() );
439 wxString msg = wxString::Format(
_(
"Folder '%s' is not writable." ), fileName.GetPath() );
442 KIDIALOG errorDlg( m_parent, msg,
_(
"Error" ), wxYES_NO | wxCANCEL | wxICON_ERROR );
443 errorDlg.SetYesNoCancelLabels(
_(
"Retry" ),
_(
"Skip" ),
_(
"Cancel" ) );
447 if(
result == wxID_CANCEL )
451 else if(
result == wxID_NO )
467 wxFFileOutputStream out( fileName.GetFullPath() );
471 wxString msg = wxString::Format(
_(
"Failed to open file '%s'." ), fileName.GetFullName() );
473 KIDIALOG errorDlg( m_parent, msg,
_(
"Error" ), wxOK | wxICON_ERROR );
478 out.Write( file->decompressedData.data(), file->decompressedData.size() );
480 if( !out.IsOk() || ( out.LastWrite() != file->decompressedData.size() ) )
482 wxString msg = wxString::Format(
_(
"Failed to write file '%s'." ), fileName.GetFullName() );
484 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)
STD_BITMAP_BUTTON * m_browse_button
STD_BITMAP_BUTTON * m_delete_button
bool RemoveEmbeddedFile(const wxString &aFileName)
void onFontEmbedClick(wxCommandEvent &event) override
void onAddEmbeddedFiles(wxCommandEvent &event) override
PANEL_EMBEDDED_FILES(wxWindow *aParent, EMBEDDED_FILES *aFiles, int aFlags=0)
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.
This file is part of the common library.
static const std::string KiCadUriPrefix
wxString result
Test unit parsing edge cases and error handling.