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();
99 for(
auto& [
name, file] :
m_files->EmbeddedFileMap() )
101 EMBEDDED_FILES::EMBEDDED_FILE* newFile = new EMBEDDED_FILES::EMBEDDED_FILE( *file );
102 m_localFiles->AddFile( newFile );
116 for(
int ii = 0; ii <
m_files_grid->GetNumberRows(); ii++ )
149 int panel_width = GetClientRect().GetWidth();
155 if( first_width + second_width > 0 )
156 ratio = (double)first_width / (
double)( first_width + second_width );
162 m_files_grid->SetColSize( 1, panel_width * ( 1 - ratio ) );
195 std::optional<bool> deleteReferences;
202 if( parent->Type() ==
PCB_T )
204 return IsOK( m_parent,
_(
"Deleted embedded files are also referenced in some footprints.\n"
205 "Delete from footprints as well?" ) );
209 return IsOK( m_parent,
_(
"Deleted embedded files are also referenced in some symbols.\n"
210 "Delete from symbols as well?" ) );
214 wxFAIL_MSG( wxT(
"Unexpected embedded files owner" ) );
218 for(
const auto& [
name, file] :
m_files->EmbeddedFileMap() )
222 m_files->RunOnNestedEmbeddedFiles(
227 if( !deleteReferences.has_value() )
228 deleteReferences = confirmDelete();
230 if( deleteReferences.value() )
236 if( deleteReferences.has_value() && deleteReferences.value() ==
false )
242 std::vector<EMBEDDED_FILES::EMBEDDED_FILE*> files;
245 files.push_back( file );
261 wxWindowUpdateLocker updateLock(
this );
270 for(
int ii = 0; ii <
m_files_grid->GetNumberRows(); ii++ )
286 std::set<KIFONT::OUTLINE_FONT*>
fonts =
m_files->GetFonts();
294 wxLogTrace( wxT(
"KICAD_EMBED" ), wxString::Format(
"Could not embed font %s",
295 font->GetFileName() ) );
303 col_pos = std::max( std::min( col_pos,
m_files_grid->GetNumberCols() - 1 ), 0 );
304 row_pos = std::max( std::min( row_pos,
m_files_grid->GetNumberRows() - 1 ), 0 );
307 for(
int ii = 0; ii <
m_files_grid->GetNumberRows(); ++ii )
321 wxFileName fileName( aFile );
322 wxString
name = fileName.GetFullName();
326 wxString msg = wxString::Format(
_(
"File '%s' already exists." ),
name );
328 KIDIALOG errorDlg( m_parent, msg,
_(
"Confirmation" ), wxOK | wxCANCEL | wxICON_WARNING );
329 errorDlg.SetOKLabel(
_(
"Overwrite" ) );
334 for(
int ii = 0; ii <
m_files_grid->GetNumberRows(); ii++ )
348 wxString msg = wxString::Format(
_(
"Failed to add file '%s'." ),
name );
350 KIDIALOG errorDlg( m_parent, msg,
_(
"Error" ), wxOK | wxICON_ERROR );
362 wxFileDialog fileDialog(
this,
_(
"Select a file to embed" ), wxEmptyString, wxEmptyString,
363 _(
"All Files" ) + wxT(
" (*.*)|*.*" ),
364 wxFD_OPEN | wxFD_FILE_MUST_EXIST | wxFD_MULTIPLE );
366 if( fileDialog.ShowModal() == wxID_OK )
369 fileDialog.GetPaths( paths );
371 for(
const wxString&
path : paths )
379 wxString
name = aFileName;
384 int row = std::max( 0,
m_files_grid->GetGridCursorRow() );
386 for(
int ii = 0; ii <
m_files_grid->GetNumberRows(); ii++ )
393 if( row < m_files_grid->GetNumberRows() )
421 wxDirDialog dirDialog(
this,
_(
"Select a directory to export files" ) );
423 if( dirDialog.ShowModal() != wxID_OK )
426 wxString
path = dirDialog.GetPath();
432 if( fileName.FileExists() )
434 wxString msg = wxString::Format(
_(
"File '%s' already exists." ), fileName.GetFullName() );
436 KIDIALOG errorDlg( m_parent, msg,
_(
"Confirmation" ), wxOK | wxCANCEL | wxICON_WARNING );
444 bool skip_file =
false;
448 if( !fileName.IsDirWritable() )
451 wxString msg = wxString::Format(
_(
"Directory '%s' is not writable." ), fileName.GetFullName() );
453 wxString msg = wxString::Format(
_(
"Folder '%s' is not writable." ), fileName.GetPath() );
456 KIDIALOG errorDlg( m_parent, msg,
_(
"Error" ), wxYES_NO | wxCANCEL | wxICON_ERROR );
457 errorDlg.SetYesNoCancelLabels(
_(
"Retry" ),
_(
"Skip" ),
_(
"Cancel" ) );
461 if(
result == wxID_CANCEL )
465 else if(
result == wxID_NO )
481 wxFFileOutputStream out( fileName.GetFullPath() );
485 wxString msg = wxString::Format(
_(
"Failed to open file '%s'." ), fileName.GetFullName() );
487 KIDIALOG errorDlg( m_parent, msg,
_(
"Error" ), wxOK | wxICON_ERROR );
492 out.Write( file->decompressedData.data(), file->decompressedData.size() );
494 if( !out.IsOk() || ( out.LastWrite() != file->decompressedData.size() ) )
496 wxString msg = wxString::Format(
_(
"Failed to write file '%s'." ), fileName.GetFullName() );
498 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)
PANEL_EMBEDDED_FILES(wxWindow *parent, EMBEDDED_FILES *aFiles)
void onFontEmbedClick(wxCommandEvent &event) override
void onAddEmbeddedFiles(wxCommandEvent &event) override
void onDeleteEmbeddedFile(wxCommandEvent &event) override
~PANEL_EMBEDDED_FILES() override
bool TransferDataToWindow() override
void onSize(wxSizeEvent &event) 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.