Fixed issue #1701: Changing commit order in rebase dialog doesn't auto scroll
[TortoiseGit.git] / src / TortoiseProc / CreateBranchTagDlg.cpp
blob24b268c619e73f72456045d8cc0490350eba3f1d
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_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 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 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, TTI_ERROR);
169 return;
171 if (!m_bForce && g_Git.BranchTagExists(m_BranchTagName, !m_bIsTag))
173 CString msg;
174 if (m_bIsTag)
175 msg.LoadString(IDS_T_EXISTS);
176 else
177 msg.LoadString(IDS_B_EXISTS);
178 ShowEditBalloon(IDC_BRANCH_TAG, msg + _T(" ") + CString(MAKEINTRESOURCE(IDS_B_T_DIFFERENTNAMEORFORCE)), CString(MAKEINTRESOURCE(IDS_WARN_WARNING)));
179 return;
181 if (g_Git.BranchTagExists(m_BranchTagName, m_bIsTag == TRUE))
183 CString msg;
184 if (m_bIsTag)
185 msg.LoadString(IDS_T_SAMEBRANCHNAMEEXISTS);
186 else
187 msg.LoadString(IDS_B_SAMETAGNAMEEXISTS);
188 if (CMessageBox::Show(m_hWnd, msg, _T("TortoiseGit"), 2, IDI_EXCLAMATION, CString(MAKEINTRESOURCE(IDS_CONTINUEBUTTON)), CString(MAKEINTRESOURCE(IDS_ABORTBUTTON))) == 2)
189 return;
192 this->UpdateRevsionName();
193 OnOK();
196 void CCreateBranchTagDlg::OnCbnSelchangeComboboxexBranch()
198 if (this->m_ChooseVersioinBranch.GetString().Left(8)==_T("remotes/") && !m_bIsTag)
200 bool isDefault = false;
201 this->UpdateData();
203 CString str = this->m_OldSelectBranch;
204 int start = str.ReverseFind(_T('/'));
205 if(start>=0)
206 str=str.Mid(start+1);
207 if(str == m_BranchTagName)
208 isDefault =true;
210 this->GetDlgItem(IDC_CHECK_TRACK)->EnableWindow(TRUE);
212 if( m_BranchTagName.IsEmpty() || isDefault)
214 m_BranchTagName= m_ChooseVersioinBranch.GetString();
215 int start = m_BranchTagName.Find(_T('/'), 9);;
216 if(start>=0)
217 m_BranchTagName = m_BranchTagName.Mid(start+1);
219 UpdateData(FALSE);
222 else
223 this->GetDlgItem(IDC_CHECK_TRACK)->EnableWindow(FALSE);
225 if(this->m_bIsTag)
226 this->GetDlgItem(IDC_CHECK_TRACK)->EnableWindow(FALSE);
228 m_OldSelectBranch = m_ChooseVersioinBranch.GetString();
231 void CCreateBranchTagDlg::OnEnChangeBranchTag()
233 if (!((CButton *)GetDlgItem(IDC_RADIO_BRANCH))->GetCheck())
234 return;
236 CString name;
237 GetDlgItem(IDC_BRANCH_TAG)->GetWindowText(name);
238 name = _T("/") + name;
239 CString remoteName = m_ChooseVersioinBranch.GetString();
240 if (remoteName.Left(8) == _T("remotes/") && remoteName.Right(name.GetLength()) != name)
241 ((CButton *)GetDlgItem(IDC_CHECK_TRACK))->SetCheck(FALSE);
244 void CCreateBranchTagDlg::OnVersionChanged()
246 int radio=GetCheckedRadioButton(IDC_RADIO_HEAD,IDC_RADIO_VERSION);
247 if (radio == IDC_RADIO_BRANCH)
248 OnCbnSelchangeComboboxexBranch();
249 else
250 GetDlgItem(IDC_CHECK_TRACK)->EnableWindow(FALSE);
253 void CCreateBranchTagDlg::OnDestroy()
255 WaitForFinishLoading();
256 __super::OnDestroy();