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
);
102 this->SetDefaultChoose(IDC_RADIO_VERSION
);
103 this->GetDlgItem(IDC_COMBOBOXEX_VERSION
)->SetWindowTextW(m_Base
);
108 this->GetDlgItem(IDC_CHECK_TRACK
)->EnableWindow(FALSE
);
110 CString sWindowTitle
;
113 sWindowTitle
= _T("Create Tag");
114 this->GetDlgItem(IDC_LABEL_BRANCH
)->SetWindowTextW(_T("Tag"));
115 this->GetDlgItem(IDC_CHECK_SIGN
)->EnableWindow(!g_Git
.GetConfigValue(_T("user.signingkey")).IsEmpty());
119 sWindowTitle
= _T("Create Branch");
120 this->GetDlgItem(IDC_LABEL_BRANCH
)->SetWindowTextW(_T("Branch"));
121 this->GetDlgItem(IDC_EDIT_MESSAGE
)->EnableWindow(false);
122 this->GetDlgItem(IDC_CHECK_SIGN
)->ShowWindow(SW_HIDE
);
125 CAppUtils::SetWindowTitle(m_hWnd
, g_Git
.m_CurrentDir
, sWindowTitle
);
127 // show the switch checkbox if we are a create branch dialog
128 this->GetDlgItem(IDC_CHECK_SWITCH
)->ShowWindow( !m_bIsTag
);
129 CWnd
* pHead
= GetDlgItem(IDC_RADIO_HEAD
);
131 pHead
->GetWindowText( HeadText
);
132 pHead
->SetWindowText( HeadText
+ " (" + g_Git
.GetCurrentBranch() + ")");
133 EnableSaveRestore(_T("BranchTagDlg"));
135 //Create the ToolTip control
136 if( !m_ToolTip
.Create(this))
138 TRACE0("Unable to create the ToolTip!");
142 m_ToolTip
.AddTool(GetDlgItem(IDC_CHECK_FORCE
), _T("Force creationg of branch/tag - even if already exists."));
143 m_ToolTip
.AddTool(GetDlgItem(IDC_CHECK_SIGN
), _T("Requires GPG and a key without passphrase."));
144 m_ToolTip
.Activate(TRUE
);
147 OnCbnSelchangeComboboxexBranch();
150 // CCreateBranchTagDlg message handlers
152 void CCreateBranchTagDlg::OnBnClickedOk()
154 this->UpdateData(TRUE
);
156 if(this->m_bSign
&& this->m_Message
.IsEmpty())
158 CMessageBox::Show(NULL
, IDS_COMMITDLG_NOMESSAGE
, IDS_TORTOISEGIT
, MB_OK
);
162 this->m_BranchTagName
.Trim();
163 if(!g_Git
.IsBranchNameValid(this->m_BranchTagName
))
165 CMessageBox::Show(NULL
, IDS_B_T_NOTEMPTY
, IDS_TORTOISEGIT
, MB_OK
);
168 this->UpdateRevsionName();
172 void CCreateBranchTagDlg::OnCbnSelchangeComboboxexBranch()
174 if(this->m_ChooseVersioinBranch
.GetString().Left(8)==_T("remotes/"))
176 bool isDefault
= false;
179 CString str
= this->m_OldSelectBranch
;
180 int start
= str
.ReverseFind(_T('/'));
182 str
=str
.Mid(start
+1);
183 if(str
== m_BranchTagName
)
186 if( m_BranchTagName
.IsEmpty() || isDefault
)
188 this->GetDlgItem(IDC_CHECK_TRACK
)->EnableWindow(TRUE
);
190 m_BranchTagName
= m_ChooseVersioinBranch
.GetString();
192 start
= m_BranchTagName
.ReverseFind(_T('/'));
194 m_BranchTagName
= m_BranchTagName
.Mid(start
+1);
200 this->GetDlgItem(IDC_CHECK_TRACK
)->EnableWindow(FALSE
);
203 this->GetDlgItem(IDC_CHECK_TRACK
)->EnableWindow(FALSE
);
205 m_OldSelectBranch
= m_ChooseVersioinBranch
.GetString();
208 void CCreateBranchTagDlg::OnVersionChanged()
210 int radio
=GetCheckedRadioButton(IDC_RADIO_HEAD
,IDC_RADIO_VERSION
);
211 if (radio
== IDC_RADIO_BRANCH
)
212 OnCbnSelchangeComboboxexBranch();
214 GetDlgItem(IDC_CHECK_TRACK
)->EnableWindow(FALSE
);
217 void CCreateBranchTagDlg::OnDestroy()
219 WaitForFinishLoading();
220 __super::OnDestroy();