31#include <wx/checkbox.h>
32#include <wx/listctrl.h>
37#include <wx/stattext.h>
38#include <wx/textctrl.h>
44 DIALOG_SHIM( aParent, wxID_ANY,
_(
"Git Branch Switch" ), wxDefaultPosition, wxDefaultSize,
45 wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER ),
48 wxBoxSizer* sizer =
new wxBoxSizer( wxVERTICAL );
51 wxStaticText* explanationText =
52 new wxStaticText(
this, wxID_ANY,
_(
"Select or enter a branch name:" ) );
53 sizer->Add( explanationText, 0, wxALL, 10 );
56 m_branchList =
new wxListView(
this, wxID_ANY, wxDefaultPosition, wxDefaultSize,
57 wxLC_REPORT | wxLC_SINGLE_SEL );
64 m_branchNameText =
new wxTextCtrl(
this, wxID_ANY, wxEmptyString, wxDefaultPosition,
65 wxDefaultSize, wxTE_PROCESS_ENTER );
69 wxStdDialogButtonSizer* buttonSizer =
new wxStdDialogButtonSizer();
73 wxButton* cancelButton =
new wxButton(
this, wxID_CANCEL,
_(
"Cancel" ) );
74 buttonSizer->AddButton( cancelButton );
75 buttonSizer->Realize();
76 sizer->Add( buttonSizer, 0, wxALIGN_RIGHT | wxALL, 10 );
90 SetSizerAndFit( sizer );
113 wxDateTime lastUpdated( data.lastUpdated );
114 wxString lastUpdatedString = lastUpdated.Format();
117 m_branchList->SetItem( itemIndex, 1, data.commitString );
118 m_branchList->SetItem( itemIndex, 2, lastUpdatedString );
130 int selection = aEvent.GetIndex();
132 if( selection != wxNOT_FOUND )
134 wxString branchName =
m_branchList->GetItemText( selection );
145 int selection = aEvent.GetIndex();
147 if( selection != wxNOT_FOUND )
149 wxString branchName =
m_branchList->GetItemText( selection );
157 for(
int ii = 0; ii <
m_branchList->GetItemCount(); ++ii )
167 bool branchExists =
m_branches.count(branchName);
182 EndModal(wxID_CANCEL);
214 bool branchExists =
m_branches.count( branchName );
240 git_branch_iterator* branchIterator =
nullptr;
241 git_branch_t branchType;
244 git_reference* currentBranchReference =
nullptr;
245 git_repository_head( ¤tBranchReference,
m_repository );
247 if( !currentBranchReference )
249 wxLogTrace(
traceGit,
"Failed to get current branch" );
257 git_branch_iterator_new( &branchIterator,
m_repository, GIT_BRANCH_ALL );
261 git_reference* branchReference =
nullptr;
262 while( git_branch_next( &branchReference, &branchType, branchIterator ) == 0 )
267 const git_oid* branchOid = git_reference_target( branchReference );
273 git_commit* commit =
nullptr;
275 if( git_commit_lookup( &commit,
m_repository, branchOid ) )
286 branchData.
lastUpdated =
static_cast<time_t
>( git_commit_time( commit ) );
287 branchData.
isRemote = branchType == GIT_BRANCH_REMOTE;
289 m_branches[git_reference_shorthand( branchReference )] = branchData;
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)
void finishDialogSettings()
In all dialogs, we must call the same functions to fix minimal dlg size, the default position and per...
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)
const wxChar *const traceGit
Flag to enable Git debugging output.
std::unique_ptr< git_commit, decltype([](git_commit *aCommit) { git_commit_free(aCommit); })> GitCommitPtr
A unique pointer for git_commit objects with automatic cleanup.
std::unique_ptr< git_reference, decltype([](git_reference *aRef) { git_reference_free(aRef); })> GitReferencePtr
A unique pointer for git_reference objects with automatic cleanup.
std::unique_ptr< git_branch_iterator, decltype([](git_branch_iterator *aIter) { git_branch_iterator_free(aIter); })> GitBranchIteratorPtr
A unique pointer for git_branch_iterator objects with automatic cleanup.
wxLogTrace helper definitions.