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_EN_CHANGE(IDC_BRANCH_TAG
, &CCreateBranchTagDlg::OnEnChangeBranchTag
)
67 // ON_BN_CLICKED(IDC_BUTTON_BROWSE_REF, &CCreateBranchTagDlg::OnBnClickedButtonBrowseRef)
71 BOOL
CCreateBranchTagDlg::PreTranslateMessage(MSG
* pMsg
)
73 m_ToolTip
.RelayEvent(pMsg
);
75 return CDialog::PreTranslateMessage(pMsg
);
78 BOOL
CCreateBranchTagDlg::OnInitDialog()
80 CResizableStandAloneDialog::OnInitDialog();
81 CAppUtils::MarkWindowAsUnpinnable(m_hWnd
);
83 CHOOSE_VERSION_ADDANCHOR
;
85 AddAnchor(IDC_GROUP_BRANCH
, TOP_LEFT
, TOP_RIGHT
);
87 AddAnchor(IDC_GROUP_OPTION
, TOP_LEFT
, TOP_RIGHT
);
89 AddAnchor(IDOK
,BOTTOM_RIGHT
);
90 AddAnchor(IDCANCEL
,BOTTOM_RIGHT
);
91 AddAnchor(IDHELP
, BOTTOM_RIGHT
);
92 AddAnchor(IDC_GROUP_MESSAGE
,TOP_LEFT
,BOTTOM_RIGHT
);
93 AddAnchor(IDC_EDIT_MESSAGE
,TOP_LEFT
,BOTTOM_RIGHT
);
95 this->AddOthersToAnchor();
97 AdjustControlSize(IDC_RADIO_BRANCH
);
98 AdjustControlSize(IDC_RADIO_TAGS
);
99 AdjustControlSize(IDC_RADIO_VERSION
);
100 AdjustControlSize(IDC_CHECK_TRACK
);
101 AdjustControlSize(IDC_CHECK_FORCE
);
102 AdjustControlSize(IDC_CHECK_SWITCH
);
103 AdjustControlSize(IDC_CHECK_SIGN
);
105 this->SetDefaultChoose(IDC_RADIO_HEAD
);
109 this->GetDlgItem(IDC_CHECK_TRACK
)->EnableWindow(FALSE
);
111 CString sWindowTitle
;
114 sWindowTitle
= CString(MAKEINTRESOURCE(IDS_PROGS_TITLE_CREATETAG
));
115 this->GetDlgItem(IDC_LABEL_BRANCH
)->SetWindowText(CString(MAKEINTRESOURCE(IDS_PROC_TAG
)));
116 this->GetDlgItem(IDC_CHECK_SIGN
)->EnableWindow(!g_Git
.GetConfigValue(_T("user.signingkey")).IsEmpty());
120 sWindowTitle
= CString(MAKEINTRESOURCE(IDS_PROGS_TITLE_CREATEBRANCH
));
121 this->GetDlgItem(IDC_LABEL_BRANCH
)->SetWindowText(CString(MAKEINTRESOURCE(IDS_PROC_BRANCH
)));
122 this->GetDlgItem(IDC_EDIT_MESSAGE
)->EnableWindow(FALSE
);
123 this->GetDlgItem(IDC_CHECK_SIGN
)->ShowWindow(SW_HIDE
);
126 CAppUtils::SetWindowTitle(m_hWnd
, g_Git
.m_CurrentDir
, sWindowTitle
);
128 // show the switch checkbox if we are a create branch dialog
129 this->GetDlgItem(IDC_CHECK_SWITCH
)->ShowWindow( !m_bIsTag
&& !g_GitAdminDir
.IsBareRepo(g_Git
.m_CurrentDir
));
130 CWnd
* pHead
= GetDlgItem(IDC_RADIO_HEAD
);
132 pHead
->GetWindowText( HeadText
);
133 pHead
->SetWindowText( HeadText
+ " (" + g_Git
.GetCurrentBranch() + ")");
134 AdjustControlSize(IDC_RADIO_HEAD
);
135 EnableSaveRestore(_T("BranchTagDlg"));
137 //Create the ToolTip control
138 if( !m_ToolTip
.Create(this))
140 TRACE0("Unable to create the ToolTip!");
144 m_ToolTip
.AddTool(GetDlgItem(IDC_CHECK_FORCE
), CString(MAKEINTRESOURCE(IDS_PROC_NEWBRANCHTAG_FORCE_TT
)));
145 m_ToolTip
.AddTool(GetDlgItem(IDC_CHECK_SIGN
), CString(MAKEINTRESOURCE(IDS_PROC_NEWBRANCHTAG_SIGN_TT
)));
146 m_ToolTip
.AddTool(GetDlgItem(IDC_CHECK_TRACK
), CString(MAKEINTRESOURCE(IDS_PROC_NEWBRANCHTAG_TRACK_TT
)));
147 m_ToolTip
.Activate(TRUE
);
150 OnCbnSelchangeComboboxexBranch();
153 // CCreateBranchTagDlg message handlers
155 void CCreateBranchTagDlg::OnBnClickedOk()
157 this->UpdateData(TRUE
);
159 if(this->m_bSign
&& this->m_Message
.IsEmpty())
161 CMessageBox::Show(NULL
, IDS_COMMITDLG_NOMESSAGE
, IDS_APPNAME
, MB_OK
);
165 this->m_BranchTagName
.Trim();
166 if(!g_Git
.IsBranchNameValid(this->m_BranchTagName
))
168 ShowEditBalloon(IDC_BRANCH_TAG
, IDS_B_T_NOTEMPTY
, TTI_ERROR
);
171 if (!m_bForce
&& g_Git
.BranchTagExists(m_BranchTagName
, !m_bIsTag
))
175 msg
.LoadString(IDS_T_EXISTS
);
177 msg
.LoadString(IDS_B_EXISTS
);
178 ShowEditBalloon(IDC_BRANCH_TAG
, msg
+ _T(" ") + CString(MAKEINTRESOURCE(IDS_B_T_DIFFERENTNAMEORFORCE
)), CString(MAKEINTRESOURCE(IDS_WARN_WARNING
)));
181 if (g_Git
.BranchTagExists(m_BranchTagName
, m_bIsTag
== TRUE
))
185 msg
.LoadString(IDS_T_SAMEBRANCHNAMEEXISTS
);
187 msg
.LoadString(IDS_B_SAMETAGNAMEEXISTS
);
188 if (CMessageBox::Show(m_hWnd
, msg
, _T("TortoiseGit"), 2, IDI_EXCLAMATION
, CString(MAKEINTRESOURCE(IDS_CONTINUEBUTTON
)), CString(MAKEINTRESOURCE(IDS_ABORTBUTTON
))) == 2)
192 this->UpdateRevsionName();
196 void CCreateBranchTagDlg::OnCbnSelchangeComboboxexBranch()
198 if (this->m_ChooseVersioinBranch
.GetString().Left(8)==_T("remotes/") && !m_bIsTag
)
200 bool isDefault
= false;
203 CString str
= this->m_OldSelectBranch
;
204 int start
= str
.ReverseFind(_T('/'));
206 str
=str
.Mid(start
+1);
207 if(str
== m_BranchTagName
)
210 this->GetDlgItem(IDC_CHECK_TRACK
)->EnableWindow(TRUE
);
212 if( m_BranchTagName
.IsEmpty() || isDefault
)
214 m_BranchTagName
= m_ChooseVersioinBranch
.GetString();
215 int start
= m_BranchTagName
.Find(_T('/'), 9);;
217 m_BranchTagName
= m_BranchTagName
.Mid(start
+1);
223 this->GetDlgItem(IDC_CHECK_TRACK
)->EnableWindow(FALSE
);
226 this->GetDlgItem(IDC_CHECK_TRACK
)->EnableWindow(FALSE
);
228 m_OldSelectBranch
= m_ChooseVersioinBranch
.GetString();
231 void CCreateBranchTagDlg::OnEnChangeBranchTag()
233 if (!((CButton
*)GetDlgItem(IDC_RADIO_BRANCH
))->GetCheck())
237 GetDlgItem(IDC_BRANCH_TAG
)->GetWindowText(name
);
238 name
= _T("/") + name
;
239 CString remoteName
= m_ChooseVersioinBranch
.GetString();
240 if (remoteName
.Left(8) == _T("remotes/") && remoteName
.Right(name
.GetLength()) != name
)
241 ((CButton
*)GetDlgItem(IDC_CHECK_TRACK
))->SetCheck(FALSE
);
244 void CCreateBranchTagDlg::OnVersionChanged()
246 int radio
=GetCheckedRadioButton(IDC_RADIO_HEAD
,IDC_RADIO_VERSION
);
247 if (radio
== IDC_RADIO_BRANCH
)
248 OnCbnSelchangeComboboxexBranch();
250 GetDlgItem(IDC_CHECK_TRACK
)->EnableWindow(FALSE
);
253 void CCreateBranchTagDlg::OnDestroy()
255 WaitForFinishLoading();
256 __super::OnDestroy();