31#include <wx/checkbox.h>
32#include <wx/listctrl.h>
37#include <wx/stattext.h>
38#include <wx/textctrl.h>
46 if( aName.StartsWith( wxS(
"* " ) ) || aName.StartsWith( wxS(
" " ) ) )
47 return aName.Mid( 2 );
54 DIALOG_SHIM( aParent, wxID_ANY,
_(
"Git Branch Switch" ), wxDefaultPosition, wxDefaultSize,
55 wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER ),
58 wxBoxSizer* sizer =
new wxBoxSizer( wxVERTICAL );
61 wxStaticText* explanationText =
62 new wxStaticText(
this, wxID_ANY,
_(
"Select or enter a branch name:" ) );
63 sizer->Add( explanationText, 0, wxALL, 10 );
66 m_branchList =
new wxListView(
this, wxID_ANY, wxDefaultPosition, wxDefaultSize,
67 wxLC_REPORT | wxLC_SINGLE_SEL );
74 m_branchNameText =
new wxTextCtrl(
this, wxID_ANY, wxEmptyString, wxDefaultPosition,
75 wxDefaultSize, wxTE_PROCESS_ENTER );
79 wxStdDialogButtonSizer* buttonSizer =
new wxStdDialogButtonSizer();
83 wxButton* cancelButton =
new wxButton(
this, wxID_CANCEL,
_(
"Cancel" ) );
84 buttonSizer->AddButton( cancelButton );
85 buttonSizer->Realize();
86 sizer->Add( buttonSizer, 0, wxALIGN_RIGHT | wxALL, 10 );
100 SetSizerAndFit( sizer );
120 long currentIndex = -1;
125 wxDateTime lastUpdated( data.lastUpdated );
126 wxString lastUpdatedString = lastUpdated.Format();
130 m_branchList->SetItem( itemIndex, 1, data.commitString );
131 m_branchList->SetItem( itemIndex, 2, lastUpdatedString );
134 currentIndex = itemIndex;
141 if( currentIndex >= 0 )
152 int selection = aEvent.GetIndex();
154 if( selection != wxNOT_FOUND )
167 int selection = aEvent.GetIndex();
169 if( selection != wxNOT_FOUND )
179 for(
int ii = 0; ii <
m_branchList->GetItemCount(); ++ii )
189 bool branchExists =
m_branches.count(branchName);
204 EndModal(wxID_CANCEL);
236 bool branchExists =
m_branches.count( branchName );
262 git_branch_iterator* branchIterator =
nullptr;
263 git_branch_t branchType;
266 git_reference* currentBranchReference =
nullptr;
267 git_repository_head( ¤tBranchReference,
m_repository );
269 if( !currentBranchReference )
271 wxLogTrace(
traceGit,
"Failed to get current branch" );
279 git_branch_iterator_new( &branchIterator,
m_repository, GIT_BRANCH_ALL );
283 git_reference* branchReference =
nullptr;
284 while( git_branch_next( &branchReference, &branchType, branchIterator ) == 0 )
289 const git_oid* branchOid = git_reference_target( branchReference );
295 git_commit* commit =
nullptr;
297 if( git_commit_lookup( &commit,
m_repository, branchOid ) )
308 branchData.
lastUpdated =
static_cast<time_t
>( git_commit_time( commit ) );
309 branchData.
isRemote = branchType == GIT_BRANCH_REMOTE;
311 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)
static wxString stripBranchMarker(const wxString &aName)
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.