Fixed issue #438: Slow load Switch/Checkout dialog
[TortoiseGit.git] / src / TortoiseProc / CreateBranchTagDlg.cpp
blobae2948c3d601c3fb78122982f6e532e1fcbab68b
1 // CreateBranchTagDlg.cpp : implementation file
2 //
4 #include "stdafx.h"
5 #include "Git.h"
6 #include "TortoiseProc.h"
7 #include "CreateBranchTagDlg.h"
9 #include "Messagebox.h"
11 // CCreateBranchTagDlg dialog
13 IMPLEMENT_DYNAMIC(CCreateBranchTagDlg, CResizableStandAloneDialog)
15 CCreateBranchTagDlg::CCreateBranchTagDlg(CWnd* pParent /*=NULL*/)
16 : CResizableStandAloneDialog(CCreateBranchTagDlg::IDD, pParent),
17 CChooseVersion(this)
19 m_bIsTag=0;
20 m_bSwitch = 0; // default switch to checkbox not selected
21 m_bTrack=0;
24 CCreateBranchTagDlg::~CCreateBranchTagDlg()
28 void CCreateBranchTagDlg::DoDataExchange(CDataExchange* pDX)
30 CDialog::DoDataExchange(pDX);
32 CHOOSE_VERSION_DDX;
34 DDX_Text(pDX, IDC_BRANCH_TAG, this->m_BranchTagName);
35 DDX_Check(pDX,IDC_CHECK_FORCE,this->m_bForce);
36 DDX_Check(pDX,IDC_CHECK_TRACK,this->m_bTrack);
37 DDX_Check(pDX,IDC_CHECK_SWITCH,this->m_bSwitch);
38 DDX_Text(pDX, IDC_EDIT_MESSAGE,this->m_Message);
43 BEGIN_MESSAGE_MAP(CCreateBranchTagDlg, CResizableStandAloneDialog)
44 CHOOSE_VERSION_EVENT
45 ON_BN_CLICKED(IDOK, &CCreateBranchTagDlg::OnBnClickedOk)
46 ON_CBN_SELCHANGE(IDC_COMBOBOXEX_BRANCH, &CCreateBranchTagDlg::OnCbnSelchangeComboboxexBranch)
47 // ON_BN_CLICKED(IDC_BUTTON_BROWSE_REF, &CCreateBranchTagDlg::OnBnClickedButtonBrowseRef)
48 ON_WM_DESTROY()
49 END_MESSAGE_MAP()
51 BOOL CCreateBranchTagDlg::OnInitDialog()
53 CResizableStandAloneDialog::OnInitDialog();
55 CHOOSE_VERSION_ADDANCHOR;
57 AddAnchor(IDC_GROUP_BRANCH, TOP_LEFT, TOP_RIGHT);
59 AddAnchor(IDC_GROUP_OPTION, TOP_LEFT, TOP_RIGHT);
61 AddAnchor(IDOK,BOTTOM_RIGHT);
62 AddAnchor(IDCANCEL,BOTTOM_RIGHT);
63 AddAnchor(IDHELP, BOTTOM_RIGHT);
64 AddAnchor(IDC_GROUP_MESSAGE,TOP_LEFT,BOTTOM_RIGHT);
65 AddAnchor(IDC_EDIT_MESSAGE,TOP_LEFT,BOTTOM_RIGHT);
67 this->AddOthersToAnchor();
69 if(m_Base.IsEmpty())
71 this->SetDefaultChoose(IDC_RADIO_HEAD);
73 }else
75 this->SetDefaultChoose(IDC_RADIO_VERSION);
76 this->GetDlgItem(IDC_COMBOBOXEX_VERSION)->SetWindowTextW(m_Base);
79 Init();
81 this->GetDlgItem(IDC_CHECK_TRACK)->EnableWindow(FALSE);
83 if(this->m_bIsTag)
85 this->SetWindowTextW(_T("Create Tag"));
86 this->GetDlgItem(IDC_LABEL_BRANCH)->SetWindowTextW(_T("Tag"));
88 else
90 this->SetWindowTextW(_T("Create Branch"));
91 this->GetDlgItem(IDC_LABEL_BRANCH)->SetWindowTextW(_T("Branch"));
92 this->GetDlgItem(IDC_EDIT_MESSAGE)->EnableWindow(false);
94 // show the switch checkbox if we are a create branch dialog
95 this->GetDlgItem(IDC_CHECK_SWITCH)->ShowWindow( !m_bIsTag );
96 CWnd* pHead = GetDlgItem(IDC_RADIO_HEAD);
97 CString HeadText;
98 pHead->GetWindowText( HeadText );
99 pHead->SetWindowText( HeadText + " (" + g_Git.GetCurrentBranch() + ")");
100 EnableSaveRestore(_T("BranchTagDlg"));
102 OnCbnSelchangeComboboxexBranch();
103 return TRUE;
107 // CCreateBranchTagDlg message handlers
109 void CCreateBranchTagDlg::OnBnClickedOk()
111 // TODO: Add your control notification handler code here
112 this->UpdateData(TRUE);
114 this->m_BranchTagName.Trim();
115 if(this->m_BranchTagName.IsEmpty() || this->m_BranchTagName.Find(' ') >= 0 )
117 CMessageBox::Show(NULL, IDS_B_T_NOTEMPTY, IDS_TORTOISEGIT, MB_OK);
118 return;
120 this->UpdateRevsionName();
121 OnOK();
124 void CCreateBranchTagDlg::OnCbnSelchangeComboboxexBranch()
126 // TODO: Add your control notification handler code here
128 if(this->m_ChooseVersioinBranch.GetString().Left(8)==_T("remotes/"))
130 bool isDefault = false;
131 this->UpdateData();
133 CString str = this->m_OldSelectBranch;
134 int start = str.ReverseFind(_T('/'));
135 if(start>=0)
136 str=str.Mid(start+1);
137 if(str == m_BranchTagName)
138 isDefault =true;
140 if( m_BranchTagName.IsEmpty() || isDefault)
142 this->GetDlgItem(IDC_CHECK_TRACK)->EnableWindow(TRUE);
144 m_BranchTagName= m_ChooseVersioinBranch.GetString();
145 int start =0;
146 start = m_BranchTagName.ReverseFind(_T('/'));
147 if(start>=0)
148 m_BranchTagName = m_BranchTagName.Mid(start+1);
150 UpdateData(FALSE);
153 else
154 this->GetDlgItem(IDC_CHECK_TRACK)->EnableWindow(FALSE);
156 if(this->m_bIsTag)
157 this->GetDlgItem(IDC_CHECK_TRACK)->EnableWindow(FALSE);
159 m_OldSelectBranch = m_ChooseVersioinBranch.GetString();
162 void CCreateBranchTagDlg::OnVersionChanged()
164 int radio=GetCheckedRadioButton(IDC_RADIO_HEAD,IDC_RADIO_VERSION);
165 if (radio == IDC_RADIO_BRANCH)
166 OnCbnSelchangeComboboxexBranch();
167 else
168 GetDlgItem(IDC_CHECK_TRACK)->EnableWindow(FALSE);
171 void CCreateBranchTagDlg::OnDestroy()
173 WaitForFinishLoading();
174 __super::OnDestroy();
176 // TODO: Add your message handler code here