KiCad PCB EDA Suite
Loading...
Searching...
No Matches
dialog_restore_local_history.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/button.h>
27#include <wx/listctrl.h>
28#include <wx/sizer.h>
29#include <wx/textctrl.h>
30
31
33 wxWindow* aParent, const std::vector<LOCAL_HISTORY_SNAPSHOT_INFO>& aSnapshots ) :
34 DIALOG_SHIM( aParent, wxID_ANY, _( "Restore Project from Local History..." ) ),
35 m_snapshots( aSnapshots )
36{
37 BuildUi();
38 Populate();
39 Centre();
40}
41
42
44{
45 m_list = new wxListCtrl( this, wxID_ANY, wxDefaultPosition, wxDefaultSize,
46 wxLC_HRULES | wxLC_REPORT | wxLC_SINGLE_SEL | wxLC_VRULES );
47 m_list->AppendColumn( _( "Time" ) );
48 m_list->AppendColumn( _( "Action" ) );
49 m_list->AppendColumn( _( "Count" ) );
50
51 m_details = new wxTextCtrl( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize,
52 wxTE_MULTILINE | wxTE_READONLY );
53
54 wxStdDialogButtonSizer* buttons = new wxStdDialogButtonSizer();
55 m_restoreButton = new wxButton( this, wxID_OK, _( "Restore" ) );
56 m_restoreButton->Enable( false );
58 buttons->AddButton( m_restoreButton );
59 buttons->AddButton( new wxButton( this, wxID_CANCEL ) );
60 buttons->Realize();
61
62 wxBoxSizer* topSizer = new wxBoxSizer( wxVERTICAL );
63 topSizer->Add( m_list, 1, wxEXPAND | wxALL, 5 );
64 topSizer->Add( m_details, 1, wxEXPAND | wxLEFT | wxRIGHT | wxBOTTOM, 5 );
65 topSizer->Add( buttons, 0, wxEXPAND | wxALL, 5 );
66 SetSizerAndFit( topSizer );
67
68 SetMinSize( FromDIP( wxSize( 700, 500 ) ) );
69
70 m_list->Bind( wxEVT_LIST_ITEM_SELECTED, &DIALOG_RESTORE_LOCAL_HISTORY::OnSelectionChanged, this );
71 m_list->Bind( wxEVT_LIST_ITEM_ACTIVATED, &DIALOG_RESTORE_LOCAL_HISTORY::OnItemActivated, this );
72}
73
74
76{
77 for( size_t i = 0; i < m_snapshots.size(); ++i )
78 {
79 const auto& snapshot = m_snapshots[i];
80 long row = m_list->InsertItem( m_list->GetItemCount(), snapshot.date.FormatISOCombined() );
81 wxString countText =
82 snapshot.filesChanged > 0 ? wxString::Format( "%d", snapshot.filesChanged ) : wxString( "-" );
83
84 m_list->SetItem( row, 1, snapshot.summary );
85
86 m_list->SetItem( row, 2, countText );
87 }
88
89 m_list->SetColumnWidth( 0, FromDIP( 170 ) );
90 m_list->SetColumnWidth( 1, FromDIP( 380 ) );
91 m_list->SetColumnWidth( 2, FromDIP( 70 ) );
92
93 m_details->Clear();
94 m_selectedIndex = wxNOT_FOUND;
95 m_selectedHash.clear();
96
97 if( m_restoreButton )
98 m_restoreButton->Enable( false );
99}
100
101
103{
104 if( aIndex < 0 || aIndex >= static_cast<long>( m_snapshots.size() ) )
105 return;
106
107 const auto& snapshot = m_snapshots[aIndex];
108
109 wxString text;
110 text << snapshot.summary << "\n";
111 text << snapshot.date.FormatISOCombined() << "\n";
112 text << snapshot.hash;
113
114 if( !snapshot.changedFiles.empty() )
115 text << "\n\n";
116
117 for( size_t ii = 0; ii < snapshot.changedFiles.size(); ++ii )
118 {
119 if( ii > 0 )
120 text << "\n";
121
122 text << snapshot.changedFiles[ii];
123 }
124
125 m_details->SetValue( text );
126}
127
128
130{
131 if( m_selectedIndex == wxNOT_FOUND || m_selectedIndex >= static_cast<long>( m_snapshots.size() ) )
132 {
133 return wxEmptyString;
134 }
135
136 return m_snapshots[m_selectedIndex].hash;
137}
138
139
141{
142 long selected = m_list->GetNextItem( -1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED );
143
144 if( selected == wxNOT_FOUND )
145 {
146 m_selectedIndex = wxNOT_FOUND;
147 m_selectedHash.clear();
148 m_details->Clear();
149
150 if( m_restoreButton )
151 m_restoreButton->Enable( false );
152 }
153 else
154 {
155 m_selectedIndex = selected;
156 m_selectedHash = m_snapshots[selected].hash;
157 UpdateDetails( selected );
158
159 if( m_restoreButton )
160 m_restoreButton->Enable( true );
161 }
162
163 aEvent.Skip();
164}
165
166
168{
169 long index = aEvent.GetIndex();
170
171 if( index >= 0 && index < static_cast<long>( m_snapshots.size() ) )
172 {
176 }
177
178 if( !m_selectedHash.IsEmpty() )
179 EndModal( wxID_OK );
180}
181
182
184{
185 long index = m_list->GetNextItem( -1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED );
186
187 if( index == wxNOT_FOUND )
188 index = m_list->GetNextItem( -1, wxLIST_NEXT_ALL, wxLIST_STATE_FOCUSED );
189
190 if( index == wxNOT_FOUND || index >= static_cast<long>( m_snapshots.size() ) )
191 return;
192
195
196 aEvent.Skip();
197}
int index
DIALOG_RESTORE_LOCAL_HISTORY(wxWindow *aParent, const std::vector< LOCAL_HISTORY_SNAPSHOT_INFO > &aSnapshots)
void OnRestoreClicked(wxCommandEvent &aEvent)
const std::vector< LOCAL_HISTORY_SNAPSHOT_INFO > & m_snapshots
DIALOG_SHIM(wxWindow *aParent, wxWindowID id, const wxString &title, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=wxDEFAULT_FRAME_STYLE|wxRESIZE_BORDER, const wxString &name=wxDialogNameStr)
#define _(s)