1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2018 - 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"
27 #include "MessageBox.h"
29 // CGitSwitchDlg dialog
31 IMPLEMENT_DYNAMIC(CGitSwitchDlg
, CHorizontalResizableStandAloneDialog
)
33 CGitSwitchDlg::CGitSwitchDlg(CWnd
* pParent
/*=nullptr*/)
34 : CHorizontalResizableStandAloneDialog(CGitSwitchDlg::IDD
, pParent
)
35 , CChooseVersion(this)
36 , m_bBranch(BST_UNCHECKED
)
37 , m_bMerge(BST_UNCHECKED
)
38 , m_bTrack(BST_INDETERMINATE
)
39 , m_bForce(BST_UNCHECKED
)
40 , m_bBranchOverride(BST_UNCHECKED
)
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_MERGE
, m_bMerge
);
55 DDX_Check(pDX
,IDC_CHECK_TRACK
,this->m_bTrack
);
56 DDX_Check(pDX
,IDC_CHECK_BRANCH
,this->m_bBranch
);
57 DDX_Check(pDX
,IDC_CHECK_BRANCHOVERRIDE
,this->m_bBranchOverride
);
59 DDX_Text(pDX
,IDC_EDIT_BRANCH
,this->m_NewBranch
);
63 BEGIN_MESSAGE_MAP(CGitSwitchDlg
, CHorizontalResizableStandAloneDialog
)
66 ON_BN_CLICKED(IDC_CHECK_BRANCH
, &CGitSwitchDlg::OnBnClickedCheckBranch
)
67 ON_BN_CLICKED(IDOK
, &CGitSwitchDlg::OnBnClickedOk
)
68 ON_CBN_SELCHANGE(IDC_COMBOBOXEX_BRANCH
, &CGitSwitchDlg::OnCbnEditchangeComboboxexVersion
)
69 ON_CBN_SELCHANGE(IDC_COMBOBOXEX_TAGS
, &CGitSwitchDlg::OnCbnEditchangeComboboxexVersion
)
71 ON_CBN_EDITCHANGE(IDC_COMBOBOXEX_VERSION
, &CGitSwitchDlg::OnCbnEditchangeComboboxexVersion
)
72 ON_EN_CHANGE(IDC_EDIT_BRANCH
, &CGitSwitchDlg::OnEnChangeEditBranch
)
75 BOOL
CGitSwitchDlg::OnInitDialog()
77 CHorizontalResizableStandAloneDialog::OnInitDialog();
78 CAppUtils::MarkWindowAsUnpinnable(m_hWnd
);
80 AdjustControlSize(IDC_RADIO_BRANCH
);
81 AdjustControlSize(IDC_RADIO_TAGS
);
82 AdjustControlSize(IDC_RADIO_VERSION
);
83 AdjustControlSize(IDC_CHECK_BRANCH
);
84 AdjustControlSize(IDC_CHECK_FORCE
);
85 AdjustControlSize(IDC_CHECK_MERGE
);
86 AdjustControlSize(IDC_CHECK_TRACK
);
87 AdjustControlSize(IDC_CHECK_BRANCHOVERRIDE
);
89 AddAnchor(IDC_GROUP_OPTION
, TOP_LEFT
, TOP_RIGHT
);
91 AddAnchor(IDC_EDIT_BRANCH
, TOP_LEFT
, TOP_RIGHT
);
93 AddAnchor(IDOK
,BOTTOM_RIGHT
);
94 AddAnchor(IDCANCEL
,BOTTOM_RIGHT
);
95 AddAnchor(IDHELP
,BOTTOM_RIGHT
);
97 CHOOSE_VERSION_ADDANCHOR
;
98 this->AddOthersToAnchor();
100 EnableSaveRestore(L
"SwitchDlg");
102 CString sWindowTitle
;
103 GetWindowText(sWindowTitle
);
104 CAppUtils::SetWindowTitle(m_hWnd
, g_Git
.m_CurrentDir
, sWindowTitle
);
106 InitChooseVersion(true);
108 SetDefaultChoose(IDC_RADIO_BRANCH
);
109 GetDlgItem(IDC_CHECK_BRANCH
)->SetFocus();
111 this->GetDlgItem(IDC_CHECK_TRACK
)->EnableWindow(FALSE
);
113 m_tooltips
.AddTool(GetDlgItem(IDC_CHECK_BRANCHOVERRIDE
), CString(MAKEINTRESOURCE(IDS_PROC_NEWBRANCHTAG_FORCE_TT
)));
114 m_tooltips
.AddTool(GetDlgItem(IDC_CHECK_MERGE
), CString(MAKEINTRESOURCE(IDS_PROC_SWITCH_MERGE_TT
)));
115 m_tooltips
.AddTool(GetDlgItem(IDC_CHECK_TRACK
), CString(MAKEINTRESOURCE(IDS_PROC_NEWBRANCHTAG_TRACK_TT
)));
116 m_tooltips
.Activate(TRUE
);
120 // CCreateBranchTagDlg message handlers
122 void CGitSwitchDlg::OnBnClickedChooseRadioHost()
124 OnBnClickedChooseRadio();
125 SetDefaultName(TRUE
);
128 void CGitSwitchDlg::OnBnClickedShow()
130 OnBnClickedChooseVersion();
133 void CGitSwitchDlg::OnBnClickedOk()
135 this->UpdateData(TRUE
);
137 // make sure a valid branch has been entered if a new branch is required
141 if (!g_Git
.IsBranchNameValid(m_NewBranch
))
143 // new branch requested but name is empty or contains spaces
144 ShowEditBalloon(IDC_EDIT_BRANCH
, IDS_B_T_NOTEMPTY
, IDS_ERR_ERROR
, TTI_ERROR
);
147 else if (!m_bBranchOverride
&& g_Git
.BranchTagExists(m_NewBranch
))
149 // branch already exists
151 msg
.LoadString(IDS_B_EXISTS
);
152 ShowEditBalloon(IDC_EDIT_BRANCH
, msg
+ L
' ' + CString(MAKEINTRESOURCE(IDS_B_DIFFERENTNAMEOROVERRIDE
)), CString(MAKEINTRESOURCE(IDS_WARN_WARNING
)));
155 else if (g_Git
.BranchTagExists(m_NewBranch
, false))
157 // tag with the same name exists -> shortref is ambiguous
158 if (CMessageBox::Show(m_hWnd
, IDS_B_SAMETAGNAMEEXISTS
, IDS_APPNAME
, 2, IDI_EXCLAMATION
, IDS_CONTINUEBUTTON
, IDS_ABORTBUTTON
) == 2)
164 //this->m_Version.SaveHistory();
167 void CGitSwitchDlg::SetDefaultName(BOOL isUpdateCreateBranch
)
169 this->UpdateData(TRUE
);
170 this->UpdateRevsionName();
172 CString version
= m_VersionName
;
175 if (CStringUtils::StartsWith(version
, L
"origin/"))
176 start
= version
.Find(L
'/', 8);
177 else if (CStringUtils::StartsWith(version
, L
"remotes/"))
178 start
= version
.Find(L
'/', 9);
182 version
= version
.Mid(start
+ 1);
183 this->GetDlgItem(IDC_CHECK_TRACK
)->EnableWindow(TRUE
);
184 this->m_NewBranch
=version
;
186 if(isUpdateCreateBranch
)
187 this->m_bBranch
=TRUE
;
193 if (CStringUtils::StartsWith(m_VersionName
, L
"refs/heads/"))
194 version
= m_VersionName
.Mid(11);
196 version
= version
.Left(g_Git
.GetShortHASHLength());
197 m_NewBranch
= L
"Branch_" + version
;
198 this->GetDlgItem(IDC_CHECK_TRACK
)->EnableWindow(FALSE
);
200 if(isUpdateCreateBranch
)
201 this->m_bBranch
=FALSE
;
203 this->m_bTrack
=FALSE
;
206 int radio
=GetCheckedRadioButton(IDC_RADIO_BRANCH
,IDC_RADIO_VERSION
);
207 if(radio
==IDC_RADIO_TAGS
|| radio
==IDC_RADIO_VERSION
)
209 if(isUpdateCreateBranch
)
210 this->m_bBranch
=TRUE
;
213 GetDlgItem(IDC_EDIT_BRANCH
)->EnableWindow(m_bBranch
);
214 GetDlgItem(IDC_CHECK_BRANCHOVERRIDE
)->EnableWindow(m_bBranch
);
217 this->m_bBranchOverride
=FALSE
;
218 this->GetDlgItem(IDC_CHECK_TRACK
)->EnableWindow(FALSE
);
219 this->m_bTrack
=FALSE
;
221 this->UpdateData(FALSE
);
224 void CGitSwitchDlg::OnDestroy()
226 WaitForFinishLoading();
227 __super::OnDestroy();
230 void CGitSwitchDlg::OnCbnEditchangeComboboxexVersion()
235 void CGitSwitchDlg::OnEnChangeEditBranch()
237 if (!((CButton
*)GetDlgItem(IDC_RADIO_BRANCH
))->GetCheck())
241 GetDlgItem(IDC_EDIT_BRANCH
)->GetWindowText(name
);
243 CString remoteName
= m_ChooseVersioinBranch
.GetString();
244 if (CStringUtils::StartsWith(remoteName
, L
"remotes/") && remoteName
.Right(name
.GetLength()) != name
)
245 ((CButton
*)GetDlgItem(IDC_CHECK_TRACK
))->SetCheck(FALSE
);
248 void CGitSwitchDlg::OnVersionChanged()
250 SetDefaultName(TRUE
);
252 void CGitSwitchDlg::OnBnClickedCheckBranch()
255 GetDlgItem(IDC_EDIT_BRANCH
)->EnableWindow(m_bBranch
);