Fix typos
[TortoiseGit.git] / src / TortoiseProc / RequestPullDlg.cpp
blob02d288f1a6e7cf4fdb15eccab2d2bce41a2a3d4e
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2011-2014, 2016-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 "RequestPullDlg.h"
25 #include "Git.h"
26 #include "LogDlg.h"
27 #include "MessageBox.h"
28 #include "AppUtils.h"
29 #include "StringUtils.h"
31 IMPLEMENT_DYNAMIC(CRequestPullDlg, CHorizontalResizableStandAloneDialog)
33 CRequestPullDlg::CRequestPullDlg(CWnd* pParent /*=nullptr*/)
34 : CHorizontalResizableStandAloneDialog(CRequestPullDlg::IDD, pParent)
35 , m_regSendMail(L"Software\\TortoiseGit\\TortoiseProc\\RequestPull\\SendMail", FALSE)
37 m_bSendMail = m_regSendMail;
40 CRequestPullDlg::~CRequestPullDlg()
44 void CRequestPullDlg::DoDataExchange(CDataExchange* pDX)
46 CHorizontalResizableStandAloneDialog::DoDataExchange(pDX);
47 DDX_Control(pDX, IDC_COMBOBOXEX_LOCAL_BRANCH, m_cStartRevision);
48 DDX_Control(pDX, IDC_COMBOBOXEX_URL, m_cRepositoryURL);
49 DDX_Control(pDX, IDC_REMOTE_BRANCH, m_cEndRevision);
50 DDX_Check(pDX, IDC_CHECK_SENDMAIL, m_bSendMail);
54 BEGIN_MESSAGE_MAP(CRequestPullDlg, CHorizontalResizableStandAloneDialog)
55 ON_BN_CLICKED(IDOK, &CRequestPullDlg::OnBnClickedOk)
56 ON_BN_CLICKED(IDC_BUTTON_LOCAL_BRANCH, &CRequestPullDlg::OnBnClickedButtonLocalBranch)
57 END_MESSAGE_MAP()
59 BOOL CRequestPullDlg::OnInitDialog()
61 CHorizontalResizableStandAloneDialog::OnInitDialog();
62 CAppUtils::MarkWindowAsUnpinnable(m_hWnd);
64 AddAnchor(IDOK,BOTTOM_RIGHT);
65 AddAnchor(IDCANCEL,BOTTOM_RIGHT);
66 AddAnchor(IDHELP,BOTTOM_RIGHT);
68 AddAnchor(IDC_BUTTON_LOCAL_BRANCH, TOP_RIGHT);
69 AddAnchor(IDC_COMBOBOXEX_LOCAL_BRANCH, TOP_LEFT,TOP_RIGHT);
70 AddAnchor(IDC_COMBOBOXEX_URL, TOP_LEFT,TOP_RIGHT);
71 AddAnchor(IDC_REMOTE_BRANCH, TOP_LEFT,TOP_RIGHT);
73 EnableSaveRestore(L"RequestPullDlg");
75 CAppUtils::SetWindowTitle(*this, g_Git.m_CurrentDir);
77 STRING_VECTOR list;
78 g_Git.GetBranchList(list, nullptr, CGit::BRANCH_ALL);
79 m_cStartRevision.SetMaxHistoryItems(0x7FFFFFFF);
80 m_cStartRevision.SetList(list);
82 CString WorkingDir=g_Git.m_CurrentDir;
83 WorkingDir.Replace(L':', L'_');
85 m_RegStartRevision = CRegString(L"Software\\TortoiseGit\\History\\RequestPull\\" + WorkingDir + L"\\startrevision");
86 if (m_StartRevision.IsEmpty())
87 m_StartRevision = m_RegStartRevision;
88 m_cStartRevision.SetWindowTextW(m_StartRevision);
90 // store URLs in global history, but save last used local url separately,
91 // because one normally has only one writable repository
92 m_cRepositoryURL.SetCaseSensitive(TRUE);
93 m_cRepositoryURL.SetURLHistory(TRUE);
94 m_cRepositoryURL.LoadHistory(L"Software\\TortoiseGit\\History\\RequestPull", L"url");
95 m_RegRepositoryURL = CRegString(L"Software\\TortoiseGit\\History\\RequestPull\\" + WorkingDir + L"\\repositoryurl");
96 if(m_RepositoryURL.IsEmpty())
97 m_RepositoryURL = m_RegRepositoryURL;
98 m_cRepositoryURL.SetWindowTextW(m_RepositoryURL);
100 m_RegEndRevision = CRegString(L"Software\\TortoiseGit\\History\\RequestPull\\" + WorkingDir + L"\\endrevision", L"HEAD");
101 if (m_EndRevision.IsEmpty())
102 m_EndRevision = m_RegEndRevision;
103 m_cEndRevision.SetWindowTextW(m_EndRevision);
105 this->UpdateData(FALSE);
107 SetTheme(CTheme::Instance().IsDarkTheme());
109 return TRUE;
112 void CRequestPullDlg::OnBnClickedOk()
114 CHorizontalResizableStandAloneDialog::UpdateData(TRUE);
116 m_cRepositoryURL.SaveHistory();
118 m_cStartRevision.GetWindowTextW(m_StartRevision);
119 m_RepositoryURL = m_cRepositoryURL.GetString();
120 m_cEndRevision.GetWindowTextW(m_EndRevision);
122 m_RegStartRevision = m_StartRevision;
123 m_RegRepositoryURL = m_RepositoryURL;
124 m_RegEndRevision = m_EndRevision.Trim();
126 if(!g_Git.IsBranchNameValid(m_EndRevision))
128 CMessageBox::Show(GetSafeHwnd(), IDS_B_T_NOTEMPTY, IDS_APPNAME, MB_OK | MB_ICONEXCLAMATION);
129 return;
132 if (CStringUtils::StartsWith(m_StartRevision, L"remotes/"))
133 m_StartRevision = m_StartRevision.Mid(static_cast<int>(wcslen(L"remotes/")));
135 m_regSendMail = m_bSendMail;
137 CHorizontalResizableStandAloneDialog::OnOK();
140 void CRequestPullDlg::OnBnClickedButtonLocalBranch()
142 // use the git log to allow selection of a version
143 CLogDlg dlg;
144 if (dlg.IsThreadRunning())
146 CMessageBox::Show(GetSafeHwnd(), IDS_PROC_LOG_ONLYONCE, IDS_APPNAME, MB_ICONEXCLAMATION);
147 return;
149 CString revision;
150 m_cStartRevision.GetWindowText(revision);
151 dlg.SetParams(CTGitPath(), CTGitPath(), revision, revision, 0);
152 // tell the dialog to use mode for selecting revisions
153 dlg.SetSelect(true);
154 dlg.ShowWorkingTreeChanges(false);
155 // only one revision must be selected however
156 dlg.SingleSelection(true);
157 if (dlg.DoModal() == IDOK && !dlg.GetSelectedHash().empty())
158 m_cStartRevision.SetWindowText(dlg.GetSelectedHash().at(0).ToString());
159 BringWindowToTop(); /* cf. issue #3493 */