1
// TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2017, 2019-2021 - 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.
18 // CreateBranchTagDlg.cpp : implementation file
23 #include "TortoiseProc.h"
24 #include "CreateBranchTagDlg.h"
26 #include "MessageBox.h"
28 // CCreateBranchTagDlg dialog
30 IMPLEMENT_DYNAMIC(CCreateBranchTagDlg
, CResizableStandAloneDialog
)
32 CCreateBranchTagDlg::CCreateBranchTagDlg(CWnd
* pParent
/*=nullptr*/)
33 : CResizableStandAloneDialog(CCreateBranchTagDlg::IDD
, pParent
)
35 , CChooseVersion(this)
37 , m_regNewBranch(L
"Software\\TortoiseGit\\NewBranchSwitchTo", FALSE
)
38 , m_bSwitch(BST_UNCHECKED
) // default switch to checkbox not selected
39 , m_bTrack(BST_INDETERMINATE
)
40 , m_bSign(BST_UNCHECKED
)
44 CCreateBranchTagDlg::~CCreateBranchTagDlg()
48 void CCreateBranchTagDlg::DoDataExchange(CDataExchange
* pDX
)
50 CDialog::DoDataExchange(pDX
);
54 DDX_Text(pDX
, IDC_BRANCH_TAG
, this->m_BranchTagName
);
55 DDX_Check(pDX
,IDC_CHECK_FORCE
,this->m_bForce
);
56 DDX_Check(pDX
,IDC_CHECK_TRACK
,this->m_bTrack
);
57 DDX_Check(pDX
,IDC_CHECK_SWITCH
,this->m_bSwitch
);
58 DDX_Check(pDX
,IDC_CHECK_SIGN
,this->m_bSign
);
59 DDX_Text(pDX
, IDC_EDIT_MESSAGE
,this->m_Message
);
63 BEGIN_MESSAGE_MAP(CCreateBranchTagDlg
, CResizableStandAloneDialog
)
65 ON_BN_CLICKED(IDOK
, &CCreateBranchTagDlg::OnBnClickedOk
)
66 ON_CBN_SELCHANGE(IDC_COMBOBOXEX_BRANCH
, &CCreateBranchTagDlg::OnCbnSelchangeComboboxexBranch
)
67 ON_EN_CHANGE(IDC_BRANCH_TAG
, &CCreateBranchTagDlg::OnEnChangeBranchTag
)
68 // ON_BN_CLICKED(IDC_BUTTON_BROWSE_REF, &CCreateBranchTagDlg::OnBnClickedButtonBrowseRef)
72 BOOL
CCreateBranchTagDlg::OnInitDialog()
74 CResizableStandAloneDialog::OnInitDialog();
75 CAppUtils::MarkWindowAsUnpinnable(m_hWnd
);
77 this->SetDefaultChoose(IDC_RADIO_HEAD
);
81 this->GetDlgItem(IDC_CHECK_TRACK
)->EnableWindow(FALSE
);
86 sWindowTitle
= CString(MAKEINTRESOURCE(IDS_PROGS_TITLE_CREATETAG
));
87 this->GetDlgItem(IDC_LABEL_BRANCH
)->SetWindowText(CString(MAKEINTRESOURCE(IDS_PROC_TAG
)));
88 this->GetDlgItem(IDC_CHECK_SIGN
)->EnableWindow(!g_Git
.GetConfigValue(L
"user.signingkey").IsEmpty());
92 sWindowTitle
= CString(MAKEINTRESOURCE(IDS_PROGS_TITLE_CREATEBRANCH
));
93 this->GetDlgItem(IDC_LABEL_BRANCH
)->SetWindowText(CString(MAKEINTRESOURCE(IDS_PROC_BRANCH
)));
94 GetDlgItem(IDC_CHECK_SIGN
)->ShowWindow(SW_HIDE
); // deactivated by default
95 GetDlgItem(IDC_GROUP_MESSAGE
)->SetWindowText(CString(MAKEINTRESOURCE(IDS_DESCRIPTION
)));
98 m_bSwitch
= BST_CHECKED
;
103 CAppUtils::SetWindowTitle(m_hWnd
, g_Git
.m_CurrentDir
, sWindowTitle
);
105 // show the switch checkbox if we are a create branch dialog
106 bool canSwitch
= !m_bIsTag
&& !GitAdminDir::IsBareRepo(g_Git
.m_CurrentDir
);
107 GetDlgItem(IDC_CHECK_SWITCH
)->ShowWindow(canSwitch
? SW_SHOW
: SW_HIDE
);
108 DialogEnableWindow(IDC_CHECK_SWITCH
, canSwitch
);
109 CWnd
* pHead
= GetDlgItem(IDC_RADIO_HEAD
);
111 pHead
->GetWindowText( HeadText
);
112 pHead
->SetWindowText( HeadText
+ " (" + g_Git
.GetCurrentBranch() + ")");
114 AdjustControlSize(IDC_RADIO_BRANCH
);
115 AdjustControlSize(IDC_RADIO_TAGS
);
116 AdjustControlSize(IDC_RADIO_VERSION
);
117 AdjustControlSize(IDC_CHECK_TRACK
);
118 AdjustControlSize(IDC_CHECK_FORCE
);
119 AdjustControlSize(IDC_CHECK_SWITCH
);
120 AdjustControlSize(IDC_CHECK_SIGN
);
121 AdjustControlSize(IDC_RADIO_HEAD
);
123 CHOOSE_VERSION_ADDANCHOR
;
125 AddAnchor(IDC_BRANCH_TAG
, TOP_LEFT
, TOP_RIGHT
);
126 AddAnchor(IDC_GROUP_BRANCH
, TOP_LEFT
, TOP_RIGHT
);
128 AddAnchor(IDC_GROUP_OPTION
, TOP_LEFT
, TOP_RIGHT
);
130 AddAnchor(IDOK
, BOTTOM_RIGHT
);
131 AddAnchor(IDCANCEL
, BOTTOM_RIGHT
);
132 AddAnchor(IDHELP
, BOTTOM_RIGHT
);
133 AddAnchor(IDC_GROUP_MESSAGE
, TOP_LEFT
, BOTTOM_RIGHT
);
134 AddAnchor(IDC_EDIT_MESSAGE
, TOP_LEFT
, BOTTOM_RIGHT
);
138 EnableSaveRestore(L
"BranchTagDlg");
140 m_tooltips
.AddTool(GetDlgItem(IDC_CHECK_FORCE
), CString(MAKEINTRESOURCE(IDS_PROC_NEWBRANCHTAG_FORCE_TT
)));
141 m_tooltips
.AddTool(GetDlgItem(IDC_CHECK_SIGN
), CString(MAKEINTRESOURCE(IDS_PROC_NEWBRANCHTAG_SIGN_TT
)));
142 m_tooltips
.AddTool(GetDlgItem(IDC_CHECK_TRACK
), CString(MAKEINTRESOURCE(IDS_PROC_NEWBRANCHTAG_TRACK_TT
)));
143 m_tooltips
.Activate(TRUE
);
145 OnCbnSelchangeComboboxexBranch();
146 SetTheme(CTheme::Instance().IsDarkTheme());
149 // CCreateBranchTagDlg message handlers
151 void CCreateBranchTagDlg::OnBnClickedOk()
153 this->UpdateData(TRUE
);
155 if(this->m_bSign
&& this->m_Message
.IsEmpty())
157 CMessageBox::Show(GetSafeHwnd(), IDS_COMMITDLG_NOMESSAGE
, IDS_APPNAME
, MB_OK
| MB_ICONEXCLAMATION
);
161 this->m_BranchTagName
.Trim();
162 if(!g_Git
.IsBranchNameValid(this->m_BranchTagName
))
164 ShowEditBalloon(IDC_BRANCH_TAG
, IDS_B_T_NOTEMPTY
, IDS_ERR_ERROR
, TTI_ERROR
);
167 if (!m_bForce
&& g_Git
.BranchTagExists(m_BranchTagName
, !m_bIsTag
))
169 if (!m_bIsTag
&& g_Git
.GetCurrentBranch(true) == m_BranchTagName
)
171 ShowEditBalloon(IDC_BRANCH_TAG
, CString(MAKEINTRESOURCE(IDS_B_CANNOTFORCECURRENT
)), CString(MAKEINTRESOURCE(IDS_WARN_WARNING
)));
176 msg
.LoadString(IDS_T_EXISTS
);
178 msg
.LoadString(IDS_B_EXISTS
);
179 ShowEditBalloon(IDC_BRANCH_TAG
, msg
+ L
' ' + CString(MAKEINTRESOURCE(IDS_B_T_DIFFERENTNAMEORFORCE
)), CString(MAKEINTRESOURCE(IDS_WARN_WARNING
)));
182 if (g_Git
.BranchTagExists(m_BranchTagName
, m_bIsTag
== TRUE
))
186 msg
.LoadString(IDS_T_SAMEBRANCHNAMEEXISTS
);
188 msg
.LoadString(IDS_B_SAMETAGNAMEEXISTS
);
189 if (CMessageBox::Show(GetSafeHwnd(), msg
, L
"TortoiseGit", 2, IDI_EXCLAMATION
, CString(MAKEINTRESOURCE(IDS_CONTINUEBUTTON
)), CString(MAKEINTRESOURCE(IDS_ABORTBUTTON
))) == 2)
193 m_regNewBranch
= (m_bSwitch
== BST_CHECKED
);
195 this->UpdateRevsionName();
199 void CCreateBranchTagDlg::OnCbnSelchangeComboboxexBranch()
201 if (CStringUtils::StartsWith(m_ChooseVersioinBranch
.GetString(), L
"remotes/") && !m_bIsTag
)
203 bool isDefault
= false;
206 CString str
= this->m_OldSelectBranch
;
207 int start
= str
.ReverseFind(L
'/');
209 str
=str
.Mid(start
+1);
210 if(str
== m_BranchTagName
)
213 this->GetDlgItem(IDC_CHECK_TRACK
)->EnableWindow(TRUE
);
215 if( m_BranchTagName
.IsEmpty() || isDefault
)
217 m_BranchTagName
= m_ChooseVersioinBranch
.GetString();
218 start
= m_BranchTagName
.Find(L
'/', 9);
220 m_BranchTagName
= m_BranchTagName
.Mid(start
+1);
226 this->GetDlgItem(IDC_CHECK_TRACK
)->EnableWindow(FALSE
);
229 this->GetDlgItem(IDC_CHECK_TRACK
)->EnableWindow(FALSE
);
231 m_OldSelectBranch
= m_ChooseVersioinBranch
.GetString();
234 void CCreateBranchTagDlg::OnEnChangeBranchTag()
236 if (!static_cast<CButton
*>(GetDlgItem(IDC_RADIO_BRANCH
))->GetCheck())
240 GetDlgItem(IDC_BRANCH_TAG
)->GetWindowText(name
);
242 CString remoteName
= m_ChooseVersioinBranch
.GetString();
243 if (CStringUtils::StartsWith(remoteName
, L
"remotes/") && remoteName
.Right(name
.GetLength()) != name
)
244 static_cast<CButton
*>(GetDlgItem(IDC_CHECK_TRACK
))->SetCheck(FALSE
);
247 void CCreateBranchTagDlg::OnVersionChanged()
249 int radio
=GetCheckedRadioButton(IDC_RADIO_HEAD
,IDC_RADIO_VERSION
);
250 if (radio
== IDC_RADIO_BRANCH
)
251 OnCbnSelchangeComboboxexBranch();
253 GetDlgItem(IDC_CHECK_TRACK
)->EnableWindow(FALSE
);
256 void CCreateBranchTagDlg::OnDestroy()
258 WaitForFinishLoading();
259 __super::OnDestroy();