1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2012 - 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
)
35 , CChooseVersion(this)
38 m_bSwitch
= 0; // default switch to checkbox not selected
43 CCreateBranchTagDlg::~CCreateBranchTagDlg()
47 void CCreateBranchTagDlg::DoDataExchange(CDataExchange
* pDX
)
49 CDialog::DoDataExchange(pDX
);
53 DDX_Text(pDX
, IDC_BRANCH_TAG
, this->m_BranchTagName
);
54 DDX_Check(pDX
,IDC_CHECK_FORCE
,this->m_bForce
);
55 DDX_Check(pDX
,IDC_CHECK_TRACK
,this->m_bTrack
);
56 DDX_Check(pDX
,IDC_CHECK_SWITCH
,this->m_bSwitch
);
57 DDX_Check(pDX
,IDC_CHECK_SIGN
,this->m_bSign
);
58 DDX_Text(pDX
, IDC_EDIT_MESSAGE
,this->m_Message
);
62 BEGIN_MESSAGE_MAP(CCreateBranchTagDlg
, CResizableStandAloneDialog
)
64 ON_BN_CLICKED(IDOK
, &CCreateBranchTagDlg::OnBnClickedOk
)
65 ON_CBN_SELCHANGE(IDC_COMBOBOXEX_BRANCH
, &CCreateBranchTagDlg::OnCbnSelchangeComboboxexBranch
)
66 // ON_BN_CLICKED(IDC_BUTTON_BROWSE_REF, &CCreateBranchTagDlg::OnBnClickedButtonBrowseRef)
70 BOOL
CCreateBranchTagDlg::PreTranslateMessage(MSG
* pMsg
)
72 m_ToolTip
.RelayEvent(pMsg
);
74 return CDialog::PreTranslateMessage(pMsg
);
77 BOOL
CCreateBranchTagDlg::OnInitDialog()
79 CResizableStandAloneDialog::OnInitDialog();
80 CAppUtils::MarkWindowAsUnpinnable(m_hWnd
);
82 CHOOSE_VERSION_ADDANCHOR
;
84 AddAnchor(IDC_GROUP_BRANCH
, TOP_LEFT
, TOP_RIGHT
);
86 AddAnchor(IDC_GROUP_OPTION
, TOP_LEFT
, TOP_RIGHT
);
88 AddAnchor(IDOK
,BOTTOM_RIGHT
);
89 AddAnchor(IDCANCEL
,BOTTOM_RIGHT
);
90 AddAnchor(IDHELP
, BOTTOM_RIGHT
);
91 AddAnchor(IDC_GROUP_MESSAGE
,TOP_LEFT
,BOTTOM_RIGHT
);
92 AddAnchor(IDC_EDIT_MESSAGE
,TOP_LEFT
,BOTTOM_RIGHT
);
94 this->AddOthersToAnchor();
96 AdjustControlSize(IDC_RADIO_BRANCH
);
97 AdjustControlSize(IDC_RADIO_TAGS
);
98 AdjustControlSize(IDC_RADIO_VERSION
);
99 AdjustControlSize(IDC_CHECK_TRACK
);
100 AdjustControlSize(IDC_CHECK_FORCE
);
101 AdjustControlSize(IDC_CHECK_SWITCH
);
102 AdjustControlSize(IDC_CHECK_SIGN
);
104 this->SetDefaultChoose(IDC_RADIO_HEAD
);
108 this->GetDlgItem(IDC_CHECK_TRACK
)->EnableWindow(FALSE
);
110 CString sWindowTitle
;
113 sWindowTitle
= CString(MAKEINTRESOURCE(IDS_PROGS_TITLE_CREATETAG
));
114 this->GetDlgItem(IDC_LABEL_BRANCH
)->SetWindowText(CString(MAKEINTRESOURCE(IDS_PROC_TAG
)));
115 this->GetDlgItem(IDC_CHECK_SIGN
)->EnableWindow(!g_Git
.GetConfigValue(_T("user.signingkey")).IsEmpty());
119 sWindowTitle
= CString(MAKEINTRESOURCE(IDS_PROGS_TITLE_CREATEBRANCH
));
120 this->GetDlgItem(IDC_LABEL_BRANCH
)->SetWindowText(CString(MAKEINTRESOURCE(IDS_PROC_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
&& !g_GitAdminDir
.IsBareRepo(g_Git
.m_CurrentDir
));
129 CWnd
* pHead
= GetDlgItem(IDC_RADIO_HEAD
);
131 pHead
->GetWindowText( HeadText
);
132 pHead
->SetWindowText( HeadText
+ " (" + g_Git
.GetCurrentBranch() + ")");
133 AdjustControlSize(IDC_RADIO_HEAD
);
134 EnableSaveRestore(_T("BranchTagDlg"));
136 //Create the ToolTip control
137 if( !m_ToolTip
.Create(this))
139 TRACE0("Unable to create the ToolTip!");
143 m_ToolTip
.AddTool(GetDlgItem(IDC_CHECK_FORCE
), CString(MAKEINTRESOURCE(IDS_PROC_NEWBRANCHTAG_FORCE_TT
)));
144 m_ToolTip
.AddTool(GetDlgItem(IDC_CHECK_SIGN
), CString(MAKEINTRESOURCE(IDS_PROC_NEWBRANCHTAG_SIGN_TT
)));
145 m_ToolTip
.AddTool(GetDlgItem(IDC_CHECK_TRACK
), CString(MAKEINTRESOURCE(IDS_PROC_NEWBRANCHTAG_TRACK_TT
)));
146 m_ToolTip
.Activate(TRUE
);
149 OnCbnSelchangeComboboxexBranch();
152 // CCreateBranchTagDlg message handlers
154 void CCreateBranchTagDlg::OnBnClickedOk()
156 this->UpdateData(TRUE
);
158 if(this->m_bSign
&& this->m_Message
.IsEmpty())
160 CMessageBox::Show(NULL
, IDS_COMMITDLG_NOMESSAGE
, IDS_APPNAME
, MB_OK
);
164 this->m_BranchTagName
.Trim();
165 if(!g_Git
.IsBranchNameValid(this->m_BranchTagName
))
167 ShowEditBalloon(IDC_BRANCH_TAG
, IDS_B_T_NOTEMPTY
, TTI_ERROR
);
170 if (!m_bForce
&& g_Git
.BranchTagExists(m_BranchTagName
, !m_bIsTag
))
174 msg
.LoadString(IDS_T_EXISTS
);
176 msg
.LoadString(IDS_B_EXISTS
);
177 ShowEditBalloon(IDC_BRANCH_TAG
, msg
+ _T(" ") + CString(MAKEINTRESOURCE(IDS_B_T_DIFFERENTNAMEORFORCE
)), CString(MAKEINTRESOURCE(IDS_WARN_WARNING
)));
180 if (g_Git
.BranchTagExists(m_BranchTagName
, m_bIsTag
== TRUE
))
184 msg
.LoadString(IDS_T_SAMEBRANCHNAMEEXISTS
);
186 msg
.LoadString(IDS_B_SAMETAGNAMEEXISTS
);
187 if (CMessageBox::Show(m_hWnd
, msg
, _T("TortoiseGit"), 2, IDI_EXCLAMATION
, CString(MAKEINTRESOURCE(IDS_CONTINUEBUTTON
)), CString(MAKEINTRESOURCE(IDS_ABORTBUTTON
))) == 2)
191 this->UpdateRevsionName();
195 void CCreateBranchTagDlg::OnCbnSelchangeComboboxexBranch()
197 if (this->m_ChooseVersioinBranch
.GetString().Left(8)==_T("remotes/") && !m_bIsTag
)
199 bool isDefault
= false;
202 CString str
= this->m_OldSelectBranch
;
203 int start
= str
.ReverseFind(_T('/'));
205 str
=str
.Mid(start
+1);
206 if(str
== m_BranchTagName
)
209 this->GetDlgItem(IDC_CHECK_TRACK
)->EnableWindow(TRUE
);
211 if( m_BranchTagName
.IsEmpty() || isDefault
)
213 m_BranchTagName
= m_ChooseVersioinBranch
.GetString();
214 int start
= m_BranchTagName
.Find(_T('/'), 9);;
216 m_BranchTagName
= m_BranchTagName
.Mid(start
+1);
222 this->GetDlgItem(IDC_CHECK_TRACK
)->EnableWindow(FALSE
);
225 this->GetDlgItem(IDC_CHECK_TRACK
)->EnableWindow(FALSE
);
227 m_OldSelectBranch
= m_ChooseVersioinBranch
.GetString();
230 void CCreateBranchTagDlg::OnVersionChanged()
232 int radio
=GetCheckedRadioButton(IDC_RADIO_HEAD
,IDC_RADIO_VERSION
);
233 if (radio
== IDC_RADIO_BRANCH
)
234 OnCbnSelchangeComboboxexBranch();
236 GetDlgItem(IDC_CHECK_TRACK
)->EnableWindow(FALSE
);
239 void CCreateBranchTagDlg::OnDestroy()
241 WaitForFinishLoading();
242 __super::OnDestroy();