Do not use GitAdminDir objects
[TortoiseGit.git] / src / TortoiseProc / CreateBranchTagDlg.cpp
blob823da0ba5a6c6f68047fe362e195909a555ff58b
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2015 - 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_EN_CHANGE(IDC_BRANCH_TAG, &CCreateBranchTagDlg::OnEnChangeBranchTag)
67 // ON_BN_CLICKED(IDC_BUTTON_BROWSE_REF, &CCreateBranchTagDlg::OnBnClickedButtonBrowseRef)
68 ON_WM_DESTROY()
69 END_MESSAGE_MAP()
71 BOOL CCreateBranchTagDlg::PreTranslateMessage(MSG* pMsg)
73 m_ToolTip.RelayEvent(pMsg);
75 return CDialog::PreTranslateMessage(pMsg);
78 BOOL CCreateBranchTagDlg::OnInitDialog()
80 CResizableStandAloneDialog::OnInitDialog();
81 CAppUtils::MarkWindowAsUnpinnable(m_hWnd);
83 CHOOSE_VERSION_ADDANCHOR;
85 AddAnchor(IDC_GROUP_BRANCH, TOP_LEFT, TOP_RIGHT);
87 AddAnchor(IDC_GROUP_OPTION, TOP_LEFT, TOP_RIGHT);
89 AddAnchor(IDOK,BOTTOM_RIGHT);
90 AddAnchor(IDCANCEL,BOTTOM_RIGHT);
91 AddAnchor(IDHELP, BOTTOM_RIGHT);
92 AddAnchor(IDC_GROUP_MESSAGE,TOP_LEFT,BOTTOM_RIGHT);
93 AddAnchor(IDC_EDIT_MESSAGE,TOP_LEFT,BOTTOM_RIGHT);
95 this->AddOthersToAnchor();
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 InitChooseVersion();
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 && !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 AdjustControlSize(IDC_RADIO_HEAD);
135 EnableSaveRestore(_T("BranchTagDlg"));
137 //Create the ToolTip control
138 if( !m_ToolTip.Create(this))
140 TRACE0("Unable to create the ToolTip!");
142 else
144 m_ToolTip.AddTool(GetDlgItem(IDC_CHECK_FORCE), CString(MAKEINTRESOURCE(IDS_PROC_NEWBRANCHTAG_FORCE_TT)));
145 m_ToolTip.AddTool(GetDlgItem(IDC_CHECK_SIGN), CString(MAKEINTRESOURCE(IDS_PROC_NEWBRANCHTAG_SIGN_TT)));
146 m_ToolTip.AddTool(GetDlgItem(IDC_CHECK_TRACK), CString(MAKEINTRESOURCE(IDS_PROC_NEWBRANCHTAG_TRACK_TT)));
147 m_ToolTip.Activate(TRUE);
150 OnCbnSelchangeComboboxexBranch();
151 return TRUE;
153 // CCreateBranchTagDlg message handlers
155 void CCreateBranchTagDlg::OnBnClickedOk()
157 this->UpdateData(TRUE);
159 if(this->m_bSign && this->m_Message.IsEmpty())
161 CMessageBox::Show(NULL, IDS_COMMITDLG_NOMESSAGE, IDS_APPNAME, MB_OK);
162 return;
165 this->m_BranchTagName.Trim();
166 if(!g_Git.IsBranchNameValid(this->m_BranchTagName))
168 ShowEditBalloon(IDC_BRANCH_TAG, IDS_B_T_NOTEMPTY, IDS_ERR_ERROR, TTI_ERROR);
169 return;
171 if (!m_bForce && g_Git.BranchTagExists(m_BranchTagName, !m_bIsTag))
173 if (!m_bIsTag && g_Git.GetCurrentBranch(true) == m_BranchTagName)
175 ShowEditBalloon(IDC_BRANCH_TAG, CString(MAKEINTRESOURCE(IDS_B_CANNOTFORCECURRENT)), CString(MAKEINTRESOURCE(IDS_WARN_WARNING)));
176 return;
178 CString msg;
179 if (m_bIsTag)
180 msg.LoadString(IDS_T_EXISTS);
181 else
182 msg.LoadString(IDS_B_EXISTS);
183 ShowEditBalloon(IDC_BRANCH_TAG, msg + _T(" ") + CString(MAKEINTRESOURCE(IDS_B_T_DIFFERENTNAMEORFORCE)), CString(MAKEINTRESOURCE(IDS_WARN_WARNING)));
184 return;
186 if (g_Git.BranchTagExists(m_BranchTagName, m_bIsTag == TRUE))
188 CString msg;
189 if (m_bIsTag)
190 msg.LoadString(IDS_T_SAMEBRANCHNAMEEXISTS);
191 else
192 msg.LoadString(IDS_B_SAMETAGNAMEEXISTS);
193 if (CMessageBox::Show(m_hWnd, msg, _T("TortoiseGit"), 2, IDI_EXCLAMATION, CString(MAKEINTRESOURCE(IDS_CONTINUEBUTTON)), CString(MAKEINTRESOURCE(IDS_ABORTBUTTON))) == 2)
194 return;
197 this->UpdateRevsionName();
198 OnOK();
201 void CCreateBranchTagDlg::OnCbnSelchangeComboboxexBranch()
203 if (this->m_ChooseVersioinBranch.GetString().Left(8)==_T("remotes/") && !m_bIsTag)
205 bool isDefault = false;
206 this->UpdateData();
208 CString str = this->m_OldSelectBranch;
209 int start = str.ReverseFind(_T('/'));
210 if(start>=0)
211 str=str.Mid(start+1);
212 if(str == m_BranchTagName)
213 isDefault =true;
215 this->GetDlgItem(IDC_CHECK_TRACK)->EnableWindow(TRUE);
217 if( m_BranchTagName.IsEmpty() || isDefault)
219 m_BranchTagName= m_ChooseVersioinBranch.GetString();
220 int start = m_BranchTagName.Find(_T('/'), 9);;
221 if(start>=0)
222 m_BranchTagName = m_BranchTagName.Mid(start+1);
224 UpdateData(FALSE);
227 else
228 this->GetDlgItem(IDC_CHECK_TRACK)->EnableWindow(FALSE);
230 if(this->m_bIsTag)
231 this->GetDlgItem(IDC_CHECK_TRACK)->EnableWindow(FALSE);
233 m_OldSelectBranch = m_ChooseVersioinBranch.GetString();
236 void CCreateBranchTagDlg::OnEnChangeBranchTag()
238 if (!((CButton *)GetDlgItem(IDC_RADIO_BRANCH))->GetCheck())
239 return;
241 CString name;
242 GetDlgItem(IDC_BRANCH_TAG)->GetWindowText(name);
243 name = _T("/") + name;
244 CString remoteName = m_ChooseVersioinBranch.GetString();
245 if (remoteName.Left(8) == _T("remotes/") && remoteName.Right(name.GetLength()) != name)
246 ((CButton *)GetDlgItem(IDC_CHECK_TRACK))->SetCheck(FALSE);
249 void CCreateBranchTagDlg::OnVersionChanged()
251 int radio=GetCheckedRadioButton(IDC_RADIO_HEAD,IDC_RADIO_VERSION);
252 if (radio == IDC_RADIO_BRANCH)
253 OnCbnSelchangeComboboxexBranch();
254 else
255 GetDlgItem(IDC_CHECK_TRACK)->EnableWindow(FALSE);
258 void CCreateBranchTagDlg::OnDestroy()
260 WaitForFinishLoading();
261 __super::OnDestroy();