SyncDlg: Disallow in/out changes to include local context menu
[TortoiseGit.git] / src / TortoiseProc / CreateBranchTagDlg.cpp
blob049607562843db125246627efa1160c4cbeed6b0
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2016 - 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_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);
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_BRANCH_TAG, TOP_LEFT, TOP_RIGHT);
79 AddAnchor(IDC_GROUP_BRANCH, TOP_LEFT, TOP_RIGHT);
81 AddAnchor(IDC_GROUP_OPTION, TOP_LEFT, TOP_RIGHT);
83 AddAnchor(IDOK,BOTTOM_RIGHT);
84 AddAnchor(IDCANCEL,BOTTOM_RIGHT);
85 AddAnchor(IDHELP, BOTTOM_RIGHT);
86 AddAnchor(IDC_GROUP_MESSAGE,TOP_LEFT,BOTTOM_RIGHT);
87 AddAnchor(IDC_EDIT_MESSAGE,TOP_LEFT,BOTTOM_RIGHT);
89 this->AddOthersToAnchor();
91 AdjustControlSize(IDC_RADIO_BRANCH);
92 AdjustControlSize(IDC_RADIO_TAGS);
93 AdjustControlSize(IDC_RADIO_VERSION);
94 AdjustControlSize(IDC_CHECK_TRACK);
95 AdjustControlSize(IDC_CHECK_FORCE);
96 AdjustControlSize(IDC_CHECK_SWITCH);
97 AdjustControlSize(IDC_CHECK_SIGN);
99 this->SetDefaultChoose(IDC_RADIO_HEAD);
101 InitChooseVersion();
103 this->GetDlgItem(IDC_CHECK_TRACK)->EnableWindow(FALSE);
105 CString sWindowTitle;
106 if(this->m_bIsTag)
108 sWindowTitle = CString(MAKEINTRESOURCE(IDS_PROGS_TITLE_CREATETAG));
109 this->GetDlgItem(IDC_LABEL_BRANCH)->SetWindowText(CString(MAKEINTRESOURCE(IDS_PROC_TAG)));
110 this->GetDlgItem(IDC_CHECK_SIGN)->EnableWindow(!g_Git.GetConfigValue(L"user.signingkey").IsEmpty());
112 else
114 sWindowTitle = CString(MAKEINTRESOURCE(IDS_PROGS_TITLE_CREATEBRANCH));
115 this->GetDlgItem(IDC_LABEL_BRANCH)->SetWindowText(CString(MAKEINTRESOURCE(IDS_PROC_BRANCH)));
116 this->GetDlgItem(IDC_CHECK_SIGN)->ShowWindow(SW_HIDE);
117 GetDlgItem(IDC_GROUP_MESSAGE)->SetWindowText(CString(MAKEINTRESOURCE(IDS_DESCRIPTION)));
120 CAppUtils::SetWindowTitle(m_hWnd, g_Git.m_CurrentDir, sWindowTitle);
122 // show the switch checkbox if we are a create branch dialog
123 this->GetDlgItem(IDC_CHECK_SWITCH)->ShowWindow(!m_bIsTag && !GitAdminDir::IsBareRepo(g_Git.m_CurrentDir));
124 CWnd* pHead = GetDlgItem(IDC_RADIO_HEAD);
125 CString HeadText;
126 pHead->GetWindowText( HeadText );
127 pHead->SetWindowText( HeadText + " (" + g_Git.GetCurrentBranch() + ")");
128 AdjustControlSize(IDC_RADIO_HEAD);
129 EnableSaveRestore(L"BranchTagDlg");
131 m_tooltips.AddTool(GetDlgItem(IDC_CHECK_FORCE), CString(MAKEINTRESOURCE(IDS_PROC_NEWBRANCHTAG_FORCE_TT)));
132 m_tooltips.AddTool(GetDlgItem(IDC_CHECK_SIGN), CString(MAKEINTRESOURCE(IDS_PROC_NEWBRANCHTAG_SIGN_TT)));
133 m_tooltips.AddTool(GetDlgItem(IDC_CHECK_TRACK), CString(MAKEINTRESOURCE(IDS_PROC_NEWBRANCHTAG_TRACK_TT)));
134 m_tooltips.Activate(TRUE);
136 OnCbnSelchangeComboboxexBranch();
137 return TRUE;
139 // CCreateBranchTagDlg message handlers
141 void CCreateBranchTagDlg::OnBnClickedOk()
143 this->UpdateData(TRUE);
145 if(this->m_bSign && this->m_Message.IsEmpty())
147 CMessageBox::Show(GetSafeHwnd(), IDS_COMMITDLG_NOMESSAGE, IDS_APPNAME, MB_OK | MB_ICONEXCLAMATION);
148 return;
151 this->m_BranchTagName.Trim();
152 if(!g_Git.IsBranchNameValid(this->m_BranchTagName))
154 ShowEditBalloon(IDC_BRANCH_TAG, IDS_B_T_NOTEMPTY, IDS_ERR_ERROR, TTI_ERROR);
155 return;
157 if (!m_bForce && g_Git.BranchTagExists(m_BranchTagName, !m_bIsTag))
159 if (!m_bIsTag && g_Git.GetCurrentBranch(true) == m_BranchTagName)
161 ShowEditBalloon(IDC_BRANCH_TAG, CString(MAKEINTRESOURCE(IDS_B_CANNOTFORCECURRENT)), CString(MAKEINTRESOURCE(IDS_WARN_WARNING)));
162 return;
164 CString msg;
165 if (m_bIsTag)
166 msg.LoadString(IDS_T_EXISTS);
167 else
168 msg.LoadString(IDS_B_EXISTS);
169 ShowEditBalloon(IDC_BRANCH_TAG, msg + L' ' + CString(MAKEINTRESOURCE(IDS_B_T_DIFFERENTNAMEORFORCE)), CString(MAKEINTRESOURCE(IDS_WARN_WARNING)));
170 return;
172 if (g_Git.BranchTagExists(m_BranchTagName, m_bIsTag == TRUE))
174 CString msg;
175 if (m_bIsTag)
176 msg.LoadString(IDS_T_SAMEBRANCHNAMEEXISTS);
177 else
178 msg.LoadString(IDS_B_SAMETAGNAMEEXISTS);
179 if (CMessageBox::Show(GetSafeHwnd(), msg, L"TortoiseGit", 2, IDI_EXCLAMATION, CString(MAKEINTRESOURCE(IDS_CONTINUEBUTTON)), CString(MAKEINTRESOURCE(IDS_ABORTBUTTON))) == 2)
180 return;
183 this->UpdateRevsionName();
184 OnOK();
187 void CCreateBranchTagDlg::OnCbnSelchangeComboboxexBranch()
189 if (CStringUtils::StartsWith(m_ChooseVersioinBranch.GetString(), L"remotes/") && !m_bIsTag)
191 bool isDefault = false;
192 this->UpdateData();
194 CString str = this->m_OldSelectBranch;
195 int start = str.ReverseFind(L'/');
196 if(start>=0)
197 str=str.Mid(start+1);
198 if(str == m_BranchTagName)
199 isDefault =true;
201 this->GetDlgItem(IDC_CHECK_TRACK)->EnableWindow(TRUE);
203 if( m_BranchTagName.IsEmpty() || isDefault)
205 m_BranchTagName= m_ChooseVersioinBranch.GetString();
206 start = m_BranchTagName.Find(L'/', 9);
207 if(start>=0)
208 m_BranchTagName = m_BranchTagName.Mid(start+1);
210 UpdateData(FALSE);
213 else
214 this->GetDlgItem(IDC_CHECK_TRACK)->EnableWindow(FALSE);
216 if(this->m_bIsTag)
217 this->GetDlgItem(IDC_CHECK_TRACK)->EnableWindow(FALSE);
219 m_OldSelectBranch = m_ChooseVersioinBranch.GetString();
222 void CCreateBranchTagDlg::OnEnChangeBranchTag()
224 if (!((CButton *)GetDlgItem(IDC_RADIO_BRANCH))->GetCheck())
225 return;
227 CString name;
228 GetDlgItem(IDC_BRANCH_TAG)->GetWindowText(name);
229 name = L'/' + name;
230 CString remoteName = m_ChooseVersioinBranch.GetString();
231 if (CStringUtils::StartsWith(remoteName, L"remotes/") && remoteName.Right(name.GetLength()) != name)
232 ((CButton *)GetDlgItem(IDC_CHECK_TRACK))->SetCheck(FALSE);
235 void CCreateBranchTagDlg::OnVersionChanged()
237 int radio=GetCheckedRadioButton(IDC_RADIO_HEAD,IDC_RADIO_VERSION);
238 if (radio == IDC_RADIO_BRANCH)
239 OnCbnSelchangeComboboxexBranch();
240 else
241 GetDlgItem(IDC_CHECK_TRACK)->EnableWindow(FALSE);
244 void CCreateBranchTagDlg::OnDestroy()
246 WaitForFinishLoading();
247 __super::OnDestroy();