27#include <wx/checkbox.h>
28#include <wx/listctrl.h>
33#include <wx/stattext.h>
34#include <wx/textctrl.h>
42 if( aName.StartsWith( wxS(
"* " ) ) || aName.StartsWith( wxS(
" " ) ) )
43 return aName.Mid( 2 );
50 DIALOG_SHIM( aParent, wxID_ANY,
_(
"Git Branch Switch" ), wxDefaultPosition, wxDefaultSize,
51 wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER ),
54 wxBoxSizer* sizer =
new wxBoxSizer( wxVERTICAL );
57 wxStaticText* explanationText =
58 new wxStaticText(
this, wxID_ANY,
_(
"Select or enter a branch name:" ) );
59 sizer->Add( explanationText, 0, wxALL, 10 );
62 m_branchList =
new wxListView(
this, wxID_ANY, wxDefaultPosition, wxDefaultSize,
63 wxLC_REPORT | wxLC_SINGLE_SEL );
70 m_branchNameText =
new wxTextCtrl(
this, wxID_ANY, wxEmptyString, wxDefaultPosition,
71 wxDefaultSize, wxTE_PROCESS_ENTER );
75 wxStdDialogButtonSizer* buttonSizer =
new wxStdDialogButtonSizer();
79 wxButton* cancelButton =
new wxButton(
this, wxID_CANCEL,
_(
"Cancel" ) );
80 buttonSizer->AddButton( cancelButton );
81 buttonSizer->Realize();
82 sizer->Add( buttonSizer, 0, wxALIGN_RIGHT | wxALL, 10 );
96 SetSizerAndFit( sizer );
116 long currentIndex = -1;
121 wxDateTime lastUpdated( data.lastUpdated );
122 wxString lastUpdatedString = lastUpdated.Format();
126 m_branchList->SetItem( itemIndex, 1, data.commitString );
127 m_branchList->SetItem( itemIndex, 2, lastUpdatedString );
130 currentIndex = itemIndex;
137 if( currentIndex >= 0 )
148 int selection = aEvent.GetIndex();
150 if( selection != wxNOT_FOUND )
163 int selection = aEvent.GetIndex();
165 if( selection != wxNOT_FOUND )
175 for(
int ii = 0; ii <
m_branchList->GetItemCount(); ++ii )
185 bool branchExists =
m_branches.count(branchName);
200 EndModal(wxID_CANCEL);
232 bool branchExists =
m_branches.count( branchName );
258 git_branch_iterator* branchIterator =
nullptr;
259 git_branch_t branchType;
262 git_reference* currentBranchReference =
nullptr;
263 git_repository_head( ¤tBranchReference,
m_repository );
265 if( !currentBranchReference )
267 wxLogTrace(
traceGit,
"Failed to get current branch" );
275 git_branch_iterator_new( &branchIterator,
m_repository, GIT_BRANCH_ALL );
279 git_reference* branchReference =
nullptr;
280 while( git_branch_next( &branchReference, &branchType, branchIterator ) == 0 )
285 const git_oid* branchOid = git_reference_target( branchReference );
291 git_commit* commit =
nullptr;
293 if( git_commit_lookup( &commit,
m_repository, branchOid ) )
304 branchData.
lastUpdated =
static_cast<time_t
>( git_commit_time( commit ) );
305 branchData.
isRemote = branchType == GIT_BRANCH_REMOTE;
307 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.