KiCad PCB EDA Suite
Loading...
Searching...
No Matches
dialog_autosave_recovery.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 The KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 3
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, you may find one here:
18 * http://www.gnu.org/licenses/gpl-3.0.html
19 * or you may search the http://www.gnu.org website for the version 3 license,
20 * or you may write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22 */
23
25
26#include <wx/datetime.h>
27#include <wx/filename.h>
28
29
30static wxString formatStamp( const wxDateTime& aDt )
31{
32 if( !aDt.IsValid() )
33 return _( "(missing)" );
34
35 return aDt.Format( wxS( "%Y-%m-%d %H:%M:%S" ) );
36}
37
38
40 const std::vector<std::pair<wxString, wxString>>& aStale ) :
43 m_stale( aStale )
44{
45 m_fileList->AppendColumn( _( "File" ), wxLIST_FORMAT_LEFT, 260 );
46 m_fileList->AppendColumn( _( "Saved version" ), wxLIST_FORMAT_LEFT, 150 );
47 m_fileList->AppendColumn( _( "Auto-saved copy" ), wxLIST_FORMAT_LEFT, 150 );
48
49 m_fileList->EnableCheckBoxes( true );
50
51 for( const auto& [autosavePath, srcPath] : m_stale )
52 {
53 wxFileName srcFn( srcPath );
54 wxFileName autosaveFn( autosavePath );
55
56 wxDateTime srcTime;
57 wxDateTime autosaveTime;
58
59 if( srcFn.FileExists() )
60 srcTime = srcFn.GetModificationTime();
61
62 if( autosaveFn.FileExists() )
63 autosaveTime = autosaveFn.GetModificationTime();
64
65 long row = m_fileList->InsertItem( m_fileList->GetItemCount(), srcFn.GetFullName() );
66 m_fileList->SetItem( row, 1, formatStamp( srcTime ) );
67 m_fileList->SetItem( row, 2, formatStamp( autosaveTime ) );
68 m_fileList->CheckItem( row, true );
69 }
70
71 m_fileList->Bind( wxEVT_LIST_ITEM_CHECKED, &DIALOG_AUTOSAVE_RECOVERY::onItemCheckChanged, this );
72 m_fileList->Bind( wxEVT_LIST_ITEM_UNCHECKED, &DIALOG_AUTOSAVE_RECOVERY::onItemCheckChanged, this );
73
75}
76
77
78std::vector<std::pair<wxString, wxString>> DIALOG_AUTOSAVE_RECOVERY::GetSelectedStale() const
79{
80 std::vector<std::pair<wxString, wxString>> selected;
81
82 for( long i = 0; i < m_fileList->GetItemCount(); ++i )
83 {
84 if( m_fileList->IsItemChecked( i ) )
85 selected.push_back( m_stale[static_cast<size_t>( i )] );
86 }
87
88 return selected;
89}
90
91
93{
95 aEvent.Skip();
96}
97
98
100{
101 bool anyChecked = false;
102
103 for( long i = 0; i < m_fileList->GetItemCount(); ++i )
104 {
105 if( m_fileList->IsItemChecked( i ) )
106 {
107 anyChecked = true;
108 break;
109 }
110 }
111
112 m_btnRestore->Enable( anyChecked );
113 m_btnKeepCurrent->Enable( anyChecked );
114 m_btnKeepBoth->Enable( anyChecked );
115}
116
117
118void DIALOG_AUTOSAVE_RECOVERY::OnRestore( wxCommandEvent& aEvent )
119{
121 EndModal( wxID_OK );
122}
123
124
125void DIALOG_AUTOSAVE_RECOVERY::OnKeepCurrent( wxCommandEvent& aEvent )
126{
128 EndModal( wxID_OK );
129}
130
131
132void DIALOG_AUTOSAVE_RECOVERY::OnKeepBoth( wxCommandEvent& aEvent )
133{
135 EndModal( wxID_OK );
136}
137
138
139void DIALOG_AUTOSAVE_RECOVERY::OnCancel( wxCommandEvent& aEvent )
140{
142 EndModal( wxID_CANCEL );
143}
DIALOG_AUTOSAVE_RECOVERY_BASE(wxWindow *parent, wxWindowID id=wxID_ANY, const wxString &title=_("Auto-Save Recovery"), const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxSize(600, 400), long style=wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER)
void onItemCheckChanged(wxListEvent &aEvent)
DIALOG_AUTOSAVE_RECOVERY(wxWindow *aParent, const std::vector< std::pair< wxString, wxString > > &aStale)
void OnCancel(wxCommandEvent &aEvent) override
std::vector< std::pair< wxString, wxString > > m_stale
std::vector< std::pair< wxString, wxString > > GetSelectedStale() const
void OnKeepBoth(wxCommandEvent &aEvent) override
AUTOSAVE_RECOVERY_CHOICE m_choice
void OnKeepCurrent(wxCommandEvent &aEvent) override
void OnRestore(wxCommandEvent &aEvent) override
static wxString formatStamp(const wxDateTime &aDt)
#define _(s)