Fixed blame crash at XP system
[TortoiseGit.git] / src / TortoiseProc / CreateBranchTagDlg.cpp
blob6f727fddb32ce5a5f88eae8b5704bcfe7e7a5d7f
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"
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();
80 CHOOSE_VERSION_ADDANCHOR;
82 AddAnchor(IDC_GROUP_BRANCH, TOP_LEFT, TOP_RIGHT);
84 AddAnchor(IDC_GROUP_OPTION, TOP_LEFT, TOP_RIGHT);
86 AddAnchor(IDOK,BOTTOM_RIGHT);
87 AddAnchor(IDCANCEL,BOTTOM_RIGHT);
88 AddAnchor(IDHELP, BOTTOM_RIGHT);
89 AddAnchor(IDC_GROUP_MESSAGE,TOP_LEFT,BOTTOM_RIGHT);
90 AddAnchor(IDC_EDIT_MESSAGE,TOP_LEFT,BOTTOM_RIGHT);
92 this->AddOthersToAnchor();
94 if(m_Base.IsEmpty())
96 this->SetDefaultChoose(IDC_RADIO_HEAD);
98 }else
100 this->SetDefaultChoose(IDC_RADIO_VERSION);
101 this->GetDlgItem(IDC_COMBOBOXEX_VERSION)->SetWindowTextW(m_Base);
104 Init();
106 this->GetDlgItem(IDC_CHECK_TRACK)->EnableWindow(FALSE);
108 if(this->m_bIsTag)
110 this->SetWindowTextW(_T("Create Tag"));
111 this->GetDlgItem(IDC_LABEL_BRANCH)->SetWindowTextW(_T("Tag"));
112 this->GetDlgItem(IDC_CHECK_SIGN)->EnableWindow(!g_Git.GetConfigValue(_T("user.signingkey")).IsEmpty());
114 else
116 this->SetWindowTextW(_T("Create Branch"));
117 this->GetDlgItem(IDC_LABEL_BRANCH)->SetWindowTextW(_T("Branch"));
118 this->GetDlgItem(IDC_EDIT_MESSAGE)->EnableWindow(false);
119 this->GetDlgItem(IDC_CHECK_SIGN)->ShowWindow(SW_HIDE);
121 // show the switch checkbox if we are a create branch dialog
122 this->GetDlgItem(IDC_CHECK_SWITCH)->ShowWindow( !m_bIsTag );
123 CWnd* pHead = GetDlgItem(IDC_RADIO_HEAD);
124 CString HeadText;
125 pHead->GetWindowText( HeadText );
126 pHead->SetWindowText( HeadText + " (" + g_Git.GetCurrentBranch() + ")");
127 EnableSaveRestore(_T("BranchTagDlg"));
129 //Create the ToolTip control
130 if( !m_ToolTip.Create(this))
132 TRACE0("Unable to create the ToolTip!");
134 else
136 m_ToolTip.AddTool(GetDlgItem(IDC_CHECK_FORCE), _T("Force creationg of branch/tag - even if already exists."));
137 m_ToolTip.AddTool(GetDlgItem(IDC_CHECK_SIGN), _T("Requires GPG and a key without passphrase."));
138 m_ToolTip.Activate(TRUE);
141 OnCbnSelchangeComboboxexBranch();
142 return TRUE;
144 // CCreateBranchTagDlg message handlers
146 void CCreateBranchTagDlg::OnBnClickedOk()
148 this->UpdateData(TRUE);
150 if(this->m_bSign && this->m_Message.IsEmpty())
152 CMessageBox::Show(NULL, IDS_COMMITDLG_NOMESSAGE, IDS_TORTOISEGIT, MB_OK);
153 return;
156 this->m_BranchTagName.Trim();
157 if(!g_Git.IsBranchNameValid(this->m_BranchTagName))
159 CMessageBox::Show(NULL, IDS_B_T_NOTEMPTY, IDS_TORTOISEGIT, MB_OK);
160 return;
162 this->UpdateRevsionName();
163 OnOK();
166 void CCreateBranchTagDlg::OnCbnSelchangeComboboxexBranch()
168 if(this->m_ChooseVersioinBranch.GetString().Left(8)==_T("remotes/"))
170 bool isDefault = false;
171 this->UpdateData();
173 CString str = this->m_OldSelectBranch;
174 int start = str.ReverseFind(_T('/'));
175 if(start>=0)
176 str=str.Mid(start+1);
177 if(str == m_BranchTagName)
178 isDefault =true;
180 if( m_BranchTagName.IsEmpty() || isDefault)
182 this->GetDlgItem(IDC_CHECK_TRACK)->EnableWindow(TRUE);
184 m_BranchTagName= m_ChooseVersioinBranch.GetString();
185 int start =0;
186 start = m_BranchTagName.ReverseFind(_T('/'));
187 if(start>=0)
188 m_BranchTagName = m_BranchTagName.Mid(start+1);
190 UpdateData(FALSE);
193 else
194 this->GetDlgItem(IDC_CHECK_TRACK)->EnableWindow(FALSE);
196 if(this->m_bIsTag)
197 this->GetDlgItem(IDC_CHECK_TRACK)->EnableWindow(FALSE);
199 m_OldSelectBranch = m_ChooseVersioinBranch.GetString();
202 void CCreateBranchTagDlg::OnVersionChanged()
204 int radio=GetCheckedRadioButton(IDC_RADIO_HEAD,IDC_RADIO_VERSION);
205 if (radio == IDC_RADIO_BRANCH)
206 OnCbnSelchangeComboboxexBranch();
207 else
208 GetDlgItem(IDC_CHECK_TRACK)->EnableWindow(FALSE);
211 void CCreateBranchTagDlg::OnDestroy()
213 WaitForFinishLoading();
214 __super::OnDestroy();