32#include <wx/clipbrd.h>
35#include <wx/filedlg.h>
36#include <wx/filename.h>
50 if(
const int row = aEvent.GetRow(); row >= 0 && row < m_grid->GetNumberRows() )
54 _(
"Copy the reference for this embedded file" ) );
55 menu.AppendSeparator();
73 if( wxTheClipboard->Open() )
75 wxTheClipboard->SetData(
new wxTextDataObject( cellValue ) );
76 wxTheClipboard->Close();
124 int panel_width = GetClientRect().GetWidth();
130 if( first_width + second_width > 0 )
131 ratio = (double)first_width / (
double)( first_width + second_width );
137 m_files_grid->SetColSize( 1, panel_width * ( 1 - ratio ) );
173 std::vector<EMBEDDED_FILES::EMBEDDED_FILE*> files;
177 files.push_back( it->second );
179 for(
auto& file : files )
201 for(
int ii = 0; ii <
m_files_grid->GetNumberRows(); ii++ )
226 wxLogTrace( wxT(
"KICAD_EMBED" ), wxString::Format(
"Could not embed font %s",
227 font->GetFileName() ) );
240 col_pos = std::max( std::min( col_pos,
m_files_grid->GetNumberCols() - 1 ), 0 );
241 row_pos = std::max( std::min( row_pos,
m_files_grid->GetNumberRows() - 1 ), 0 );
244 for(
int ii = 0; ii <
m_files_grid->GetNumberRows(); ++ii )
260 wxFileDialog fileDialog(
this,
_(
"Select a file to embed" ), wxEmptyString, wxEmptyString,
261 _(
"All files|*.*" ), wxFD_OPEN | wxFD_FILE_MUST_EXIST );
263 if( fileDialog.ShowModal() == wxID_OK )
265 wxFileName fileName( fileDialog.GetPath() );
266 wxString
name = fileName.GetFullName();
270 wxString msg = wxString::Format(
_(
"File '%s' already exists." ),
name );
272 KIDIALOG errorDlg( m_parent, msg,
_(
"Confirmation" ),
273 wxOK | wxCANCEL | wxICON_WARNING );
274 errorDlg.SetOKLabel(
_(
"Overwrite" ) );
279 for(
int ii = 0; ii <
m_files_grid->GetNumberRows(); ii++ )
293 wxString msg = wxString::Format(
_(
"Failed to add file '%s'." ),
296 KIDIALOG errorDlg( m_parent, msg,
_(
"Error" ), wxOK | wxICON_ERROR );
321 if( row < m_files_grid->GetNumberRows() )
330 wxDirDialog dirDialog(
this,
_(
"Select a directory to export files" ) );
332 if( dirDialog.ShowModal() != wxID_OK )
335 wxString
path = dirDialog.GetPath();
341 if( fileName.FileExists() )
343 wxString msg = wxString::Format(
_(
"File '%s' already exists." ),
344 fileName.GetFullName() );
346 KIDIALOG errorDlg( m_parent, msg,
_(
"Confirmation" ),
347 wxOK | wxCANCEL | wxICON_WARNING );
355 bool skip_file =
false;
359 if( !fileName.IsDirWritable() )
362 wxString msg = wxString::Format(
_(
"Directory '%s' is not writable." ),
363 fileName.GetFullName() );
365 wxString msg = wxString::Format(
_(
"Folder '%s' is not writable." ),
366 fileName.GetPath() );
369 KIDIALOG errorDlg( m_parent, msg,
_(
"Error" ), wxYES_NO | wxCANCEL | wxICON_ERROR );
370 errorDlg.SetYesNoCancelLabels(
_(
"Retry" ),
_(
"Skip" ),
_(
"Cancel" ) );
374 if( result == wxID_CANCEL )
378 else if( result == wxID_NO )
393 wxFFile ffile( fileName.GetFullPath(), wxT(
"w" ) );
395 if( !ffile.IsOpened() )
397 wxString msg = wxString::Format(
_(
"Failed to open file '%s'." ),
398 fileName.GetFullName() );
400 KIDIALOG errorDlg( m_parent, msg,
_(
"Error" ), wxOK | wxICON_ERROR );
405 if( !ffile.Write( file->decompressedData.data(), file->decompressedData.size() ) )
407 wxString msg = wxString::Format(
_(
"Failed to write file '%s'." ),
408 fileName.GetFullName() );
410 KIDIALOG errorDlg( m_parent, msg,
_(
"Error" ), wxOK | wxICON_ERROR );
wxBitmapBundle KiBitmapBundle(BITMAPS aBitmap)
@ 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)
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
PANEL_EMBEDDED_FILES(wxWindow *parent, EMBEDDED_FILES *aFiles)
void onFontEmbedClick(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
void onAddEmbeddedFile(wxCommandEvent &event) override
bool TransferDataFromWindow() override
void EnableAlternateRowColors(bool aEnable=true)
Enable alternate row highlighting, where every odd row has a different background color than the even...
This file is part of the common library.