1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2013 - 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.
19 // GitSwitch.cpp : implementation file
24 #include "TortoiseProc.h"
25 #include "GitSwitchDlg.h"
28 #include "Messagebox.h"
30 // CGitSwitchDlg dialog
32 IMPLEMENT_DYNAMIC(CGitSwitchDlg
, CHorizontalResizableStandAloneDialog
)
34 CGitSwitchDlg::CGitSwitchDlg(CWnd
* pParent
/*=NULL*/)
35 : CHorizontalResizableStandAloneDialog(CGitSwitchDlg::IDD
, pParent
)
41 m_bBranchOverride
= FALSE
;
44 CGitSwitchDlg::~CGitSwitchDlg()
48 void CGitSwitchDlg::DoDataExchange(CDataExchange
* pDX
)
50 CDialog::DoDataExchange(pDX
);
53 DDX_Check(pDX
,IDC_CHECK_FORCE
,this->m_bForce
);
54 DDX_Check(pDX
,IDC_CHECK_TRACK
,this->m_bTrack
);
55 DDX_Check(pDX
,IDC_CHECK_BRANCH
,this->m_bBranch
);
56 DDX_Check(pDX
,IDC_CHECK_BRANCHOVERRIDE
,this->m_bBranchOverride
);
58 DDX_Text(pDX
,IDC_EDIT_BRANCH
,this->m_NewBranch
);
62 BEGIN_MESSAGE_MAP(CGitSwitchDlg
, CHorizontalResizableStandAloneDialog
)
65 ON_BN_CLICKED(IDC_CHECK_BRANCH
, &CGitSwitchDlg::OnBnClickedCheckBranch
)
66 ON_BN_CLICKED(IDOK
, &CGitSwitchDlg::OnBnClickedOk
)
67 ON_CBN_SELCHANGE(IDC_COMBOBOXEX_BRANCH
, &CGitSwitchDlg::OnCbnEditchangeComboboxexVersion
)
68 ON_CBN_SELCHANGE(IDC_COMBOBOXEX_TAGS
, &CGitSwitchDlg::OnCbnEditchangeComboboxexVersion
)
70 ON_CBN_EDITCHANGE(IDC_COMBOBOXEX_VERSION
, &CGitSwitchDlg::OnCbnEditchangeComboboxexVersion
)
71 ON_EN_CHANGE(IDC_EDIT_BRANCH
, &CGitSwitchDlg::OnEnChangeEditBranch
)
74 BOOL
CGitSwitchDlg::PreTranslateMessage(MSG
* pMsg
)
76 m_ToolTip
.RelayEvent(pMsg
);
78 return CDialog::PreTranslateMessage(pMsg
);
81 BOOL
CGitSwitchDlg::OnInitDialog()
83 CHorizontalResizableStandAloneDialog::OnInitDialog();
84 CAppUtils::MarkWindowAsUnpinnable(m_hWnd
);
86 AddAnchor(IDC_GROUP_OPTION
, TOP_LEFT
, TOP_RIGHT
);
88 AddAnchor(IDC_EDIT_BRANCH
, TOP_LEFT
, TOP_RIGHT
);
90 AddAnchor(IDOK
,BOTTOM_RIGHT
);
91 AddAnchor(IDCANCEL
,BOTTOM_RIGHT
);
92 AddAnchor(IDHELP
,BOTTOM_RIGHT
);
94 CHOOSE_VERSION_ADDANCHOR
;
95 this->AddOthersToAnchor();
97 AdjustControlSize(IDC_RADIO_BRANCH
);
98 AdjustControlSize(IDC_RADIO_TAGS
);
99 AdjustControlSize(IDC_RADIO_VERSION
);
100 AdjustControlSize(IDC_CHECK_BRANCH
);
101 AdjustControlSize(IDC_CHECK_FORCE
);
102 AdjustControlSize(IDC_CHECK_TRACK
);
103 AdjustControlSize(IDC_CHECK_BRANCHOVERRIDE
);
105 EnableSaveRestore(_T("SwitchDlg"));
107 CString sWindowTitle
;
108 GetWindowText(sWindowTitle
);
109 CAppUtils::SetWindowTitle(m_hWnd
, g_Git
.m_CurrentDir
, sWindowTitle
);
113 SetDefaultChoose(IDC_RADIO_BRANCH
);
114 GetDlgItem(IDC_CHECK_BRANCH
)->SetFocus();
116 this->GetDlgItem(IDC_CHECK_TRACK
)->EnableWindow(FALSE
);
118 //Create the ToolTip control
119 if (!m_ToolTip
.Create(this))
121 TRACE0("Unable to create the ToolTip!");
125 m_ToolTip
.AddTool(GetDlgItem(IDC_CHECK_FORCE
), CString(MAKEINTRESOURCE(IDS_PROC_NEWBRANCHTAG_FORCE_TT
)));
126 m_ToolTip
.AddTool(GetDlgItem(IDC_CHECK_TRACK
), CString(MAKEINTRESOURCE(IDS_PROC_NEWBRANCHTAG_TRACK_TT
)));
127 m_ToolTip
.Activate(TRUE
);
132 // CCreateBranchTagDlg message handlers
134 void CGitSwitchDlg::OnBnClickedChooseRadioHost()
136 OnBnClickedChooseRadio();
137 SetDefaultName(TRUE
);
140 void CGitSwitchDlg::OnBnClickedShow()
142 OnBnClickedChooseVersion();
145 void CGitSwitchDlg::OnBnClickedOk()
147 this->UpdateData(TRUE
);
149 // make sure a valid branch has been entered if a new branch is required
153 if (!g_Git
.IsBranchNameValid(m_NewBranch
))
155 // new branch requested but name is empty or contains spaces
156 ShowEditBalloon(IDC_EDIT_BRANCH
, IDS_B_T_NOTEMPTY
, TTI_ERROR
);
159 else if (!m_bBranchOverride
&& g_Git
.BranchTagExists(m_NewBranch
))
161 // branch already exists
163 msg
.LoadString(IDS_B_EXISTS
);
164 ShowEditBalloon(IDC_EDIT_BRANCH
, msg
+ _T(" ") + CString(MAKEINTRESOURCE(IDS_B_DIFFERENTNAMEOROVERRIDE
)), CString(MAKEINTRESOURCE(IDS_WARN_WARNING
)));
167 else if (g_Git
.BranchTagExists(m_NewBranch
, false))
169 // tag with the same name exists -> shortref is ambiguous
170 if (CMessageBox::Show(m_hWnd
, IDS_B_SAMETAGNAMEEXISTS
, IDS_APPNAME
, 2, IDI_EXCLAMATION
, IDS_CONTINUEBUTTON
, IDS_ABORTBUTTON
) == 2)
176 //this->m_Version.SaveHistory();
179 void CGitSwitchDlg::SetDefaultName(BOOL isUpdateCreateBranch
)
181 this->UpdateData(TRUE
);
182 this->UpdateRevsionName();
184 CString version
= m_VersionName
;
187 if (version
.Left(7)==_T("origin/"))
188 start
= version
.Find(_T('/'), 8);
189 else if (version
.Left(8)==_T("remotes/"))
190 start
= version
.Find(_T('/'), 9);
194 version
= version
.Mid(start
+ 1);
195 this->GetDlgItem(IDC_CHECK_TRACK
)->EnableWindow(TRUE
);
196 this->m_NewBranch
=version
;
198 if(isUpdateCreateBranch
)
199 this->m_bBranch
=TRUE
;
205 if (m_VersionName
.Left(11) == _T("refs/heads/"))
206 version
= m_VersionName
.Mid(11);
207 m_NewBranch
= CString(_T("Branch_")) + version
;
208 this->GetDlgItem(IDC_CHECK_TRACK
)->EnableWindow(FALSE
);
210 if(isUpdateCreateBranch
)
211 this->m_bBranch
=FALSE
;
213 this->m_bTrack
=FALSE
;
216 int radio
=GetCheckedRadioButton(IDC_RADIO_BRANCH
,IDC_RADIO_VERSION
);
217 if(radio
==IDC_RADIO_TAGS
|| radio
==IDC_RADIO_VERSION
)
219 if(isUpdateCreateBranch
)
220 this->m_bBranch
=TRUE
;
223 GetDlgItem(IDC_EDIT_BRANCH
)->EnableWindow(m_bBranch
);
224 GetDlgItem(IDC_CHECK_BRANCHOVERRIDE
)->EnableWindow(m_bBranch
);
227 this->m_bBranchOverride
=FALSE
;
228 this->GetDlgItem(IDC_CHECK_TRACK
)->EnableWindow(FALSE
);
229 this->m_bTrack
=FALSE
;
231 this->UpdateData(FALSE
);
234 void CGitSwitchDlg::OnDestroy()
236 WaitForFinishLoading();
237 __super::OnDestroy();
240 void CGitSwitchDlg::OnCbnEditchangeComboboxexVersion()
245 void CGitSwitchDlg::OnEnChangeEditBranch()
247 if (!((CButton
*)GetDlgItem(IDC_RADIO_BRANCH
))->GetCheck())
251 GetDlgItem(IDC_EDIT_BRANCH
)->GetWindowText(name
);
252 name
= _T("/") + name
;
253 CString remoteName
= m_ChooseVersioinBranch
.GetString();
254 if (remoteName
.Left(8) == _T("remotes/") && remoteName
.Right(name
.GetLength()) != name
)
255 ((CButton
*)GetDlgItem(IDC_CHECK_TRACK
))->SetCheck(FALSE
);
258 void CGitSwitchDlg::OnVersionChanged()
260 SetDefaultName(TRUE
);
262 void CGitSwitchDlg::OnBnClickedCheckBranch()
265 GetDlgItem(IDC_EDIT_BRANCH
)->EnableWindow(m_bBranch
);