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
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
),
37 m_bSwitch
= 0; // default switch to checkbox not selected
42 CCreateBranchTagDlg::~CCreateBranchTagDlg()
46 void CCreateBranchTagDlg::DoDataExchange(CDataExchange
* pDX
)
48 CDialog::DoDataExchange(pDX
);
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
)
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)
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();
97 this->SetDefaultChoose(IDC_RADIO_HEAD
);
101 this->SetDefaultChoose(IDC_RADIO_VERSION
);
102 this->GetDlgItem(IDC_COMBOBOXEX_VERSION
)->SetWindowTextW(m_Base
);
107 this->GetDlgItem(IDC_CHECK_TRACK
)->EnableWindow(FALSE
);
109 CString sWindowTitle
;
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());
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
);
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!");
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();
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
);
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
);
167 this->UpdateRevsionName();
171 void CCreateBranchTagDlg::OnCbnSelchangeComboboxexBranch()
173 if(this->m_ChooseVersioinBranch
.GetString().Left(8)==_T("remotes/"))
175 bool isDefault
= false;
178 CString str
= this->m_OldSelectBranch
;
179 int start
= str
.ReverseFind(_T('/'));
181 str
=str
.Mid(start
+1);
182 if(str
== m_BranchTagName
)
185 if( m_BranchTagName
.IsEmpty() || isDefault
)
187 this->GetDlgItem(IDC_CHECK_TRACK
)->EnableWindow(TRUE
);
189 m_BranchTagName
= m_ChooseVersioinBranch
.GetString();
191 start
= m_BranchTagName
.ReverseFind(_T('/'));
193 m_BranchTagName
= m_BranchTagName
.Mid(start
+1);
199 this->GetDlgItem(IDC_CHECK_TRACK
)->EnableWindow(FALSE
);
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();
213 GetDlgItem(IDC_CHECK_TRACK
)->EnableWindow(FALSE
);
216 void CCreateBranchTagDlg::OnDestroy()
218 WaitForFinishLoading();
219 __super::OnDestroy();