Can run cleanup without using recycle bin and add dry run option
[TortoiseGit.git] / src / TortoiseProc / GitSwitchDlg.cpp
blob1972907c7d2f3fc826ce4c8189d35f9eabcdd731
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
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_bTrack = 2;
40 m_bForce=FALSE;
43 CGitSwitchDlg::~CGitSwitchDlg()
47 void CGitSwitchDlg::DoDataExchange(CDataExchange* pDX)
49 CDialog::DoDataExchange(pDX);
50 CHOOSE_VERSION_DDX;
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)
63 CHOOSE_VERSION_EVENT
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)
68 ON_WM_DESTROY()
69 ON_CBN_EDITCHANGE(IDC_COMBOBOXEX_VERSION, &CGitSwitchDlg::OnCbnEditchangeComboboxexVersion)
70 END_MESSAGE_MAP()
72 BOOL CGitSwitchDlg::PreTranslateMessage(MSG* pMsg)
74 m_ToolTip.RelayEvent(pMsg);
76 return CDialog::PreTranslateMessage(pMsg);
79 BOOL CGitSwitchDlg::OnInitDialog()
81 CHorizontalResizableStandAloneDialog::OnInitDialog();
82 CAppUtils::MarkWindowAsUnpinnable(m_hWnd);
84 AddAnchor(IDC_GROUP_OPTION, TOP_LEFT, TOP_RIGHT);
86 AddAnchor(IDC_EDIT_BRANCH, TOP_LEFT, TOP_RIGHT);
88 AddAnchor(IDOK,BOTTOM_RIGHT);
89 AddAnchor(IDCANCEL,BOTTOM_RIGHT);
90 AddAnchor(IDHELP,BOTTOM_RIGHT);
92 CHOOSE_VERSION_ADDANCHOR;
93 this->AddOthersToAnchor();
95 AdjustControlSize(IDC_RADIO_BRANCH);
96 AdjustControlSize(IDC_RADIO_TAGS);
97 AdjustControlSize(IDC_RADIO_VERSION);
98 AdjustControlSize(IDC_CHECK_BRANCH);
99 AdjustControlSize(IDC_CHECK_FORCE);
100 AdjustControlSize(IDC_CHECK_TRACK);
101 AdjustControlSize(IDC_CHECK_BRANCHOVERRIDE);
103 EnableSaveRestore(_T("SwitchDlg"));
105 CString sWindowTitle;
106 GetWindowText(sWindowTitle);
107 CAppUtils::SetWindowTitle(m_hWnd, g_Git.m_CurrentDir, sWindowTitle);
109 Init();
111 SetDefaultChoose(IDC_RADIO_BRANCH);
112 GetDlgItem(IDC_RADIO_BRANCH)->SetFocus();
114 this->GetDlgItem(IDC_CHECK_TRACK)->EnableWindow(FALSE);
116 //Create the ToolTip control
117 if (!m_ToolTip.Create(this))
119 TRACE0("Unable to create the ToolTip!");
121 else
123 m_ToolTip.AddTool(GetDlgItem(IDC_CHECK_FORCE), CString(MAKEINTRESOURCE(IDS_PROC_NEWBRANCHTAG_FORCE_TT)));
124 m_ToolTip.AddTool(GetDlgItem(IDC_CHECK_TRACK), CString(MAKEINTRESOURCE(IDS_PROC_NEWBRANCHTAG_TRACK_TT)));
125 m_ToolTip.Activate(TRUE);
128 return TRUE;
130 // CCreateBranchTagDlg message handlers
132 void CGitSwitchDlg::OnBnClickedChooseRadioHost()
134 OnBnClickedChooseRadio();
135 SetDefaultName(TRUE);
138 void CGitSwitchDlg::OnBnClickedShow()
140 OnBnClickedChooseVersion();
143 void CGitSwitchDlg::OnBnClickedOk()
145 this->UpdateData(TRUE);
147 // make sure a valid branch has been entered if a new branch is required
148 m_NewBranch.Trim();
149 if (m_bBranch)
151 if (!g_Git.IsBranchNameValid(m_NewBranch))
153 // new branch requested but name is empty or contains spaces
154 ShowEditBalloon(IDC_EDIT_BRANCH, IDS_B_T_NOTEMPTY, TTI_ERROR);
155 return;
157 else if (!m_bBranchOverride && g_Git.BranchTagExists(m_NewBranch))
159 // branch already exists
160 CString msg;
161 msg.LoadString(IDS_B_EXISTS);
162 ShowEditBalloon(IDC_EDIT_BRANCH, msg + _T(" ") + CString(MAKEINTRESOURCE(IDS_B_DIFFERENTNAMEOROVERRIDE)), CString(MAKEINTRESOURCE(IDS_WARN_WARNING)));
163 return;
165 else if (g_Git.BranchTagExists(m_NewBranch, false))
167 // tag with the same name exists -> shortref is ambiguous
168 if (CMessageBox::Show(m_hWnd, IDS_B_SAMETAGNAMEEXISTS, IDS_APPNAME, 2, IDI_EXCLAMATION, IDS_CONTINUEBUTTON, IDS_ABORTBUTTON) == 2)
169 return;
173 UpdateRevsionName();
174 //this->m_Version.SaveHistory();
175 OnOK();
177 void CGitSwitchDlg::SetDefaultName(BOOL isUpdateCreateBranch)
179 this->UpdateData(TRUE);
180 this->UpdateRevsionName();
182 CString version = m_VersionName;
184 int start = -1;
185 if (version.Left(7)==_T("origin/"))
186 start = version.Find(_T('/'), 8);
187 else if (version.Left(8)==_T("remotes/"))
188 start = version.Find(_T('/'), 9);
190 if (start >= 0)
192 version = version.Mid(start + 1);
193 this->GetDlgItem(IDC_CHECK_TRACK)->EnableWindow(TRUE);
194 this->m_NewBranch=version;
196 if(isUpdateCreateBranch)
197 this->m_bBranch=TRUE;
199 this->m_bTrack = 2;
201 else
203 if (m_VersionName.Left(11) == _T("refs/heads/"))
204 version = m_VersionName.Mid(11);
205 m_NewBranch = CString(_T("Branch_")) + version;
206 this->GetDlgItem(IDC_CHECK_TRACK)->EnableWindow(FALSE);
208 if(isUpdateCreateBranch)
209 this->m_bBranch=FALSE;
211 this->m_bTrack=FALSE;
214 int radio=GetCheckedRadioButton(IDC_RADIO_BRANCH,IDC_RADIO_VERSION);
215 if(radio==IDC_RADIO_TAGS || radio==IDC_RADIO_VERSION)
217 if(isUpdateCreateBranch)
218 this->m_bBranch=TRUE;
221 GetDlgItem(IDC_EDIT_BRANCH)->EnableWindow(m_bBranch);
222 GetDlgItem(IDC_CHECK_BRANCHOVERRIDE)->EnableWindow(m_bBranch);
223 if (!m_bBranch)
225 this->m_bBranchOverride=FALSE;
226 this->GetDlgItem(IDC_CHECK_TRACK)->EnableWindow(FALSE);
227 this->m_bTrack=FALSE;
229 this->UpdateData(FALSE);
232 void CGitSwitchDlg::OnDestroy()
234 WaitForFinishLoading();
235 __super::OnDestroy();
238 void CGitSwitchDlg::OnCbnEditchangeComboboxexVersion()
240 OnVersionChanged();
243 void CGitSwitchDlg::OnVersionChanged()
245 SetDefaultName(TRUE);
247 void CGitSwitchDlg::OnBnClickedCheckBranch()
249 UpdateData();
250 GetDlgItem(IDC_EDIT_BRANCH)->EnableWindow(m_bBranch);