1
// TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2011-2014, 2016-2017 - 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.
23 #include "TortoiseProc.h"
24 #include "RequestPullDlg.h"
27 #include "MessageBox.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
)
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");
76 GetWindowText(sWindowTitle
);
77 CAppUtils::SetWindowTitle(m_hWnd
, g_Git
.m_CurrentDir
, sWindowTitle
);
80 g_Git
.GetBranchList(list
, nullptr, CGit::BRANCH_ALL
);
81 m_cStartRevision
.SetMaxHistoryItems(0x7FFFFFFF);
82 m_cStartRevision
.SetList(list
);
84 CString WorkingDir
=g_Git
.m_CurrentDir
;
85 WorkingDir
.Replace(L
':', L
'_');
87 m_RegStartRevision
= CRegString(L
"Software\\TortoiseGit\\History\\RequestPull\\" + WorkingDir
+ L
"\\startrevision");
88 if (m_StartRevision
.IsEmpty())
89 m_StartRevision
= m_RegStartRevision
;
90 m_cStartRevision
.SetWindowTextW(m_StartRevision
);
92 // store URLs in global history, but save last used local url separately,
93 // because one normally has only one writable repository
94 m_cRepositoryURL
.SetCaseSensitive(TRUE
);
95 m_cRepositoryURL
.SetURLHistory(TRUE
);
96 m_cRepositoryURL
.LoadHistory(L
"Software\\TortoiseGit\\History\\RequestPull", L
"url");
97 m_RegRepositoryURL
= CRegString(L
"Software\\TortoiseGit\\History\\RequestPull\\" + WorkingDir
+ L
"\\repositoryurl");
98 if(m_RepositoryURL
.IsEmpty())
99 m_RepositoryURL
= m_RegRepositoryURL
;
100 m_cRepositoryURL
.SetWindowTextW(m_RepositoryURL
);
102 m_RegEndRevision
= CRegString(L
"Software\\TortoiseGit\\History\\RequestPull\\" + WorkingDir
+ L
"\\endrevision", L
"HEAD");
103 if (m_EndRevision
.IsEmpty())
104 m_EndRevision
= m_RegEndRevision
;
105 m_cEndRevision
.SetWindowTextW(m_EndRevision
);
107 this->UpdateData(FALSE
);
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
);
132 if (CStringUtils::StartsWith(m_StartRevision
, L
"remotes/"))
133 m_StartRevision
= m_StartRevision
.Mid((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
145 m_cStartRevision
.GetWindowText(revision
);
146 dlg
.SetParams(CTGitPath(), CTGitPath(), revision
, revision
, 0);
147 // tell the dialog to use mode for selecting revisions
149 dlg
.ShowWorkingTreeChanges(false);
150 // only one revision must be selected however
151 dlg
.SingleSelection(true);
152 if (dlg
.DoModal() == IDOK
&& !dlg
.GetSelectedHash().empty())
153 m_cStartRevision
.SetWindowText(dlg
.GetSelectedHash().at(0).ToString());