Fixed issue #492: Fix AutoLoad Putty Key operation in push dialog
[TortoiseGit.git] / src / TortoiseProc / PushDlg.cpp
blob80e7b3cdf7a778cf557387f93ec00992200a473d
1 // PushDlg.cpp : implementation file
2 //
4 #include "stdafx.h"
5 #include "TortoiseProc.h"
6 #include "PushDlg.h"
8 #include "Git.h"
9 #include "registry.h"
10 #include "AppUtils.h"
11 #include "BrowseRefsDlg.h"
13 // CPushDlg dialog
15 IMPLEMENT_DYNAMIC(CPushDlg, CResizableStandAloneDialog)
17 CPushDlg::CPushDlg(CWnd* pParent /*=NULL*/)
18 : CResizableStandAloneDialog(CPushDlg::IDD, pParent)
20 m_bAutoLoad = CAppUtils::IsSSHPutty();
23 CPushDlg::~CPushDlg()
27 void CPushDlg::DoDataExchange(CDataExchange* pDX)
29 CResizableStandAloneDialog::DoDataExchange(pDX);
30 DDX_Control(pDX, IDC_BRANCH_REMOTE, this->m_BranchRemote);
31 DDX_Control(pDX, IDC_BRANCH_SOURCE, this->m_BranchSource);
32 DDX_Control(pDX, IDC_REMOTE, this->m_Remote);
33 DDX_Control(pDX, IDC_URL, this->m_RemoteURL);
34 DDX_Check(pDX,IDC_FORCE,this->m_bForce);
35 DDX_Check(pDX,IDC_PACK,this->m_bPack);
36 DDX_Check(pDX,IDC_TAGS,this->m_bTags);
37 DDX_Check(pDX,IDC_PUTTYKEY_AUTOLOAD,this->m_bAutoLoad);
42 BEGIN_MESSAGE_MAP(CPushDlg, CResizableStandAloneDialog)
43 ON_BN_CLICKED(IDC_RD_REMOTE, &CPushDlg::OnBnClickedRd)
44 ON_BN_CLICKED(IDC_RD_URL, &CPushDlg::OnBnClickedRd)
45 ON_CBN_SELCHANGE(IDC_BRANCH_SOURCE, &CPushDlg::OnCbnSelchangeBranchSource)
46 ON_BN_CLICKED(IDOK, &CPushDlg::OnBnClickedOk)
47 ON_BN_CLICKED(IDC_REMOTE_MANAGE, &CPushDlg::OnBnClickedRemoteManage)
48 ON_BN_CLICKED(IDC_BUTTON_BROWSE_SOURCE_BRANCH, &CPushDlg::OnBnClickedButtonBrowseSourceBranch)
49 ON_BN_CLICKED(IDC_BUTTON_BROWSE_DEST_BRANCH, &CPushDlg::OnBnClickedButtonBrowseDestBranch)
50 END_MESSAGE_MAP()
52 BOOL CPushDlg::OnInitDialog()
54 CResizableStandAloneDialog::OnInitDialog();
56 AddAnchor(IDOK,BOTTOM_RIGHT);
57 AddAnchor(IDCANCEL,BOTTOM_RIGHT);
58 AddAnchor(IDC_BRANCH_GROUP, TOP_LEFT,TOP_RIGHT);
59 AddAnchor(IDC_STATIC_REMOTE, TOP_RIGHT);
60 AddAnchor(IDC_STATIC_SOURCE, TOP_LEFT);
62 AddAnchor(IDC_BRANCH_REMOTE, TOP_RIGHT);
63 AddAnchor(IDC_BUTTON_BROWSE_DEST_BRANCH, TOP_RIGHT);
64 AddAnchor(IDC_BRANCH_SOURCE, TOP_LEFT);
65 AddAnchor(IDC_BUTTON_BROWSE_SOURCE_BRANCH, TOP_LEFT);
67 AddAnchor(IDC_URL_GROUP, TOP_LEFT,TOP_RIGHT);
68 AddAnchor(IDC_RD_REMOTE, TOP_LEFT);
69 AddAnchor(IDC_RD_URL, TOP_LEFT);
71 AddAnchor(IDC_REMOTE, TOP_LEFT, TOP_RIGHT);
73 AddAnchor(IDC_URL, TOP_LEFT,TOP_RIGHT);
75 AddAnchor(IDC_OPTION_GROUP, TOP_LEFT,TOP_RIGHT);
77 AddAnchor(IDC_FORCE, TOP_LEFT);
78 AddAnchor(IDC_PACK, TOP_LEFT);
79 AddAnchor(IDC_TAGS, TOP_LEFT);
80 AddAnchor(IDC_PUTTYKEY_AUTOLOAD,TOP_LEFT);
82 AddAnchor(IDC_REMOTE_MANAGE,TOP_RIGHT);
83 AddAnchor(IDHELP, BOTTOM_RIGHT);
85 AddOthersToAnchor();
87 this->GetDlgItem(IDC_PUTTYKEY_AUTOLOAD)->EnableWindow(CAppUtils::IsSSHPutty());
89 EnableSaveRestore(_T("PushDlg"));
91 m_RemoteURL.SetURLHistory(TRUE);
93 CString WorkingDir=g_Git.m_CurrentDir;
94 WorkingDir.Replace(_T(':'),_T('_'));
95 m_RemoteURL.LoadHistory(CString(_T("Software\\TortoiseGit\\History\\PushURLS\\"))+WorkingDir, _T("url"));
96 CString clippath=CAppUtils::GetClipboardLink();
97 if(clippath.IsEmpty())
98 m_RemoteURL.SetCurSel(0);
99 else
100 m_RemoteURL.SetWindowText(clippath);
102 m_RemoteURL.EnableWindow(FALSE);
103 CheckRadioButton(IDC_RD_REMOTE,IDC_RD_URL,IDC_RD_REMOTE);
106 this->m_regAutoLoad = CRegDWORD(CString(_T("Software\\TortoiseGit\\History\\PushDlgAutoLoad\\"))+WorkingDir,
107 m_bAutoLoad);
108 m_bAutoLoad = this->m_regAutoLoad;
109 if(!CAppUtils::IsSSHPutty())
110 m_bAutoLoad = false;
112 Refresh();
115 //m_BranchRemote.SetWindowTextW(m_BranchSource.GetString());
117 this->UpdateData(false);
118 return TRUE;
121 void CPushDlg::Refresh()
123 CString WorkingDir=g_Git.m_CurrentDir;
124 WorkingDir.Replace(_T(':'),_T('_'));
126 CRegString remote(CString(_T("Software\\TortoiseGit\\History\\PushRemote\\")+WorkingDir));
127 m_RemoteReg = remote;
128 int sel=0;
130 CString currentBranch = g_Git.GetSymbolicRef();
131 CString configName;
133 configName.Format(L"branch.%s.pushremote", currentBranch);
134 CString pushRemote = g_Git.GetConfigValue(configName);
135 if( pushRemote.IsEmpty() )
137 configName.Format(L"branch.%s.remote", currentBranch);
138 pushRemote = g_Git.GetConfigValue(configName);
141 if( !pushRemote.IsEmpty() )
142 remote=pushRemote;
144 //Select pull-branch from current branch
145 configName.Format(L"branch.%s.pushbranch", currentBranch);
146 CString pushBranch = CGit::StripRefName(g_Git.GetConfigValue(configName));
147 if( pushBranch.IsEmpty() )
149 configName.Format(L"branch.%s.merge", currentBranch);
150 pushBranch = CGit::StripRefName(g_Git.GetConfigValue(configName));
153 STRING_VECTOR list;
154 m_Remote.Reset();
156 if(!g_Git.GetRemoteList(list))
158 for(unsigned int i=0;i<list.size();i++)
160 m_Remote.AddString(list[i]);
161 if(list[i] == remote)
162 sel = i;
165 m_Remote.SetCurSel(sel);
167 int current=0;
168 list.clear();
169 m_BranchSource.Reset();
170 m_BranchSource.SetMaxHistoryItems(0x7FFFFFFF);
171 if(!g_Git.GetBranchList(list,&current))
173 for(unsigned int i=0;i<list.size();i++)
174 m_BranchSource.AddString(list[i]);
176 m_BranchSource.SetCurSel(current);
178 m_BranchRemote.LoadHistory(CString(_T("Software\\TortoiseGit\\History\\RemoteBranch\\"))+WorkingDir, _T("branch"));
179 if( !pushBranch.IsEmpty() )
181 m_BranchRemote.AddString(pushBranch);
184 else
185 m_BranchRemote.SetCurSel(-1);
188 // CPushDlg message handlers
190 void CPushDlg::OnBnClickedRd()
192 // TODO: Add your control notification handler code here
193 // TODO: Add your control notification handler code here
194 if( GetCheckedRadioButton(IDC_RD_REMOTE,IDC_RD_URL) == IDC_RD_REMOTE)
196 m_Remote.EnableWindow(TRUE);
197 m_RemoteURL.EnableWindow(FALSE);;
199 if( GetCheckedRadioButton(IDC_RD_REMOTE,IDC_RD_URL) == IDC_RD_URL)
201 m_Remote.EnableWindow(FALSE);
202 m_RemoteURL.EnableWindow(TRUE);
207 void CPushDlg::OnCbnSelchangeBranchSource()
209 // TODO: Add your control notification handler code here
210 m_BranchRemote.AddString(m_BranchSource.GetString());
213 void CPushDlg::OnBnClickedOk()
215 // TODO: Add your control notification handler code here
216 CResizableStandAloneDialog::UpdateData(TRUE);
218 if( GetCheckedRadioButton(IDC_RD_REMOTE,IDC_RD_URL) == IDC_RD_REMOTE)
220 m_URL=m_Remote.GetString();
222 if( GetCheckedRadioButton(IDC_RD_REMOTE,IDC_RD_URL) == IDC_RD_URL)
224 m_URL=m_RemoteURL.GetString();
227 this->m_BranchRemoteName=m_BranchRemote.GetString();
228 this->m_BranchSourceName=m_BranchSource.GetString();
230 this->m_RemoteURL.SaveHistory();
231 this->m_BranchRemote.SaveHistory();
233 m_RemoteReg = m_Remote.GetString();
235 this->m_regAutoLoad = m_bAutoLoad ;
237 CResizableStandAloneDialog::OnOK();
240 void CPushDlg::OnBnClickedRemoteManage()
242 // TODO: Add your control notification handler code here
243 CAppUtils::LaunchRemoteSetting();
246 void CPushDlg::OnBnClickedButtonBrowseSourceBranch()
248 if(CBrowseRefsDlg::PickRefForCombo(&m_BranchSource, gPickRef_Head))
249 OnCbnSelchangeBranchSource();
252 void CPushDlg::OnBnClickedButtonBrowseDestBranch()
254 CString remoteBranchName;
255 CString remoteName;
256 m_BranchRemote.GetWindowText(remoteBranchName);
257 remoteName = m_Remote.GetString();
258 remoteBranchName = remoteName + '/' + remoteBranchName;
259 remoteBranchName = CBrowseRefsDlg::PickRef(false, remoteBranchName, gPickRef_Remote);
260 if(remoteBranchName.IsEmpty())
261 return; //Canceled
262 remoteBranchName = remoteBranchName.Mid(13);//Strip 'refs/remotes/'
263 int slashPlace = remoteBranchName.Find('/');
264 remoteName = remoteBranchName.Left(slashPlace);
265 remoteBranchName = remoteBranchName.Mid(slashPlace + 1); //Strip remote name (for example 'origin/')
267 //Select remote
268 int remoteSel = m_Remote.FindStringExact(0,remoteName);
269 if(remoteSel >= 0)
270 m_Remote.SetCurSel(remoteSel);
272 //Select branch
273 m_BranchRemote.AddString(remoteBranchName);
276 BOOL CPushDlg::PreTranslateMessage(MSG* pMsg)
278 if (pMsg->message == WM_KEYDOWN)
280 switch (pMsg->wParam)
282 case VK_F5:
284 Refresh();
286 break;
290 return CResizableStandAloneDialog::PreTranslateMessage(pMsg);