36#include <wx/filedlg.h>
37#include <wx/filename.h>
38#include <wx/stdpaths.h>
43 wxCommandEvent saveEvent;
44 saveEvent.SetId( wxID_SAVE );
57 if( !filename.IsEmpty() )
72 ::wxSetWorkingDirectory( ::wxPathOnly( filename ) );
77 msg.Printf(
_(
"File '%s' loaded"), filename );
96 int id =
event.GetId();
100 if( filename.IsEmpty() &&
id == wxID_SAVE )
127 wxFileDialog openFileDialog(
this,
_(
"Append Existing Drawing Sheet" ),
128 wxEmptyString, wxEmptyString,
133 if( openFileDialog.ShowModal() == wxID_CANCEL )
136 filename = openFileDialog.GetPath();
140 msg.Printf(
_(
"Unable to load %s file" ), filename );
147 msg.Printf(
_(
"File '%s' inserted" ), filename );
148 SetStatusText( msg );
156 wxFileDialog openFileDialog(
this,
_(
"Open Drawing Sheet" ), wxEmptyString, wxEmptyString,
161 if( openFileDialog.ShowModal() == wxID_CANCEL )
164 filename = openFileDialog.GetPath();
168 msg.Printf(
_(
"Unable to load %s file" ), filename );
174 msg.Printf(
_(
"File '%s' saved." ), filename );
175 SetStatusText( msg );
184 msg.Printf(
_(
"Unable to write '%s'." ), filename );
189 msg.Printf(
_(
"File '%s' saved."), filename );
190 SetStatusText( msg );
198 wxFileDialog openFileDialog(
this,
_(
"Save Drawing Sheet As" ), dir, wxEmptyString,
200 wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
204 if( openFileDialog.ShowModal() == wxID_CANCEL )
207 filename = openFileDialog.GetPath();
212 wxFileName fn(filename);
219 msg.Printf(
_(
"Failed to create file '%s'." ), filename );
224 msg.Printf(
_(
"File '%s' saved." ), filename );
225 SetStatusText( msg );
242 if( wxFileExists( aFullFileName ) )
249 wxString::Format(
_(
"Error loading drawing sheet '%s'." ),
259 wxFileName fn = aFullFileName;
266 m_infoBar->ShowMessage(
_(
"This file was created by an older version of KiCad. "
267 "It will be converted to the new format when saved." ),
268 wxICON_WARNING, WX_INFOBAR::MESSAGE_TYPE::OUTDATED_SAVE );
271 if( fn.FileExists() && !fn.IsFileWritable() )
275 m_infoBar->ShowMessage(
_(
"Layout file is read only." ),
276 wxICON_WARNING, WX_INFOBAR::MESSAGE_TYPE::OUTDATED_SAVE );
288 if( wxFileExists( aFullFileName ) )
290 const bool append =
true;
302 if( !aFullFileName.IsEmpty() )
304 wxString tempFile = wxFileName::CreateTempFileName(
"pledit" );
313 wxRemoveFile( tempFile);
321 if( !wxRenameFile( tempFile, aFullFileName ) )
324 if(
m_infoBar->GetMessageType() == WX_INFOBAR::MESSAGE_TYPE::OUTDATED_SAVE )
void SetContentModified(bool aModified=true)
Handle the graphic items list to draw/plot the frame and title block.
bool LoadDrawingSheet(const wxString &aFullFileName, wxString *aMsg, bool aAppend=false)
Populate the list with a custom layout or the default layout if no custom layout is available.
static DS_DATA_MODEL & GetTheInstance()
Return the instance of DS_DATA_MODEL used in the application.
void AllowVoidList(bool Allow)
In KiCad applications, a drawing sheet is needed So if the list is empty, a default drawing sheet is ...
void ClearList()
Erase the list of items.
void Save(const wxString &aFullFileName)
Save the description in a file.
std::vector< wxFileName > m_AcceptedFiles
void UpdateFileHistory(const wxString &FullFileName, FILE_HISTORY *aFileHistory=nullptr)
Update the list of recently opened files.
virtual void ClearFileHistory()
Remove all files from the file history.
wxString GetFileFromHistory(int cmdId, const wxString &type, FILE_HISTORY *aFileHistory=nullptr)
Fetch the file name from the file history list.
virtual BASE_SCREEN * GetScreen() const
Return a pointer to a BASE_SCREEN or one of its derivatives.
Hold an error message and may be used when throwing exceptions containing meaningful error messages.
static wxString GetUserTemplatesPath()
Gets the user path for custom templates.
bool OpenProjectFiles(const std::vector< wxString > &aFileSet, int aCtl) override
Open a project or set of files given by aFileList.
void OnNewDrawingSheet()
Must be called to initialize parameters when a new drawing sheet is loaded.
void SetCurrentFileName(const wxString &aName)
Store the current layout description file filename.
bool IsContentModified() const override
Get if the drawing sheet has been modified but not saved.
void Files_io(wxCommandEvent &event)
bool saveCurrentPageLayout()
void OnClearFileHistory(wxCommandEvent &aEvent)
wxString GetCurrentFileName() const override
void OnFileHistory(wxCommandEvent &event)
void DoWithAcceptedFiles() override
Execute action on accepted dropped file.
void UpdateTitleAndInfo()
Display the short filename (if exists) loaded file on the caption of the main window.
bool SaveDrawingSheetFile(const wxString &aFullFileName)
Save the current layout in a .kicad_wks drawing sheet file.
bool InsertDrawingSheetFile(const wxString &aFullFileName)
Load a .kicad_wks drawing sheet file, and add items to the current layout list.
void SaveCopyInUndoList()
Save a copy of the description (in a S expr string) for Undo/redo commands.
void HardRedraw() override
Refresh the library tree and redraw the window.
bool LoadDrawingSheetFile(const wxString &aFullFileName)
Load a .kicad_wks drawing sheet file.
bool HandleUnsavedChanges(wxWindow *aParent, const wxString &aMessage, const std::function< bool()> &aSaveFunction)
Display a dialog with Save, Cancel and Discard Changes buttons.
void DisplayErrorMessage(wxWindow *aParent, const wxString &aText, const wxString &aExtraInfo)
Display an error message with aMessage.
This file is part of the common library.
#define SEXPR_WORKSHEET_FILE_VERSION
This file contains the file format version information for the s-expression drawing sheet file format...
static const std::string DrawingSheetFileExtension
static wxString DrawingSheetFileWildcard()
#define KICTL_CREATE
caller thinks requested project files may not exist.
Definition of file extensions used in Kicad.