Fixed issue #4126: Capitalize the first letter in the Push dialog
[TortoiseGit.git] / src / TortoiseProc / BisectStartDlg.cpp
blobdd10fff550b337d941ab0540cf1474f2164c8930
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2014-2020, 2024 TortoiseGit
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 "AppUtils.h"
28 #include "StringUtils.h"
29 #include "MessageBox.h"
31 IMPLEMENT_DYNAMIC(CBisectStartDlg, CHorizontalResizableStandAloneDialog)
33 CBisectStartDlg::CBisectStartDlg(CWnd* pParent /*=nullptr*/)
34 : CHorizontalResizableStandAloneDialog(CBisectStartDlg::IDD, pParent)
38 CBisectStartDlg::~CBisectStartDlg()
42 void CBisectStartDlg::DoDataExchange(CDataExchange* pDX)
44 CHorizontalResizableStandAloneDialog::DoDataExchange(pDX);
45 DDX_Control(pDX, IDC_COMBOBOXEX_GOOD, m_cLastGoodRevision);
46 DDX_Control(pDX, IDC_COMBOBOXEX_BAD, m_cFirstBadRevision);
49 BEGIN_MESSAGE_MAP(CBisectStartDlg, CHorizontalResizableStandAloneDialog)
50 ON_BN_CLICKED(IDOK, &CBisectStartDlg::OnBnClickedOk)
51 ON_BN_CLICKED(IDC_BUTTON_GOOD, &CBisectStartDlg::OnBnClickedButtonGood)
52 ON_BN_CLICKED(IDC_BUTTON_BAD, &CBisectStartDlg::OnBnClickedButtonBad)
53 ON_CBN_SELCHANGE(IDC_COMBOBOXEX_GOOD, &CBisectStartDlg::OnChangedRevision)
54 ON_CBN_SELCHANGE(IDC_COMBOBOXEX_BAD, &CBisectStartDlg::OnChangedRevision)
55 ON_CBN_EDITCHANGE(IDC_COMBOBOXEX_GOOD, &CBisectStartDlg::OnChangedRevision)
56 ON_CBN_EDITCHANGE(IDC_COMBOBOXEX_BAD, &CBisectStartDlg::OnChangedRevision)
57 END_MESSAGE_MAP()
59 static void uniqueMergeLists(STRING_VECTOR& list, const STRING_VECTOR& listToMerge)
61 std::map<CString, int> map;
62 for (CString entry : list)
63 map[entry] = 1;
65 for (CString entry : listToMerge)
67 if (map.find(entry) == map.end())
68 list.push_back(entry);
72 BOOL CBisectStartDlg::OnInitDialog()
74 CHorizontalResizableStandAloneDialog::OnInitDialog();
75 CAppUtils::MarkWindowAsUnpinnable(m_hWnd);
77 AddAnchor(IDOK, BOTTOM_RIGHT);
78 AddAnchor(IDCANCEL, BOTTOM_RIGHT);
79 AddAnchor(IDHELP, BOTTOM_RIGHT);
81 AddAnchor(IDC_STATIC_LOCAL_BRANCH, TOP_LEFT);
82 AddAnchor(IDC_STATIC_REMOTE_BRANCH, TOP_LEFT);
84 AddAnchor(IDC_BUTTON_GOOD, TOP_RIGHT);
85 AddAnchor(IDC_BUTTON_BAD, TOP_RIGHT);
86 AddAnchor(IDC_COMBOBOXEX_GOOD, TOP_LEFT, TOP_RIGHT);
87 AddAnchor(IDC_COMBOBOXEX_BAD, TOP_LEFT, TOP_RIGHT);
89 EnableSaveRestore(L"BisectStartDlg");
91 CAppUtils::SetWindowTitle(*this, g_Git.m_CurrentDir);
93 STRING_VECTOR list;
94 int current = -1;
95 g_Git.GetBranchList(list, &current, CGit::BRANCH_ALL);
96 m_cLastGoodRevision.SetMaxHistoryItems(0x7FFFFFFF);
97 m_cFirstBadRevision.SetMaxHistoryItems(0x7FFFFFFF);
98 STRING_VECTOR tagsList;
99 g_Git.GetTagList(tagsList);
100 uniqueMergeLists(list, tagsList);
101 m_cLastGoodRevision.SetList(list);
102 m_cFirstBadRevision.SetList(list);
103 if (m_sLastGood.IsEmpty())
104 m_cLastGoodRevision.SetCurSel(-1);
105 else
106 m_cLastGoodRevision.SetWindowTextW(m_sLastGood);
107 if (!m_sFirstBad.IsEmpty())
108 m_cFirstBadRevision.SetWindowTextW(m_sFirstBad);
109 else if (current >= 0)
110 m_cFirstBadRevision.SetCurSel(current);
111 else
112 m_cFirstBadRevision.SetWindowTextW(L"HEAD");
113 this->UpdateData(FALSE);
115 // EnDisable OK Button
116 OnChangedRevision();
118 return TRUE;
121 void CBisectStartDlg::OnChangedRevision()
123 this->GetDlgItem(IDOK)->EnableWindow(!(m_cLastGoodRevision.GetString().Trim().IsEmpty() || m_cFirstBadRevision.GetString().Trim().IsEmpty()));
126 void CBisectStartDlg::OnBnClickedOk()
128 CHorizontalResizableStandAloneDialog::UpdateData(TRUE);
130 m_LastGoodRevision = m_cLastGoodRevision.GetString().Trim();
131 m_FirstBadRevision = m_cFirstBadRevision.GetString().Trim();
133 if (CStringUtils::StartsWith(m_FirstBadRevision, L"remotes/"))
134 m_FirstBadRevision = m_FirstBadRevision.Mid(static_cast<int>(wcslen(L"remotes/")));
136 if (CStringUtils::StartsWith(m_FirstBadRevision, L"remotes/"))
137 m_FirstBadRevision = m_FirstBadRevision.Mid(static_cast<int>(wcslen(L"remotes/")));
139 CHorizontalResizableStandAloneDialog::OnOK();
142 void CBisectStartDlg::OnBnClickedButtonGood()
144 // use the git log to allow selection of a version
145 CLogDlg dlg;
146 if (dlg.IsThreadRunning())
148 CMessageBox::Show(GetSafeHwnd(), IDS_PROC_LOG_ONLYONCE, IDS_APPNAME, MB_ICONEXCLAMATION);
149 return;
151 CString revision;
152 m_cLastGoodRevision.GetWindowText(revision);
153 dlg.SetParams(CTGitPath(), CTGitPath(), revision, revision, 0);
154 // tell the dialog to use mode for selecting revisions
155 dlg.SetSelect(true);
156 dlg.ShowWorkingTreeChanges(false);
157 // only one revision must be selected however
158 dlg.SingleSelection(true);
159 if (dlg.DoModal() == IDOK && !dlg.GetSelectedHash().empty())
161 m_cLastGoodRevision.SetWindowText(dlg.GetSelectedHash().at(0).ToString());
162 OnChangedRevision();
164 BringWindowToTop(); /* cf. issue #3493 */
167 void CBisectStartDlg::OnBnClickedButtonBad()
169 // use the git log to allow selection of a version
170 CLogDlg dlg;
171 if (dlg.IsThreadRunning())
173 CMessageBox::Show(GetSafeHwnd(), IDS_PROC_LOG_ONLYONCE, IDS_APPNAME, MB_ICONEXCLAMATION);
174 return;
176 CString revision;
177 m_cFirstBadRevision.GetWindowText(revision);
178 dlg.SetParams(CTGitPath(), CTGitPath(), revision, revision, 0);
179 // tell the dialog to use mode for selecting revisions
180 dlg.SetSelect(true);
181 dlg.ShowWorkingTreeChanges(false);
182 // only one revision must be selected however
183 dlg.SingleSelection(true);
184 if (dlg.DoModal() == IDOK && !dlg.GetSelectedHash().empty())
186 m_cFirstBadRevision.SetWindowText(dlg.GetSelectedHash().at(0).ToString());
187 OnChangedRevision();
189 BringWindowToTop(); /* cf. issue #3493 */