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.
19 // GitSwitch.cpp : implementation file
24 #include "TortoiseProc.h"
25 #include "GitSwitchDlg.h"
28 #include "Messagebox.h"
30 // CGitSwitchDlg dialog
32 IMPLEMENT_DYNAMIC(CGitSwitchDlg
, CHorizontalResizableStandAloneDialog
)
34 CGitSwitchDlg::CGitSwitchDlg(CWnd
* pParent
/*=NULL*/)
35 : CHorizontalResizableStandAloneDialog(CGitSwitchDlg::IDD
, pParent
)
43 CGitSwitchDlg::~CGitSwitchDlg()
47 void CGitSwitchDlg::DoDataExchange(CDataExchange
* pDX
)
49 CDialog::DoDataExchange(pDX
);
52 DDX_Check(pDX
,IDC_CHECK_FORCE
,this->m_bForce
);
53 DDX_Check(pDX
,IDC_CHECK_TRACK
,this->m_bTrack
);
54 DDX_Check(pDX
,IDC_CHECK_BRANCH
,this->m_bBranch
);
55 DDX_Check(pDX
,IDC_CHECK_BRANCHOVERRIDE
,this->m_bBranchOverride
);
57 DDX_Text(pDX
,IDC_EDIT_BRANCH
,this->m_NewBranch
);
61 BEGIN_MESSAGE_MAP(CGitSwitchDlg
, CHorizontalResizableStandAloneDialog
)
64 ON_BN_CLICKED(IDC_CHECK_BRANCH
, &CGitSwitchDlg::OnBnClickedCheckBranch
)
65 ON_BN_CLICKED(IDOK
, &CGitSwitchDlg::OnBnClickedOk
)
66 ON_CBN_SELCHANGE(IDC_COMBOBOXEX_BRANCH
, &CGitSwitchDlg::OnCbnEditchangeComboboxexVersion
)
67 ON_CBN_SELCHANGE(IDC_COMBOBOXEX_TAGS
, &CGitSwitchDlg::OnCbnEditchangeComboboxexVersion
)
69 ON_CBN_EDITCHANGE(IDC_COMBOBOXEX_VERSION
, &CGitSwitchDlg::OnCbnEditchangeComboboxexVersion
)
72 BOOL
CGitSwitchDlg::OnInitDialog()
74 CHorizontalResizableStandAloneDialog::OnInitDialog();
75 CAppUtils::MarkWindowAsUnpinnable(m_hWnd
);
77 AddAnchor(IDC_GROUP_OPTION
, TOP_LEFT
, TOP_RIGHT
);
79 AddAnchor(IDC_EDIT_BRANCH
, TOP_LEFT
, TOP_RIGHT
);
81 AddAnchor(IDOK
,BOTTOM_RIGHT
);
82 AddAnchor(IDCANCEL
,BOTTOM_RIGHT
);
83 AddAnchor(IDHELP
,BOTTOM_RIGHT
);
85 CHOOSE_VERSION_ADDANCHOR
;
86 this->AddOthersToAnchor();
88 AdjustControlSize(IDC_RADIO_BRANCH
);
89 AdjustControlSize(IDC_RADIO_TAGS
);
90 AdjustControlSize(IDC_RADIO_VERSION
);
91 AdjustControlSize(IDC_CHECK_BRANCH
);
92 AdjustControlSize(IDC_CHECK_FORCE
);
93 AdjustControlSize(IDC_CHECK_TRACK
);
94 AdjustControlSize(IDC_CHECK_BRANCHOVERRIDE
);
96 EnableSaveRestore(_T("SwitchDlg"));
99 GetWindowText(sWindowTitle
);
100 CAppUtils::SetWindowTitle(m_hWnd
, g_Git
.m_CurrentDir
, sWindowTitle
);
105 SetDefaultChoose(IDC_RADIO_BRANCH
);
108 this->GetDlgItem(IDC_COMBOBOXEX_VERSION
)->SetWindowTextW(m_Base
);
109 SetDefaultChoose(IDC_RADIO_VERSION
);
112 SetDefaultName(TRUE
);
113 this->GetDlgItem(IDC_CHECK_TRACK
)->EnableWindow(FALSE
);
117 // CCreateBranchTagDlg message handlers
119 void CGitSwitchDlg::OnBnClickedChooseRadioHost()
121 OnBnClickedChooseRadio();
122 SetDefaultName(TRUE
);
125 void CGitSwitchDlg::OnBnClickedShow()
127 OnBnClickedChooseVersion();
130 void CGitSwitchDlg::OnBnClickedOk()
132 this->UpdateData(TRUE
);
134 // make sure a valid branch has been entered if a new branch is required
136 if ( m_bBranch
&& (!g_Git
.IsBranchNameValid(m_NewBranch
)))
138 // new branch requested but name is empty or contains spaces
139 CMessageBox::Show(NULL
, IDS_B_T_NOTEMPTY
, IDS_APPNAME
, MB_OK
);
144 //this->m_Version.SaveHistory();
148 void CGitSwitchDlg::SetDefaultName(BOOL isUpdateCreateBranch
)
150 this->UpdateData(TRUE
);
151 this->UpdateRevsionName();
153 CString version
= m_VersionName
;
156 if (version
.Left(7)==_T("origin/"))
157 start
= version
.Find(_T('/'), 8);
158 else if (version
.Left(8)==_T("remotes/"))
159 start
= version
.Find(_T('/'), 9);
163 version
= version
.Mid(start
+ 1);
164 this->GetDlgItem(IDC_CHECK_TRACK
)->EnableWindow(TRUE
);
165 this->m_NewBranch
=version
;
167 if(isUpdateCreateBranch
)
168 this->m_bBranch
=TRUE
;
174 m_NewBranch
= CString(_T("Branch_"))+this->m_VersionName
;
175 this->GetDlgItem(IDC_CHECK_TRACK
)->EnableWindow(FALSE
);
177 if(isUpdateCreateBranch
)
178 this->m_bBranch
=FALSE
;
180 this->m_bTrack
=FALSE
;
183 int radio
=GetCheckedRadioButton(IDC_RADIO_BRANCH
,IDC_RADIO_VERSION
);
184 if(radio
==IDC_RADIO_TAGS
|| radio
==IDC_RADIO_VERSION
)
186 if(isUpdateCreateBranch
)
187 this->m_bBranch
=TRUE
;
190 GetDlgItem(IDC_EDIT_BRANCH
)->EnableWindow(m_bBranch
);
191 GetDlgItem(IDC_CHECK_BRANCHOVERRIDE
)->EnableWindow(m_bBranch
);
194 this->m_bBranchOverride
=FALSE
;
195 this->GetDlgItem(IDC_CHECK_TRACK
)->EnableWindow(FALSE
);
196 this->m_bTrack
=FALSE
;
198 this->UpdateData(FALSE
);
201 void CGitSwitchDlg::OnDestroy()
203 WaitForFinishLoading();
204 __super::OnDestroy();
207 void CGitSwitchDlg::OnCbnEditchangeComboboxexVersion()
209 SetDefaultName(TRUE
);
212 void CGitSwitchDlg::OnBnClickedCheckBranch()
214 SetDefaultName(FALSE
);