Fixed c&p error: Usage of wrong path
[TortoiseGit.git] / src / TortoiseProc / GitSwitchDlg.cpp
blob7004b09dcbfc00f9895c334c79d551f68ced978a
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2014 - 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
22 #include "stdafx.h"
23 #include "Git.h"
24 #include "TortoiseProc.h"
25 #include "GitSwitchDlg.h"
26 #include "AppUtils.h"
28 #include "Messagebox.h"
30 // CGitSwitchDlg dialog
32 IMPLEMENT_DYNAMIC(CGitSwitchDlg, CHorizontalResizableStandAloneDialog)
34 CGitSwitchDlg::CGitSwitchDlg(CWnd* pParent /*=NULL*/)
35 : CHorizontalResizableStandAloneDialog(CGitSwitchDlg::IDD, pParent)
36 ,CChooseVersion(this)
38 m_bBranch=FALSE;
39 m_bMerge = FALSE;
40 m_bTrack = 2;
41 m_bForce=FALSE;
42 m_bBranchOverride = FALSE;
45 CGitSwitchDlg::~CGitSwitchDlg()
49 void CGitSwitchDlg::DoDataExchange(CDataExchange* pDX)
51 CDialog::DoDataExchange(pDX);
52 CHOOSE_VERSION_DDX;
54 DDX_Check(pDX,IDC_CHECK_FORCE,this->m_bForce);
55 DDX_Check(pDX, IDC_CHECK_MERGE, m_bMerge);
56 DDX_Check(pDX,IDC_CHECK_TRACK,this->m_bTrack);
57 DDX_Check(pDX,IDC_CHECK_BRANCH,this->m_bBranch);
58 DDX_Check(pDX,IDC_CHECK_BRANCHOVERRIDE,this->m_bBranchOverride);
60 DDX_Text(pDX,IDC_EDIT_BRANCH,this->m_NewBranch);
64 BEGIN_MESSAGE_MAP(CGitSwitchDlg, CHorizontalResizableStandAloneDialog)
66 CHOOSE_VERSION_EVENT
67 ON_BN_CLICKED(IDC_CHECK_BRANCH, &CGitSwitchDlg::OnBnClickedCheckBranch)
68 ON_BN_CLICKED(IDOK, &CGitSwitchDlg::OnBnClickedOk)
69 ON_CBN_SELCHANGE(IDC_COMBOBOXEX_BRANCH, &CGitSwitchDlg::OnCbnEditchangeComboboxexVersion)
70 ON_CBN_SELCHANGE(IDC_COMBOBOXEX_TAGS, &CGitSwitchDlg::OnCbnEditchangeComboboxexVersion)
71 ON_WM_DESTROY()
72 ON_CBN_EDITCHANGE(IDC_COMBOBOXEX_VERSION, &CGitSwitchDlg::OnCbnEditchangeComboboxexVersion)
73 ON_EN_CHANGE(IDC_EDIT_BRANCH, &CGitSwitchDlg::OnEnChangeEditBranch)
74 END_MESSAGE_MAP()
76 BOOL CGitSwitchDlg::PreTranslateMessage(MSG* pMsg)
78 m_ToolTip.RelayEvent(pMsg);
80 return CDialog::PreTranslateMessage(pMsg);
83 BOOL CGitSwitchDlg::OnInitDialog()
85 CHorizontalResizableStandAloneDialog::OnInitDialog();
86 CAppUtils::MarkWindowAsUnpinnable(m_hWnd);
88 AddAnchor(IDC_GROUP_OPTION, TOP_LEFT, TOP_RIGHT);
90 AddAnchor(IDC_EDIT_BRANCH, TOP_LEFT, TOP_RIGHT);
92 AddAnchor(IDOK,BOTTOM_RIGHT);
93 AddAnchor(IDCANCEL,BOTTOM_RIGHT);
94 AddAnchor(IDHELP,BOTTOM_RIGHT);
96 CHOOSE_VERSION_ADDANCHOR;
97 this->AddOthersToAnchor();
99 AdjustControlSize(IDC_RADIO_BRANCH);
100 AdjustControlSize(IDC_RADIO_TAGS);
101 AdjustControlSize(IDC_RADIO_VERSION);
102 AdjustControlSize(IDC_CHECK_BRANCH);
103 AdjustControlSize(IDC_CHECK_FORCE);
104 AdjustControlSize(IDC_CHECK_MERGE);
105 AdjustControlSize(IDC_CHECK_TRACK);
106 AdjustControlSize(IDC_CHECK_BRANCHOVERRIDE);
108 EnableSaveRestore(_T("SwitchDlg"));
110 CString sWindowTitle;
111 GetWindowText(sWindowTitle);
112 CAppUtils::SetWindowTitle(m_hWnd, g_Git.m_CurrentDir, sWindowTitle);
114 InitChooseVersion(true);
116 SetDefaultChoose(IDC_RADIO_BRANCH);
117 GetDlgItem(IDC_CHECK_BRANCH)->SetFocus();
119 this->GetDlgItem(IDC_CHECK_TRACK)->EnableWindow(FALSE);
121 //Create the ToolTip control
122 if (!m_ToolTip.Create(this))
124 TRACE0("Unable to create the ToolTip!");
126 else
128 m_ToolTip.AddTool(GetDlgItem(IDC_CHECK_FORCE), CString(MAKEINTRESOURCE(IDS_PROC_NEWBRANCHTAG_FORCE_TT)));
129 m_ToolTip.AddTool(GetDlgItem(IDC_CHECK_MERGE), CString(MAKEINTRESOURCE(IDS_PROC_SWITCH_MERGE_TT)));
130 m_ToolTip.AddTool(GetDlgItem(IDC_CHECK_TRACK), CString(MAKEINTRESOURCE(IDS_PROC_NEWBRANCHTAG_TRACK_TT)));
131 m_ToolTip.Activate(TRUE);
134 return FALSE;
136 // CCreateBranchTagDlg message handlers
138 void CGitSwitchDlg::OnBnClickedChooseRadioHost()
140 OnBnClickedChooseRadio();
141 SetDefaultName(TRUE);
144 void CGitSwitchDlg::OnBnClickedShow()
146 OnBnClickedChooseVersion();
149 void CGitSwitchDlg::OnBnClickedOk()
151 this->UpdateData(TRUE);
153 // make sure a valid branch has been entered if a new branch is required
154 m_NewBranch.Trim();
155 if (m_bBranch)
157 if (!g_Git.IsBranchNameValid(m_NewBranch))
159 // new branch requested but name is empty or contains spaces
160 ShowEditBalloon(IDC_EDIT_BRANCH, IDS_B_T_NOTEMPTY, IDS_ERR_ERROR, TTI_ERROR);
161 return;
163 else if (!m_bBranchOverride && g_Git.BranchTagExists(m_NewBranch))
165 // branch already exists
166 CString msg;
167 msg.LoadString(IDS_B_EXISTS);
168 ShowEditBalloon(IDC_EDIT_BRANCH, msg + _T(" ") + CString(MAKEINTRESOURCE(IDS_B_DIFFERENTNAMEOROVERRIDE)), CString(MAKEINTRESOURCE(IDS_WARN_WARNING)));
169 return;
171 else if (g_Git.BranchTagExists(m_NewBranch, false))
173 // tag with the same name exists -> shortref is ambiguous
174 if (CMessageBox::Show(m_hWnd, IDS_B_SAMETAGNAMEEXISTS, IDS_APPNAME, 2, IDI_EXCLAMATION, IDS_CONTINUEBUTTON, IDS_ABORTBUTTON) == 2)
175 return;
179 UpdateRevsionName();
180 //this->m_Version.SaveHistory();
181 OnOK();
183 void CGitSwitchDlg::SetDefaultName(BOOL isUpdateCreateBranch)
185 this->UpdateData(TRUE);
186 this->UpdateRevsionName();
188 CString version = m_VersionName;
190 int start = -1;
191 if (version.Left(7)==_T("origin/"))
192 start = version.Find(_T('/'), 8);
193 else if (version.Left(8)==_T("remotes/"))
194 start = version.Find(_T('/'), 9);
196 if (start >= 0)
198 version = version.Mid(start + 1);
199 this->GetDlgItem(IDC_CHECK_TRACK)->EnableWindow(TRUE);
200 this->m_NewBranch=version;
202 if(isUpdateCreateBranch)
203 this->m_bBranch=TRUE;
205 this->m_bTrack = 2;
207 else
209 if (m_VersionName.Left(11) == _T("refs/heads/"))
210 version = m_VersionName.Mid(11);
211 m_NewBranch = CString(_T("Branch_")) + version;
212 this->GetDlgItem(IDC_CHECK_TRACK)->EnableWindow(FALSE);
214 if(isUpdateCreateBranch)
215 this->m_bBranch=FALSE;
217 this->m_bTrack=FALSE;
220 int radio=GetCheckedRadioButton(IDC_RADIO_BRANCH,IDC_RADIO_VERSION);
221 if(radio==IDC_RADIO_TAGS || radio==IDC_RADIO_VERSION)
223 if(isUpdateCreateBranch)
224 this->m_bBranch=TRUE;
227 GetDlgItem(IDC_EDIT_BRANCH)->EnableWindow(m_bBranch);
228 GetDlgItem(IDC_CHECK_BRANCHOVERRIDE)->EnableWindow(m_bBranch);
229 if (!m_bBranch)
231 this->m_bBranchOverride=FALSE;
232 this->GetDlgItem(IDC_CHECK_TRACK)->EnableWindow(FALSE);
233 this->m_bTrack=FALSE;
235 this->UpdateData(FALSE);
238 void CGitSwitchDlg::OnDestroy()
240 WaitForFinishLoading();
241 __super::OnDestroy();
244 void CGitSwitchDlg::OnCbnEditchangeComboboxexVersion()
246 OnVersionChanged();
249 void CGitSwitchDlg::OnEnChangeEditBranch()
251 if (!((CButton *)GetDlgItem(IDC_RADIO_BRANCH))->GetCheck())
252 return;
254 CString name;
255 GetDlgItem(IDC_EDIT_BRANCH)->GetWindowText(name);
256 name = _T("/") + name;
257 CString remoteName = m_ChooseVersioinBranch.GetString();
258 if (remoteName.Left(8) == _T("remotes/") && remoteName.Right(name.GetLength()) != name)
259 ((CButton *)GetDlgItem(IDC_CHECK_TRACK))->SetCheck(FALSE);
262 void CGitSwitchDlg::OnVersionChanged()
264 SetDefaultName(TRUE);
266 void CGitSwitchDlg::OnBnClickedCheckBranch()
268 UpdateData();
269 GetDlgItem(IDC_EDIT_BRANCH)->EnableWindow(m_bBranch);