Use libgit2 git_reference_is_valid_name() to validate branch name
[TortoiseGit.git] / src / TortoiseProc / BisectStartDlg.cpp
blobb67857f67d6cb01bfc216d7a2fc699921787c48b
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2011-2013 Sven Strickroth, <email@cs-ware.de>
5 // with code of PullFetchDlg.cpp
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License
9 // as published by the Free Software Foundation; either version 2
10 // of the License, or (at your option) any later version.
12 // This program is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software Foundation,
19 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 #include "stdafx.h"
23 #include "TortoiseProc.h"
24 #include "BisectStartDlg.h"
25 #include "git.h"
26 #include "LogDlg.h"
27 #include "MessageBox.h"
28 #include "AppUtils.h"
30 IMPLEMENT_DYNAMIC(CBisectStartDlg, CHorizontalResizableStandAloneDialog)
32 CBisectStartDlg::CBisectStartDlg(CWnd* pParent /*=NULL*/)
33 : CHorizontalResizableStandAloneDialog(CBisectStartDlg::IDD, pParent)
37 CBisectStartDlg::~CBisectStartDlg()
41 void CBisectStartDlg::DoDataExchange(CDataExchange* pDX)
43 CHorizontalResizableStandAloneDialog::DoDataExchange(pDX);
44 DDX_Control(pDX, IDC_COMBOBOXEX_GOOD, m_cLastGoodRevision);
45 DDX_Control(pDX, IDC_COMBOBOXEX_BAD, m_cFirstBadRevision);
48 BEGIN_MESSAGE_MAP(CBisectStartDlg, CHorizontalResizableStandAloneDialog)
49 ON_BN_CLICKED(IDOK, &CBisectStartDlg::OnBnClickedOk)
50 ON_BN_CLICKED(IDC_BUTTON_GOOD, &CBisectStartDlg::OnBnClickedButtonGood)
51 ON_BN_CLICKED(IDC_BUTTON_BAD, &CBisectStartDlg::OnBnClickedButtonBad)
52 ON_CBN_SELCHANGE(IDC_COMBOBOXEX_GOOD, &CBisectStartDlg::OnChangedRevision)
53 ON_CBN_SELCHANGE(IDC_COMBOBOXEX_BAD, &CBisectStartDlg::OnChangedRevision)
54 ON_CBN_EDITCHANGE(IDC_COMBOBOXEX_GOOD, &CBisectStartDlg::OnChangedRevision)
55 ON_CBN_EDITCHANGE(IDC_COMBOBOXEX_BAD, &CBisectStartDlg::OnChangedRevision)
56 END_MESSAGE_MAP()
58 BOOL CBisectStartDlg::OnInitDialog()
60 CHorizontalResizableStandAloneDialog::OnInitDialog();
61 CAppUtils::MarkWindowAsUnpinnable(m_hWnd);
63 AddAnchor(IDOK, BOTTOM_RIGHT);
64 AddAnchor(IDCANCEL, BOTTOM_RIGHT);
65 AddAnchor(IDHELP, BOTTOM_RIGHT);
67 AddAnchor(IDC_BUTTON_GOOD, TOP_RIGHT);
68 AddAnchor(IDC_BUTTON_BAD, TOP_RIGHT);
69 AddAnchor(IDC_COMBOBOXEX_GOOD, TOP_LEFT, TOP_RIGHT);
70 AddAnchor(IDC_COMBOBOXEX_BAD, TOP_LEFT, TOP_RIGHT);
72 EnableSaveRestore(_T("BisectStartDlg"));
74 CString sWindowTitle;
75 GetWindowText(sWindowTitle);
76 CAppUtils::SetWindowTitle(m_hWnd, g_Git.m_CurrentDir, sWindowTitle);
78 STRING_VECTOR list;
79 int current;
80 g_Git.GetBranchList(list, &current, CGit::BRANCH_ALL);
81 m_cLastGoodRevision.SetMaxHistoryItems(0x7FFFFFFF);
82 m_cFirstBadRevision.SetMaxHistoryItems(0x7FFFFFFF);
83 for (unsigned int i = 0; i < list.size(); ++i)
85 m_cLastGoodRevision.AddString(list[i]);
86 m_cFirstBadRevision.AddString(list[i]);
88 list.clear();
89 g_Git.GetTagList(list);
90 for (unsigned int i = 0; i < list.size(); ++i)
92 m_cLastGoodRevision.AddString(list[i]);
93 m_cFirstBadRevision.AddString(list[i]);
96 if (m_sLastGood.IsEmpty())
97 m_cLastGoodRevision.SetCurSel(-1);
98 else
99 m_cLastGoodRevision.SetWindowTextW(m_sLastGood);
100 if (m_sFirstBad.IsEmpty())
101 m_cFirstBadRevision.SetCurSel(current);
102 else
103 m_cFirstBadRevision.SetWindowTextW(m_sFirstBad);
105 this->UpdateData(FALSE);
107 // EnDisable OK Button
108 OnChangedRevision();
110 return TRUE;
113 void CBisectStartDlg::OnChangedRevision()
115 this->GetDlgItem(IDOK)->EnableWindow(!(m_cLastGoodRevision.GetString().Trim().IsEmpty() || m_cFirstBadRevision.GetString().Trim().IsEmpty()));
118 void CBisectStartDlg::OnBnClickedOk()
120 CHorizontalResizableStandAloneDialog::UpdateData(TRUE);
122 m_LastGoodRevision = m_cLastGoodRevision.GetString().Trim();
123 m_FirstBadRevision = m_cFirstBadRevision.GetString().Trim();
125 if(m_FirstBadRevision.Find(_T("remotes/")) == 0)
126 m_FirstBadRevision = m_FirstBadRevision.Mid(8);
128 if(m_FirstBadRevision.Find(_T("remotes/")) == 0)
129 m_FirstBadRevision = m_FirstBadRevision.Mid(8);
131 CHorizontalResizableStandAloneDialog::OnOK();
134 void CBisectStartDlg::OnBnClickedButtonGood()
136 // use the git log to allow selection of a version
137 CLogDlg dlg;
138 // tell the dialog to use mode for selecting revisions
139 dlg.SetSelect(true);
140 // only one revision must be selected however
141 dlg.SingleSelection(true);
142 if (dlg.DoModal() == IDOK)
144 // get selected hash if any
145 CString selectedHash = dlg.GetSelectedHash();
146 // load into window, do this even if empty so that it is clear that nothing has been selected
147 m_cLastGoodRevision.SetWindowText(selectedHash);
148 OnChangedRevision();
152 void CBisectStartDlg::OnBnClickedButtonBad()
154 // use the git log to allow selection of a version
155 CLogDlg dlg;
156 // tell the dialog to use mode for selecting revisions
157 dlg.SetSelect(true);
158 // only one revision must be selected however
159 dlg.SingleSelection(true);
160 if (dlg.DoModal() == IDOK)
162 // get selected hash if any
163 CString selectedHash = dlg.GetSelectedHash();
164 // load into window, do this even if empty so that it is clear that nothing has been selected
165 m_cFirstBadRevision.SetWindowText(selectedHash);
166 OnChangedRevision();