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, see <https://www.gnu.org/licenses/>.
19 */
20
21#include <wx/dir.h>
22#include <wx/filedlg.h>
23#include <wx/dirdlg.h>
24
25#include <kiplatform/ui.h>
26#include <kiway.h>
28#include <reporter.h>
31#include <local_history.h>
32
33#include "kicad_manager_frame.h"
34
35
36void KICAD_MANAGER_FRAME::OnFileHistory( wxCommandEvent& event )
37{
38 wxString filename = GetFileFromHistory( event.GetId(), _( "KiCad project file" ) );
39
40 if( !filename.IsEmpty() )
41 LoadProject( wxFileName( filename ) );
42}
43
44
45void KICAD_MANAGER_FRAME::OnClearFileHistory( wxCommandEvent& aEvent )
46{
48}
49
50
52{
53 wxFileName fn = Prj().GetProjectFullName();
54
56
57 wxFileDialog zipfiledlg( this, _( "Unzip Project" ), fn.GetPath(), fn.GetFullName(),
58 FILEEXT::ZipFileWildcard(), wxFD_OPEN | wxFD_FILE_MUST_EXIST );
59
61
62 if( zipfiledlg.ShowModal() == wxID_CANCEL )
63 return;
64
65 wxString msg = wxString::Format( _( "\nOpen '%s'\n" ), zipfiledlg.GetPath() );
66 PrintMsg( msg );
67
68 wxDirDialog dirDlg( this, _( "Target Directory" ), fn.GetPath(), wxDD_DEFAULT_STYLE );
69
70 if( dirDlg.ShowModal() == wxID_CANCEL )
71 return;
72
73 wxString unzipDir = dirDlg.GetPath() + wxT( "/" );
74 msg.Printf( _( "Unzipping project in '%s'.\n" ), unzipDir );
75 PrintMsg( msg );
76
77 if( unzipDir == Prj().GetProjectPath() )
78 {
79 if( !Kiway().PlayersClose( false ) )
80 return;
81 }
82
83 STATUSBAR_REPORTER reporter( GetStatusBar(), 1 );
84
85 if( PROJECT_ARCHIVER::Unarchive( zipfiledlg.GetPath(), unzipDir, reporter ) )
86 {
87 wxArrayString projectFiles;
88 wxDir::GetAllFiles( unzipDir, &projectFiles,
89 wxT( "*." ) + wxString::FromUTF8( FILEEXT::ProjectFileExtension ),
90 wxDIR_FILES );
91
92 if( projectFiles.size() == 1 )
93 LoadProject( wxFileName( projectFiles[0] ) );
94 }
95}
96
98{
99 Kiway().LocalHistory().ShowRestoreDialog( Prj().GetProjectPath(), this );
100}
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 OnFileHistory(wxCommandEvent &event)
bool LoadProject(const wxFileName &aProjectFileName)
Loads a new project.
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:422
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:177
A wrapper for reporting to a specific text location in a statusbar.
Definition reporter.h:357
#define _(s)
static const std::string ProjectFileExtension
static const std::string ArchiveFileExtension
static wxString ZipFileWildcard()
void AllowNetworkFileSystems(wxDialog *aDialog)
Configure a file dialog to show network and virtual file systems.
Definition wxgtk/ui.cpp:448
IbisParser parser & reporter
Definition of file extensions used in Kicad.