TortoiseSVN -> TortoiseGit
[TortoiseGit.git] / src / TortoiseProc / GitSwitchDlg.cpp
blobc4628c99e815278128379e70f843f9d90fdd6794
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2011 - 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=FALSE;
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::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 EnableSaveRestore(_T("SwitchDlg"));
90 CString sWindowTitle;
91 GetWindowText(sWindowTitle);
92 CAppUtils::SetWindowTitle(m_hWnd, g_Git.m_CurrentDir, sWindowTitle);
94 Init();
96 if(m_Base.IsEmpty())
97 SetDefaultChoose(IDC_RADIO_BRANCH);
98 else
100 this->GetDlgItem(IDC_COMBOBOXEX_VERSION)->SetWindowTextW(m_Base);
101 SetDefaultChoose(IDC_RADIO_VERSION);
104 SetDefaultName(TRUE);
105 this->GetDlgItem(IDC_CHECK_TRACK)->EnableWindow(FALSE);
107 return TRUE;
109 // CCreateBranchTagDlg message handlers
111 void CGitSwitchDlg::OnBnClickedChooseRadioHost()
113 OnBnClickedChooseRadio();
114 SetDefaultName(TRUE);
117 void CGitSwitchDlg::OnBnClickedShow()
119 OnBnClickedChooseVersion();
122 void CGitSwitchDlg::OnBnClickedOk()
124 this->UpdateData(TRUE);
126 // make sure a valid branch has been entered if a new branch is required
127 m_NewBranch.Trim();
128 if ( m_bBranch && (!g_Git.IsBranchNameValid(m_NewBranch)))
130 // new branch requested but name is empty or contains spaces
131 CMessageBox::Show(NULL, IDS_B_T_NOTEMPTY, IDS_TORTOISEGIT, MB_OK);
133 else
135 UpdateRevsionName();
136 //this->m_Version.SaveHistory();
137 OnOK();
140 void CGitSwitchDlg::SetDefaultName(BOOL isUpdateCreateBranch)
142 this->UpdateData(TRUE);
143 this->UpdateRevsionName();
145 CString version = m_VersionName;
147 if((version.Left(7)==_T("origin/") || version.Left(8)==_T("remotes/")))
149 int start=0;
150 start = version.ReverseFind(_T('/'));
151 if(start>=0)
152 version = version.Mid(start+1);
153 this->GetDlgItem(IDC_CHECK_TRACK)->EnableWindow(TRUE);
154 this->m_NewBranch=version;
156 if(isUpdateCreateBranch)
157 this->m_bBranch=TRUE;
159 this->m_bTrack=TRUE;
161 else
163 m_NewBranch = CString(_T("Branch_"))+this->m_VersionName;
164 this->GetDlgItem(IDC_CHECK_TRACK)->EnableWindow(FALSE);
166 if(isUpdateCreateBranch)
167 this->m_bBranch=FALSE;
169 this->m_bTrack=FALSE;
172 int radio=GetCheckedRadioButton(IDC_RADIO_BRANCH,IDC_RADIO_VERSION);
173 if(radio==IDC_RADIO_TAGS || radio==IDC_RADIO_VERSION)
175 if(isUpdateCreateBranch)
176 this->m_bBranch=TRUE;
179 GetDlgItem(IDC_EDIT_BRANCH)->EnableWindow(m_bBranch);
180 GetDlgItem(IDC_CHECK_BRANCHOVERRIDE)->EnableWindow(m_bBranch);
181 if (!m_bBranch)
183 this->m_bBranchOverride=FALSE;
184 this->GetDlgItem(IDC_CHECK_TRACK)->EnableWindow(FALSE);
185 this->m_bTrack=FALSE;
187 this->UpdateData(FALSE);
190 void CGitSwitchDlg::OnDestroy()
192 WaitForFinishLoading();
193 __super::OnDestroy();
196 void CGitSwitchDlg::OnCbnEditchangeComboboxexVersion()
198 SetDefaultName(TRUE);
201 void CGitSwitchDlg::OnBnClickedCheckBranch()
203 SetDefaultName(FALSE);