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 The 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
25#include <wx/dir.h>
26#include <wx/filedlg.h>
27#include <wx/dirdlg.h>
28
29#include <kiway.h>
31#include <reporter.h>
34
35#include "kicad_manager_frame.h"
36
37
38void KICAD_MANAGER_FRAME::OnFileHistory( wxCommandEvent& event )
39{
40 wxFileName projFileName = GetFileFromHistory( event.GetId(), _( "KiCad project file" ) );
41
42 if( !projFileName.FileExists() )
43 return;
44
45 LoadProject( projFileName );
46}
47
48
49void KICAD_MANAGER_FRAME::OnClearFileHistory( wxCommandEvent& aEvent )
50{
52}
53
54
56{
57 wxFileName fn = Prj().GetProjectFullName();
58
60
61 wxFileDialog zipfiledlg( this, _( "Unzip Project" ), fn.GetPath(), fn.GetFullName(),
62 FILEEXT::ZipFileWildcard(), wxFD_OPEN | wxFD_FILE_MUST_EXIST );
63
64 if( zipfiledlg.ShowModal() == wxID_CANCEL )
65 return;
66
67 wxString msg = wxString::Format( _( "\nOpen '%s'\n" ), zipfiledlg.GetPath() );
68 PrintMsg( msg );
69
70 wxDirDialog dirDlg( this, _( "Target Directory" ), fn.GetPath(), wxDD_DEFAULT_STYLE );
71
72 if( dirDlg.ShowModal() == wxID_CANCEL )
73 return;
74
75 wxString unzipDir = dirDlg.GetPath() + wxT( "/" );
76 msg.Printf( _( "Unzipping project in '%s'.\n" ), unzipDir );
77 PrintMsg( msg );
78
79 if( unzipDir == Prj().GetProjectPath() )
80 {
81 if( !Kiway().PlayersClose( false ) )
82 return;
83 }
84
85 STATUSBAR_REPORTER reporter( GetStatusBar(), 1 );
86
87 if( PROJECT_ARCHIVER::Unarchive( zipfiledlg.GetPath(), unzipDir, reporter ) )
88 {
89 wxArrayString projectFiles;
90 wxDir::GetAllFiles( unzipDir, &projectFiles,
91 wxT( "*." ) + wxString::FromUTF8( FILEEXT::ProjectFileExtension ),
92 wxDIR_FILES );
93
94 if( projectFiles.size() == 1 )
95 LoadProject( wxFileName( projectFiles[0] ) );
96 }
97}
void PrintMsg(const wxString &text)
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.
void LoadProject(const wxFileName &aProjectFileName)
void OnFileHistory(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.
static bool Unarchive(const wxString &aSrcFile, const wxString &aDestDir, REPORTER &aReporter)
Extract an archive of the current project over existing files.
virtual const wxString GetProjectFullName() const
Return the full path and name of the project.
Definition project.cpp:156
A wrapper for reporting to a specific text location in a statusbar.
Definition reporter.h:297
#define _(s)
static const std::string ProjectFileExtension
static const std::string ArchiveFileExtension
static wxString ZipFileWildcard()
Definition of file extensions used in Kicad.