OSDN Git Service

e26b4621872a9b415d53550e402e2041d8fffa90
[tortoisegit/TortoiseGitJp.git] / src / TortoiseProc / PushDlg.cpp
1 // PushDlg.cpp : implementation file\r
2 //\r
3 \r
4 #include "stdafx.h"\r
5 #include "TortoiseProc.h"\r
6 #include "PushDlg.h"\r
7 \r
8 #include "Git.h"\r
9 #include "registry.h"\r
10 #include "AppUtils.h"\r
11 #include "BrowseRefsDlg.h"\r
12 \r
13 // CPushDlg dialog\r
14 \r
15 IMPLEMENT_DYNAMIC(CPushDlg, CResizableStandAloneDialog)\r
16 \r
17 CPushDlg::CPushDlg(CWnd* pParent /*=NULL*/)\r
18         : CResizableStandAloneDialog(CPushDlg::IDD, pParent)\r
19 {\r
20     m_bAutoLoad = CAppUtils::IsSSHPutty();\r
21 }\r
22 \r
23 CPushDlg::~CPushDlg()\r
24 {\r
25 }\r
26 \r
27 void CPushDlg::DoDataExchange(CDataExchange* pDX)\r
28 {\r
29         CResizableStandAloneDialog::DoDataExchange(pDX);\r
30         DDX_Control(pDX, IDC_BRANCH_REMOTE, this->m_BranchRemote);\r
31         DDX_Control(pDX, IDC_BRANCH_SOURCE, this->m_BranchSource);\r
32         DDX_Control(pDX, IDC_REMOTE, this->m_Remote);\r
33         DDX_Control(pDX, IDC_URL, this->m_RemoteURL);\r
34         DDX_Check(pDX,IDC_FORCE,this->m_bForce);\r
35         DDX_Check(pDX,IDC_PACK,this->m_bPack);\r
36         DDX_Check(pDX,IDC_TAGS,this->m_bTags);\r
37     DDX_Check(pDX,IDC_PUTTYKEY_AUTOLOAD,this->m_bAutoLoad);\r
38 \r
39 }\r
40 \r
41 \r
42 BEGIN_MESSAGE_MAP(CPushDlg, CResizableStandAloneDialog)\r
43         ON_BN_CLICKED(IDC_RD_REMOTE, &CPushDlg::OnBnClickedRd)\r
44         ON_BN_CLICKED(IDC_RD_URL, &CPushDlg::OnBnClickedRd)\r
45         ON_CBN_SELCHANGE(IDC_BRANCH_SOURCE, &CPushDlg::OnCbnSelchangeBranchSource)\r
46         ON_BN_CLICKED(IDOK, &CPushDlg::OnBnClickedOk)\r
47     ON_BN_CLICKED(IDC_REMOTE_MANAGE, &CPushDlg::OnBnClickedRemoteManage)\r
48         ON_BN_CLICKED(IDC_BUTTON_BROWSE_SOURCE_BRANCH, &CPushDlg::OnBnClickedButtonBrowseSourceBranch)\r
49         ON_BN_CLICKED(IDC_BUTTON_BROWSE_DEST_BRANCH, &CPushDlg::OnBnClickedButtonBrowseDestBranch)\r
50 END_MESSAGE_MAP()\r
51 \r
52 BOOL CPushDlg::OnInitDialog()\r
53 {\r
54         CResizableStandAloneDialog::OnInitDialog();\r
55         \r
56         AddAnchor(IDOK,BOTTOM_RIGHT);\r
57         AddAnchor(IDCANCEL,BOTTOM_RIGHT);\r
58         AddAnchor(IDC_BRANCH_GROUP, TOP_LEFT,TOP_RIGHT);\r
59         AddAnchor(IDC_STATIC_REMOTE, TOP_RIGHT);\r
60         AddAnchor(IDC_STATIC_SOURCE, TOP_LEFT);\r
61 \r
62         AddAnchor(IDC_BRANCH_REMOTE, TOP_RIGHT);\r
63         AddAnchor(IDC_BUTTON_BROWSE_DEST_BRANCH, TOP_RIGHT);\r
64         AddAnchor(IDC_BRANCH_SOURCE, TOP_LEFT);\r
65         AddAnchor(IDC_BUTTON_BROWSE_SOURCE_BRANCH, TOP_LEFT);\r
66 \r
67         AddAnchor(IDC_URL_GROUP, TOP_LEFT,TOP_RIGHT);\r
68         AddAnchor(IDC_RD_REMOTE, TOP_LEFT);\r
69         AddAnchor(IDC_RD_URL, TOP_LEFT);\r
70 \r
71         AddAnchor(IDC_REMOTE, TOP_LEFT, TOP_RIGHT);\r
72         \r
73         AddAnchor(IDC_URL, TOP_LEFT,TOP_RIGHT);\r
74 \r
75         AddAnchor(IDC_OPTION_GROUP, TOP_LEFT,TOP_RIGHT);\r
76         \r
77         AddAnchor(IDC_FORCE, TOP_LEFT);\r
78         AddAnchor(IDC_PACK, TOP_LEFT);\r
79         AddAnchor(IDC_TAGS, TOP_LEFT);\r
80     AddAnchor(IDC_PUTTYKEY_AUTOLOAD,TOP_LEFT);\r
81 \r
82     AddAnchor(IDC_REMOTE_MANAGE,TOP_RIGHT);\r
83 \r
84         AddOthersToAnchor();\r
85 \r
86     this->GetDlgItem(IDC_PUTTYKEY_AUTOLOAD)->EnableWindow(m_bAutoLoad);\r
87 \r
88         EnableSaveRestore(_T("PushDlg"));\r
89 \r
90         m_RemoteURL.SetURLHistory(TRUE);\r
91         \r
92         CString WorkingDir=g_Git.m_CurrentDir;\r
93         WorkingDir.Replace(_T(':'),_T('_'));\r
94         m_RemoteURL.LoadHistory(CString(_T("Software\\TortoiseGit\\History\\PushURLS\\"))+WorkingDir, _T("url"));\r
95         CString clippath=CAppUtils::GetClipboardLink();\r
96         if(clippath.IsEmpty())\r
97                 m_RemoteURL.SetCurSel(0);\r
98         else\r
99                 m_RemoteURL.SetWindowText(clippath);\r
100 \r
101         m_RemoteURL.EnableWindow(FALSE);\r
102         CheckRadioButton(IDC_RD_REMOTE,IDC_RD_URL,IDC_RD_REMOTE);\r
103 \r
104         STRING_VECTOR list;\r
105         CRegString remote(CString(_T("Software\\TortoiseGit\\History\\PushRemote\\")+WorkingDir));\r
106         m_RemoteReg = remote;\r
107         int sel=0;\r
108 \r
109         if(!g_Git.GetRemoteList(list))\r
110         {       \r
111                 for(unsigned int i=0;i<list.size();i++)\r
112                 {\r
113                         m_Remote.AddString(list[i]);\r
114                         if(list[i] == remote)\r
115                                 sel = i;\r
116                 }\r
117         }\r
118         m_Remote.SetCurSel(sel);\r
119 \r
120         int current=0;\r
121         list.clear();\r
122         if(!g_Git.GetBranchList(list,&current))\r
123         {\r
124                 for(unsigned int i=0;i<list.size();i++)\r
125                         m_BranchSource.AddString(list[i]);\r
126         }\r
127         m_BranchSource.SetCurSel(current);\r
128         \r
129         m_BranchRemote.LoadHistory(CString(_T("Software\\TortoiseGit\\History\\RemoteBranch\\"))+WorkingDir, _T("branch"));\r
130         m_BranchRemote.SetCurSel(0);\r
131 \r
132         //m_BranchRemote.SetWindowTextW(m_BranchSource.GetString());\r
133 \r
134         \r
135         return TRUE;\r
136 }\r
137 \r
138 // CPushDlg message handlers\r
139 \r
140 void CPushDlg::OnBnClickedRd()\r
141 {\r
142         // TODO: Add your control notification handler code here\r
143         // TODO: Add your control notification handler code here\r
144         if( GetCheckedRadioButton(IDC_RD_REMOTE,IDC_RD_URL) == IDC_RD_REMOTE)\r
145         {\r
146                 m_Remote.EnableWindow(TRUE);\r
147                 m_RemoteURL.EnableWindow(FALSE);;\r
148         }\r
149         if( GetCheckedRadioButton(IDC_RD_REMOTE,IDC_RD_URL) == IDC_RD_URL)\r
150         {\r
151                 m_Remote.EnableWindow(FALSE);\r
152                 m_RemoteURL.EnableWindow(TRUE);\r
153         }\r
154 }\r
155 \r
156 \r
157 void CPushDlg::OnCbnSelchangeBranchSource()\r
158 {\r
159         // TODO: Add your control notification handler code here\r
160         m_BranchRemote.SetWindowTextW(m_BranchSource.GetString());\r
161 }\r
162 \r
163 void CPushDlg::OnBnClickedOk()\r
164 {\r
165         // TODO: Add your control notification handler code here\r
166         CResizableStandAloneDialog::UpdateData(TRUE);\r
167 \r
168         if( GetCheckedRadioButton(IDC_RD_REMOTE,IDC_RD_URL) == IDC_RD_REMOTE)\r
169         {\r
170                 m_URL=m_Remote.GetString();\r
171         }\r
172         if( GetCheckedRadioButton(IDC_RD_REMOTE,IDC_RD_URL) == IDC_RD_URL)\r
173         {\r
174                 m_URL=m_RemoteURL.GetString();\r
175         }\r
176 \r
177         this->m_BranchRemoteName=m_BranchRemote.GetString();\r
178         this->m_BranchSourceName=m_BranchSource.GetString();\r
179 \r
180         this->m_RemoteURL.SaveHistory();\r
181         this->m_BranchRemote.SaveHistory();\r
182         \r
183         m_RemoteReg = m_Remote.GetString();\r
184 \r
185         CResizableStandAloneDialog::OnOK();\r
186 }\r
187 \r
188 void CPushDlg::OnBnClickedRemoteManage()\r
189 {\r
190     // TODO: Add your control notification handler code here\r
191     CAppUtils::LaunchRemoteSetting();\r
192 }\r
193 \r
194 void CPushDlg::OnBnClickedButtonBrowseSourceBranch()\r
195 {\r
196         if(CBrowseRefsDlg::PickRefForCombo(&m_BranchSource, gPickRef_Head))\r
197                 OnCbnSelchangeBranchSource();\r
198 }\r
199 \r
200 void CPushDlg::OnBnClickedButtonBrowseDestBranch()\r
201 {\r
202         CString remoteBranchName;\r
203         m_BranchRemote.GetWindowText(remoteBranchName);\r
204         remoteBranchName = CBrowseRefsDlg::PickRef(false, remoteBranchName, gPickRef_Remote);\r
205         if(remoteBranchName.IsEmpty())\r
206                 return; //Canceled\r
207         remoteBranchName = remoteBranchName.Mid(13);//Strip 'refs/remotes/'\r
208         remoteBranchName = remoteBranchName.Mid(remoteBranchName.Find('/') + 1); //Strip remote name (for example 'origin/')\r
209 \r
210         m_BranchRemote.SetWindowText(remoteBranchName);\r
211 }\r