some spaces-tabs code cleanup
[TortoiseGit.git] / src / TortoiseProc / PullFetchDlg.cpp
blobba6aac003600abdfb3fd612671daf68d5167261d
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2011 - TortoiseGit
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 2
8 // of the License, or (at your option) any later version.
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software Foundation,
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 // PullFetchDlg.cpp : implementation file
23 #include "stdafx.h"
24 #include "TortoiseProc.h"
25 #include "PullFetchDlg.h"
26 #include "Git.h"
27 #include "AppUtils.h"
28 #include "BrowseRefsDlg.h"
29 // CPullFetchDlg dialog
31 IMPLEMENT_DYNAMIC(CPullFetchDlg, CHorizontalResizableStandAloneDialog)
33 CPullFetchDlg::CPullFetchDlg(CWnd* pParent /*=NULL*/)
34 : CHorizontalResizableStandAloneDialog(CPullFetchDlg::IDD, pParent)
36 m_IsPull=TRUE;
37 m_bAutoLoad = CAppUtils::IsSSHPutty();
38 m_bAutoLoadEnable=CAppUtils::IsSSHPutty();;
39 m_regRebase = false;
40 m_bNoFF = false;
41 m_bSquash = false;
42 m_bNoCommit = false;
45 CPullFetchDlg::~CPullFetchDlg()
49 void CPullFetchDlg::DoDataExchange(CDataExchange* pDX)
51 CDialog::DoDataExchange(pDX);
52 DDX_Control(pDX, IDC_REMOTE_COMBO, this->m_Remote);
53 DDX_Control(pDX, IDC_OTHER, this->m_Other);
54 DDX_Control(pDX, IDC_REMOTE_BRANCH, this->m_RemoteBranch);
55 DDX_Control(pDX,IDC_REMOTE_MANAGE, this->m_RemoteManage);
56 DDX_Check(pDX,IDC_CHECK_NOFF, this->m_bNoFF);
57 DDX_Check(pDX,IDC_CHECK_SQUASH, this->m_bSquash);
58 DDX_Check(pDX,IDC_CHECK_NOCOMMIT, this->m_bNoCommit);
59 DDX_Check(pDX,IDC_PUTTYKEY_AUTOLOAD,m_bAutoLoad);
60 DDX_Check(pDX,IDC_CHECK_REBASE,m_bRebase);
61 DDX_Check(pDX,IDC_CHECK_PRUNE,m_bPrune);
65 BEGIN_MESSAGE_MAP(CPullFetchDlg, CHorizontalResizableStandAloneDialog)
66 ON_BN_CLICKED(IDC_REMOTE_RD, &CPullFetchDlg::OnBnClickedRd)
67 ON_BN_CLICKED(IDC_OTHER_RD, &CPullFetchDlg::OnBnClickedRd)
68 ON_BN_CLICKED(IDOK, &CPullFetchDlg::OnBnClickedOk)
69 ON_STN_CLICKED(IDC_REMOTE_MANAGE, &CPullFetchDlg::OnStnClickedRemoteManage)
70 ON_BN_CLICKED(IDC_BUTTON_BROWSE_REF, &CPullFetchDlg::OnBnClickedButtonBrowseRef)
71 END_MESSAGE_MAP()
73 BOOL CPullFetchDlg::OnInitDialog()
75 CHorizontalResizableStandAloneDialog::OnInitDialog();
76 CAppUtils::MarkWindowAsUnpinnable(m_hWnd);
78 AddAnchor(IDC_REMOTE_COMBO, TOP_LEFT, TOP_RIGHT);
79 AddAnchor(IDC_OTHER, TOP_LEFT,TOP_RIGHT);
81 AddAnchor(IDC_REMOTE_BRANCH, TOP_LEFT,TOP_RIGHT);
82 AddAnchor(IDC_BUTTON_BROWSE_REF,TOP_RIGHT);
84 AddAnchor(IDOK,BOTTOM_RIGHT);
85 AddAnchor(IDCANCEL,BOTTOM_RIGHT);
86 AddAnchor(IDC_GROUPT_REMOTE,TOP_LEFT,TOP_RIGHT);
87 AddAnchor(IDC_GROUP_OPTION,TOP_LEFT,TOP_RIGHT);
88 AddAnchor(IDC_PUTTYKEY_AUTOLOAD,BOTTOM_LEFT);
89 AddAnchor(IDC_CHECK_PRUNE,BOTTOM_LEFT);
90 AddAnchor(IDC_CHECK_REBASE,BOTTOM_LEFT);
91 AddAnchor(IDC_REMOTE_MANAGE,BOTTOM_LEFT);
92 AddAnchor(IDHELP, BOTTOM_RIGHT);
94 CString WorkingDir=g_Git.m_CurrentDir;
95 WorkingDir.Replace(_T(':'),_T('_'));
97 m_RemoteReg = CRegString(CString(_T("Software\\TortoiseGit\\History\\PullRemote\\")+WorkingDir));
98 CString regkey;
99 regkey.Format(_T("Software\\TortoiseGit\\TortoiseProc\\PullFetch\\%s_%d\\rebase"),WorkingDir,this->m_IsPull);
100 m_regRebase=CRegDWORD(regkey,false);
101 regkey.Format(_T("Software\\TortoiseGit\\TortoiseProc\\PullFetch\\%s_%d\\autoload"),WorkingDir,this->m_IsPull);
103 m_regAutoLoadPutty = CRegDWORD(regkey,this->m_bAutoLoad);
104 m_bAutoLoad = m_regAutoLoadPutty;
106 if(!CAppUtils::IsSSHPutty())
107 m_bAutoLoad = false;
109 if(m_bAllowRebase)
111 this->m_bRebase = m_regRebase;
113 else
115 GetDlgItem(IDC_CHECK_REBASE)->ShowWindow(SW_HIDE);
116 this->m_bRebase = FALSE;
119 this->UpdateData(FALSE);
121 this->AddOthersToAnchor();
123 this->GetDlgItem(IDC_PUTTYKEY_AUTOLOAD)->EnableWindow(m_bAutoLoadEnable);
125 CheckRadioButton(IDC_REMOTE_RD,IDC_OTHER_RD,IDC_REMOTE_RD);
126 m_Remote.EnableWindow(TRUE);
127 m_Other.EnableWindow(FALSE);
128 if(!m_IsPull)
129 m_RemoteBranch.EnableWindow(FALSE);
131 if(m_IsPull)
133 GetDlgItem(IDC_CHECK_REBASE)->ShowWindow(SW_HIDE);
134 GetDlgItem(IDC_CHECK_PRUNE)->ShowWindow(SW_HIDE);
136 else
138 this->GetDlgItem(IDC_GROUP_OPTION)->EnableWindow(FALSE);
139 this->GetDlgItem(IDC_CHECK_SQUASH)->EnableWindow(FALSE);
140 this->GetDlgItem(IDC_CHECK_NOFF)->EnableWindow(FALSE);
141 this->GetDlgItem(IDC_CHECK_NOCOMMIT)->EnableWindow(FALSE);
144 m_Other.SetURLHistory(TRUE);
145 m_Other.LoadHistory(_T("Software\\TortoiseGit\\History\\PullURLS"), _T("url"));
146 CString clippath=CAppUtils::GetClipboardLink();
147 if(clippath.IsEmpty())
148 m_Other.SetCurSel(0);
149 else
150 m_Other.SetWindowText(clippath);
152 m_RemoteBranch.LoadHistory(_T("Software\\TortoiseGit\\History\\PullRemoteBranch"), _T("br"));
153 m_RemoteBranch.SetCurSel(0);
155 CString sWindowTitle;
156 if(m_IsPull)
157 sWindowTitle = _T("Pull - ");
158 else
159 sWindowTitle = _T("Fetch - ");
161 GetWindowText(sWindowTitle);
162 CAppUtils::SetWindowTitle(m_hWnd, g_Git.m_CurrentDir, sWindowTitle);
164 Refresh();
166 EnableSaveRestore(_T("PullFetchDlg"));
167 this->m_RemoteManage.SetURL(CString());
168 return TRUE;
171 void CPullFetchDlg::Refresh()
173 //Select pull-remote from current branch
174 CString currentBranch = g_Git.GetSymbolicRef();
175 CString configName;
176 configName.Format(L"branch.%s.remote", currentBranch);
177 CString pullRemote = this->m_configPullRemote = g_Git.GetConfigValue(configName);
179 //Select pull-branch from current branch
180 configName.Format(L"branch.%s.merge", currentBranch);
181 CString pullBranch = m_configPullBranch = CGit::StripRefName(g_Git.GetConfigValue(configName));
182 m_RemoteBranch.AddString(pullBranch);
184 if(pullRemote.IsEmpty())
185 pullRemote = m_RemoteReg;
187 if (!m_PreSelectRemote.IsEmpty())
188 pullRemote = m_PreSelectRemote;
190 STRING_VECTOR list;
191 int sel=0;
192 if(!g_Git.GetRemoteList(list))
194 for(unsigned int i=0;i<list.size();i++)
196 m_Remote.AddString(list[i]);
197 if(list[i] == pullRemote)
198 sel = i;
201 m_Remote.SetCurSel(sel);
203 // CPullFetchDlg message handlers
205 void CPullFetchDlg::OnBnClickedRd()
207 if( GetCheckedRadioButton(IDC_REMOTE_RD,IDC_OTHER_RD) == IDC_REMOTE_RD)
209 m_Remote.EnableWindow(TRUE);
210 m_Other.EnableWindow(FALSE);
211 if(!m_IsPull)
212 m_RemoteBranch.EnableWindow(FALSE);
214 if( GetCheckedRadioButton(IDC_REMOTE_RD,IDC_OTHER_RD) == IDC_OTHER_RD)
216 m_Remote.EnableWindow(FALSE);
217 m_Other.EnableWindow(TRUE);;
218 if(!m_IsPull)
219 m_RemoteBranch.EnableWindow(TRUE);
223 void CPullFetchDlg::OnBnClickedOk()
225 this->UpdateData();
226 if( GetCheckedRadioButton(IDC_REMOTE_RD,IDC_OTHER_RD) == IDC_REMOTE_RD)
228 m_RemoteURL=m_Remote.GetString();
229 if( !m_IsPull ||
230 (m_configPullRemote == m_RemoteURL && m_configPullBranch == m_RemoteBranch.GetString() ))
231 //When fetching or when pulling from the configured tracking branch, dont explicitly set the remote branch name,
232 //because otherwise git will not update the remote tracking branches.
233 m_RemoteBranchName.Empty();
234 else
235 m_RemoteBranchName=m_RemoteBranch.GetString();
237 if( GetCheckedRadioButton(IDC_REMOTE_RD,IDC_OTHER_RD) == IDC_OTHER_RD)
239 m_Other.GetWindowTextW(m_RemoteURL);
240 m_RemoteBranchName=m_RemoteBranch.GetString();
243 m_RemoteReg = m_Remote.GetString();
245 m_Other.SaveHistory();
246 m_RemoteBranch.SaveHistory();
247 this->m_regRebase=this->m_bRebase;
249 m_regAutoLoadPutty = m_bAutoLoad;
251 this->OnOK();
254 void CPullFetchDlg::OnStnClickedRemoteManage()
256 CAppUtils::LaunchRemoteSetting();
257 Refresh();
260 void CPullFetchDlg::OnBnClickedButtonBrowseRef()
262 CString initialRef;
263 initialRef.Format(L"refs/remotes/%s/%s", m_Remote.GetString(), m_RemoteBranch.GetString());
264 CString selectedRef = CBrowseRefsDlg::PickRef(false, initialRef, gPickRef_Remote);
265 if(selectedRef.Left(13) != "refs/remotes/")
266 return;
268 selectedRef = selectedRef.Mid(13);
269 int ixSlash = selectedRef.Find('/');
271 CString remoteName = selectedRef.Left(ixSlash);
272 CString remoteBranch = selectedRef.Mid(ixSlash + 1);
274 int ixFound = m_Remote.FindStringExact(0, remoteName);
275 if(ixFound >= 0)
276 m_Remote.SetCurSel(ixFound);
277 m_RemoteBranch.AddString(remoteBranch);
279 CheckRadioButton(IDC_REMOTE_RD,IDC_OTHER_RD,IDC_REMOTE_RD);