Fixed issue #3307: Abort Merge on a single file always results in a parameter error...
[TortoiseGit.git] / src / TortoiseProc / BisectStartDlg.cpp
blob7f330773a10c74b0b067cf5cb87e2608d0ccf130
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2014-2018 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"
30 IMPLEMENT_DYNAMIC(CBisectStartDlg, CHorizontalResizableStandAloneDialog)
32 CBisectStartDlg::CBisectStartDlg(CWnd* pParent /*=nullptr*/)
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 static void uniqueMergeLists(STRING_VECTOR& list, const STRING_VECTOR& listToMerge)
60 std::map<CString, int> map;
61 for (CString entry : list)
62 map[entry] = 1;
64 for (CString entry : listToMerge)
66 if (map.find(entry) == map.end())
67 list.push_back(entry);
71 BOOL CBisectStartDlg::OnInitDialog()
73 CHorizontalResizableStandAloneDialog::OnInitDialog();
74 CAppUtils::MarkWindowAsUnpinnable(m_hWnd);
76 AddAnchor(IDOK, BOTTOM_RIGHT);
77 AddAnchor(IDCANCEL, BOTTOM_RIGHT);
78 AddAnchor(IDHELP, BOTTOM_RIGHT);
80 AddAnchor(IDC_STATIC_LOCAL_BRANCH, TOP_LEFT);
81 AddAnchor(IDC_STATIC_REMOTE_BRANCH, TOP_LEFT);
83 AddAnchor(IDC_BUTTON_GOOD, TOP_RIGHT);
84 AddAnchor(IDC_BUTTON_BAD, TOP_RIGHT);
85 AddAnchor(IDC_COMBOBOXEX_GOOD, TOP_LEFT, TOP_RIGHT);
86 AddAnchor(IDC_COMBOBOXEX_BAD, TOP_LEFT, TOP_RIGHT);
88 EnableSaveRestore(L"BisectStartDlg");
90 CString sWindowTitle;
91 GetWindowText(sWindowTitle);
92 CAppUtils::SetWindowTitle(m_hWnd, g_Git.m_CurrentDir, sWindowTitle);
94 STRING_VECTOR list;
95 int current = -1;
96 g_Git.GetBranchList(list, &current, CGit::BRANCH_ALL);
97 m_cLastGoodRevision.SetMaxHistoryItems(0x7FFFFFFF);
98 m_cFirstBadRevision.SetMaxHistoryItems(0x7FFFFFFF);
99 STRING_VECTOR tagsList;
100 g_Git.GetTagList(tagsList);
101 uniqueMergeLists(list, tagsList);
102 m_cLastGoodRevision.SetList(list);
103 m_cFirstBadRevision.SetList(list);
104 if (m_sLastGood.IsEmpty())
105 m_cLastGoodRevision.SetCurSel(-1);
106 else
107 m_cLastGoodRevision.SetWindowTextW(m_sLastGood);
108 if (!m_sFirstBad.IsEmpty())
109 m_cFirstBadRevision.SetWindowTextW(m_sFirstBad);
110 else if (current >= 0)
111 m_cFirstBadRevision.SetCurSel(current);
112 else
113 m_cFirstBadRevision.SetWindowTextW(L"HEAD");
114 this->UpdateData(FALSE);
116 // EnDisable OK Button
117 OnChangedRevision();
119 return TRUE;
122 void CBisectStartDlg::OnChangedRevision()
124 this->GetDlgItem(IDOK)->EnableWindow(!(m_cLastGoodRevision.GetString().Trim().IsEmpty() || m_cFirstBadRevision.GetString().Trim().IsEmpty()));
127 void CBisectStartDlg::OnBnClickedOk()
129 CHorizontalResizableStandAloneDialog::UpdateData(TRUE);
131 m_LastGoodRevision = m_cLastGoodRevision.GetString().Trim();
132 m_FirstBadRevision = m_cFirstBadRevision.GetString().Trim();
134 if (CStringUtils::StartsWith(m_FirstBadRevision, L"remotes/"))
135 m_FirstBadRevision = m_FirstBadRevision.Mid((int)wcslen(L"remotes/"));
137 if (CStringUtils::StartsWith(m_FirstBadRevision, L"remotes/"))
138 m_FirstBadRevision = m_FirstBadRevision.Mid((int)wcslen(L"remotes/"));
140 CHorizontalResizableStandAloneDialog::OnOK();
143 void CBisectStartDlg::OnBnClickedButtonGood()
145 // use the git log to allow selection of a version
146 CLogDlg dlg;
147 CString revision;
148 m_cLastGoodRevision.GetWindowText(revision);
149 dlg.SetParams(CTGitPath(), CTGitPath(), revision, revision, 0);
150 // tell the dialog to use mode for selecting revisions
151 dlg.SetSelect(true);
152 dlg.ShowWorkingTreeChanges(false);
153 // only one revision must be selected however
154 dlg.SingleSelection(true);
155 if (dlg.DoModal() == IDOK && !dlg.GetSelectedHash().empty())
157 m_cLastGoodRevision.SetWindowText(dlg.GetSelectedHash().at(0).ToString());
158 OnChangedRevision();
162 void CBisectStartDlg::OnBnClickedButtonBad()
164 // use the git log to allow selection of a version
165 CLogDlg dlg;
166 CString revision;
167 m_cFirstBadRevision.GetWindowText(revision);
168 dlg.SetParams(CTGitPath(), CTGitPath(), revision, revision, 0);
169 // tell the dialog to use mode for selecting revisions
170 dlg.SetSelect(true);
171 dlg.ShowWorkingTreeChanges(false);
172 // only one revision must be selected however
173 dlg.SingleSelection(true);
174 if (dlg.DoModal() == IDOK && !dlg.GetSelectedHash().empty())
176 m_cFirstBadRevision.SetWindowText(dlg.GetSelectedHash().at(0).ToString());
177 OnChangedRevision();