1 // PushDlg.cpp : implementation file
5 #include "TortoiseProc.h"
11 #include "BrowseRefsDlg.h"
15 IMPLEMENT_DYNAMIC(CPushDlg
, CResizableStandAloneDialog
)
17 CPushDlg::CPushDlg(CWnd
* pParent
/*=NULL*/)
18 : CResizableStandAloneDialog(CPushDlg::IDD
, pParent
)
20 m_bAutoLoad
= CAppUtils::IsSSHPutty();
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
)
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
);
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);
100 m_RemoteURL
.SetWindowText(clippath
);
102 m_RemoteURL
.EnableWindow(FALSE
);
103 CheckRadioButton(IDC_RD_REMOTE
,IDC_RD_URL
,IDC_RD_REMOTE
);
109 //m_BranchRemote.SetWindowTextW(m_BranchSource.GetString());
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
;
124 CString currentBranch
= g_Git
.GetSymbolicRef();
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() )
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
));
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
)
159 m_Remote
.SetCurSel(sel
);
163 m_BranchSource
.Reset();
164 m_BranchSource
.SetMaxHistoryItems(0x7FFFFFFF);
165 if(!g_Git
.GetBranchList(list
,¤t
))
167 for(unsigned int i
=0;i
<list
.size();i
++)
168 m_BranchSource
.AddString(list
[i
]);
170 m_BranchSource
.SetCurSel(current
);
172 m_BranchRemote
.LoadHistory(CString(_T("Software\\TortoiseGit\\History\\RemoteBranch\\"))+WorkingDir
, _T("branch"));
173 if( !pushBranch
.IsEmpty() )
175 m_BranchRemote
.AddString(pushBranch
);
176 m_BranchRemote
.SetCurSel(0);
179 m_BranchRemote
.SetCurSel(-1);
182 // CPushDlg message handlers
184 void CPushDlg::OnBnClickedRd()
186 // TODO: Add your control notification handler code here
187 // TODO: Add your control notification handler code here
188 if( GetCheckedRadioButton(IDC_RD_REMOTE
,IDC_RD_URL
) == IDC_RD_REMOTE
)
190 m_Remote
.EnableWindow(TRUE
);
191 m_RemoteURL
.EnableWindow(FALSE
);;
193 if( GetCheckedRadioButton(IDC_RD_REMOTE
,IDC_RD_URL
) == IDC_RD_URL
)
195 m_Remote
.EnableWindow(FALSE
);
196 m_RemoteURL
.EnableWindow(TRUE
);
201 void CPushDlg::OnCbnSelchangeBranchSource()
203 // TODO: Add your control notification handler code here
204 m_BranchRemote
.AddString(m_BranchSource
.GetString());
207 void CPushDlg::OnBnClickedOk()
209 // TODO: Add your control notification handler code here
210 CResizableStandAloneDialog::UpdateData(TRUE
);
212 if( GetCheckedRadioButton(IDC_RD_REMOTE
,IDC_RD_URL
) == IDC_RD_REMOTE
)
214 m_URL
=m_Remote
.GetString();
216 if( GetCheckedRadioButton(IDC_RD_REMOTE
,IDC_RD_URL
) == IDC_RD_URL
)
218 m_URL
=m_RemoteURL
.GetString();
221 this->m_BranchRemoteName
=m_BranchRemote
.GetString();
222 this->m_BranchSourceName
=m_BranchSource
.GetString();
224 this->m_RemoteURL
.SaveHistory();
225 this->m_BranchRemote
.SaveHistory();
227 m_RemoteReg
= m_Remote
.GetString();
229 CResizableStandAloneDialog::OnOK();
232 void CPushDlg::OnBnClickedRemoteManage()
234 // TODO: Add your control notification handler code here
235 CAppUtils::LaunchRemoteSetting();
238 void CPushDlg::OnBnClickedButtonBrowseSourceBranch()
240 if(CBrowseRefsDlg::PickRefForCombo(&m_BranchSource
, gPickRef_Head
))
241 OnCbnSelchangeBranchSource();
244 void CPushDlg::OnBnClickedButtonBrowseDestBranch()
246 CString remoteBranchName
;
248 m_BranchRemote
.GetWindowText(remoteBranchName
);
249 remoteName
= m_Remote
.GetString();
250 remoteBranchName
= remoteName
+ '/' + remoteBranchName
;
251 remoteBranchName
= CBrowseRefsDlg::PickRef(false, remoteBranchName
, gPickRef_Remote
);
252 if(remoteBranchName
.IsEmpty())
254 remoteBranchName
= remoteBranchName
.Mid(13);//Strip 'refs/remotes/'
255 int slashPlace
= remoteBranchName
.Find('/');
256 remoteName
= remoteBranchName
.Left(slashPlace
);
257 remoteBranchName
= remoteBranchName
.Mid(slashPlace
+ 1); //Strip remote name (for example 'origin/')
260 int remoteSel
= m_Remote
.FindStringExact(0,remoteName
);
262 m_Remote
.SetCurSel(remoteSel
);
265 m_BranchRemote
.AddString(remoteBranchName
);
268 BOOL
CPushDlg::PreTranslateMessage(MSG
* pMsg
)
270 if (pMsg
->message
== WM_KEYDOWN
)
272 switch (pMsg
->wParam
)
282 return CResizableStandAloneDialog::PreTranslateMessage(pMsg
);