Fixed Issue #138: "Format patch" in "Show log" dialog doesn't work
[TortoiseGit.git] / src / TortoiseProc / PushDlg.cpp
blob48291a3e05b1f6e5819f704fc51da5cf13f7a33e
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(m_bAutoLoad);
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 Refresh();
109 //m_BranchRemote.SetWindowTextW(m_BranchSource.GetString());
112 return TRUE;
115 void CPushDlg::Refresh()
117 CString WorkingDir=g_Git.m_CurrentDir;
118 WorkingDir.Replace(_T(':'),_T('_'));
120 CRegString remote(CString(_T("Software\\TortoiseGit\\History\\PushRemote\\")+WorkingDir));
121 m_RemoteReg = remote;
122 int sel=0;
124 CString currentBranch = g_Git.GetSymbolicRef();
125 CString configName;
127 configName.Format(L"branch.%s.pushremote", currentBranch);
128 CString pushRemote = g_Git.GetConfigValue(configName);
129 if( pushRemote.IsEmpty() )
131 configName.Format(L"branch.%s.remote", currentBranch);
132 pushRemote = g_Git.GetConfigValue(configName);
135 if( !pushRemote.IsEmpty() )
136 remote=pushRemote;
138 //Select pull-branch from current branch
139 configName.Format(L"branch.%s.pushbranch", currentBranch);
140 CString pushBranch = CGit::StripRefName(g_Git.GetConfigValue(configName));
141 if( pushBranch.IsEmpty() )
143 configName.Format(L"branch.%s.merge", currentBranch);
144 pushBranch = CGit::StripRefName(g_Git.GetConfigValue(configName));
147 STRING_VECTOR list;
148 m_Remote.Reset();
150 if(!g_Git.GetRemoteList(list))
152 for(unsigned int i=0;i<list.size();i++)
154 m_Remote.AddString(list[i]);
155 if(list[i] == remote)
156 sel = i;
159 m_Remote.SetCurSel(sel);
161 int current=0;
162 list.clear();
163 m_BranchSource.Reset();
164 if(!g_Git.GetBranchList(list,&current))
166 for(unsigned int i=0;i<list.size();i++)
167 m_BranchSource.AddString(list[i]);
169 m_BranchSource.SetCurSel(current);
171 m_BranchRemote.LoadHistory(CString(_T("Software\\TortoiseGit\\History\\RemoteBranch\\"))+WorkingDir, _T("branch"));
172 if( !pushBranch.IsEmpty() )
173 m_BranchRemote.AddString(pushBranch);
175 m_BranchRemote.SetCurSel(0);
178 // CPushDlg message handlers
180 void CPushDlg::OnBnClickedRd()
182 // TODO: Add your control notification handler code here
183 // TODO: Add your control notification handler code here
184 if( GetCheckedRadioButton(IDC_RD_REMOTE,IDC_RD_URL) == IDC_RD_REMOTE)
186 m_Remote.EnableWindow(TRUE);
187 m_RemoteURL.EnableWindow(FALSE);;
189 if( GetCheckedRadioButton(IDC_RD_REMOTE,IDC_RD_URL) == IDC_RD_URL)
191 m_Remote.EnableWindow(FALSE);
192 m_RemoteURL.EnableWindow(TRUE);
197 void CPushDlg::OnCbnSelchangeBranchSource()
199 // TODO: Add your control notification handler code here
200 m_BranchRemote.AddString(m_BranchSource.GetString());
203 void CPushDlg::OnBnClickedOk()
205 // TODO: Add your control notification handler code here
206 CResizableStandAloneDialog::UpdateData(TRUE);
208 if( GetCheckedRadioButton(IDC_RD_REMOTE,IDC_RD_URL) == IDC_RD_REMOTE)
210 m_URL=m_Remote.GetString();
212 if( GetCheckedRadioButton(IDC_RD_REMOTE,IDC_RD_URL) == IDC_RD_URL)
214 m_URL=m_RemoteURL.GetString();
217 this->m_BranchRemoteName=m_BranchRemote.GetString();
218 this->m_BranchSourceName=m_BranchSource.GetString();
220 this->m_RemoteURL.SaveHistory();
221 this->m_BranchRemote.SaveHistory();
223 m_RemoteReg = m_Remote.GetString();
225 CResizableStandAloneDialog::OnOK();
228 void CPushDlg::OnBnClickedRemoteManage()
230 // TODO: Add your control notification handler code here
231 CAppUtils::LaunchRemoteSetting();
234 void CPushDlg::OnBnClickedButtonBrowseSourceBranch()
236 if(CBrowseRefsDlg::PickRefForCombo(&m_BranchSource, gPickRef_Head))
237 OnCbnSelchangeBranchSource();
240 void CPushDlg::OnBnClickedButtonBrowseDestBranch()
242 CString remoteBranchName;
243 CString remoteName;
244 m_BranchRemote.GetWindowText(remoteBranchName);
245 remoteName = m_Remote.GetString();
246 remoteBranchName = remoteName + '/' + remoteBranchName;
247 remoteBranchName = CBrowseRefsDlg::PickRef(false, remoteBranchName, gPickRef_Remote);
248 if(remoteBranchName.IsEmpty())
249 return; //Canceled
250 remoteBranchName = remoteBranchName.Mid(13);//Strip 'refs/remotes/'
251 int slashPlace = remoteBranchName.Find('/');
252 remoteName = remoteBranchName.Left(slashPlace);
253 remoteBranchName = remoteBranchName.Mid(slashPlace + 1); //Strip remote name (for example 'origin/')
255 //Select remote
256 int remoteSel = m_Remote.FindStringExact(0,remoteName);
257 if(remoteSel >= 0)
258 m_Remote.SetCurSel(remoteSel);
260 //Select branch
261 m_BranchRemote.AddString(remoteBranchName);
264 BOOL CPushDlg::PreTranslateMessage(MSG* pMsg)
266 if (pMsg->message == WM_KEYDOWN)
268 switch (pMsg->wParam)
270 case VK_F5:
272 Refresh();
274 break;
278 return CResizableStandAloneDialog::PreTranslateMessage(pMsg);