1 // PushDlg.cpp : implementation file
\r
5 #include "TortoiseProc.h"
\r
9 #include "registry.h"
\r
10 #include "AppUtils.h"
\r
11 #include "BrowseRefsDlg.h"
\r
15 IMPLEMENT_DYNAMIC(CPushDlg, CResizableStandAloneDialog)
\r
17 CPushDlg::CPushDlg(CWnd* pParent /*=NULL*/)
\r
18 : CResizableStandAloneDialog(CPushDlg::IDD, pParent)
\r
20 m_bAutoLoad = CAppUtils::IsSSHPutty();
\r
23 CPushDlg::~CPushDlg()
\r
27 void CPushDlg::DoDataExchange(CDataExchange* pDX)
\r
29 CResizableStandAloneDialog::DoDataExchange(pDX);
\r
30 DDX_Control(pDX, IDC_BRANCH_REMOTE, this->m_BranchRemote);
\r
31 DDX_Control(pDX, IDC_BRANCH_SOURCE, this->m_BranchSource);
\r
32 DDX_Control(pDX, IDC_REMOTE, this->m_Remote);
\r
33 DDX_Control(pDX, IDC_URL, this->m_RemoteURL);
\r
34 DDX_Check(pDX,IDC_FORCE,this->m_bForce);
\r
35 DDX_Check(pDX,IDC_PACK,this->m_bPack);
\r
36 DDX_Check(pDX,IDC_TAGS,this->m_bTags);
\r
37 DDX_Check(pDX,IDC_PUTTYKEY_AUTOLOAD,this->m_bAutoLoad);
\r
42 BEGIN_MESSAGE_MAP(CPushDlg, CResizableStandAloneDialog)
\r
43 ON_BN_CLICKED(IDC_RD_REMOTE, &CPushDlg::OnBnClickedRd)
\r
44 ON_BN_CLICKED(IDC_RD_URL, &CPushDlg::OnBnClickedRd)
\r
45 ON_CBN_SELCHANGE(IDC_BRANCH_SOURCE, &CPushDlg::OnCbnSelchangeBranchSource)
\r
46 ON_BN_CLICKED(IDOK, &CPushDlg::OnBnClickedOk)
\r
47 ON_BN_CLICKED(IDC_REMOTE_MANAGE, &CPushDlg::OnBnClickedRemoteManage)
\r
48 ON_BN_CLICKED(IDC_BUTTON_BROWSE_SOURCE_BRANCH, &CPushDlg::OnBnClickedButtonBrowseSourceBranch)
\r
49 ON_BN_CLICKED(IDC_BUTTON_BROWSE_DEST_BRANCH, &CPushDlg::OnBnClickedButtonBrowseDestBranch)
\r
52 BOOL CPushDlg::OnInitDialog()
\r
54 CResizableStandAloneDialog::OnInitDialog();
\r
56 AddAnchor(IDOK,BOTTOM_RIGHT);
\r
57 AddAnchor(IDCANCEL,BOTTOM_RIGHT);
\r
58 AddAnchor(IDC_BRANCH_GROUP, TOP_LEFT,TOP_RIGHT);
\r
59 AddAnchor(IDC_STATIC_REMOTE, TOP_RIGHT);
\r
60 AddAnchor(IDC_STATIC_SOURCE, TOP_LEFT);
\r
62 AddAnchor(IDC_BRANCH_REMOTE, TOP_RIGHT);
\r
63 AddAnchor(IDC_BUTTON_BROWSE_DEST_BRANCH, TOP_RIGHT);
\r
64 AddAnchor(IDC_BRANCH_SOURCE, TOP_LEFT);
\r
65 AddAnchor(IDC_BUTTON_BROWSE_SOURCE_BRANCH, TOP_LEFT);
\r
67 AddAnchor(IDC_URL_GROUP, TOP_LEFT,TOP_RIGHT);
\r
68 AddAnchor(IDC_RD_REMOTE, TOP_LEFT);
\r
69 AddAnchor(IDC_RD_URL, TOP_LEFT);
\r
71 AddAnchor(IDC_REMOTE, TOP_LEFT, TOP_RIGHT);
\r
73 AddAnchor(IDC_URL, TOP_LEFT,TOP_RIGHT);
\r
75 AddAnchor(IDC_OPTION_GROUP, TOP_LEFT,TOP_RIGHT);
\r
77 AddAnchor(IDC_FORCE, TOP_LEFT);
\r
78 AddAnchor(IDC_PACK, TOP_LEFT);
\r
79 AddAnchor(IDC_TAGS, TOP_LEFT);
\r
80 AddAnchor(IDC_PUTTYKEY_AUTOLOAD,TOP_LEFT);
\r
82 AddAnchor(IDC_REMOTE_MANAGE,TOP_RIGHT);
\r
83 AddAnchor(IDHELP, BOTTOM_RIGHT);
\r
85 AddOthersToAnchor();
\r
87 this->GetDlgItem(IDC_PUTTYKEY_AUTOLOAD)->EnableWindow(m_bAutoLoad);
\r
89 EnableSaveRestore(_T("PushDlg"));
\r
91 m_RemoteURL.SetURLHistory(TRUE);
\r
93 CString WorkingDir=g_Git.m_CurrentDir;
\r
94 WorkingDir.Replace(_T(':'),_T('_'));
\r
95 m_RemoteURL.LoadHistory(CString(_T("Software\\TortoiseGit\\History\\PushURLS\\"))+WorkingDir, _T("url"));
\r
96 CString clippath=CAppUtils::GetClipboardLink();
\r
97 if(clippath.IsEmpty())
\r
98 m_RemoteURL.SetCurSel(0);
\r
100 m_RemoteURL.SetWindowText(clippath);
\r
102 m_RemoteURL.EnableWindow(FALSE);
\r
103 CheckRadioButton(IDC_RD_REMOTE,IDC_RD_URL,IDC_RD_REMOTE);
\r
109 //m_BranchRemote.SetWindowTextW(m_BranchSource.GetString());
\r
115 void CPushDlg::Refresh()
\r
117 CString WorkingDir=g_Git.m_CurrentDir;
\r
118 WorkingDir.Replace(_T(':'),_T('_'));
\r
120 CRegString remote(CString(_T("Software\\TortoiseGit\\History\\PushRemote\\")+WorkingDir));
\r
121 m_RemoteReg = remote;
\r
124 CString currentBranch = g_Git.GetSymbolicRef();
\r
125 CString configName;
\r
127 configName.Format(L"branch.%s.pushremote", currentBranch);
\r
128 CString pushRemote = g_Git.GetConfigValue(configName);
\r
129 if( pushRemote.IsEmpty() )
\r
131 configName.Format(L"branch.%s.remote", currentBranch);
\r
132 pushRemote = g_Git.GetConfigValue(configName);
\r
135 if( !pushRemote.IsEmpty() )
\r
138 //Select pull-branch from current branch
\r
139 configName.Format(L"branch.%s.pushbranch", currentBranch);
\r
140 CString pushBranch = CGit::StripRefName(g_Git.GetConfigValue(configName));
\r
141 if( pushBranch.IsEmpty() )
\r
143 configName.Format(L"branch.%s.merge", currentBranch);
\r
144 pushBranch = CGit::StripRefName(g_Git.GetConfigValue(configName));
\r
147 STRING_VECTOR list;
\r
150 if(!g_Git.GetRemoteList(list))
\r
152 for(unsigned int i=0;i<list.size();i++)
\r
154 m_Remote.AddString(list[i]);
\r
155 if(list[i] == remote)
\r
159 m_Remote.SetCurSel(sel);
\r
163 m_BranchSource.Reset();
\r
164 if(!g_Git.GetBranchList(list,¤t))
\r
166 for(unsigned int i=0;i<list.size();i++)
\r
167 m_BranchSource.AddString(list[i]);
\r
169 m_BranchSource.SetCurSel(current);
\r
171 m_BranchRemote.LoadHistory(CString(_T("Software\\TortoiseGit\\History\\RemoteBranch\\"))+WorkingDir, _T("branch"));
\r
172 if( !pushBranch.IsEmpty() )
\r
174 m_BranchRemote.AddString(pushBranch);
\r
175 m_BranchRemote.SetCurSel(0);
\r
178 m_BranchRemote.SetCurSel(-1);
\r
181 // CPushDlg message handlers
\r
183 void CPushDlg::OnBnClickedRd()
\r
185 // TODO: Add your control notification handler code here
\r
186 // TODO: Add your control notification handler code here
\r
187 if( GetCheckedRadioButton(IDC_RD_REMOTE,IDC_RD_URL) == IDC_RD_REMOTE)
\r
189 m_Remote.EnableWindow(TRUE);
\r
190 m_RemoteURL.EnableWindow(FALSE);;
\r
192 if( GetCheckedRadioButton(IDC_RD_REMOTE,IDC_RD_URL) == IDC_RD_URL)
\r
194 m_Remote.EnableWindow(FALSE);
\r
195 m_RemoteURL.EnableWindow(TRUE);
\r
200 void CPushDlg::OnCbnSelchangeBranchSource()
\r
202 // TODO: Add your control notification handler code here
\r
203 m_BranchRemote.AddString(m_BranchSource.GetString());
\r
206 void CPushDlg::OnBnClickedOk()
\r
208 // TODO: Add your control notification handler code here
\r
209 CResizableStandAloneDialog::UpdateData(TRUE);
\r
211 if( GetCheckedRadioButton(IDC_RD_REMOTE,IDC_RD_URL) == IDC_RD_REMOTE)
\r
213 m_URL=m_Remote.GetString();
\r
215 if( GetCheckedRadioButton(IDC_RD_REMOTE,IDC_RD_URL) == IDC_RD_URL)
\r
217 m_URL=m_RemoteURL.GetString();
\r
220 this->m_BranchRemoteName=m_BranchRemote.GetString();
\r
221 this->m_BranchSourceName=m_BranchSource.GetString();
\r
223 this->m_RemoteURL.SaveHistory();
\r
224 this->m_BranchRemote.SaveHistory();
\r
226 m_RemoteReg = m_Remote.GetString();
\r
228 CResizableStandAloneDialog::OnOK();
\r
231 void CPushDlg::OnBnClickedRemoteManage()
\r
233 // TODO: Add your control notification handler code here
\r
234 CAppUtils::LaunchRemoteSetting();
\r
237 void CPushDlg::OnBnClickedButtonBrowseSourceBranch()
\r
239 if(CBrowseRefsDlg::PickRefForCombo(&m_BranchSource, gPickRef_Head))
\r
240 OnCbnSelchangeBranchSource();
\r
243 void CPushDlg::OnBnClickedButtonBrowseDestBranch()
\r
245 CString remoteBranchName;
\r
246 CString remoteName;
\r
247 m_BranchRemote.GetWindowText(remoteBranchName);
\r
248 remoteName = m_Remote.GetString();
\r
249 remoteBranchName = remoteName + '/' + remoteBranchName;
\r
250 remoteBranchName = CBrowseRefsDlg::PickRef(false, remoteBranchName, gPickRef_Remote);
\r
251 if(remoteBranchName.IsEmpty())
\r
253 remoteBranchName = remoteBranchName.Mid(13);//Strip 'refs/remotes/'
\r
254 int slashPlace = remoteBranchName.Find('/');
\r
255 remoteName = remoteBranchName.Left(slashPlace);
\r
256 remoteBranchName = remoteBranchName.Mid(slashPlace + 1); //Strip remote name (for example 'origin/')
\r
259 int remoteSel = m_Remote.FindStringExact(0,remoteName);
\r
261 m_Remote.SetCurSel(remoteSel);
\r
264 m_BranchRemote.AddString(remoteBranchName);
\r
267 BOOL CPushDlg::PreTranslateMessage(MSG* pMsg)
\r
269 if (pMsg->message == WM_KEYDOWN)
\r
271 switch (pMsg->wParam)
\r
281 return CResizableStandAloneDialog::PreTranslateMessage(pMsg);
\r