KiCad PCB EDA Suite
Loading...
Searching...
No Matches
panel_git_tags.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 modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation, either version 3 of the License, or (at your
9 * option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
21
22#include <memory>
23
24#include <confirm.h>
28#include <eda_base_frame.h>
30#include <project.h>
31
32
33PANEL_GIT_TAGS::PANEL_GIT_TAGS( wxWindow* aParent, GIT_ADVANCED_DIALOG* aDialog, EDA_BASE_FRAME* aFrame ) :
34 PANEL_GIT_TAGS_BASE( aParent ),
35 m_dialog( aDialog ),
36 m_frame( aFrame )
37{
38 m_tagsList->AppendColumn( _( "Tag" ), wxLIST_FORMAT_LEFT, FromDIP( 220 ) );
39 m_tagsList->AppendColumn( _( "Commit" ), wxLIST_FORMAT_LEFT, FromDIP( 100 ) );
40 m_tagsList->AppendColumn( _( "Date" ), wxLIST_FORMAT_LEFT, FromDIP( 110 ) );
41
43
45
46 // The detail pane appears once a tag is selected.
47 m_tagSashPos = FromDIP( 460 );
48 m_tagsSplitter->Unsplit( m_tagDetail );
49
50 m_tagsList->Bind( wxEVT_LIST_ITEM_SELECTED,
51 [this]( wxListEvent& aEvent )
52 {
53 if( !m_fillingTags )
54 showTagDetail( m_tagsList->GetItemText( aEvent.GetIndex(), 0 ) );
55 } );
56
57 m_tagsList->Bind( wxEVT_LIST_ITEM_DESELECTED,
58 [this]( wxListEvent& )
59 {
60 if( !m_fillingTags
61 && m_tagsList->GetNextItem( -1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED ) == -1 )
62 {
64 }
65 } );
66
67 m_checkoutTagButton->Bind( wxEVT_BUTTON,
68 [this]( wxCommandEvent& )
69 {
71 } );
72 m_deleteTagButton->Bind( wxEVT_BUTTON,
73 [this]( wxCommandEvent& )
74 {
76 } );
77 m_createTagButton->Bind( wxEVT_BUTTON,
78 [this]( wxCommandEvent& )
79 {
80 onNewTag();
81 } );
82}
83
84
86{
87 if( !m_dialog->SessionStillCurrent() )
88 return;
89
90 m_detailQuery.Cancel();
91
92 auto tags = std::make_shared<std::vector<KIGIT_TAG_INFO>>();
93
94 m_listQuery.Run(
95 m_frame->Prj().GetGitCommon(),
96 [tags]( KIGIT_COMMON& aCommon )
97 {
98 *tags = aCommon.GetTags();
99 },
100 [this, tags]()
101 {
102 if( !m_dialog->SessionStillCurrent() )
103 return;
104
105 wxString selected = KIGIT::SelectedText( m_tagsList, 0 );
106 long selectRow = wxNOT_FOUND;
107
108 m_detailQuery.Cancel();
109 m_fillingTags = true;
110 m_tagsList->DeleteAllItems();
111
112 for( const KIGIT_TAG_INFO& t : *tags )
113 {
114 long idx = m_tagsList->InsertItem( m_tagsList->GetItemCount(), t.name );
115 m_tagsList->SetItem( idx, 1, t.hash );
116 m_tagsList->SetItem( idx, 2, KIGIT::RelativeDate( t.when ) );
117
118 if( t.name == selected || ( selected.IsEmpty() && idx == 0 ) )
119 selectRow = idx;
120 }
121
122 int shown = m_tagsList->GetItemCount();
123 m_tagCount->SetLabel( wxString::Format( wxPLURAL( "%d tag", "%d tags", shown ), shown ) );
124
125 if( selectRow != wxNOT_FOUND )
126 {
127 m_tagsList->SetItemState( selectRow, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED );
128 showTagDetail( m_tagsList->GetItemText( selectRow, 0 ) );
129 }
130 else
131 {
133 }
134
135 m_fillingTags = false;
136 } );
137}
138
139
140void PANEL_GIT_TAGS::showTagDetail( const wxString& aTag )
141{
143
144 if( aTag.IsEmpty() || !m_dialog->SessionStillCurrent() )
145 return;
146
147 auto detail = std::make_shared<KIGIT_TAG_DETAIL>();
148
149 m_detailQuery.Run(
150 m_frame->Prj().GetGitCommon(),
151 [detail, aTag]( KIGIT_COMMON& aCommon )
152 {
153 *detail = aCommon.GetTagDetail( aTag );
154 },
155 [this, detail, aTag]()
156 {
157 if( m_dialog->SessionStillCurrent() && KIGIT::SelectedText( m_tagsList, 0 ) == aTag )
158 {
159 fillTagDetail( *detail );
160 }
161 } );
162}
163
164
166{
167 if( !aDetail.found )
168 {
170 return;
171 }
172
173 m_tagTitle->SetLabel( wxString::Format( _( "Tag: %s" ), aDetail.name ) );
174 m_tagCommit->SetLabel( wxString::Format( _( "Commit: %s" ), aDetail.hash ) );
175 m_tagAuthor->SetLabel( wxString::Format( _( "Author: %s <%s>" ), aDetail.author, aDetail.email ) );
176 m_tagWhen->SetLabel( wxString::Format( _( "Date: %s" ), KIGIT::RelativeDate( aDetail.when ) ) );
177 m_tagMessage->ChangeValue( aDetail.message );
178
179 if( !m_tagsSplitter->IsSplit() )
181
182 m_tagDetail->Layout();
183}
184
185
191
192
194{
195 if( !m_dialog->SessionStillCurrent() )
196 return;
197
198 DIALOG_GIT_NEW_TAG dlg( this );
199
200 if( dlg.ShowModal() != wxID_OK )
201 return;
202
203 wxString name = dlg.GetTagName();
204 wxString message = dlg.GetMessage();
205
206 m_dialog->RunGitAction(
207 [name, message]( KIGIT_COMMON& aCommon )
208 {
209 return aCommon.CreateTag( name, message );
210 },
211 wxString::Format( _( "Could not create tag '%s'." ), name ) );
212}
213
214
216{
217 if( !m_dialog->SessionStillCurrent() )
218 return;
219
220 wxString name = KIGIT::SelectedText( m_tagsList, 0 );
221
222 if( name.IsEmpty() )
223 return;
224
225 m_dialog->RefuseOverUncommittedWork(
226 [this, name]( const GIT_WORKTREE_STATUS& aStatus )
227 {
228 if( !IsOK( this, wxString::Format( _( "Check out tag '%s'? This shows an old snapshot of the "
229 "project. To keep any commits you make here, create a new "
230 "branch before committing. Switching away without one "
231 "leaves those commits outside every branch." ),
232 name ) ) )
233 {
234 return;
235 }
236
237 if( !m_dialog->ConfirmWorkingTreeChange( aStatus ) )
238 return;
239
240 m_dialog->RunGitAction(
241 [name]( KIGIT_COMMON& aCommon )
242 {
243 return aCommon.CheckoutTag( name );
244 },
245 wxString::Format( _( "Could not check out tag '%s'." ), name ),
246 /* rewrites working tree */ true );
247 } );
248}
249
250
252{
253 if( !m_dialog->SessionStillCurrent() )
254 return;
255
256 wxString name = KIGIT::SelectedText( m_tagsList, 0 );
257
258 if( name.IsEmpty() )
259 return;
260
261 if( !IsOK( this, wxString::Format( _( "Delete tag '%s'?" ), name ) ) )
262 return;
263
264 m_dialog->RunGitAction(
265 [name]( KIGIT_COMMON& aCommon )
266 {
267 return aCommon.DeleteTag( name );
268 },
269 wxString::Format( _( "Could not delete tag '%s'." ), name ) );
270}
const char * name
Ask for a tag's name and its optional message. A message makes the tag annotated.
wxString GetTagName() const
wxString GetMessage() const
int ShowModal() override
The base frame for deriving all KiCad main window classes.
The advanced Git window: a non-modal dialog with a top bar naming the repository and branch and a sid...
The project's git session.
bool CheckoutTag(const wxString &aName)
bool DeleteTag(const wxString &aName)
bool CreateTag(const wxString &aName, const wxString &aMessage=wxEmptyString)
WX_SPLITTER_WINDOW * m_tagsSplitter
PANEL_GIT_TAGS_BASE(wxWindow *parent, wxWindowID id=wxID_ANY, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxSize(-1,-1), long style=wxTAB_TRAVERSAL, const wxString &name=wxEmptyString)
KIGIT_QUERY m_listQuery
List and detail reads share the session lock without waiting on the UI thread.
int m_tagSashPos
Where the user left the sash between the list and its detail pane.
PANEL_GIT_TAGS(wxWindow *aParent, GIT_ADVANCED_DIALOG *aDialog, EDA_BASE_FRAME *aFrame)
KIGIT_QUERY m_detailQuery
void showTagDetail(const wxString &aTag)
Fill the detail pane with aTag, or hide it when the name is empty or gone.
GIT_ADVANCED_DIALOG * m_dialog
bool m_fillingTags
True while the list is being refilled, when its selection events are its own.
void fillTagDetail(const KIGIT_TAG_DETAIL &aDetail)
EDA_BASE_FRAME * m_frame
void Populate()
Fill the list from the repository's tags. The repository is read on a worker.
bool IsOK(wxWindow *aParent, const wxString &aMessage)
Display a yes/no dialog with aMessage and returns the user response.
Definition confirm.cpp:274
This file is part of the common library.
#define _(s)
Base window classes and related definitions.
std::string message
void UnsplitKeepingSash(wxSplitterWindow *aSplitter, wxWindow *aPane, int &aSashPos)
Close a splitter's second pane, keeping the sash where the user left it for next time.
wxString SelectedText(wxListCtrl *aList, int aColumn)
The text of the selected row in a report list, or empty when nothing is selected.
wxString RelativeDate(const wxDateTime &aWhen)
"just now", "3 hours ago", or the ISO date once it is more than a month old.
void KeepDetailWidth(WX_SPLITTER_WINDOW *aSplitter)
Keep a split detail pane at the width its controls need, against both a narrow window and a dragged s...
void MarkDestructive(wxButton *aButton)
Paint a button's text the diff's red, for one that throws something away.
Repository state used before an operation that requires a clean working tree.
wxString message
The tag's own message, or the commit's for a lightweight tag.
wxString email
Their email.
wxString name
The tag name.
wxString hash
Short hash of the tagged commit.
wxDateTime when
When the tag was made, or the commit for a lightweight tag.
wxString author
Who made the tag, or the commit for a lightweight tag.
bool found
False when no tag of that name points at a commit.