32#include <wx/clipbrd.h>
35#include <wx/filedlg.h>
36#include <wx/filename.h>
39#include <wx/wfstream.h>
52 if(
const int row = aEvent.GetRow(); row >= 0 && row < m_grid->GetNumberRows() )
56 _(
"Copy the reference for this embedded file" ) );
57 menu.AppendSeparator();
75 if( wxTheClipboard->Open() )
77 wxTheClipboard->SetData(
new wxTextDataObject( cellValue ) );
78 wxTheClipboard->Close();
114 for(
int ii = 0; ii <
m_files_grid->GetNumberRows(); ii++ )
118 m_files_grid->DeleteRows( ii );
147 int panel_width = GetClientRect().GetWidth();
153 if( first_width + second_width > 0 )
154 ratio = (double)first_width / (
double)( first_width + second_width );
160 m_files_grid->SetColSize( 1, panel_width * ( 1 - ratio ) );
197 std::vector<EMBEDDED_FILES::EMBEDDED_FILE*> files;
200 files.push_back( file );
224 for(
int ii = 0; ii <
m_files_grid->GetNumberRows(); ii++ )
248 wxLogTrace( wxT(
"KICAD_EMBED" ), wxString::Format(
"Could not embed font %s",
249 font->GetFileName() ) );
262 col_pos = std::max( std::min( col_pos,
m_files_grid->GetNumberCols() - 1 ), 0 );
263 row_pos = std::max( std::min( row_pos,
m_files_grid->GetNumberRows() - 1 ), 0 );
266 for(
int ii = 0; ii <
m_files_grid->GetNumberRows(); ++ii )
282 wxFileName fileName( aFile );
283 wxString
name = fileName.GetFullName();
287 wxString msg = wxString::Format(
_(
"File '%s' already exists." ),
name );
289 KIDIALOG errorDlg( m_parent, msg,
_(
"Confirmation" ), wxOK | wxCANCEL | wxICON_WARNING );
290 errorDlg.SetOKLabel(
_(
"Overwrite" ) );
295 for(
int ii = 0; ii <
m_files_grid->GetNumberRows(); ii++ )
309 wxString msg = wxString::Format(
_(
"Failed to add file '%s'." ),
name );
311 KIDIALOG errorDlg( m_parent, msg,
_(
"Error" ), wxOK | wxICON_ERROR );
323 wxFileDialog fileDialog(
this,
_(
"Select a file to embed" ), wxEmptyString, wxEmptyString,
324 _(
"All Files" ) + wxT(
" (*.*)|*.*" ),
325 wxFD_OPEN | wxFD_FILE_MUST_EXIST | wxFD_MULTIPLE );
327 if( fileDialog.ShowModal() == wxID_OK )
330 fileDialog.GetPaths( paths );
332 for(
const wxString&
path : paths )
340 wxString
name = aFileName;
345 int row = std::max( 0,
m_files_grid->GetGridCursorRow() );
347 for(
int ii = 0; ii <
m_files_grid->GetNumberRows(); ii++ )
354 if( row < m_files_grid->GetNumberRows() )
380 if( row < m_files_grid->GetNumberRows() )
389 wxDirDialog dirDialog(
this,
_(
"Select a directory to export files" ) );
391 if( dirDialog.ShowModal() != wxID_OK )
394 wxString
path = dirDialog.GetPath();
400 if( fileName.FileExists() )
402 wxString msg = wxString::Format(
_(
"File '%s' already exists." ), fileName.GetFullName() );
404 KIDIALOG errorDlg( m_parent, msg,
_(
"Confirmation" ), wxOK | wxCANCEL | wxICON_WARNING );
412 bool skip_file =
false;
416 if( !fileName.IsDirWritable() )
419 wxString msg = wxString::Format(
_(
"Directory '%s' is not writable." ), fileName.GetFullName() );
421 wxString msg = wxString::Format(
_(
"Folder '%s' is not writable." ), fileName.GetPath() );
424 KIDIALOG errorDlg( m_parent, msg,
_(
"Error" ), wxYES_NO | wxCANCEL | wxICON_ERROR );
425 errorDlg.SetYesNoCancelLabels(
_(
"Retry" ),
_(
"Skip" ),
_(
"Cancel" ) );
429 if( result == wxID_CANCEL )
433 else if( result == wxID_NO )
449 wxFFileOutputStream out( fileName.GetFullPath() );
453 wxString msg = wxString::Format(
_(
"Failed to open file '%s'." ), fileName.GetFullName() );
455 KIDIALOG errorDlg( m_parent, msg,
_(
"Error" ), wxOK | wxICON_ERROR );
460 out.Write( file->decompressedData.data(), file->decompressedData.size() );
462 if( !out.IsOk() || ( out.LastWrite() != file->decompressedData.size() ) )
464 wxString msg = wxString::Format(
_(
"Failed to write file '%s'." ), fileName.GetFullName() );
466 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.