28#include <wx/checkbox.h>
29#include <wx/listctrl.h>
32#include <wx/stattext.h>
33#include <wx/textctrl.h>
39 DIALOG_SHIM( aParent, wxID_ANY,
_(
"Git Branch Switch" ), wxDefaultPosition, wxDefaultSize,
40 wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER ),
41 m_timer( this ), m_repository( aRepository )
43 wxBoxSizer* sizer =
new wxBoxSizer( wxVERTICAL );
46 wxStaticText* explanationText =
47 new wxStaticText(
this, wxID_ANY,
_(
"Select or enter a branch name:" ) );
48 sizer->Add( explanationText, 0, wxALL, 10 );
51 m_branchList =
new wxListView(
this, wxID_ANY, wxDefaultPosition, wxDefaultSize,
52 wxLC_REPORT | wxLC_SINGLE_SEL );
59 m_branchNameText =
new wxTextCtrl(
this, wxID_ANY, wxEmptyString, wxDefaultPosition,
60 wxDefaultSize, wxTE_PROCESS_ENTER );
64 wxStdDialogButtonSizer* buttonSizer =
new wxStdDialogButtonSizer();
68 wxButton* cancelButton =
new wxButton(
this, wxID_CANCEL,
_(
"Cancel" ) );
69 buttonSizer->AddButton( cancelButton );
70 buttonSizer->Realize();
71 sizer->Add( buttonSizer, 0, wxALIGN_RIGHT | wxALL, 10 );
85 SetSizerAndFit( sizer );
108 wxDateTime lastUpdated( data.lastUpdated );
109 wxString lastUpdatedString = lastUpdated.Format();
112 m_branchList->SetItem( itemIndex, 1, data.commitString );
113 m_branchList->SetItem( itemIndex, 2, lastUpdatedString );
125 int selection = aEvent.GetIndex();
127 if( selection != wxNOT_FOUND )
129 wxString branchName =
m_branchList->GetItemText( selection );
140 int selection = aEvent.GetIndex();
142 if( selection != wxNOT_FOUND )
144 wxString branchName =
m_branchList->GetItemText( selection );
152 for(
int ii = 0; ii <
m_branchList->GetItemCount(); ++ii )
162 bool branchExists =
m_branches.count(branchName);
177 EndModal(wxID_CANCEL);
209 bool branchExists =
m_branches.count( branchName );
235 git_branch_iterator* branchIterator =
nullptr;
236 git_branch_t branchType;
239 git_reference* currentBranchReference =
nullptr;
240 git_repository_head( ¤tBranchReference,
m_repository );
243 if( currentBranchReference )
246 git_reference_free( currentBranchReference );
250 git_branch_iterator_new( &branchIterator,
m_repository, GIT_BRANCH_ALL );
253 git_reference* branchReference =
nullptr;
254 while( git_branch_next( &branchReference, &branchType, branchIterator ) == 0 )
257 const git_oid* branchOid = git_reference_target( branchReference );
262 git_reference_free( branchReference );
266 git_commit* commit =
nullptr;
268 if( git_commit_lookup( &commit,
m_repository, branchOid ) )
271 git_reference_free( branchReference );
278 branchData.
lastUpdated =
static_cast<time_t
>( git_commit_time( commit ) );
279 branchData.
isRemote = branchType == GIT_BRANCH_REMOTE;
281 m_branches[git_reference_shorthand( branchReference )] = branchData;
283 git_commit_free( commit );
284 git_reference_free( branchReference );
287 git_branch_iterator_free( branchIterator );
DIALOG_GIT_SWITCH(wxWindow *aParent, git_repository *aRepository)
void PopulateBranchList()
wxListView * m_branchList
git_repository * m_repository
virtual ~DIALOG_GIT_SWITCH()
wxString GetBranchName() const
void OnTextChanged(wxCommandEvent &event)
wxButton * m_switchButton
wxString m_lastEnteredText
std::map< wxString, BranchData > m_branches
void OnCancelButton(wxCommandEvent &event)
wxTextCtrl * m_branchNameText
void OnBranchListSelection(wxListEvent &event)
void OnBranchListDClick(wxListEvent &event)
void OnTimer(wxTimerEvent &event)
void OnSwitchButton(wxCommandEvent &event)
Dialog helper object to sit in the inheritance tree between wxDialog and any class written by wxFormB...
void finishDialogSettings()
In all dialogs, we must call the same functions to fix minimal dlg size, the default position and per...