31#include <wx/clipbrd.h>
34#include <wx/filedlg.h>
35#include <wx/filename.h>
66 int panel_width = GetClientRect().GetWidth();
72 if( first_width + second_width > 0 )
73 ratio = (double)first_width / (
double)( first_width + second_width );
79 m_files_grid->SetColSize( 1, panel_width * ( 1 - ratio ) );
87 menu.Append( wxID_COPY,
_(
"Copy Embedded Reference" ) );
89 menu.Bind( wxEVT_COMMAND_MENU_SELECTED,
90 [&]( wxCommandEvent& )
92 int row =
event.GetRow();
93 if( row >= 0 && row < m_files_grid->GetNumberRows() )
95 wxString cellValue =
m_files_grid->GetCellValue( row, 1 );
97 if( wxTheClipboard->Open() )
99 wxTheClipboard->SetData( new wxTextDataObject( cellValue ) );
100 wxTheClipboard->Close();
140 std::vector<EMBEDDED_FILES::EMBEDDED_FILE*> files;
143 files.push_back( it->second );
145 for(
auto& file : files )
159 wxFileDialog fileDialog(
this,
_(
"Select a file to embed" ), wxEmptyString, wxEmptyString,
160 _(
"All files|*.*" ), wxFD_OPEN | wxFD_FILE_MUST_EXIST );
162 if( fileDialog.ShowModal() == wxID_OK )
164 wxFileName fileName( fileDialog.GetPath() );
165 wxString
name = fileName.GetFullName();
169 wxString msg = wxString::Format(
_(
"File '%s' already exists." ),
172 KIDIALOG errorDlg( m_parent, msg,
_(
"Confirmation" ),
173 wxOK | wxCANCEL | wxICON_WARNING );
174 errorDlg.SetOKLabel(
_(
"Overwrite" ) );
179 for(
int ii = 0; ii <
m_files_grid->GetNumberRows(); ii++ )
193 wxString msg = wxString::Format(
_(
"Failed to add file '%s'." ),
196 KIDIALOG errorDlg( m_parent, msg,
_(
"Error" ), wxOK | wxICON_ERROR );
221 if( row < m_files_grid->GetNumberRows() )
230 wxDirDialog dirDialog(
this,
_(
"Select a directory to export files" ) );
232 if( dirDialog.ShowModal() != wxID_OK )
235 wxString
path = dirDialog.GetPath();
241 if( fileName.FileExists() )
243 wxString msg = wxString::Format(
_(
"File '%s' already exists." ),
244 fileName.GetFullName() );
246 KIDIALOG errorDlg( m_parent, msg,
_(
"Confirmation" ),
247 wxOK | wxCANCEL | wxICON_WARNING );
255 bool skip_file =
false;
259 if( !fileName.IsDirWritable() )
262 wxString msg = wxString::Format(
_(
"Directory '%s' is not writable." ),
263 fileName.GetFullName() );
265 wxString msg = wxString::Format(
_(
"Folder '%s' is not writable." ),
266 fileName.GetPath() );
269 KIDIALOG errorDlg( m_parent, msg,
_(
"Error" ), wxYES_NO | wxCANCEL | wxICON_ERROR );
270 errorDlg.SetYesNoCancelLabels(
_(
"Retry" ),
_(
"Skip" ),
_(
"Cancel" ) );
274 if( result == wxID_CANCEL )
278 else if( result == wxID_NO )
293 wxFFile ffile( fileName.GetFullPath(), wxT(
"w" ) );
295 if( !ffile.IsOpened() )
297 wxString msg = wxString::Format(
_(
"Failed to open file '%s'." ),
298 fileName.GetFullName() );
300 KIDIALOG errorDlg( m_parent, msg,
_(
"Error" ), wxOK | wxICON_ERROR );
305 if( !ffile.Write( file->decompressedData.data(), file->decompressedData.size() ) )
307 wxString msg = wxString::Format(
_(
"Failed to write file '%s'." ),
308 fileName.GetFullName() );
310 KIDIALOG errorDlg( m_parent, msg,
_(
"Error" ), wxOK | wxICON_ERROR );
wxBitmapBundle KiBitmapBundle(BITMAPS aBitmap)
void RemoveFile(const wxString &name, bool aErase=true)
Removes a file from the collection and frees the memory.
bool HasFile(const wxString &name) const
void ClearEmbeddedFiles(bool aDeleteFiles=true)
EMBEDDED_FILE * AddFile(const wxFileName &aName, bool aOverwrite)
Loads 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
Helper class to create more flexible dialogs, including 'do not show again' checkbox handling.
void DoNotShowCheckbox(wxString file, int line)
Checks the 'do not show again' setting for the dialog.
bool SetOKCancelLabels(const ButtonLabel &ok, const ButtonLabel &cancel) override
Shows the 'do not show again' checkbox.
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 onGridRightClick(wxGridEvent &event) override
void onDeleteEmbeddedFile(wxCommandEvent &event) 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.