OSDN Git Service

Fix issue 17 Switch should default branch to current branch
[tortoisegit/TortoiseGitJp.git] / src / TortoiseProc / GitSwitchDlg.cpp
1 // GitSwitch.cpp : implementation file\r
2 //\r
3 \r
4 #include "stdafx.h"\r
5 #include "Git.h"\r
6 #include "TortoiseProc.h"\r
7 #include "GitSwitchDlg.h"\r
8 \r
9 \r
10 #include "Messagebox.h"\r
11 \r
12 // CGitSwitchDlg dialog\r
13 \r
14 IMPLEMENT_DYNAMIC(CGitSwitchDlg, CResizableStandAloneDialog)\r
15 \r
16 CGitSwitchDlg::CGitSwitchDlg(CWnd* pParent /*=NULL*/)\r
17         : CResizableStandAloneDialog(CGitSwitchDlg::IDD, pParent)\r
18         ,CChooseVersion(this)\r
19 {\r
20         m_bBranch=FALSE;\r
21 }\r
22 \r
23 CGitSwitchDlg::~CGitSwitchDlg()\r
24 {\r
25 }\r
26 \r
27 void CGitSwitchDlg::DoDataExchange(CDataExchange* pDX)\r
28 {\r
29         CDialog::DoDataExchange(pDX);\r
30         CHOOSE_VERSION_DDX;\r
31                                 \r
32         DDX_Check(pDX,IDC_CHECK_FORCE,this->m_bForce);\r
33         DDX_Check(pDX,IDC_CHECK_TRACK,this->m_bTrack);\r
34         DDX_Check(pDX,IDC_CHECK_BRANCH,this->m_bBranch);\r
35 \r
36         DDX_Text(pDX,IDC_EDIT_BRANCH,this->m_NewBranch);\r
37 }\r
38 \r
39 \r
40 BEGIN_MESSAGE_MAP(CGitSwitchDlg, CResizableStandAloneDialog)\r
41 \r
42         CHOOSE_VERSION_EVENT\r
43         ON_BN_CLICKED(IDC_CHECK_BRANCH, &CGitSwitchDlg::OnBnClickedCheckBranch)\r
44         ON_BN_CLICKED(IDOK, &CGitSwitchDlg::OnBnClickedOk)\r
45         ON_CBN_SELCHANGE(IDC_COMBOBOXEX_BRANCH, &CGitSwitchDlg::OnCbnSelchangeComboboxexBranch)\r
46 END_MESSAGE_MAP()\r
47 \r
48 BOOL CGitSwitchDlg::OnInitDialog()\r
49 {\r
50         CResizableStandAloneDialog::OnInitDialog();\r
51 \r
52         AddAnchor(IDC_GROUP_OPTION, TOP_LEFT, TOP_RIGHT);\r
53 \r
54         AddAnchor(IDC_EDIT_BRANCH, TOP_LEFT, TOP_RIGHT);\r
55 \r
56         AddAnchor(IDOK,BOTTOM_RIGHT);\r
57         AddAnchor(IDCANCEL,BOTTOM_RIGHT);\r
58 \r
59         \r
60         CHOOSE_VERSION_ADDANCHOR;\r
61 \r
62         EnableSaveRestore(_T("SwitchDlg"));\r
63 \r
64         Init();\r
65 \r
66         if(m_Base.IsEmpty())\r
67                 SetDefaultChoose(IDC_RADIO_BRANCH);\r
68         else\r
69         {\r
70                 this->GetDlgItem(IDC_COMBOBOXEX_VERSION)->SetWindowTextW(m_Base);\r
71                 SetDefaultChoose(IDC_RADIO_VERSION);\r
72         }\r
73 \r
74         OnBnClickedCheckBranch();\r
75         this->GetDlgItem(IDC_CHECK_TRACK)->EnableWindow(FALSE);\r
76 \r
77         return TRUE;\r
78 \r
79 \r
80 }\r
81 // CCreateBranchTagDlg message handlers\r
82 \r
83 void CGitSwitchDlg::OnBnClickedChooseRadioHost()\r
84 {\r
85         // TODO: Add your control notification handler code here\r
86         OnBnClickedChooseRadio();\r
87         OnCbnSelchangeComboboxexBranch();\r
88         OnBnClickedCheckBranch();\r
89         \r
90 }\r
91 \r
92 void CGitSwitchDlg::OnBnClickedOk()\r
93 {\r
94         this->UpdateData(TRUE);\r
95         \r
96         // make sure a valid branch has been entered if a new branch is required\r
97         if ( m_bBranch  &&  ( m_NewBranch.Trim().IsEmpty() ||  m_NewBranch.Find(' ') >= 0 ) )\r
98         {\r
99                 // new branch requested but name is empty or contains spaces\r
100                 CMessageBox::Show(NULL, IDS_B_T_NOTEMPTY, IDS_TORTOISEGIT, MB_OK);\r
101         }\r
102         else\r
103         {\r
104                 UpdateRevsionName();\r
105                 //this->m_Version.SaveHistory();\r
106                 OnOK();\r
107         }\r
108 }\r
109 void CGitSwitchDlg::OnBnClickedCheckBranch()\r
110 {\r
111         // TODO: Add your control notification handler code here\r
112         this->UpdateData(TRUE);\r
113         this->UpdateRevsionName();\r
114         GetDlgItem(IDC_EDIT_BRANCH)->SetWindowTextW(CString(_T("Branch_"))+this->m_VersionName);\r
115 \r
116 #if 0   \r
117         int radio=GetCheckedRadioButton(IDC_RADIO_BRANCH,IDC_RADIO_VERSION);\r
118         if(radio==IDC_RADIO_TAGS || radio==IDC_RADIO_VERSION)\r
119         {\r
120                 this->m_bBranch=TRUE;\r
121                 this->UpdateData(FALSE);\r
122                 this->UpdateRevsionName();\r
123                 \r
124         }else\r
125         {\r
126                 this->m_bBranch=FALSE;\r
127                 this->UpdateData(FALSE);\r
128         }\r
129 #endif\r
130         this->GetDlgItem(IDC_EDIT_BRANCH)->EnableWindow(this->m_bBranch);\r
131 }\r
132 \r
133 void CGitSwitchDlg::OnCbnSelchangeComboboxexBranch()\r
134 {\r
135         // TODO: Add your control notification handler code here\r
136         int radio=GetCheckedRadioButton(IDC_RADIO_BRANCH,IDC_RADIO_VERSION);\r
137         if(this->m_ChooseVersioinBranch.GetString().Left(6)==_T("origin") && radio==IDC_RADIO_BRANCH )\r
138                 this->GetDlgItem(IDC_CHECK_TRACK)->EnableWindow(TRUE);\r
139         else\r
140                 this->GetDlgItem(IDC_CHECK_TRACK)->EnableWindow(FALSE);\r
141 }\r