do not allow the dialogs to be changed in height
[TortoiseGit.git] / src / TortoiseProc / PushDlg.cpp
blob257d3012677cab189fa650caeb175aa6a9f4d447
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, CResizableStandAloneDialog)
37 CPushDlg::CPushDlg(CWnd* pParent /*=NULL*/)
38 : CResizableStandAloneDialog(CPushDlg::IDD, pParent)
39 , m_bPushAllBranches(FALSE)
41 m_bAutoLoad = CAppUtils::IsSSHPutty();
44 CPushDlg::~CPushDlg()
48 void CPushDlg::DoDataExchange(CDataExchange* pDX)
50 CResizableStandAloneDialog::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, CResizableStandAloneDialog)
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 ON_WM_SIZING()
72 END_MESSAGE_MAP()
74 BOOL CPushDlg::OnInitDialog()
76 CResizableStandAloneDialog::OnInitDialog();
77 CAppUtils::MarkWindowAsUnpinnable(m_hWnd);
79 AddAnchor(IDOK,BOTTOM_RIGHT);
80 AddAnchor(IDCANCEL,BOTTOM_RIGHT);
81 AddAnchor(IDC_BRANCH_GROUP, TOP_LEFT,TOP_RIGHT);
82 AddAnchor(IDC_STATIC_REMOTE, TOP_RIGHT);
83 AddAnchor(IDC_STATIC_SOURCE, TOP_LEFT);
85 AddAnchor(IDC_PUSHALL, TOP_RIGHT);
86 AddAnchor(IDC_BRANCH_REMOTE, TOP_RIGHT);
87 AddAnchor(IDC_BUTTON_BROWSE_DEST_BRANCH, TOP_RIGHT);
88 AddAnchor(IDC_BRANCH_SOURCE, TOP_LEFT);
89 AddAnchor(IDC_BUTTON_BROWSE_SOURCE_BRANCH, TOP_LEFT);
91 AddAnchor(IDC_URL_GROUP, TOP_LEFT,TOP_RIGHT);
92 AddAnchor(IDC_RD_REMOTE, TOP_LEFT);
93 AddAnchor(IDC_RD_URL, TOP_LEFT);
95 AddAnchor(IDC_REMOTE, TOP_LEFT, TOP_RIGHT);
97 AddAnchor(IDC_URL, TOP_LEFT,TOP_RIGHT);
99 AddAnchor(IDC_OPTION_GROUP, TOP_LEFT,TOP_RIGHT);
101 AddAnchor(IDC_FORCE, TOP_LEFT);
102 AddAnchor(IDC_PACK, TOP_LEFT);
103 AddAnchor(IDC_TAGS, TOP_LEFT);
104 AddAnchor(IDC_PUTTYKEY_AUTOLOAD,TOP_LEFT);
106 AddAnchor(IDC_REMOTE_MANAGE,TOP_RIGHT);
107 AddAnchor(IDHELP, BOTTOM_RIGHT);
109 AddOthersToAnchor();
111 RECT rect;
112 GetWindowRect(&rect);
113 m_height = rect.bottom - rect.top;
115 this->GetDlgItem(IDC_PUTTYKEY_AUTOLOAD)->EnableWindow(CAppUtils::IsSSHPutty());
117 EnableSaveRestore(_T("PushDlg"));
119 m_RemoteURL.SetURLHistory(TRUE);
121 CString WorkingDir=g_Git.m_CurrentDir;
122 WorkingDir.Replace(_T(':'),_T('_'));
123 m_RemoteURL.LoadHistory(CString(_T("Software\\TortoiseGit\\History\\PushURLS\\"))+WorkingDir, _T("url"));
124 CString clippath=CAppUtils::GetClipboardLink();
125 if(clippath.IsEmpty())
126 m_RemoteURL.SetCurSel(0);
127 else
128 m_RemoteURL.SetWindowText(clippath);
130 m_RemoteURL.EnableWindow(FALSE);
131 CheckRadioButton(IDC_RD_REMOTE,IDC_RD_URL,IDC_RD_REMOTE);
134 this->m_regAutoLoad = CRegDWORD(CString(_T("Software\\TortoiseGit\\History\\PushDlgAutoLoad\\"))+WorkingDir,
135 m_bAutoLoad);
136 m_bAutoLoad = this->m_regAutoLoad;
137 if(!CAppUtils::IsSSHPutty())
138 m_bAutoLoad = false;
140 Refresh();
143 //m_BranchRemote.SetWindowTextW(m_BranchSource.GetString());
145 this->UpdateData(false);
146 return TRUE;
149 void CPushDlg::Refresh()
151 CString WorkingDir=g_Git.m_CurrentDir;
152 WorkingDir.Replace(_T(':'),_T('_'));
154 CRegString remote(CString(_T("Software\\TortoiseGit\\History\\PushRemote\\")+WorkingDir));
155 m_RemoteReg = remote;
156 int sel=0;
158 CString currentBranch = g_Git.GetSymbolicRef();
159 CString configName;
161 configName.Format(L"branch.%s.pushremote", currentBranch);
162 CString pushRemote = g_Git.GetConfigValue(configName);
163 if( pushRemote.IsEmpty() )
165 configName.Format(L"branch.%s.remote", currentBranch);
166 pushRemote = g_Git.GetConfigValue(configName);
169 if( !pushRemote.IsEmpty() )
170 remote=pushRemote;
172 //Select pull-branch from current branch
173 configName.Format(L"branch.%s.pushbranch", currentBranch);
174 CString pushBranch = CGit::StripRefName(g_Git.GetConfigValue(configName));
175 if( pushBranch.IsEmpty() )
177 configName.Format(L"branch.%s.merge", currentBranch);
178 pushBranch = CGit::StripRefName(g_Git.GetConfigValue(configName));
181 STRING_VECTOR list;
182 m_Remote.Reset();
184 if(!g_Git.GetRemoteList(list))
186 for(unsigned int i=0;i<list.size();i++)
188 m_Remote.AddString(list[i]);
189 if(list[i] == remote)
190 sel = i;
193 m_Remote.SetCurSel(sel);
195 int current=0;
196 list.clear();
197 m_BranchSource.Reset();
198 m_BranchSource.SetMaxHistoryItems(0x7FFFFFFF);
199 if(!g_Git.GetBranchList(list,&current))
201 for(unsigned int i=0;i<list.size();i++)
202 m_BranchSource.AddString(list[i]);
204 m_BranchSource.SetCurSel(current);
206 m_BranchRemote.LoadHistory(CString(_T("Software\\TortoiseGit\\History\\RemoteBranch\\"))+WorkingDir, _T("branch"));
207 if( !pushBranch.IsEmpty() )
209 m_BranchRemote.AddString(pushBranch);
212 else
213 m_BranchRemote.SetCurSel(-1);
216 // CPushDlg message handlers
218 void CPushDlg::OnBnClickedRd()
220 if( GetCheckedRadioButton(IDC_RD_REMOTE,IDC_RD_URL) == IDC_RD_REMOTE)
222 m_Remote.EnableWindow(TRUE);
223 GetDlgItem(IDC_REMOTE_MANAGE)->EnableWindow(TRUE);
224 m_RemoteURL.EnableWindow(FALSE);
226 if( GetCheckedRadioButton(IDC_RD_REMOTE,IDC_RD_URL) == IDC_RD_URL)
228 m_Remote.EnableWindow(FALSE);
229 GetDlgItem(IDC_REMOTE_MANAGE)->EnableWindow(FALSE);
230 m_RemoteURL.EnableWindow(TRUE);
235 void CPushDlg::OnCbnSelchangeBranchSource()
237 m_BranchRemote.AddString(m_BranchSource.GetString());
240 void CPushDlg::OnBnClickedOk()
242 CResizableStandAloneDialog::UpdateData(TRUE);
244 if( GetCheckedRadioButton(IDC_RD_REMOTE,IDC_RD_URL) == IDC_RD_REMOTE)
246 m_URL=m_Remote.GetString();
248 if( GetCheckedRadioButton(IDC_RD_REMOTE,IDC_RD_URL) == IDC_RD_URL)
250 m_URL=m_RemoteURL.GetString();
253 if (!m_bPushAllBranches)
255 this->m_BranchRemoteName=m_BranchRemote.GetString().Trim();
256 this->m_BranchSourceName=m_BranchSource.GetString();
258 if(!m_BranchRemoteName.IsEmpty() && !g_Git.IsBranchNameValid(this->m_BranchRemoteName))
260 CMessageBox::Show(NULL, IDS_B_T_NOTEMPTY, IDS_TORTOISEGIT, MB_OK);
261 return;
264 this->m_RemoteURL.SaveHistory();
265 this->m_BranchRemote.SaveHistory();
266 m_RemoteReg = m_Remote.GetString();
269 this->m_regAutoLoad = m_bAutoLoad ;
271 CResizableStandAloneDialog::OnOK();
274 void CPushDlg::OnBnClickedRemoteManage()
276 CAppUtils::LaunchRemoteSetting();
277 Refresh();
280 void CPushDlg::OnBnClickedButtonBrowseSourceBranch()
282 if(CBrowseRefsDlg::PickRefForCombo(&m_BranchSource, gPickRef_Head))
283 OnCbnSelchangeBranchSource();
286 void CPushDlg::OnBnClickedButtonBrowseDestBranch()
288 CString remoteBranchName;
289 CString remoteName;
290 m_BranchRemote.GetWindowText(remoteBranchName);
291 remoteName = m_Remote.GetString();
292 remoteBranchName = remoteName + '/' + remoteBranchName;
293 remoteBranchName = CBrowseRefsDlg::PickRef(false, remoteBranchName, gPickRef_Remote);
294 if(remoteBranchName.IsEmpty())
295 return; //Canceled
296 remoteBranchName = remoteBranchName.Mid(13);//Strip 'refs/remotes/'
297 int slashPlace = remoteBranchName.Find('/');
298 remoteName = remoteBranchName.Left(slashPlace);
299 remoteBranchName = remoteBranchName.Mid(slashPlace + 1); //Strip remote name (for example 'origin/')
301 //Select remote
302 int remoteSel = m_Remote.FindStringExact(0,remoteName);
303 if(remoteSel >= 0)
304 m_Remote.SetCurSel(remoteSel);
306 //Select branch
307 m_BranchRemote.AddString(remoteBranchName);
310 BOOL CPushDlg::PreTranslateMessage(MSG* pMsg)
312 if (pMsg->message == WM_KEYDOWN)
314 switch (pMsg->wParam)
316 case VK_F5:
318 Refresh();
320 break;
324 return CResizableStandAloneDialog::PreTranslateMessage(pMsg);
327 void CPushDlg::OnBnClickedPushall()
329 this->UpdateData();
330 this->GetDlgItem(IDC_BRANCH_REMOTE)->EnableWindow(!m_bPushAllBranches);
331 this->GetDlgItem(IDC_BRANCH_SOURCE)->EnableWindow(!m_bPushAllBranches);
332 this->GetDlgItem(IDC_BUTTON_BROWSE_SOURCE_BRANCH)->EnableWindow(!m_bPushAllBranches);
333 this->GetDlgItem(IDC_BUTTON_BROWSE_DEST_BRANCH)->EnableWindow(!m_bPushAllBranches);
334 this->GetDlgItem(IDC_TAGS)->EnableWindow(!m_bPushAllBranches);
335 if (m_bTags && m_bPushAllBranches)
337 m_bTags = FALSE;
338 UpdateData(FALSE);
342 void CPushDlg::OnSizing(UINT fwSide, LPRECT pRect)
344 // don't allow the dialog to be changed in height
345 switch (fwSide)
347 case WMSZ_BOTTOM:
348 case WMSZ_BOTTOMLEFT:
349 case WMSZ_BOTTOMRIGHT:
350 pRect->bottom = pRect->top + m_height;
351 break;
352 case WMSZ_TOP:
353 case WMSZ_TOPLEFT:
354 case WMSZ_TOPRIGHT:
355 pRect->top = pRect->bottom - m_height;
356 break;
358 CResizableStandAloneDialog::OnSizing(fwSide, pRect);