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();
116 for(
int ii = 0; ii <
m_files_grid->GetNumberRows(); ii++ )
120 m_files_grid->DeleteRows( 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 ) );
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" ) );
229 if( !deleteReferences.has_value() )
230 deleteReferences = confirmDelete();
232 if( deleteReferences.value() )
233 nested_files->RemoveFile( name, true );
238 if( deleteReferences.has_value() && deleteReferences.value() ==
false )
244 std::vector<EMBEDDED_FILES::EMBEDDED_FILE*> files;
247 files.push_back( file );
263 wxWindowUpdateLocker updateLock(
this );
272 for(
int ii = 0; ii <
m_files_grid->GetNumberRows(); ii++ )
296 wxLogTrace( wxT(
"KICAD_EMBED" ), wxString::Format(
"Could not embed font %s",
297 font->GetFileName() ) );
305 col_pos = std::max( std::min( col_pos,
m_files_grid->GetNumberCols() - 1 ), 0 );
306 row_pos = std::max( std::min( row_pos,
m_files_grid->GetNumberRows() - 1 ), 0 );
309 for(
int ii = 0; ii <
m_files_grid->GetNumberRows(); ++ii )
323 wxFileName fileName( aFile );
324 wxString
name = fileName.GetFullName();
328 wxString msg = wxString::Format(
_(
"File '%s' already exists." ),
name );
330 KIDIALOG errorDlg( m_parent, msg,
_(
"Confirmation" ), wxOK | wxCANCEL | wxICON_WARNING );
331 errorDlg.SetOKLabel(
_(
"Overwrite" ) );
336 for(
int ii = 0; ii <
m_files_grid->GetNumberRows(); ii++ )
350 wxString msg = wxString::Format(
_(
"Failed to add file '%s'." ),
name );
352 KIDIALOG errorDlg( m_parent, msg,
_(
"Error" ), wxOK | wxICON_ERROR );
364 wxFileDialog fileDialog(
this,
_(
"Select a file to embed" ), wxEmptyString, wxEmptyString,
365 _(
"All Files" ) + wxT(
" (*.*)|*.*" ),
366 wxFD_OPEN | wxFD_FILE_MUST_EXIST | wxFD_MULTIPLE );
368 if( fileDialog.ShowModal() == wxID_OK )
371 fileDialog.GetPaths( paths );
373 for(
const wxString&
path : paths )
381 wxString
name = aFileName;
386 int row = std::max( 0,
m_files_grid->GetGridCursorRow() );
388 for(
int ii = 0; ii <
m_files_grid->GetNumberRows(); ii++ )
395 if( row < m_files_grid->GetNumberRows() )
423 wxDirDialog dirDialog(
this,
_(
"Select a directory to export files" ) );
425 if( dirDialog.ShowModal() != wxID_OK )
428 wxString
path = dirDialog.GetPath();
434 if( fileName.FileExists() )
436 wxString msg = wxString::Format(
_(
"File '%s' already exists." ), fileName.GetFullName() );
438 KIDIALOG errorDlg( m_parent, msg,
_(
"Confirmation" ), wxOK | wxCANCEL | wxICON_WARNING );
446 bool skip_file =
false;
450 if( !fileName.IsDirWritable() )
453 wxString msg = wxString::Format(
_(
"Directory '%s' is not writable." ), fileName.GetFullName() );
455 wxString msg = wxString::Format(
_(
"Folder '%s' is not writable." ), fileName.GetPath() );
458 KIDIALOG errorDlg( m_parent, msg,
_(
"Error" ), wxYES_NO | wxCANCEL | wxICON_ERROR );
459 errorDlg.SetYesNoCancelLabels(
_(
"Retry" ),
_(
"Skip" ),
_(
"Cancel" ) );
463 if( result == wxID_CANCEL )
467 else if( result == wxID_NO )
483 wxFFileOutputStream out( fileName.GetFullPath() );
487 wxString msg = wxString::Format(
_(
"Failed to open file '%s'." ), fileName.GetFullName() );
489 KIDIALOG errorDlg( m_parent, msg,
_(
"Error" ), wxOK | wxICON_ERROR );
494 out.Write( file->decompressedData.data(), file->decompressedData.size() );
496 if( !out.IsOk() || ( out.LastWrite() != file->decompressedData.size() ) )
498 wxString msg = wxString::Format(
_(
"Failed to write file '%s'." ), fileName.GetFullName() );
500 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.
void SetFileAddedCallback(FILE_ADDED_CALLBACK callback)
EMBEDDED_FILE * GetEmbeddedFile(const wxString &aName) const
Returns the embedded file with the given name or nullptr if it does not exist.
bool HasFile(const wxString &name) const
virtual void RunOnNestedEmbeddedFiles(const std::function< void(EMBEDDED_FILES *)> &aFunction)
Provide access to nested embedded files, such as symbols in schematics and footprints in boards.
void ClearEmbeddedFiles(bool aDeleteFiles=true)
virtual std::set< KIFONT::OUTLINE_FONT * > GetFonts() const
EMBEDDED_FILE * AddFile(const wxFileName &aName, bool aOverwrite)
Load a file from disk and adds it to the collection.
const std::map< wxString, EMBEDDED_FILE * > & EmbeddedFileMap() const
void SetAreFontsEmbedded(bool aEmbedFonts)
bool GetAreFontsEmbedded() const
Add mouse and command handling (such as cut, copy, and paste) to a WX_GRID instance.
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.
Class PANEL_EMBEDDED_FILES_BASE.
wxCheckBox * m_cbEmbedFonts
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
void OnDeleteRows(const std::function< void(int row)> &aDeleter)
Handles a row deletion event.
void EnableAlternateRowColors(bool aEnable=true)
Enable alternate row highlighting, where every odd row has a different background color than the even...
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
This file is part of the common library.