28#include <wx/checkbox.h>
29#include <wx/listctrl.h>
33#include <wx/stattext.h>
34#include <wx/textctrl.h>
40 DIALOG_SHIM( aParent, wxID_ANY,
_(
"Git Branch Switch" ), wxDefaultPosition, wxDefaultSize,
41 wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER ),
42 m_timer( this ), m_repository( aRepository )
44 wxBoxSizer* sizer =
new wxBoxSizer( wxVERTICAL );
47 wxStaticText* explanationText =
48 new wxStaticText(
this, wxID_ANY,
_(
"Select or enter a branch name:" ) );
49 sizer->Add( explanationText, 0, wxALL, 10 );
52 m_branchList =
new wxListView(
this, wxID_ANY, wxDefaultPosition, wxDefaultSize,
53 wxLC_REPORT | wxLC_SINGLE_SEL );
60 m_branchNameText =
new wxTextCtrl(
this, wxID_ANY, wxEmptyString, wxDefaultPosition,
61 wxDefaultSize, wxTE_PROCESS_ENTER );
65 wxStdDialogButtonSizer* buttonSizer =
new wxStdDialogButtonSizer();
69 wxButton* cancelButton =
new wxButton(
this, wxID_CANCEL,
_(
"Cancel" ) );
70 buttonSizer->AddButton( cancelButton );
71 buttonSizer->Realize();
72 sizer->Add( buttonSizer, 0, wxALIGN_RIGHT | wxALL, 10 );
86 SetSizerAndFit( sizer );
109 wxDateTime lastUpdated( data.lastUpdated );
110 wxString lastUpdatedString = lastUpdated.Format();
113 m_branchList->SetItem( itemIndex, 1, data.commitString );
114 m_branchList->SetItem( itemIndex, 2, lastUpdatedString );
126 int selection = aEvent.GetIndex();
128 if( selection != wxNOT_FOUND )
130 wxString branchName =
m_branchList->GetItemText( selection );
141 int selection = aEvent.GetIndex();
143 if( selection != wxNOT_FOUND )
145 wxString branchName =
m_branchList->GetItemText( selection );
153 for(
int ii = 0; ii <
m_branchList->GetItemCount(); ++ii )
163 bool branchExists =
m_branches.count(branchName);
178 EndModal(wxID_CANCEL);
210 bool branchExists =
m_branches.count( branchName );
236 git_branch_iterator* branchIterator =
nullptr;
237 git_branch_t branchType;
240 git_reference* currentBranchReference =
nullptr;
241 git_repository_head( ¤tBranchReference,
m_repository );
244 if( currentBranchReference )
247 git_reference_free( currentBranchReference );
251 git_branch_iterator_new( &branchIterator,
m_repository, GIT_BRANCH_ALL );
254 git_reference* branchReference =
nullptr;
255 while( git_branch_next( &branchReference, &branchType, branchIterator ) == 0 )
258 const git_oid* branchOid = git_reference_target( branchReference );
263 git_reference_free( branchReference );
267 git_commit* commit =
nullptr;
269 if( git_commit_lookup( &commit,
m_repository, branchOid ) )
272 git_reference_free( branchReference );
279 branchData.
lastUpdated =
static_cast<time_t
>( git_commit_time( commit ) );
280 branchData.
isRemote = branchType == GIT_BRANCH_REMOTE;
282 m_branches[git_reference_shorthand( branchReference )] = branchData;
284 git_commit_free( commit );
285 git_reference_free( branchReference );
288 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...