Merge branch 'restructure-tree'
[TortoiseGit.git] / src / TortoiseProc / PushDlg.cpp
blob312bb1cba8327e0816605243dc9a5deec12e0522
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)
41 m_bAutoLoad = CAppUtils::IsSSHPutty();
44 CPushDlg::~CPushDlg()
48 void CPushDlg::DoDataExchange(CDataExchange* pDX)
50 CHorizontalResizableStandAloneDialog::DoDataExchange(pDX);
51 DDX_Control(pDX, IDC_BRANCH_REMOTE, this->m_BranchRemote);
52 DDX_Control(pDX, IDC_BRANCH_SOURCE, this->m_BranchSource);
53 DDX_Control(pDX, IDC_REMOTE, this->m_Remote);
54 DDX_Control(pDX, IDC_URL, this->m_RemoteURL);
55 DDX_Check(pDX,IDC_FORCE,this->m_bForce);
56 DDX_Check(pDX,IDC_PUSHALL,this->m_bPushAllBranches);
57 DDX_Check(pDX,IDC_PACK,this->m_bPack);
58 DDX_Check(pDX,IDC_TAGS,this->m_bTags);
59 DDX_Check(pDX,IDC_PUTTYKEY_AUTOLOAD,this->m_bAutoLoad);
62 BEGIN_MESSAGE_MAP(CPushDlg, CHorizontalResizableStandAloneDialog)
63 ON_BN_CLICKED(IDC_RD_REMOTE, &CPushDlg::OnBnClickedRd)
64 ON_BN_CLICKED(IDC_RD_URL, &CPushDlg::OnBnClickedRd)
65 ON_CBN_SELCHANGE(IDC_BRANCH_SOURCE, &CPushDlg::OnCbnSelchangeBranchSource)
66 ON_BN_CLICKED(IDOK, &CPushDlg::OnBnClickedOk)
67 ON_BN_CLICKED(IDC_REMOTE_MANAGE, &CPushDlg::OnBnClickedRemoteManage)
68 ON_BN_CLICKED(IDC_BUTTON_BROWSE_SOURCE_BRANCH, &CPushDlg::OnBnClickedButtonBrowseSourceBranch)
69 ON_BN_CLICKED(IDC_BUTTON_BROWSE_DEST_BRANCH, &CPushDlg::OnBnClickedButtonBrowseDestBranch)
70 ON_BN_CLICKED(IDC_PUSHALL, &CPushDlg::OnBnClickedPushall)
71 END_MESSAGE_MAP()
73 BOOL CPushDlg::OnInitDialog()
75 CHorizontalResizableStandAloneDialog::OnInitDialog();
76 CAppUtils::MarkWindowAsUnpinnable(m_hWnd);
78 AddAnchor(IDOK,BOTTOM_RIGHT);
79 AddAnchor(IDCANCEL,BOTTOM_RIGHT);
80 AddAnchor(IDC_BRANCH_GROUP, TOP_LEFT,TOP_RIGHT);
81 AddAnchor(IDC_STATIC_REMOTE, TOP_LEFT);
82 AddAnchor(IDC_STATIC_SOURCE, TOP_LEFT);
84 AddAnchor(IDC_PUSHALL, TOP_LEFT);
85 AddAnchor(IDC_BRANCH_REMOTE, TOP_LEFT, TOP_RIGHT);
86 AddAnchor(IDC_BUTTON_BROWSE_DEST_BRANCH, TOP_RIGHT);
87 AddAnchor(IDC_BRANCH_SOURCE, TOP_LEFT, TOP_RIGHT);
88 AddAnchor(IDC_BUTTON_BROWSE_SOURCE_BRANCH, TOP_RIGHT);
90 AddAnchor(IDC_URL_GROUP, TOP_LEFT,TOP_RIGHT);
91 AddAnchor(IDC_RD_REMOTE, TOP_LEFT);
92 AddAnchor(IDC_RD_URL, TOP_LEFT);
94 AddAnchor(IDC_REMOTE, TOP_LEFT, TOP_RIGHT);
96 AddAnchor(IDC_URL, TOP_LEFT,TOP_RIGHT);
98 AddAnchor(IDC_OPTION_GROUP, TOP_LEFT,TOP_RIGHT);
100 AddAnchor(IDC_FORCE, TOP_LEFT);
101 AddAnchor(IDC_PACK, TOP_LEFT);
102 AddAnchor(IDC_TAGS, TOP_LEFT);
103 AddAnchor(IDC_PUTTYKEY_AUTOLOAD,TOP_LEFT);
105 AddAnchor(IDC_REMOTE_MANAGE,TOP_RIGHT);
106 AddAnchor(IDHELP, BOTTOM_RIGHT);
108 AddOthersToAnchor();
110 this->GetDlgItem(IDC_PUTTYKEY_AUTOLOAD)->EnableWindow(CAppUtils::IsSSHPutty());
112 EnableSaveRestore(_T("PushDlg"));
114 m_RemoteURL.SetURLHistory(TRUE);
116 CString WorkingDir=g_Git.m_CurrentDir;
117 WorkingDir.Replace(_T(':'),_T('_'));
118 m_RemoteURL.LoadHistory(CString(_T("Software\\TortoiseGit\\History\\PushURLS\\"))+WorkingDir, _T("url"));
119 CString clippath=CAppUtils::GetClipboardLink();
120 if(clippath.IsEmpty())
121 m_RemoteURL.SetCurSel(0);
122 else
123 m_RemoteURL.SetWindowText(clippath);
125 m_RemoteURL.EnableWindow(FALSE);
126 CheckRadioButton(IDC_RD_REMOTE,IDC_RD_URL,IDC_RD_REMOTE);
129 this->m_regAutoLoad = CRegDWORD(CString(_T("Software\\TortoiseGit\\History\\PushDlgAutoLoad\\"))+WorkingDir,
130 m_bAutoLoad);
131 m_bAutoLoad = this->m_regAutoLoad;
132 if(!CAppUtils::IsSSHPutty())
133 m_bAutoLoad = false;
135 Refresh();
138 //m_BranchRemote.SetWindowTextW(m_BranchSource.GetString());
140 this->UpdateData(false);
141 return TRUE;
144 void CPushDlg::Refresh()
146 CString WorkingDir=g_Git.m_CurrentDir;
147 WorkingDir.Replace(_T(':'),_T('_'));
149 CRegString remote(CString(_T("Software\\TortoiseGit\\History\\PushRemote\\")+WorkingDir));
150 m_RemoteReg = remote;
151 int sel=0;
153 CString currentBranch = g_Git.GetSymbolicRef();
154 CString configName;
156 configName.Format(L"branch.%s.pushremote", currentBranch);
157 CString pushRemote = g_Git.GetConfigValue(configName);
158 if( pushRemote.IsEmpty() )
160 configName.Format(L"branch.%s.remote", currentBranch);
161 pushRemote = g_Git.GetConfigValue(configName);
164 if( !pushRemote.IsEmpty() )
165 remote=pushRemote;
167 //Select pull-branch from current branch
168 configName.Format(L"branch.%s.pushbranch", currentBranch);
169 CString pushBranch = CGit::StripRefName(g_Git.GetConfigValue(configName));
170 if( pushBranch.IsEmpty() )
172 configName.Format(L"branch.%s.merge", currentBranch);
173 pushBranch = CGit::StripRefName(g_Git.GetConfigValue(configName));
176 STRING_VECTOR list;
177 m_Remote.Reset();
179 if(!g_Git.GetRemoteList(list))
181 for(unsigned int i=0;i<list.size();i++)
183 m_Remote.AddString(list[i]);
184 if(list[i] == remote)
185 sel = i;
188 m_Remote.SetCurSel(sel);
190 int current=0;
191 list.clear();
192 m_BranchSource.Reset();
193 m_BranchSource.SetMaxHistoryItems(0x7FFFFFFF);
194 if(!g_Git.GetBranchList(list,&current))
196 for(unsigned int i=0;i<list.size();i++)
197 m_BranchSource.AddString(list[i]);
199 m_BranchSource.SetCurSel(current);
201 m_BranchRemote.LoadHistory(CString(_T("Software\\TortoiseGit\\History\\RemoteBranch\\"))+WorkingDir, _T("branch"));
202 if( !pushBranch.IsEmpty() )
204 m_BranchRemote.AddString(pushBranch);
207 else
208 m_BranchRemote.SetCurSel(-1);
211 // CPushDlg message handlers
213 void CPushDlg::OnBnClickedRd()
215 if( GetCheckedRadioButton(IDC_RD_REMOTE,IDC_RD_URL) == IDC_RD_REMOTE)
217 m_Remote.EnableWindow(TRUE);
218 GetDlgItem(IDC_REMOTE_MANAGE)->EnableWindow(TRUE);
219 m_RemoteURL.EnableWindow(FALSE);
221 if( GetCheckedRadioButton(IDC_RD_REMOTE,IDC_RD_URL) == IDC_RD_URL)
223 m_Remote.EnableWindow(FALSE);
224 GetDlgItem(IDC_REMOTE_MANAGE)->EnableWindow(FALSE);
225 m_RemoteURL.EnableWindow(TRUE);
230 void CPushDlg::OnCbnSelchangeBranchSource()
232 m_BranchRemote.AddString(m_BranchSource.GetString());
235 void CPushDlg::OnBnClickedOk()
237 CHorizontalResizableStandAloneDialog::UpdateData(TRUE);
239 if( GetCheckedRadioButton(IDC_RD_REMOTE,IDC_RD_URL) == IDC_RD_REMOTE)
241 m_URL=m_Remote.GetString();
243 if( GetCheckedRadioButton(IDC_RD_REMOTE,IDC_RD_URL) == IDC_RD_URL)
245 m_URL=m_RemoteURL.GetString();
248 if (!m_bPushAllBranches)
250 this->m_BranchRemoteName=m_BranchRemote.GetString().Trim();
251 this->m_BranchSourceName=m_BranchSource.GetString();
253 if(!m_BranchRemoteName.IsEmpty() && !g_Git.IsBranchNameValid(this->m_BranchRemoteName))
255 CMessageBox::Show(NULL, IDS_B_T_NOTEMPTY, IDS_TORTOISEGIT, MB_OK);
256 return;
259 this->m_RemoteURL.SaveHistory();
260 this->m_BranchRemote.SaveHistory();
261 m_RemoteReg = m_Remote.GetString();
264 this->m_regAutoLoad = m_bAutoLoad ;
266 CHorizontalResizableStandAloneDialog::OnOK();
269 void CPushDlg::OnBnClickedRemoteManage()
271 CAppUtils::LaunchRemoteSetting();
272 Refresh();
275 void CPushDlg::OnBnClickedButtonBrowseSourceBranch()
277 if(CBrowseRefsDlg::PickRefForCombo(&m_BranchSource, gPickRef_Head))
278 OnCbnSelchangeBranchSource();
281 void CPushDlg::OnBnClickedButtonBrowseDestBranch()
283 CString remoteBranchName;
284 CString remoteName;
285 m_BranchRemote.GetWindowText(remoteBranchName);
286 remoteName = m_Remote.GetString();
287 remoteBranchName = remoteName + '/' + remoteBranchName;
288 remoteBranchName = CBrowseRefsDlg::PickRef(false, remoteBranchName, gPickRef_Remote);
289 if(remoteBranchName.IsEmpty())
290 return; //Canceled
291 remoteBranchName = remoteBranchName.Mid(13);//Strip 'refs/remotes/'
292 int slashPlace = remoteBranchName.Find('/');
293 remoteName = remoteBranchName.Left(slashPlace);
294 remoteBranchName = remoteBranchName.Mid(slashPlace + 1); //Strip remote name (for example 'origin/')
296 //Select remote
297 int remoteSel = m_Remote.FindStringExact(0,remoteName);
298 if(remoteSel >= 0)
299 m_Remote.SetCurSel(remoteSel);
301 //Select branch
302 m_BranchRemote.AddString(remoteBranchName);
305 BOOL CPushDlg::PreTranslateMessage(MSG* pMsg)
307 if (pMsg->message == WM_KEYDOWN)
309 switch (pMsg->wParam)
311 case VK_F5:
313 Refresh();
315 break;
319 return CHorizontalResizableStandAloneDialog::PreTranslateMessage(pMsg);
322 void CPushDlg::OnBnClickedPushall()
324 this->UpdateData();
325 this->GetDlgItem(IDC_BRANCH_REMOTE)->EnableWindow(!m_bPushAllBranches);
326 this->GetDlgItem(IDC_BRANCH_SOURCE)->EnableWindow(!m_bPushAllBranches);
327 this->GetDlgItem(IDC_BUTTON_BROWSE_SOURCE_BRANCH)->EnableWindow(!m_bPushAllBranches);
328 this->GetDlgItem(IDC_BUTTON_BROWSE_DEST_BRANCH)->EnableWindow(!m_bPushAllBranches);
329 this->GetDlgItem(IDC_TAGS)->EnableWindow(!m_bPushAllBranches);
330 if (m_bTags && m_bPushAllBranches)
332 m_bTags = FALSE;
333 UpdateData(FALSE);