Merge branch 'restructure-tree'
[TortoiseGit.git] / src / TortoiseProc / CreateBranchTagDlg.cpp
blob847263023feb3e0ba62d06a3873b7cd3f11fa10f
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 if(this->m_bIsTag)
111 this->SetWindowTextW(_T("Create Tag"));
112 this->GetDlgItem(IDC_LABEL_BRANCH)->SetWindowTextW(_T("Tag"));
113 this->GetDlgItem(IDC_CHECK_SIGN)->EnableWindow(!g_Git.GetConfigValue(_T("user.signingkey")).IsEmpty());
115 else
117 this->SetWindowTextW(_T("Create Branch"));
118 this->GetDlgItem(IDC_LABEL_BRANCH)->SetWindowTextW(_T("Branch"));
119 this->GetDlgItem(IDC_EDIT_MESSAGE)->EnableWindow(false);
120 this->GetDlgItem(IDC_CHECK_SIGN)->ShowWindow(SW_HIDE);
122 // show the switch checkbox if we are a create branch dialog
123 this->GetDlgItem(IDC_CHECK_SWITCH)->ShowWindow( !m_bIsTag );
124 CWnd* pHead = GetDlgItem(IDC_RADIO_HEAD);
125 CString HeadText;
126 pHead->GetWindowText( HeadText );
127 pHead->SetWindowText( HeadText + " (" + g_Git.GetCurrentBranch() + ")");
128 EnableSaveRestore(_T("BranchTagDlg"));
130 //Create the ToolTip control
131 if( !m_ToolTip.Create(this))
133 TRACE0("Unable to create the ToolTip!");
135 else
137 m_ToolTip.AddTool(GetDlgItem(IDC_CHECK_FORCE), _T("Force creationg of branch/tag - even if already exists."));
138 m_ToolTip.AddTool(GetDlgItem(IDC_CHECK_SIGN), _T("Requires GPG and a key without passphrase."));
139 m_ToolTip.Activate(TRUE);
142 OnCbnSelchangeComboboxexBranch();
143 return TRUE;
145 // CCreateBranchTagDlg message handlers
147 void CCreateBranchTagDlg::OnBnClickedOk()
149 this->UpdateData(TRUE);
151 if(this->m_bSign && this->m_Message.IsEmpty())
153 CMessageBox::Show(NULL, IDS_COMMITDLG_NOMESSAGE, IDS_TORTOISEGIT, MB_OK);
154 return;
157 this->m_BranchTagName.Trim();
158 if(!g_Git.IsBranchNameValid(this->m_BranchTagName))
160 CMessageBox::Show(NULL, IDS_B_T_NOTEMPTY, IDS_TORTOISEGIT, MB_OK);
161 return;
163 this->UpdateRevsionName();
164 OnOK();
167 void CCreateBranchTagDlg::OnCbnSelchangeComboboxexBranch()
169 if(this->m_ChooseVersioinBranch.GetString().Left(8)==_T("remotes/"))
171 bool isDefault = false;
172 this->UpdateData();
174 CString str = this->m_OldSelectBranch;
175 int start = str.ReverseFind(_T('/'));
176 if(start>=0)
177 str=str.Mid(start+1);
178 if(str == m_BranchTagName)
179 isDefault =true;
181 if( m_BranchTagName.IsEmpty() || isDefault)
183 this->GetDlgItem(IDC_CHECK_TRACK)->EnableWindow(TRUE);
185 m_BranchTagName= m_ChooseVersioinBranch.GetString();
186 int start =0;
187 start = m_BranchTagName.ReverseFind(_T('/'));
188 if(start>=0)
189 m_BranchTagName = m_BranchTagName.Mid(start+1);
191 UpdateData(FALSE);
194 else
195 this->GetDlgItem(IDC_CHECK_TRACK)->EnableWindow(FALSE);
197 if(this->m_bIsTag)
198 this->GetDlgItem(IDC_CHECK_TRACK)->EnableWindow(FALSE);
200 m_OldSelectBranch = m_ChooseVersioinBranch.GetString();
203 void CCreateBranchTagDlg::OnVersionChanged()
205 int radio=GetCheckedRadioButton(IDC_RADIO_HEAD,IDC_RADIO_VERSION);
206 if (radio == IDC_RADIO_BRANCH)
207 OnCbnSelchangeComboboxexBranch();
208 else
209 GetDlgItem(IDC_CHECK_TRACK)->EnableWindow(FALSE);
212 void CCreateBranchTagDlg::OnDestroy()
214 WaitForFinishLoading();
215 __super::OnDestroy();