Fixed issue #4126: Capitalize the first letter in the Push dialog
[TortoiseGit.git] / src / TortoiseProc / CreateBranchTagDlg.cpp
blobbee5d3aa7986cd340a2bfe1c06037d447c4ab2b3
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
21 #include "stdafx.h"
22 #include "Git.h"
23 #include "TortoiseProc.h"
24 #include "CreateBranchTagDlg.h"
25 #include "AppUtils.h"
26 #include "MessageBox.h"
28 // CCreateBranchTagDlg dialog
30 IMPLEMENT_DYNAMIC(CCreateBranchTagDlg, CResizableStandAloneDialog)
32 CCreateBranchTagDlg::CCreateBranchTagDlg(CWnd* pParent /*=nullptr*/)
33 : CResizableStandAloneDialog(CCreateBranchTagDlg::IDD, pParent)
34 , m_bForce(FALSE)
35 , CChooseVersion(this)
36 , m_bIsTag(0)
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);
52 CHOOSE_VERSION_DDX;
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)
64 CHOOSE_VERSION_EVENT
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)
69 ON_WM_DESTROY()
70 END_MESSAGE_MAP()
72 BOOL CCreateBranchTagDlg::OnInitDialog()
74 CResizableStandAloneDialog::OnInitDialog();
75 CAppUtils::MarkWindowAsUnpinnable(m_hWnd);
77 this->SetDefaultChoose(IDC_RADIO_HEAD);
79 InitChooseVersion();
81 this->GetDlgItem(IDC_CHECK_TRACK)->EnableWindow(FALSE);
83 CString sWindowTitle;
84 if(this->m_bIsTag)
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());
90 else
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)));
96 if (!!m_regNewBranch)
98 m_bSwitch = BST_CHECKED;
99 UpdateData(FALSE);
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);
110 CString HeadText;
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);
136 AddOthersToAnchor();
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());
147 return TRUE;
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);
158 return;
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);
165 return;
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)));
172 return;
174 CString msg;
175 if (m_bIsTag)
176 msg.LoadString(IDS_T_EXISTS);
177 else
178 msg.LoadString(IDS_B_EXISTS);
179 ShowEditBalloon(IDC_BRANCH_TAG, msg + L' ' + CString(MAKEINTRESOURCE(IDS_B_T_DIFFERENTNAMEORFORCE)), CString(MAKEINTRESOURCE(IDS_WARN_WARNING)));
180 return;
182 if (g_Git.BranchTagExists(m_BranchTagName, m_bIsTag == TRUE))
184 CString msg;
185 if (m_bIsTag)
186 msg.LoadString(IDS_T_SAMEBRANCHNAMEEXISTS);
187 else
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)
190 return;
192 if (!m_bIsTag)
193 m_regNewBranch = (m_bSwitch == BST_CHECKED);
195 this->UpdateRevsionName();
196 OnOK();
199 void CCreateBranchTagDlg::OnCbnSelchangeComboboxexBranch()
201 if (CStringUtils::StartsWith(m_ChooseVersioinBranch.GetString(), L"remotes/") && !m_bIsTag)
203 bool isDefault = false;
204 this->UpdateData();
206 CString str = this->m_OldSelectBranch;
207 int start = str.ReverseFind(L'/');
208 if(start>=0)
209 str=str.Mid(start+1);
210 if(str == m_BranchTagName)
211 isDefault =true;
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);
219 if(start>=0)
220 m_BranchTagName = m_BranchTagName.Mid(start+1);
222 UpdateData(FALSE);
225 else
226 this->GetDlgItem(IDC_CHECK_TRACK)->EnableWindow(FALSE);
228 if(this->m_bIsTag)
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())
237 return;
239 CString name;
240 GetDlgItem(IDC_BRANCH_TAG)->GetWindowText(name);
241 name = L'/' + 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();
252 else
253 GetDlgItem(IDC_CHECK_TRACK)->EnableWindow(FALSE);
256 void CCreateBranchTagDlg::OnDestroy()
258 WaitForFinishLoading();
259 __super::OnDestroy();