1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2017 - 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_bSwitch(BST_UNCHECKED
) // default switch to checkbox not selected
38 , m_bTrack(BST_INDETERMINATE
)
39 , m_bSign(BST_UNCHECKED
)
43 CCreateBranchTagDlg::~CCreateBranchTagDlg()
47 void CCreateBranchTagDlg::DoDataExchange(CDataExchange
* pDX
)
49 CDialog::DoDataExchange(pDX
);
53 DDX_Text(pDX
, IDC_BRANCH_TAG
, this->m_BranchTagName
);
54 DDX_Check(pDX
,IDC_CHECK_FORCE
,this->m_bForce
);
55 DDX_Check(pDX
,IDC_CHECK_TRACK
,this->m_bTrack
);
56 DDX_Check(pDX
,IDC_CHECK_SWITCH
,this->m_bSwitch
);
57 DDX_Check(pDX
,IDC_CHECK_SIGN
,this->m_bSign
);
58 DDX_Text(pDX
, IDC_EDIT_MESSAGE
,this->m_Message
);
62 BEGIN_MESSAGE_MAP(CCreateBranchTagDlg
, CResizableStandAloneDialog
)
64 ON_BN_CLICKED(IDOK
, &CCreateBranchTagDlg::OnBnClickedOk
)
65 ON_CBN_SELCHANGE(IDC_COMBOBOXEX_BRANCH
, &CCreateBranchTagDlg::OnCbnSelchangeComboboxexBranch
)
66 ON_EN_CHANGE(IDC_BRANCH_TAG
, &CCreateBranchTagDlg::OnEnChangeBranchTag
)
67 // ON_BN_CLICKED(IDC_BUTTON_BROWSE_REF, &CCreateBranchTagDlg::OnBnClickedButtonBrowseRef)
71 BOOL
CCreateBranchTagDlg::OnInitDialog()
73 CResizableStandAloneDialog::OnInitDialog();
74 CAppUtils::MarkWindowAsUnpinnable(m_hWnd
);
76 this->SetDefaultChoose(IDC_RADIO_HEAD
);
80 this->GetDlgItem(IDC_CHECK_TRACK
)->EnableWindow(FALSE
);
85 sWindowTitle
= CString(MAKEINTRESOURCE(IDS_PROGS_TITLE_CREATETAG
));
86 this->GetDlgItem(IDC_LABEL_BRANCH
)->SetWindowText(CString(MAKEINTRESOURCE(IDS_PROC_TAG
)));
87 this->GetDlgItem(IDC_CHECK_SIGN
)->EnableWindow(!g_Git
.GetConfigValue(L
"user.signingkey").IsEmpty());
91 sWindowTitle
= CString(MAKEINTRESOURCE(IDS_PROGS_TITLE_CREATEBRANCH
));
92 this->GetDlgItem(IDC_LABEL_BRANCH
)->SetWindowText(CString(MAKEINTRESOURCE(IDS_PROC_BRANCH
)));
93 this->GetDlgItem(IDC_CHECK_SIGN
)->ShowWindow(SW_HIDE
);
94 GetDlgItem(IDC_GROUP_MESSAGE
)->SetWindowText(CString(MAKEINTRESOURCE(IDS_DESCRIPTION
)));
97 CAppUtils::SetWindowTitle(m_hWnd
, g_Git
.m_CurrentDir
, sWindowTitle
);
99 // show the switch checkbox if we are a create branch dialog
100 this->GetDlgItem(IDC_CHECK_SWITCH
)->ShowWindow(!m_bIsTag
&& !GitAdminDir::IsBareRepo(g_Git
.m_CurrentDir
));
101 CWnd
* pHead
= GetDlgItem(IDC_RADIO_HEAD
);
103 pHead
->GetWindowText( HeadText
);
104 pHead
->SetWindowText( HeadText
+ " (" + g_Git
.GetCurrentBranch() + ")");
106 AdjustControlSize(IDC_RADIO_BRANCH
);
107 AdjustControlSize(IDC_RADIO_TAGS
);
108 AdjustControlSize(IDC_RADIO_VERSION
);
109 AdjustControlSize(IDC_CHECK_TRACK
);
110 AdjustControlSize(IDC_CHECK_FORCE
);
111 AdjustControlSize(IDC_CHECK_SWITCH
);
112 AdjustControlSize(IDC_CHECK_SIGN
);
113 AdjustControlSize(IDC_RADIO_HEAD
);
115 CHOOSE_VERSION_ADDANCHOR
;
117 AddAnchor(IDC_BRANCH_TAG
, TOP_LEFT
, TOP_RIGHT
);
118 AddAnchor(IDC_GROUP_BRANCH
, TOP_LEFT
, TOP_RIGHT
);
120 AddAnchor(IDC_GROUP_OPTION
, TOP_LEFT
, TOP_RIGHT
);
122 AddAnchor(IDOK
, BOTTOM_RIGHT
);
123 AddAnchor(IDCANCEL
, BOTTOM_RIGHT
);
124 AddAnchor(IDHELP
, BOTTOM_RIGHT
);
125 AddAnchor(IDC_GROUP_MESSAGE
, TOP_LEFT
, BOTTOM_RIGHT
);
126 AddAnchor(IDC_EDIT_MESSAGE
, TOP_LEFT
, BOTTOM_RIGHT
);
130 EnableSaveRestore(L
"BranchTagDlg");
132 m_tooltips
.AddTool(GetDlgItem(IDC_CHECK_FORCE
), CString(MAKEINTRESOURCE(IDS_PROC_NEWBRANCHTAG_FORCE_TT
)));
133 m_tooltips
.AddTool(GetDlgItem(IDC_CHECK_SIGN
), CString(MAKEINTRESOURCE(IDS_PROC_NEWBRANCHTAG_SIGN_TT
)));
134 m_tooltips
.AddTool(GetDlgItem(IDC_CHECK_TRACK
), CString(MAKEINTRESOURCE(IDS_PROC_NEWBRANCHTAG_TRACK_TT
)));
135 m_tooltips
.Activate(TRUE
);
137 OnCbnSelchangeComboboxexBranch();
140 // CCreateBranchTagDlg message handlers
142 void CCreateBranchTagDlg::OnBnClickedOk()
144 this->UpdateData(TRUE
);
146 if(this->m_bSign
&& this->m_Message
.IsEmpty())
148 CMessageBox::Show(GetSafeHwnd(), IDS_COMMITDLG_NOMESSAGE
, IDS_APPNAME
, MB_OK
| MB_ICONEXCLAMATION
);
152 this->m_BranchTagName
.Trim();
153 if(!g_Git
.IsBranchNameValid(this->m_BranchTagName
))
155 ShowEditBalloon(IDC_BRANCH_TAG
, IDS_B_T_NOTEMPTY
, IDS_ERR_ERROR
, TTI_ERROR
);
158 if (!m_bForce
&& g_Git
.BranchTagExists(m_BranchTagName
, !m_bIsTag
))
160 if (!m_bIsTag
&& g_Git
.GetCurrentBranch(true) == m_BranchTagName
)
162 ShowEditBalloon(IDC_BRANCH_TAG
, CString(MAKEINTRESOURCE(IDS_B_CANNOTFORCECURRENT
)), CString(MAKEINTRESOURCE(IDS_WARN_WARNING
)));
167 msg
.LoadString(IDS_T_EXISTS
);
169 msg
.LoadString(IDS_B_EXISTS
);
170 ShowEditBalloon(IDC_BRANCH_TAG
, msg
+ L
' ' + CString(MAKEINTRESOURCE(IDS_B_T_DIFFERENTNAMEORFORCE
)), CString(MAKEINTRESOURCE(IDS_WARN_WARNING
)));
173 if (g_Git
.BranchTagExists(m_BranchTagName
, m_bIsTag
== TRUE
))
177 msg
.LoadString(IDS_T_SAMEBRANCHNAMEEXISTS
);
179 msg
.LoadString(IDS_B_SAMETAGNAMEEXISTS
);
180 if (CMessageBox::Show(GetSafeHwnd(), msg
, L
"TortoiseGit", 2, IDI_EXCLAMATION
, CString(MAKEINTRESOURCE(IDS_CONTINUEBUTTON
)), CString(MAKEINTRESOURCE(IDS_ABORTBUTTON
))) == 2)
184 this->UpdateRevsionName();
188 void CCreateBranchTagDlg::OnCbnSelchangeComboboxexBranch()
190 if (CStringUtils::StartsWith(m_ChooseVersioinBranch
.GetString(), L
"remotes/") && !m_bIsTag
)
192 bool isDefault
= false;
195 CString str
= this->m_OldSelectBranch
;
196 int start
= str
.ReverseFind(L
'/');
198 str
=str
.Mid(start
+1);
199 if(str
== m_BranchTagName
)
202 this->GetDlgItem(IDC_CHECK_TRACK
)->EnableWindow(TRUE
);
204 if( m_BranchTagName
.IsEmpty() || isDefault
)
206 m_BranchTagName
= m_ChooseVersioinBranch
.GetString();
207 start
= m_BranchTagName
.Find(L
'/', 9);
209 m_BranchTagName
= m_BranchTagName
.Mid(start
+1);
215 this->GetDlgItem(IDC_CHECK_TRACK
)->EnableWindow(FALSE
);
218 this->GetDlgItem(IDC_CHECK_TRACK
)->EnableWindow(FALSE
);
220 m_OldSelectBranch
= m_ChooseVersioinBranch
.GetString();
223 void CCreateBranchTagDlg::OnEnChangeBranchTag()
225 if (!((CButton
*)GetDlgItem(IDC_RADIO_BRANCH
))->GetCheck())
229 GetDlgItem(IDC_BRANCH_TAG
)->GetWindowText(name
);
231 CString remoteName
= m_ChooseVersioinBranch
.GetString();
232 if (CStringUtils::StartsWith(remoteName
, L
"remotes/") && remoteName
.Right(name
.GetLength()) != name
)
233 ((CButton
*)GetDlgItem(IDC_CHECK_TRACK
))->SetCheck(FALSE
);
236 void CCreateBranchTagDlg::OnVersionChanged()
238 int radio
=GetCheckedRadioButton(IDC_RADIO_HEAD
,IDC_RADIO_VERSION
);
239 if (radio
== IDC_RADIO_BRANCH
)
240 OnCbnSelchangeComboboxexBranch();
242 GetDlgItem(IDC_CHECK_TRACK
)->EnableWindow(FALSE
);
245 void CCreateBranchTagDlg::OnDestroy()
247 WaitForFinishLoading();
248 __super::OnDestroy();