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#include <local_history.h>
35
36#include "kicad_manager_frame.h"
37
38
39void KICAD_MANAGER_FRAME::OnFileHistory( wxCommandEvent& event )
40{
41 wxFileName projFileName = GetFileFromHistory( event.GetId(), _( "KiCad project file" ) );
42
43 if( !projFileName.FileExists() )
44 return;
45
46 LoadProject( projFileName );
47}
48
49
50void KICAD_MANAGER_FRAME::OnClearFileHistory( wxCommandEvent& aEvent )
51{
53}
54
55
57{
58 wxFileName fn = Prj().GetProjectFullName();
59
61
62 wxFileDialog zipfiledlg( this, _( "Unzip Project" ), fn.GetPath(), fn.GetFullName(),
63 FILEEXT::ZipFileWildcard(), wxFD_OPEN | wxFD_FILE_MUST_EXIST );
64
65 if( zipfiledlg.ShowModal() == wxID_CANCEL )
66 return;
67
68 wxString msg = wxString::Format( _( "\nOpen '%s'\n" ), zipfiledlg.GetPath() );
69 PrintMsg( msg );
70
71 wxDirDialog dirDlg( this, _( "Target Directory" ), fn.GetPath(), wxDD_DEFAULT_STYLE );
72
73 if( dirDlg.ShowModal() == wxID_CANCEL )
74 return;
75
76 wxString unzipDir = dirDlg.GetPath() + wxT( "/" );
77 msg.Printf( _( "Unzipping project in '%s'.\n" ), unzipDir );
78 PrintMsg( msg );
79
80 if( unzipDir == Prj().GetProjectPath() )
81 {
82 if( !Kiway().PlayersClose( false ) )
83 return;
84 }
85
86 STATUSBAR_REPORTER reporter( GetStatusBar(), 1 );
87
88 if( PROJECT_ARCHIVER::Unarchive( zipfiledlg.GetPath(), unzipDir, reporter ) )
89 {
90 wxArrayString projectFiles;
91 wxDir::GetAllFiles( unzipDir, &projectFiles,
92 wxT( "*." ) + wxString::FromUTF8( FILEEXT::ProjectFileExtension ),
93 wxDIR_FILES );
94
95 if( projectFiles.size() == 1 )
96 LoadProject( wxFileName( projectFiles[0] ) );
97 }
98}
99
101{
102 Kiway().LocalHistory().ShowRestoreDialog( Prj().GetProjectPath(), this );
103}
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.
LOCAL_HISTORY & LocalHistory()
Return the LOCAL_HISTORY associated with this KIWAY.
Definition kiway.h:404
void ShowRestoreDialog(const wxString &aProjectPath, wxWindow *aParent)
Show a dialog allowing the user to choose a snapshot to restore.
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:159
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.