32#include <wx/clipbrd.h>
35#include <wx/filedlg.h>
36#include <wx/filename.h>
39#include <wx/wfstream.h>
51 if(
const int row = aEvent.GetRow(); row >= 0 && row < m_grid->GetNumberRows() )
55 _(
"Copy the reference for this embedded file" ) );
56 menu.AppendSeparator();
74 if( wxTheClipboard->Open() )
76 wxTheClipboard->SetData(
new wxTextDataObject( cellValue ) );
77 wxTheClipboard->Close();
110 for(
int ii = 0; ii <
m_files_grid->GetNumberRows(); ii++ )
114 m_files_grid->DeleteRows( ii );
143 int panel_width = GetClientRect().GetWidth();
149 if( first_width + second_width > 0 )
150 ratio = (double)first_width / (
double)( first_width + second_width );
156 m_files_grid->SetColSize( 1, panel_width * ( 1 - ratio ) );
192 std::vector<EMBEDDED_FILES::EMBEDDED_FILE*> files;
196 files.push_back( it->second );
198 for(
auto& file : files )
220 for(
int ii = 0; ii <
m_files_grid->GetNumberRows(); ii++ )
245 wxLogTrace( wxT(
"KICAD_EMBED" ), wxString::Format(
"Could not embed font %s",
246 font->GetFileName() ) );
259 col_pos = std::max( std::min( col_pos,
m_files_grid->GetNumberCols() - 1 ), 0 );
260 row_pos = std::max( std::min( row_pos,
m_files_grid->GetNumberRows() - 1 ), 0 );
263 for(
int ii = 0; ii <
m_files_grid->GetNumberRows(); ++ii )
279 wxFileName fileName( aFile );
280 wxString
name = fileName.GetFullName();
284 wxString msg = wxString::Format(
_(
"File '%s' already exists." ),
name );
286 KIDIALOG errorDlg( m_parent, msg,
_(
"Confirmation" ), wxOK | wxCANCEL | wxICON_WARNING );
287 errorDlg.SetOKLabel(
_(
"Overwrite" ) );
292 for(
int ii = 0; ii <
m_files_grid->GetNumberRows(); ii++ )
306 wxString msg = wxString::Format(
_(
"Failed to add file '%s'." ),
name );
308 KIDIALOG errorDlg( m_parent, msg,
_(
"Error" ), wxOK | wxICON_ERROR );
320 wxFileDialog fileDialog(
this,
_(
"Select a file to embed" ), wxEmptyString, wxEmptyString,
321 _(
"All files|*.*" ),
322 wxFD_OPEN | wxFD_FILE_MUST_EXIST | wxFD_MULTIPLE );
324 if( fileDialog.ShowModal() == wxID_OK )
327 fileDialog.GetPaths( paths );
329 for( wxString
path : paths )
337 wxString
name = aFileName;
342 int row = std::max( 0,
m_files_grid->GetGridCursorRow() );
344 for(
int ii = 0; ii <
m_files_grid->GetNumberRows(); ii++ )
351 if( row < m_files_grid->GetNumberRows() )
377 if( row < m_files_grid->GetNumberRows() )
386 wxDirDialog dirDialog(
this,
_(
"Select a directory to export files" ) );
388 if( dirDialog.ShowModal() != wxID_OK )
391 wxString
path = dirDialog.GetPath();
397 if( fileName.FileExists() )
399 wxString msg = wxString::Format(
_(
"File '%s' already exists." ),
400 fileName.GetFullName() );
402 KIDIALOG errorDlg( m_parent, msg,
_(
"Confirmation" ),
403 wxOK | wxCANCEL | wxICON_WARNING );
411 bool skip_file =
false;
415 if( !fileName.IsDirWritable() )
418 wxString msg = wxString::Format(
_(
"Directory '%s' is not writable." ),
419 fileName.GetFullName() );
421 wxString msg = wxString::Format(
_(
"Folder '%s' is not writable." ),
422 fileName.GetPath() );
425 KIDIALOG errorDlg( m_parent, msg,
_(
"Error" ), wxYES_NO | wxCANCEL | wxICON_ERROR );
426 errorDlg.SetYesNoCancelLabels(
_(
"Retry" ),
_(
"Skip" ),
_(
"Cancel" ) );
430 if( result == wxID_CANCEL )
434 else if( result == wxID_NO )
450 wxFFileOutputStream out( fileName.GetFullPath() );
454 wxString msg = wxString::Format(
_(
"Failed to open file '%s'." ),
455 fileName.GetFullName() );
457 KIDIALOG errorDlg( m_parent, msg,
_(
"Error" ), wxOK | wxICON_ERROR );
462 out.Write( file->decompressedData.data(), file->decompressedData.size() );
464 if( !out.IsOk() || ( out.LastWrite() != file->decompressedData.size() ) )
466 wxString msg = wxString::Format(
_(
"Failed to write file '%s'." ),
467 fileName.GetFullName() );
469 KIDIALOG errorDlg( m_parent, msg,
_(
"Error" ), wxOK | wxICON_ERROR );
wxBitmapBundle KiBitmapBundle(BITMAPS aBitmap, int aMinHeight)
@ 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.
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
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)
void SetFileAddedCallback(FileAddedCallback callback)
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 EnableAlternateRowColors(bool aEnable=true)
Enable alternate row highlighting, where every odd row has a different background color than the even...
static const std::string KiCadUriPrefix
This file is part of the common library.