some spaces-tabs code cleanup
[TortoiseGit.git] / src / TortoiseProc / CreateBranchTagDlg.cpp
blobcd966085a145989648967e9fd3189d91723eff15
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2011 - 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 CChooseVersion(this)
36 m_bIsTag=0;
37 m_bSwitch = 0; // default switch to checkbox not selected
38 m_bTrack=0;
39 m_bSign=0;
42 CCreateBranchTagDlg::~CCreateBranchTagDlg()
46 void CCreateBranchTagDlg::DoDataExchange(CDataExchange* pDX)
48 CDialog::DoDataExchange(pDX);
50 CHOOSE_VERSION_DDX;
52 DDX_Text(pDX, IDC_BRANCH_TAG, this->m_BranchTagName);
53 DDX_Check(pDX,IDC_CHECK_FORCE,this->m_bForce);
54 DDX_Check(pDX,IDC_CHECK_TRACK,this->m_bTrack);
55 DDX_Check(pDX,IDC_CHECK_SWITCH,this->m_bSwitch);
56 DDX_Check(pDX,IDC_CHECK_SIGN,this->m_bSign);
57 DDX_Text(pDX, IDC_EDIT_MESSAGE,this->m_Message);
61 BEGIN_MESSAGE_MAP(CCreateBranchTagDlg, CResizableStandAloneDialog)
62 CHOOSE_VERSION_EVENT
63 ON_BN_CLICKED(IDOK, &CCreateBranchTagDlg::OnBnClickedOk)
64 ON_CBN_SELCHANGE(IDC_COMBOBOXEX_BRANCH, &CCreateBranchTagDlg::OnCbnSelchangeComboboxexBranch)
65 // ON_BN_CLICKED(IDC_BUTTON_BROWSE_REF, &CCreateBranchTagDlg::OnBnClickedButtonBrowseRef)
66 ON_WM_DESTROY()
67 END_MESSAGE_MAP()
69 BOOL CCreateBranchTagDlg::PreTranslateMessage(MSG* pMsg)
71 m_ToolTip.RelayEvent(pMsg);
73 return CDialog::PreTranslateMessage(pMsg);
76 BOOL CCreateBranchTagDlg::OnInitDialog()
78 CResizableStandAloneDialog::OnInitDialog();
79 CAppUtils::MarkWindowAsUnpinnable(m_hWnd);
81 CHOOSE_VERSION_ADDANCHOR;
83 AddAnchor(IDC_GROUP_BRANCH, TOP_LEFT, TOP_RIGHT);
85 AddAnchor(IDC_GROUP_OPTION, TOP_LEFT, TOP_RIGHT);
87 AddAnchor(IDOK,BOTTOM_RIGHT);
88 AddAnchor(IDCANCEL,BOTTOM_RIGHT);
89 AddAnchor(IDHELP, BOTTOM_RIGHT);
90 AddAnchor(IDC_GROUP_MESSAGE,TOP_LEFT,BOTTOM_RIGHT);
91 AddAnchor(IDC_EDIT_MESSAGE,TOP_LEFT,BOTTOM_RIGHT);
93 this->AddOthersToAnchor();
95 if(m_Base.IsEmpty())
97 this->SetDefaultChoose(IDC_RADIO_HEAD);
99 }else
101 this->SetDefaultChoose(IDC_RADIO_VERSION);
102 this->GetDlgItem(IDC_COMBOBOXEX_VERSION)->SetWindowTextW(m_Base);
105 Init();
107 this->GetDlgItem(IDC_CHECK_TRACK)->EnableWindow(FALSE);
109 CString sWindowTitle;
110 if(this->m_bIsTag)
112 sWindowTitle = _T("Create Tag");
113 this->GetDlgItem(IDC_LABEL_BRANCH)->SetWindowTextW(_T("Tag"));
114 this->GetDlgItem(IDC_CHECK_SIGN)->EnableWindow(!g_Git.GetConfigValue(_T("user.signingkey")).IsEmpty());
116 else
118 sWindowTitle = _T("Create Branch");
119 this->GetDlgItem(IDC_LABEL_BRANCH)->SetWindowTextW(_T("Branch"));
120 this->GetDlgItem(IDC_EDIT_MESSAGE)->EnableWindow(false);
121 this->GetDlgItem(IDC_CHECK_SIGN)->ShowWindow(SW_HIDE);
124 CAppUtils::SetWindowTitle(m_hWnd, g_Git.m_CurrentDir, sWindowTitle);
126 // show the switch checkbox if we are a create branch dialog
127 this->GetDlgItem(IDC_CHECK_SWITCH)->ShowWindow( !m_bIsTag );
128 CWnd* pHead = GetDlgItem(IDC_RADIO_HEAD);
129 CString HeadText;
130 pHead->GetWindowText( HeadText );
131 pHead->SetWindowText( HeadText + " (" + g_Git.GetCurrentBranch() + ")");
132 EnableSaveRestore(_T("BranchTagDlg"));
134 //Create the ToolTip control
135 if( !m_ToolTip.Create(this))
137 TRACE0("Unable to create the ToolTip!");
139 else
141 m_ToolTip.AddTool(GetDlgItem(IDC_CHECK_FORCE), _T("Force creationg of branch/tag - even if already exists."));
142 m_ToolTip.AddTool(GetDlgItem(IDC_CHECK_SIGN), _T("Requires GPG and a key without passphrase."));
143 m_ToolTip.Activate(TRUE);
146 OnCbnSelchangeComboboxexBranch();
147 return TRUE;
149 // CCreateBranchTagDlg message handlers
151 void CCreateBranchTagDlg::OnBnClickedOk()
153 this->UpdateData(TRUE);
155 if(this->m_bSign && this->m_Message.IsEmpty())
157 CMessageBox::Show(NULL, IDS_COMMITDLG_NOMESSAGE, IDS_TORTOISEGIT, MB_OK);
158 return;
161 this->m_BranchTagName.Trim();
162 if(!g_Git.IsBranchNameValid(this->m_BranchTagName))
164 CMessageBox::Show(NULL, IDS_B_T_NOTEMPTY, IDS_TORTOISEGIT, MB_OK);
165 return;
167 this->UpdateRevsionName();
168 OnOK();
171 void CCreateBranchTagDlg::OnCbnSelchangeComboboxexBranch()
173 if(this->m_ChooseVersioinBranch.GetString().Left(8)==_T("remotes/"))
175 bool isDefault = false;
176 this->UpdateData();
178 CString str = this->m_OldSelectBranch;
179 int start = str.ReverseFind(_T('/'));
180 if(start>=0)
181 str=str.Mid(start+1);
182 if(str == m_BranchTagName)
183 isDefault =true;
185 if( m_BranchTagName.IsEmpty() || isDefault)
187 this->GetDlgItem(IDC_CHECK_TRACK)->EnableWindow(TRUE);
189 m_BranchTagName= m_ChooseVersioinBranch.GetString();
190 int start =0;
191 start = m_BranchTagName.ReverseFind(_T('/'));
192 if(start>=0)
193 m_BranchTagName = m_BranchTagName.Mid(start+1);
195 UpdateData(FALSE);
198 else
199 this->GetDlgItem(IDC_CHECK_TRACK)->EnableWindow(FALSE);
201 if(this->m_bIsTag)
202 this->GetDlgItem(IDC_CHECK_TRACK)->EnableWindow(FALSE);
204 m_OldSelectBranch = m_ChooseVersioinBranch.GetString();
207 void CCreateBranchTagDlg::OnVersionChanged()
209 int radio=GetCheckedRadioButton(IDC_RADIO_HEAD,IDC_RADIO_VERSION);
210 if (radio == IDC_RADIO_BRANCH)
211 OnCbnSelchangeComboboxexBranch();
212 else
213 GetDlgItem(IDC_CHECK_TRACK)->EnableWindow(FALSE);
216 void CCreateBranchTagDlg::OnDestroy()
218 WaitForFinishLoading();
219 __super::OnDestroy();