KiCad PCB EDA Suite
Loading...
Searching...
No Matches
kicad/files-io.cpp
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright (C) 2004-2015 Jean-Pierre Charras
5 * Copyright (C) 2004-2020 KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, you may find one here:
19 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20 * or you may search the http://www.gnu.org website for the version 2 license,
21 * or you may write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23 */
24
29#include <wx/dir.h>
30#include <wx/filedlg.h>
31#include <wx/dirdlg.h>
32
33#include <confirm.h>
35#include <kiway.h>
37#include <reporter.h>
40
41#include "kicad_manager_frame.h"
42
43
44void KICAD_MANAGER_FRAME::OnFileHistory( wxCommandEvent& event )
45{
46 wxFileName projFileName = GetFileFromHistory( event.GetId(), _( "KiCad project file" ) );
47 if( !projFileName.FileExists() )
48 return;
49
50 LoadProject( projFileName );
51}
52
53
54void KICAD_MANAGER_FRAME::OnClearFileHistory( wxCommandEvent& aEvent )
55{
57}
58
59
60void KICAD_MANAGER_FRAME::OnUnarchiveFiles( wxCommandEvent& event )
61{
62 wxFileName fn = Prj().GetProjectFullName();
63
65
66 wxFileDialog zipfiledlg( this, _( "Unzip Project" ), fn.GetPath(),
67 fn.GetFullName(), FILEEXT::ZipFileWildcard(),
68 wxFD_OPEN | wxFD_FILE_MUST_EXIST );
69
70 if( zipfiledlg.ShowModal() == wxID_CANCEL )
71 return;
72
73 wxString msg = wxString::Format( _( "\nOpen '%s'\n" ), zipfiledlg.GetPath() );
74 PrintMsg( msg );
75
76 wxDirDialog dirDlg( this, _( "Target Directory" ), fn.GetPath(), wxDD_DEFAULT_STYLE );
77
78 if( dirDlg.ShowModal() == wxID_CANCEL )
79 return;
80
81 wxString unzipDir = dirDlg.GetPath() + wxT( "/" );
82 msg.Printf( _( "Unzipping project in '%s'.\n" ), unzipDir );
83 PrintMsg( msg );
84
85 if( unzipDir == Prj().GetProjectPath() )
86 {
87 if( !Kiway().PlayersClose( false ) )
88 return;
89 }
90
91 STATUSBAR_REPORTER reporter( GetStatusBar(), 1 );
92
93 PROJECT_ARCHIVER::Unarchive( zipfiledlg.GetPath(), unzipDir, reporter );
94
95 if( unzipDir == Prj().GetProjectPath() )
96 {
97 wxString prjPath = Prj().GetProjectFullName();
98
100
101 mgr->UnloadProject( &Prj(), false );
102 mgr->LoadProject( prjPath );
103
105 }
106}
107
108
109void KICAD_MANAGER_FRAME::OnArchiveFiles( wxCommandEvent& event )
110{
111 wxFileName fileName = GetProjectFileName();
112
113 fileName.SetExt( FILEEXT::ArchiveFileExtension );
114
115 wxFileDialog dlg( this, _( "Archive Project Files" ),
116 fileName.GetPath(), fileName.GetFullName(),
117 FILEEXT::ZipFileWildcard(), wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
118
119 if( dlg.ShowModal() == wxID_CANCEL )
120 return;
121
122 wxFileName zipFile = dlg.GetPath();
123
124 wxString currdirname = fileName.GetPathWithSep();
125 wxDir dir( currdirname );
126
127 if( !dir.IsOpened() ) // wxWidgets display a error message on issue.
128 return;
129
130 STATUSBAR_REPORTER reporter( GetStatusBar(), 1 );
131 PROJECT_ARCHIVER archiver;
132
133 archiver.Archive( currdirname, zipFile.GetFullPath(), reporter, true, true );
134}
SETTINGS_MANAGER * GetSettingsManager() const
void PrintMsg(const wxString &text)
void ClearFileHistory(FILE_HISTORY *aFileHistory=nullptr)
Removes all files from the file history.
wxString GetFileFromHistory(int cmdId, const wxString &type, FILE_HISTORY *aFileHistory=nullptr)
Fetches the file name from the file history list.
void OnUnarchiveFiles(wxCommandEvent &event)
const wxString GetProjectFileName() const
void LoadProject(const wxFileName &aProjectFileName)
void OnFileHistory(wxCommandEvent &event)
void OnArchiveFiles(wxCommandEvent &event)
void OnClearFileHistory(wxCommandEvent &aEvent)
PROJECT & Prj() const
Return a reference to the PROJECT associated with this KIWAY.
KIWAY & Kiway() const
Return a reference to the KIWAY that this object has an opportunity to participate in.
Definition: kiway_holder.h:55
static bool Archive(const wxString &aSrcDir, const wxString &aDestFile, REPORTER &aReporter, bool aVerbose=true, bool aIncludeExtraFiles=false)
Creates an archive of the project.
static bool Unarchive(const wxString &aSrcFile, const wxString &aDestDir, REPORTER &aReporter)
Extracts an archive of the current project over existing files Warning: this will overwrite files in ...
virtual const wxString GetProjectFullName() const
Return the full path and name of the project.
Definition: project.cpp:129
bool LoadProject(const wxString &aFullPath, bool aSetActive=true)
Loads a project or sets up a new project with a specified path.
bool UnloadProject(PROJECT *aProject, bool aSave=true)
Saves, unloads and unregisters the given PROJECT.
A wrapper for reporting to a specific text location in a statusbar.
Definition: reporter.h:289
This file is part of the common library.
#define _(s)
static const std::string ArchiveFileExtension
static wxString ZipFileWildcard()
Definition of file extensions used in Kicad.