Fixed issue #2495: "Show Reflog" dialog shows empty action for "push" entries
[TortoiseGit.git] / src / TortoiseProc / CreateBranchTagDlg.cpp
blob39f3d1656ce26632e9d6265fed795d8d010f80c0
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::OnInitDialog()
73 CResizableStandAloneDialog::OnInitDialog();
74 CAppUtils::MarkWindowAsUnpinnable(m_hWnd);
76 CHOOSE_VERSION_ADDANCHOR;
78 AddAnchor(IDC_GROUP_BRANCH, TOP_LEFT, TOP_RIGHT);
80 AddAnchor(IDC_GROUP_OPTION, TOP_LEFT, TOP_RIGHT);
82 AddAnchor(IDOK,BOTTOM_RIGHT);
83 AddAnchor(IDCANCEL,BOTTOM_RIGHT);
84 AddAnchor(IDHELP, BOTTOM_RIGHT);
85 AddAnchor(IDC_GROUP_MESSAGE,TOP_LEFT,BOTTOM_RIGHT);
86 AddAnchor(IDC_EDIT_MESSAGE,TOP_LEFT,BOTTOM_RIGHT);
88 this->AddOthersToAnchor();
90 AdjustControlSize(IDC_RADIO_BRANCH);
91 AdjustControlSize(IDC_RADIO_TAGS);
92 AdjustControlSize(IDC_RADIO_VERSION);
93 AdjustControlSize(IDC_CHECK_TRACK);
94 AdjustControlSize(IDC_CHECK_FORCE);
95 AdjustControlSize(IDC_CHECK_SWITCH);
96 AdjustControlSize(IDC_CHECK_SIGN);
98 this->SetDefaultChoose(IDC_RADIO_HEAD);
100 InitChooseVersion();
102 this->GetDlgItem(IDC_CHECK_TRACK)->EnableWindow(FALSE);
104 CString sWindowTitle;
105 if(this->m_bIsTag)
107 sWindowTitle = CString(MAKEINTRESOURCE(IDS_PROGS_TITLE_CREATETAG));
108 this->GetDlgItem(IDC_LABEL_BRANCH)->SetWindowText(CString(MAKEINTRESOURCE(IDS_PROC_TAG)));
109 this->GetDlgItem(IDC_CHECK_SIGN)->EnableWindow(!g_Git.GetConfigValue(_T("user.signingkey")).IsEmpty());
111 else
113 sWindowTitle = CString(MAKEINTRESOURCE(IDS_PROGS_TITLE_CREATEBRANCH));
114 this->GetDlgItem(IDC_LABEL_BRANCH)->SetWindowText(CString(MAKEINTRESOURCE(IDS_PROC_BRANCH)));
115 this->GetDlgItem(IDC_EDIT_MESSAGE)->EnableWindow(FALSE);
116 this->GetDlgItem(IDC_CHECK_SIGN)->ShowWindow(SW_HIDE);
119 CAppUtils::SetWindowTitle(m_hWnd, g_Git.m_CurrentDir, sWindowTitle);
121 // show the switch checkbox if we are a create branch dialog
122 this->GetDlgItem(IDC_CHECK_SWITCH)->ShowWindow(!m_bIsTag && !GitAdminDir::IsBareRepo(g_Git.m_CurrentDir));
123 CWnd* pHead = GetDlgItem(IDC_RADIO_HEAD);
124 CString HeadText;
125 pHead->GetWindowText( HeadText );
126 pHead->SetWindowText( HeadText + " (" + g_Git.GetCurrentBranch() + ")");
127 AdjustControlSize(IDC_RADIO_HEAD);
128 EnableSaveRestore(_T("BranchTagDlg"));
130 m_tooltips.AddTool(GetDlgItem(IDC_CHECK_FORCE), CString(MAKEINTRESOURCE(IDS_PROC_NEWBRANCHTAG_FORCE_TT)));
131 m_tooltips.AddTool(GetDlgItem(IDC_CHECK_SIGN), CString(MAKEINTRESOURCE(IDS_PROC_NEWBRANCHTAG_SIGN_TT)));
132 m_tooltips.AddTool(GetDlgItem(IDC_CHECK_TRACK), CString(MAKEINTRESOURCE(IDS_PROC_NEWBRANCHTAG_TRACK_TT)));
133 m_tooltips.Activate(TRUE);
135 OnCbnSelchangeComboboxexBranch();
136 return TRUE;
138 // CCreateBranchTagDlg message handlers
140 void CCreateBranchTagDlg::OnBnClickedOk()
142 this->UpdateData(TRUE);
144 if(this->m_bSign && this->m_Message.IsEmpty())
146 CMessageBox::Show(NULL, IDS_COMMITDLG_NOMESSAGE, IDS_APPNAME, MB_OK);
147 return;
150 this->m_BranchTagName.Trim();
151 if(!g_Git.IsBranchNameValid(this->m_BranchTagName))
153 ShowEditBalloon(IDC_BRANCH_TAG, IDS_B_T_NOTEMPTY, IDS_ERR_ERROR, TTI_ERROR);
154 return;
156 if (!m_bForce && g_Git.BranchTagExists(m_BranchTagName, !m_bIsTag))
158 if (!m_bIsTag && g_Git.GetCurrentBranch(true) == m_BranchTagName)
160 ShowEditBalloon(IDC_BRANCH_TAG, CString(MAKEINTRESOURCE(IDS_B_CANNOTFORCECURRENT)), CString(MAKEINTRESOURCE(IDS_WARN_WARNING)));
161 return;
163 CString msg;
164 if (m_bIsTag)
165 msg.LoadString(IDS_T_EXISTS);
166 else
167 msg.LoadString(IDS_B_EXISTS);
168 ShowEditBalloon(IDC_BRANCH_TAG, msg + _T(" ") + CString(MAKEINTRESOURCE(IDS_B_T_DIFFERENTNAMEORFORCE)), CString(MAKEINTRESOURCE(IDS_WARN_WARNING)));
169 return;
171 if (g_Git.BranchTagExists(m_BranchTagName, m_bIsTag == TRUE))
173 CString msg;
174 if (m_bIsTag)
175 msg.LoadString(IDS_T_SAMEBRANCHNAMEEXISTS);
176 else
177 msg.LoadString(IDS_B_SAMETAGNAMEEXISTS);
178 if (CMessageBox::Show(m_hWnd, msg, _T("TortoiseGit"), 2, IDI_EXCLAMATION, CString(MAKEINTRESOURCE(IDS_CONTINUEBUTTON)), CString(MAKEINTRESOURCE(IDS_ABORTBUTTON))) == 2)
179 return;
182 this->UpdateRevsionName();
183 OnOK();
186 void CCreateBranchTagDlg::OnCbnSelchangeComboboxexBranch()
188 if (this->m_ChooseVersioinBranch.GetString().Left(8)==_T("remotes/") && !m_bIsTag)
190 bool isDefault = false;
191 this->UpdateData();
193 CString str = this->m_OldSelectBranch;
194 int start = str.ReverseFind(_T('/'));
195 if(start>=0)
196 str=str.Mid(start+1);
197 if(str == m_BranchTagName)
198 isDefault =true;
200 this->GetDlgItem(IDC_CHECK_TRACK)->EnableWindow(TRUE);
202 if( m_BranchTagName.IsEmpty() || isDefault)
204 m_BranchTagName= m_ChooseVersioinBranch.GetString();
205 int start = m_BranchTagName.Find(_T('/'), 9);;
206 if(start>=0)
207 m_BranchTagName = m_BranchTagName.Mid(start+1);
209 UpdateData(FALSE);
212 else
213 this->GetDlgItem(IDC_CHECK_TRACK)->EnableWindow(FALSE);
215 if(this->m_bIsTag)
216 this->GetDlgItem(IDC_CHECK_TRACK)->EnableWindow(FALSE);
218 m_OldSelectBranch = m_ChooseVersioinBranch.GetString();
221 void CCreateBranchTagDlg::OnEnChangeBranchTag()
223 if (!((CButton *)GetDlgItem(IDC_RADIO_BRANCH))->GetCheck())
224 return;
226 CString name;
227 GetDlgItem(IDC_BRANCH_TAG)->GetWindowText(name);
228 name = _T("/") + name;
229 CString remoteName = m_ChooseVersioinBranch.GetString();
230 if (remoteName.Left(8) == _T("remotes/") && remoteName.Right(name.GetLength()) != name)
231 ((CButton *)GetDlgItem(IDC_CHECK_TRACK))->SetCheck(FALSE);
234 void CCreateBranchTagDlg::OnVersionChanged()
236 int radio=GetCheckedRadioButton(IDC_RADIO_HEAD,IDC_RADIO_VERSION);
237 if (radio == IDC_RADIO_BRANCH)
238 OnCbnSelchangeComboboxexBranch();
239 else
240 GetDlgItem(IDC_CHECK_TRACK)->EnableWindow(FALSE);
243 void CCreateBranchTagDlg::OnDestroy()
245 WaitForFinishLoading();
246 __super::OnDestroy();