Fixed issue #1076: Error trying to delete remote branch named 1.0.0
[TortoiseGit.git] / src / TortoiseProc / CreateBranchTagDlg.cpp
bloba89cc2d7f0a34cf878c7c821c0eed199a1cfd29c
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2012 - 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 /*=NULL*/)
33 : CResizableStandAloneDialog(CCreateBranchTagDlg::IDD, pParent)
34 , m_bForce(FALSE)
35 , CChooseVersion(this)
37 m_bIsTag=0;
38 m_bSwitch = 0; // default switch to checkbox not selected
39 m_bTrack=2;
40 m_bSign=0;
43 CCreateBranchTagDlg::~CCreateBranchTagDlg()
47 void CCreateBranchTagDlg::DoDataExchange(CDataExchange* pDX)
49 CDialog::DoDataExchange(pDX);
51 CHOOSE_VERSION_DDX;
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)
63 CHOOSE_VERSION_EVENT
64 ON_BN_CLICKED(IDOK, &CCreateBranchTagDlg::OnBnClickedOk)
65 ON_CBN_SELCHANGE(IDC_COMBOBOXEX_BRANCH, &CCreateBranchTagDlg::OnCbnSelchangeComboboxexBranch)
66 // ON_BN_CLICKED(IDC_BUTTON_BROWSE_REF, &CCreateBranchTagDlg::OnBnClickedButtonBrowseRef)
67 ON_WM_DESTROY()
68 END_MESSAGE_MAP()
70 BOOL CCreateBranchTagDlg::PreTranslateMessage(MSG* pMsg)
72 m_ToolTip.RelayEvent(pMsg);
74 return CDialog::PreTranslateMessage(pMsg);
77 BOOL CCreateBranchTagDlg::OnInitDialog()
79 CResizableStandAloneDialog::OnInitDialog();
80 CAppUtils::MarkWindowAsUnpinnable(m_hWnd);
82 CHOOSE_VERSION_ADDANCHOR;
84 AddAnchor(IDC_GROUP_BRANCH, TOP_LEFT, TOP_RIGHT);
86 AddAnchor(IDC_GROUP_OPTION, TOP_LEFT, TOP_RIGHT);
88 AddAnchor(IDOK,BOTTOM_RIGHT);
89 AddAnchor(IDCANCEL,BOTTOM_RIGHT);
90 AddAnchor(IDHELP, BOTTOM_RIGHT);
91 AddAnchor(IDC_GROUP_MESSAGE,TOP_LEFT,BOTTOM_RIGHT);
92 AddAnchor(IDC_EDIT_MESSAGE,TOP_LEFT,BOTTOM_RIGHT);
94 this->AddOthersToAnchor();
96 AdjustControlSize(IDC_RADIO_HEAD);
97 AdjustControlSize(IDC_RADIO_BRANCH);
98 AdjustControlSize(IDC_RADIO_TAGS);
99 AdjustControlSize(IDC_RADIO_VERSION);
100 AdjustControlSize(IDC_CHECK_TRACK);
101 AdjustControlSize(IDC_CHECK_FORCE);
102 AdjustControlSize(IDC_CHECK_SWITCH);
103 AdjustControlSize(IDC_CHECK_SIGN);
105 this->SetDefaultChoose(IDC_RADIO_HEAD);
107 Init();
109 this->GetDlgItem(IDC_CHECK_TRACK)->EnableWindow(FALSE);
111 CString sWindowTitle;
112 if(this->m_bIsTag)
114 sWindowTitle = CString(MAKEINTRESOURCE(IDS_PROGS_TITLE_CREATETAG));
115 this->GetDlgItem(IDC_LABEL_BRANCH)->SetWindowText(CString(MAKEINTRESOURCE(IDS_PROC_TAG)));
116 this->GetDlgItem(IDC_CHECK_SIGN)->EnableWindow(!g_Git.GetConfigValue(_T("user.signingkey")).IsEmpty());
118 else
120 sWindowTitle = CString(MAKEINTRESOURCE(IDS_PROGS_TITLE_CREATEBRANCH));
121 this->GetDlgItem(IDC_LABEL_BRANCH)->SetWindowText(CString(MAKEINTRESOURCE(IDS_PROC_BRANCH)));
122 this->GetDlgItem(IDC_EDIT_MESSAGE)->EnableWindow(FALSE);
123 this->GetDlgItem(IDC_CHECK_SIGN)->ShowWindow(SW_HIDE);
126 CAppUtils::SetWindowTitle(m_hWnd, g_Git.m_CurrentDir, sWindowTitle);
128 // show the switch checkbox if we are a create branch dialog
129 this->GetDlgItem(IDC_CHECK_SWITCH)->ShowWindow( !m_bIsTag && !g_GitAdminDir.IsBareRepo(g_Git.m_CurrentDir));
130 CWnd* pHead = GetDlgItem(IDC_RADIO_HEAD);
131 CString HeadText;
132 pHead->GetWindowText( HeadText );
133 pHead->SetWindowText( HeadText + " (" + g_Git.GetCurrentBranch() + ")");
134 EnableSaveRestore(_T("BranchTagDlg"));
136 //Create the ToolTip control
137 if( !m_ToolTip.Create(this))
139 TRACE0("Unable to create the ToolTip!");
141 else
143 m_ToolTip.AddTool(GetDlgItem(IDC_CHECK_FORCE), CString(MAKEINTRESOURCE(IDS_PROC_NEWBRANCHTAG_FORCE_TT)));
144 m_ToolTip.AddTool(GetDlgItem(IDC_CHECK_SIGN), CString(MAKEINTRESOURCE(IDS_PROC_NEWBRANCHTAG_SIGN_TT)));
145 m_ToolTip.AddTool(GetDlgItem(IDC_CHECK_TRACK), CString(MAKEINTRESOURCE(IDS_PROC_NEWBRANCHTAG_TRACK_TT)));
146 m_ToolTip.Activate(TRUE);
149 OnCbnSelchangeComboboxexBranch();
150 return TRUE;
152 // CCreateBranchTagDlg message handlers
154 void CCreateBranchTagDlg::OnBnClickedOk()
156 this->UpdateData(TRUE);
158 if(this->m_bSign && this->m_Message.IsEmpty())
160 CMessageBox::Show(NULL, IDS_COMMITDLG_NOMESSAGE, IDS_APPNAME, MB_OK);
161 return;
164 this->m_BranchTagName.Trim();
165 if(!g_Git.IsBranchNameValid(this->m_BranchTagName))
167 ShowEditBalloon(IDC_BRANCH_TAG, IDS_B_T_NOTEMPTY, TTI_ERROR);
168 return;
170 if (!m_bForce && g_Git.BranchTagExists(m_BranchTagName, !m_bIsTag))
172 CString msg;
173 if (m_bIsTag)
174 msg.LoadString(IDS_T_EXISTS);
175 else
176 msg.LoadString(IDS_B_EXISTS);
177 ShowEditBalloon(IDC_BRANCH_TAG, msg + _T(" ") + CString(MAKEINTRESOURCE(IDS_B_T_DIFFERENTNAMEORFORCE)), CString(MAKEINTRESOURCE(IDS_WARN_WARNING)));
178 return;
180 if (g_Git.BranchTagExists(m_BranchTagName, m_bIsTag == TRUE))
182 CString msg;
183 if (m_bIsTag)
184 msg.LoadString(IDS_T_SAMEBRANCHNAMEEXISTS);
185 else
186 msg.LoadString(IDS_B_SAMETAGNAMEEXISTS);
187 if (CMessageBox::Show(m_hWnd, msg, _T("TortoiseGit"), 2, IDI_EXCLAMATION, CString(MAKEINTRESOURCE(IDS_CONTINUEBUTTON)), CString(MAKEINTRESOURCE(IDS_ABORTBUTTON))) == 2)
188 return;
191 this->UpdateRevsionName();
192 OnOK();
195 void CCreateBranchTagDlg::OnCbnSelchangeComboboxexBranch()
197 if(this->m_ChooseVersioinBranch.GetString().Left(8)==_T("remotes/"))
199 bool isDefault = false;
200 this->UpdateData();
202 CString str = this->m_OldSelectBranch;
203 int start = str.ReverseFind(_T('/'));
204 if(start>=0)
205 str=str.Mid(start+1);
206 if(str == m_BranchTagName)
207 isDefault =true;
209 this->GetDlgItem(IDC_CHECK_TRACK)->EnableWindow(TRUE);
211 if( m_BranchTagName.IsEmpty() || isDefault)
213 m_BranchTagName= m_ChooseVersioinBranch.GetString();
214 int start = m_BranchTagName.Find(_T('/'), 9);;
215 if(start>=0)
216 m_BranchTagName = m_BranchTagName.Mid(start+1);
218 UpdateData(FALSE);
221 else
222 this->GetDlgItem(IDC_CHECK_TRACK)->EnableWindow(FALSE);
224 if(this->m_bIsTag)
225 this->GetDlgItem(IDC_CHECK_TRACK)->EnableWindow(FALSE);
227 m_OldSelectBranch = m_ChooseVersioinBranch.GetString();
230 void CCreateBranchTagDlg::OnVersionChanged()
232 int radio=GetCheckedRadioButton(IDC_RADIO_HEAD,IDC_RADIO_VERSION);
233 if (radio == IDC_RADIO_BRANCH)
234 OnCbnSelchangeComboboxexBranch();
235 else
236 GetDlgItem(IDC_CHECK_TRACK)->EnableWindow(FALSE);
239 void CCreateBranchTagDlg::OnDestroy()
241 WaitForFinishLoading();
242 __super::OnDestroy();