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, see <https://www.gnu.org/licenses/>.
18 */
19
21
22#include <wx/datetime.h>
23#include <wx/filename.h>
24
25
26static wxString formatStamp( const wxDateTime& aDt )
27{
28 if( !aDt.IsValid() )
29 return _( "(missing)" );
30
31 return aDt.Format( wxS( "%Y-%m-%d %H:%M:%S" ) );
32}
33
34
36 const std::vector<std::pair<wxString, wxString>>& aStale ) :
39 m_stale( aStale )
40{
41 m_fileList->AppendColumn( _( "File" ), wxLIST_FORMAT_LEFT, 260 );
42 m_fileList->AppendColumn( _( "Saved version" ), wxLIST_FORMAT_LEFT, 150 );
43 m_fileList->AppendColumn( _( "Auto-saved copy" ), wxLIST_FORMAT_LEFT, 150 );
44
45 m_fileList->EnableCheckBoxes( true );
46
47 for( const auto& [autosavePath, srcPath] : m_stale )
48 {
49 wxFileName srcFn( srcPath );
50 wxFileName autosaveFn( autosavePath );
51
52 wxDateTime srcTime;
53 wxDateTime autosaveTime;
54
55 if( srcFn.FileExists() )
56 srcTime = srcFn.GetModificationTime();
57
58 if( autosaveFn.FileExists() )
59 autosaveTime = autosaveFn.GetModificationTime();
60
61 long row = m_fileList->InsertItem( m_fileList->GetItemCount(), srcFn.GetFullName() );
62 m_fileList->SetItem( row, 1, formatStamp( srcTime ) );
63 m_fileList->SetItem( row, 2, formatStamp( autosaveTime ) );
64 m_fileList->CheckItem( row, true );
65 }
66
67 m_fileList->Bind( wxEVT_LIST_ITEM_CHECKED, &DIALOG_AUTOSAVE_RECOVERY::onItemCheckChanged, this );
68 m_fileList->Bind( wxEVT_LIST_ITEM_UNCHECKED, &DIALOG_AUTOSAVE_RECOVERY::onItemCheckChanged, this );
69
71}
72
73
74std::vector<std::pair<wxString, wxString>> DIALOG_AUTOSAVE_RECOVERY::GetSelectedStale() const
75{
76 std::vector<std::pair<wxString, wxString>> selected;
77
78 for( long i = 0; i < m_fileList->GetItemCount(); ++i )
79 {
80 if( m_fileList->IsItemChecked( i ) )
81 selected.push_back( m_stale[static_cast<size_t>( i )] );
82 }
83
84 return selected;
85}
86
87
89{
91 aEvent.Skip();
92}
93
94
96{
97 bool anyChecked = false;
98
99 for( long i = 0; i < m_fileList->GetItemCount(); ++i )
100 {
101 if( m_fileList->IsItemChecked( i ) )
102 {
103 anyChecked = true;
104 break;
105 }
106 }
107
108 m_btnRestore->Enable( anyChecked );
109 m_btnKeepCurrent->Enable( anyChecked );
110 m_btnKeepBoth->Enable( anyChecked );
111}
112
113
114void DIALOG_AUTOSAVE_RECOVERY::OnRestore( wxCommandEvent& aEvent )
115{
117 EndModal( wxID_OK );
118}
119
120
121void DIALOG_AUTOSAVE_RECOVERY::OnKeepCurrent( wxCommandEvent& aEvent )
122{
124 EndModal( wxID_OK );
125}
126
127
128void DIALOG_AUTOSAVE_RECOVERY::OnKeepBoth( wxCommandEvent& aEvent )
129{
131 EndModal( wxID_OK );
132}
133
134
135void DIALOG_AUTOSAVE_RECOVERY::OnCancel( wxCommandEvent& aEvent )
136{
138 EndModal( wxID_CANCEL );
139}
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)