TortoiseSVN -> TortoiseGit
[TortoiseGit.git] / src / TortoiseProc / PushDlg.cpp
blob96bd2b46ec2cd391e1fa1e92061f028e56606830
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 // 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 this->GetDlgItem(IDC_PUTTYKEY_AUTOLOAD)->EnableWindow(CAppUtils::IsSSHPutty());
116 EnableSaveRestore(_T("PushDlg"));
118 m_RemoteURL.SetURLHistory(TRUE);
120 CString WorkingDir=g_Git.m_CurrentDir;
121 WorkingDir.Replace(_T(':'),_T('_'));
122 m_RemoteURL.LoadHistory(CString(_T("Software\\TortoiseGit\\History\\PushURLS\\"))+WorkingDir, _T("url"));
123 CString clippath=CAppUtils::GetClipboardLink();
124 if(clippath.IsEmpty())
125 m_RemoteURL.SetCurSel(0);
126 else
127 m_RemoteURL.SetWindowText(clippath);
129 m_RemoteURL.EnableWindow(FALSE);
130 CheckRadioButton(IDC_RD_REMOTE,IDC_RD_URL,IDC_RD_REMOTE);
133 this->m_regAutoLoad = CRegDWORD(CString(_T("Software\\TortoiseGit\\History\\PushDlgAutoLoad\\"))+WorkingDir,
134 m_bAutoLoad);
135 m_bAutoLoad = this->m_regAutoLoad;
136 if(!CAppUtils::IsSSHPutty())
137 m_bAutoLoad = false;
139 Refresh();
142 //m_BranchRemote.SetWindowTextW(m_BranchSource.GetString());
144 this->UpdateData(false);
145 return TRUE;
148 void CPushDlg::Refresh()
150 CString WorkingDir=g_Git.m_CurrentDir;
151 WorkingDir.Replace(_T(':'),_T('_'));
153 CRegString remote(CString(_T("Software\\TortoiseGit\\History\\PushRemote\\")+WorkingDir));
154 m_RemoteReg = remote;
155 int sel=0;
157 CString currentBranch = g_Git.GetSymbolicRef();
158 CString configName;
160 configName.Format(L"branch.%s.pushremote", currentBranch);
161 CString pushRemote = g_Git.GetConfigValue(configName);
162 if( pushRemote.IsEmpty() )
164 configName.Format(L"branch.%s.remote", currentBranch);
165 pushRemote = g_Git.GetConfigValue(configName);
168 if( !pushRemote.IsEmpty() )
169 remote=pushRemote;
171 //Select pull-branch from current branch
172 configName.Format(L"branch.%s.pushbranch", currentBranch);
173 CString pushBranch = CGit::StripRefName(g_Git.GetConfigValue(configName));
174 if( pushBranch.IsEmpty() )
176 configName.Format(L"branch.%s.merge", currentBranch);
177 pushBranch = CGit::StripRefName(g_Git.GetConfigValue(configName));
180 STRING_VECTOR list;
181 m_Remote.Reset();
183 if(!g_Git.GetRemoteList(list))
185 for(unsigned int i=0;i<list.size();i++)
187 m_Remote.AddString(list[i]);
188 if(list[i] == remote)
189 sel = i;
192 m_Remote.SetCurSel(sel);
194 int current=0;
195 list.clear();
196 m_BranchSource.Reset();
197 m_BranchSource.SetMaxHistoryItems(0x7FFFFFFF);
198 if(!g_Git.GetBranchList(list,&current))
200 for(unsigned int i=0;i<list.size();i++)
201 m_BranchSource.AddString(list[i]);
203 m_BranchSource.SetCurSel(current);
205 m_BranchRemote.LoadHistory(CString(_T("Software\\TortoiseGit\\History\\RemoteBranch\\"))+WorkingDir, _T("branch"));
206 if( !pushBranch.IsEmpty() )
208 m_BranchRemote.AddString(pushBranch);
211 else
212 m_BranchRemote.SetCurSel(-1);
215 // CPushDlg message handlers
217 void CPushDlg::OnBnClickedRd()
219 if( GetCheckedRadioButton(IDC_RD_REMOTE,IDC_RD_URL) == IDC_RD_REMOTE)
221 m_Remote.EnableWindow(TRUE);
222 GetDlgItem(IDC_REMOTE_MANAGE)->EnableWindow(TRUE);
223 m_RemoteURL.EnableWindow(FALSE);
225 if( GetCheckedRadioButton(IDC_RD_REMOTE,IDC_RD_URL) == IDC_RD_URL)
227 m_Remote.EnableWindow(FALSE);
228 GetDlgItem(IDC_REMOTE_MANAGE)->EnableWindow(FALSE);
229 m_RemoteURL.EnableWindow(TRUE);
234 void CPushDlg::OnCbnSelchangeBranchSource()
236 m_BranchRemote.AddString(m_BranchSource.GetString());
239 void CPushDlg::OnBnClickedOk()
241 CHorizontalResizableStandAloneDialog::UpdateData(TRUE);
243 if( GetCheckedRadioButton(IDC_RD_REMOTE,IDC_RD_URL) == IDC_RD_REMOTE)
245 m_URL=m_Remote.GetString();
247 if( GetCheckedRadioButton(IDC_RD_REMOTE,IDC_RD_URL) == IDC_RD_URL)
249 m_URL=m_RemoteURL.GetString();
252 if (!m_bPushAllBranches)
254 this->m_BranchRemoteName=m_BranchRemote.GetString().Trim();
255 this->m_BranchSourceName=m_BranchSource.GetString();
257 if(!m_BranchRemoteName.IsEmpty() && !g_Git.IsBranchNameValid(this->m_BranchRemoteName))
259 CMessageBox::Show(NULL, IDS_B_T_NOTEMPTY, IDS_TORTOISEGIT, MB_OK);
260 return;
263 this->m_RemoteURL.SaveHistory();
264 this->m_BranchRemote.SaveHistory();
265 m_RemoteReg = m_Remote.GetString();
268 this->m_regAutoLoad = m_bAutoLoad ;
270 CHorizontalResizableStandAloneDialog::OnOK();
273 void CPushDlg::OnBnClickedRemoteManage()
275 CAppUtils::LaunchRemoteSetting();
276 Refresh();
279 void CPushDlg::OnBnClickedButtonBrowseSourceBranch()
281 if(CBrowseRefsDlg::PickRefForCombo(&m_BranchSource, gPickRef_Head))
282 OnCbnSelchangeBranchSource();
285 void CPushDlg::OnBnClickedButtonBrowseDestBranch()
287 CString remoteBranchName;
288 CString remoteName;
289 m_BranchRemote.GetWindowText(remoteBranchName);
290 remoteName = m_Remote.GetString();
291 remoteBranchName = remoteName + '/' + remoteBranchName;
292 remoteBranchName = CBrowseRefsDlg::PickRef(false, remoteBranchName, gPickRef_Remote);
293 if(remoteBranchName.IsEmpty())
294 return; //Canceled
295 remoteBranchName = remoteBranchName.Mid(13);//Strip 'refs/remotes/'
296 int slashPlace = remoteBranchName.Find('/');
297 remoteName = remoteBranchName.Left(slashPlace);
298 remoteBranchName = remoteBranchName.Mid(slashPlace + 1); //Strip remote name (for example 'origin/')
300 //Select remote
301 int remoteSel = m_Remote.FindStringExact(0,remoteName);
302 if(remoteSel >= 0)
303 m_Remote.SetCurSel(remoteSel);
305 //Select branch
306 m_BranchRemote.AddString(remoteBranchName);
309 BOOL CPushDlg::PreTranslateMessage(MSG* pMsg)
311 if (pMsg->message == WM_KEYDOWN)
313 switch (pMsg->wParam)
315 case VK_F5:
317 Refresh();
319 break;
323 return CHorizontalResizableStandAloneDialog::PreTranslateMessage(pMsg);
326 void CPushDlg::OnBnClickedPushall()
328 this->UpdateData();
329 this->GetDlgItem(IDC_BRANCH_REMOTE)->EnableWindow(!m_bPushAllBranches);
330 this->GetDlgItem(IDC_BRANCH_SOURCE)->EnableWindow(!m_bPushAllBranches);
331 this->GetDlgItem(IDC_BUTTON_BROWSE_SOURCE_BRANCH)->EnableWindow(!m_bPushAllBranches);
332 this->GetDlgItem(IDC_BUTTON_BROWSE_DEST_BRANCH)->EnableWindow(!m_bPushAllBranches);
333 this->GetDlgItem(IDC_TAGS)->EnableWindow(!m_bPushAllBranches);
334 if (m_bTags && m_bPushAllBranches)
336 m_bTags = FALSE;
337 UpdateData(FALSE);