doc: updated images
[TortoiseGit.git] / src / TortoiseProc / PushDlg.cpp
blobef83e5e7dc188d1248ea67540c02ffd8ef7e90be
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2012 - 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 // PushDlg.cpp : implementation file
23 #include "stdafx.h"
24 #include "TortoiseProc.h"
25 #include "PushDlg.h"
27 #include "Git.h"
28 #include "registry.h"
29 #include "AppUtils.h"
30 #include "BrowseRefsDlg.h"
31 #include "MessageBox.h"
33 // CPushDlg dialog
35 IMPLEMENT_DYNAMIC(CPushDlg, CHorizontalResizableStandAloneDialog)
37 CPushDlg::CPushDlg(CWnd* pParent /*=NULL*/)
38 : CHorizontalResizableStandAloneDialog(CPushDlg::IDD, pParent)
39 , m_bPushAllBranches(FALSE)
40 , m_bForce(FALSE)
41 , m_bPack(FALSE)
42 , m_bTags(FALSE)
43 , m_bAutoLoad(FALSE)
45 m_bAutoLoad = CAppUtils::IsSSHPutty();
48 CPushDlg::~CPushDlg()
52 void CPushDlg::DoDataExchange(CDataExchange* pDX)
54 CHorizontalResizableStandAloneDialog::DoDataExchange(pDX);
55 DDX_Control(pDX, IDC_BRANCH_REMOTE, this->m_BranchRemote);
56 DDX_Control(pDX, IDC_BRANCH_SOURCE, this->m_BranchSource);
57 DDX_Control(pDX, IDC_REMOTE, this->m_Remote);
58 DDX_Control(pDX, IDC_URL, this->m_RemoteURL);
59 DDX_Check(pDX,IDC_FORCE,this->m_bForce);
60 DDX_Check(pDX,IDC_PUSHALL,this->m_bPushAllBranches);
61 DDX_Check(pDX,IDC_PACK,this->m_bPack);
62 DDX_Check(pDX,IDC_TAGS,this->m_bTags);
63 DDX_Check(pDX,IDC_PUTTYKEY_AUTOLOAD,this->m_bAutoLoad);
66 BEGIN_MESSAGE_MAP(CPushDlg, CHorizontalResizableStandAloneDialog)
67 ON_BN_CLICKED(IDC_RD_REMOTE, &CPushDlg::OnBnClickedRd)
68 ON_BN_CLICKED(IDC_RD_URL, &CPushDlg::OnBnClickedRd)
69 ON_CBN_SELCHANGE(IDC_BRANCH_SOURCE, &CPushDlg::OnCbnSelchangeBranchSource)
70 ON_BN_CLICKED(IDOK, &CPushDlg::OnBnClickedOk)
71 ON_BN_CLICKED(IDC_REMOTE_MANAGE, &CPushDlg::OnBnClickedRemoteManage)
72 ON_BN_CLICKED(IDC_BUTTON_BROWSE_SOURCE_BRANCH, &CPushDlg::OnBnClickedButtonBrowseSourceBranch)
73 ON_BN_CLICKED(IDC_BUTTON_BROWSE_DEST_BRANCH, &CPushDlg::OnBnClickedButtonBrowseDestBranch)
74 ON_BN_CLICKED(IDC_PUSHALL, &CPushDlg::OnBnClickedPushall)
75 END_MESSAGE_MAP()
77 BOOL CPushDlg::OnInitDialog()
79 CHorizontalResizableStandAloneDialog::OnInitDialog();
80 CAppUtils::MarkWindowAsUnpinnable(m_hWnd);
82 AddAnchor(IDOK,BOTTOM_RIGHT);
83 AddAnchor(IDCANCEL,BOTTOM_RIGHT);
84 AddAnchor(IDC_BRANCH_GROUP, TOP_LEFT,TOP_RIGHT);
85 AddAnchor(IDC_STATIC_REMOTE, TOP_LEFT);
86 AddAnchor(IDC_STATIC_SOURCE, TOP_LEFT);
88 AddAnchor(IDC_PUSHALL, TOP_LEFT);
89 AddAnchor(IDC_BRANCH_REMOTE, TOP_LEFT, TOP_RIGHT);
90 AddAnchor(IDC_BUTTON_BROWSE_DEST_BRANCH, TOP_RIGHT);
91 AddAnchor(IDC_BRANCH_SOURCE, TOP_LEFT, TOP_RIGHT);
92 AddAnchor(IDC_BUTTON_BROWSE_SOURCE_BRANCH, TOP_RIGHT);
94 AddAnchor(IDC_URL_GROUP, TOP_LEFT,TOP_RIGHT);
95 AddAnchor(IDC_RD_REMOTE, TOP_LEFT);
96 AddAnchor(IDC_RD_URL, TOP_LEFT);
98 AddAnchor(IDC_REMOTE, TOP_LEFT, TOP_RIGHT);
100 AddAnchor(IDC_URL, TOP_LEFT,TOP_RIGHT);
102 AddAnchor(IDC_OPTION_GROUP, TOP_LEFT,TOP_RIGHT);
104 AddAnchor(IDC_FORCE, TOP_LEFT);
105 AddAnchor(IDC_PACK, TOP_LEFT);
106 AddAnchor(IDC_TAGS, TOP_LEFT);
107 AddAnchor(IDC_PUTTYKEY_AUTOLOAD,TOP_LEFT);
109 AddAnchor(IDC_REMOTE_MANAGE,TOP_RIGHT);
110 AddAnchor(IDHELP, BOTTOM_RIGHT);
112 AddOthersToAnchor();
114 AdjustControlSize(IDC_RD_REMOTE);
115 AdjustControlSize(IDC_RD_URL);
116 AdjustControlSize(IDC_PUSHALL);
117 AdjustControlSize(IDC_FORCE);
118 AdjustControlSize(IDC_PACK);
119 AdjustControlSize(IDC_TAGS);
120 AdjustControlSize(IDC_PUTTYKEY_AUTOLOAD);
122 CString sWindowTitle;
123 GetWindowText(sWindowTitle);
124 CAppUtils::SetWindowTitle(m_hWnd, g_Git.m_CurrentDir, sWindowTitle);
126 this->GetDlgItem(IDC_PUTTYKEY_AUTOLOAD)->EnableWindow(CAppUtils::IsSSHPutty());
128 EnableSaveRestore(_T("PushDlg"));
130 m_RemoteURL.SetURLHistory(TRUE);
132 CString WorkingDir=g_Git.m_CurrentDir;
133 WorkingDir.Replace(_T(':'),_T('_'));
134 m_RemoteURL.LoadHistory(CString(_T("Software\\TortoiseGit\\History\\PushURLS\\"))+WorkingDir, _T("url"));
135 CString clippath=CAppUtils::GetClipboardLink();
136 if(clippath.IsEmpty())
137 m_RemoteURL.SetCurSel(0);
138 else
139 m_RemoteURL.SetWindowText(clippath);
141 m_RemoteURL.EnableWindow(FALSE);
142 CheckRadioButton(IDC_RD_REMOTE,IDC_RD_URL,IDC_RD_REMOTE);
145 this->m_regAutoLoad = CRegDWORD(CString(_T("Software\\TortoiseGit\\History\\PushDlgAutoLoad\\"))+WorkingDir,
146 m_bAutoLoad);
147 m_bAutoLoad = this->m_regAutoLoad;
148 if(!CAppUtils::IsSSHPutty())
149 m_bAutoLoad = false;
151 Refresh();
154 //m_BranchRemote.SetWindowTextW(m_BranchSource.GetString());
156 this->UpdateData(false);
157 return TRUE;
160 void CPushDlg::Refresh()
162 CString WorkingDir=g_Git.m_CurrentDir;
163 WorkingDir.Replace(_T(':'),_T('_'));
165 CRegString remote(CString(_T("Software\\TortoiseGit\\History\\PushRemote\\")+WorkingDir));
166 m_RemoteReg = remote;
167 int sel=0;
169 STRING_VECTOR list;
170 m_Remote.Reset();
172 if(!g_Git.GetRemoteList(list))
174 for(unsigned int i=0;i<list.size();i++)
176 m_Remote.AddString(list[i]);
177 if(list[i] == remote)
178 sel = i;
181 m_Remote.SetCurSel(sel);
183 int current=0;
184 list.clear();
185 m_BranchSource.Reset();
186 m_BranchSource.AddString(_T(" ")); // empty string does not work, for removal of remote branches/tags
187 m_BranchSource.SetMaxHistoryItems(0x7FFFFFFF);
188 if(!g_Git.GetBranchList(list,&current))
190 for(unsigned int i=0;i<list.size();i++)
191 m_BranchSource.AddString(list[i]);
192 current++; // shift for " "
194 if (wcsncmp(m_BranchSourceName, _T("refs/"), 5) == 0)
195 m_BranchSourceName = m_BranchSourceName.Mid(5);
196 if (wcsncmp(m_BranchSourceName, _T("heads/"), 6) == 0)
198 m_BranchSourceName = m_BranchSourceName.Mid(6);
199 m_BranchSource.SetCurSel(m_BranchSource.FindStringExact(-1, m_BranchSourceName));
201 else if (wcsncmp(m_BranchSourceName, _T("remotes/"), 8) == 0)
202 m_BranchSource.SetCurSel(m_BranchSource.FindStringExact(-1, m_BranchSourceName));
203 else
204 m_BranchSource.SetCurSel(current);
206 GetRemoteBranch(m_BranchSource.GetString());
208 this->GetDlgItem(IDOK)->EnableWindow(m_BranchSource.GetCount() != 0);
211 void CPushDlg::GetRemoteBranch(CString currentBranch)
213 CString WorkingDir=g_Git.m_CurrentDir;
214 WorkingDir.Replace(_T(':'), _T('_'));
216 if (currentBranch.IsEmpty())
217 return;
219 CString configName;
221 configName.Format(L"branch.%s.pushremote", currentBranch);
222 CString pushRemote = g_Git.GetConfigValue(configName);
223 if( pushRemote.IsEmpty() )
225 configName.Format(L"branch.%s.remote", currentBranch);
226 pushRemote = g_Git.GetConfigValue(configName);
229 CRegString remote(CString(_T("Software\\TortoiseGit\\History\\PushRemote\\")+WorkingDir));
231 if( !pushRemote.IsEmpty() )
232 remote=pushRemote;
234 //Select pull-branch from current branch
235 configName.Format(L"branch.%s.pushbranch", currentBranch);
236 CString pushBranch = CGit::StripRefName(g_Git.GetConfigValue(configName));
237 if( pushBranch.IsEmpty() )
239 configName.Format(L"branch.%s.merge", currentBranch);
240 pushBranch = CGit::StripRefName(g_Git.GetConfigValue(configName));
243 m_BranchRemote.LoadHistory(CString(_T("Software\\TortoiseGit\\History\\RemoteBranch\\"))+WorkingDir, _T("branch"));
244 if( !pushBranch.IsEmpty() )
245 m_BranchRemote.AddString(pushBranch);
248 // CPushDlg message handlers
250 void CPushDlg::OnBnClickedRd()
252 if( GetCheckedRadioButton(IDC_RD_REMOTE,IDC_RD_URL) == IDC_RD_REMOTE)
254 m_Remote.EnableWindow(TRUE);
255 GetDlgItem(IDC_REMOTE_MANAGE)->EnableWindow(TRUE);
256 m_RemoteURL.EnableWindow(FALSE);
258 if( GetCheckedRadioButton(IDC_RD_REMOTE,IDC_RD_URL) == IDC_RD_URL)
260 m_Remote.EnableWindow(FALSE);
261 GetDlgItem(IDC_REMOTE_MANAGE)->EnableWindow(FALSE);
262 m_RemoteURL.EnableWindow(TRUE);
267 void CPushDlg::OnCbnSelchangeBranchSource()
269 GetRemoteBranch(m_BranchSource.GetString());
272 void CPushDlg::OnBnClickedOk()
274 CHorizontalResizableStandAloneDialog::UpdateData(TRUE);
276 if( GetCheckedRadioButton(IDC_RD_REMOTE,IDC_RD_URL) == IDC_RD_REMOTE)
278 m_URL=m_Remote.GetString();
280 if( GetCheckedRadioButton(IDC_RD_REMOTE,IDC_RD_URL) == IDC_RD_URL)
282 m_URL=m_RemoteURL.GetString();
285 if (!m_bPushAllBranches)
287 this->m_BranchRemoteName=m_BranchRemote.GetString().Trim();
288 this->m_BranchSourceName=m_BranchSource.GetString().Trim();
290 if (m_BranchSourceName.IsEmpty() && m_BranchRemoteName.IsEmpty())
292 if (CMessageBox::Show(NULL, IDS_B_T_BOTHEMPTY, IDS_APPNAME, MB_ICONQUESTION | MB_YESNO) == IDNO)
293 return;
295 if (m_BranchSourceName.IsEmpty() && !m_BranchRemoteName.IsEmpty())
297 if (CMessageBox::Show(NULL, IDS_B_T_LOCALEMPTY, IDS_APPNAME, MB_ICONEXCLAMATION | MB_YESNO) == IDNO)
298 return;
300 else if (!m_BranchRemoteName.IsEmpty() && !g_Git.IsBranchNameValid(this->m_BranchRemoteName))
302 CMessageBox::Show(NULL, IDS_B_T_INVALID, IDS_APPNAME, MB_OK);
303 return;
305 else
307 // do not store branch names on removal
308 this->m_RemoteURL.SaveHistory();
309 this->m_BranchRemote.SaveHistory();
310 m_RemoteReg = m_Remote.GetString();
314 this->m_regAutoLoad = m_bAutoLoad ;
316 CHorizontalResizableStandAloneDialog::OnOK();
319 void CPushDlg::OnBnClickedRemoteManage()
321 CAppUtils::LaunchRemoteSetting();
322 Refresh();
325 void CPushDlg::OnBnClickedButtonBrowseSourceBranch()
327 if(CBrowseRefsDlg::PickRefForCombo(&m_BranchSource, gPickRef_Head))
328 OnCbnSelchangeBranchSource();
331 void CPushDlg::OnBnClickedButtonBrowseDestBranch()
333 CString remoteBranchName;
334 CString remoteName;
335 m_BranchRemote.GetWindowText(remoteBranchName);
336 remoteName = m_Remote.GetString();
337 remoteBranchName = remoteName + '/' + remoteBranchName;
338 remoteBranchName = CBrowseRefsDlg::PickRef(false, remoteBranchName, gPickRef_Remote);
339 if(remoteBranchName.IsEmpty())
340 return; //Canceled
341 remoteBranchName = remoteBranchName.Mid(13);//Strip 'refs/remotes/'
342 int slashPlace = remoteBranchName.Find('/');
343 remoteName = remoteBranchName.Left(slashPlace);
344 remoteBranchName = remoteBranchName.Mid(slashPlace + 1); //Strip remote name (for example 'origin/')
346 //Select remote
347 int remoteSel = m_Remote.FindStringExact(0,remoteName);
348 if(remoteSel >= 0)
349 m_Remote.SetCurSel(remoteSel);
351 //Select branch
352 m_BranchRemote.AddString(remoteBranchName);
355 BOOL CPushDlg::PreTranslateMessage(MSG* pMsg)
357 if (pMsg->message == WM_KEYDOWN)
359 switch (pMsg->wParam)
361 case VK_F5:
363 Refresh();
365 break;
369 return CHorizontalResizableStandAloneDialog::PreTranslateMessage(pMsg);
372 void CPushDlg::OnBnClickedPushall()
374 this->UpdateData();
375 this->GetDlgItem(IDC_BRANCH_REMOTE)->EnableWindow(!m_bPushAllBranches);
376 this->GetDlgItem(IDC_BRANCH_SOURCE)->EnableWindow(!m_bPushAllBranches);
377 this->GetDlgItem(IDC_BUTTON_BROWSE_SOURCE_BRANCH)->EnableWindow(!m_bPushAllBranches);
378 this->GetDlgItem(IDC_BUTTON_BROWSE_DEST_BRANCH)->EnableWindow(!m_bPushAllBranches);
379 this->GetDlgItem(IDC_TAGS)->EnableWindow(!m_bPushAllBranches);
380 if (m_bTags && m_bPushAllBranches)
382 m_bTags = FALSE;
383 UpdateData(FALSE);