OSDN Git Service

Add "F5" refresh remote and branch info at push dialog
[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         AddAnchor(IDHELP, BOTTOM_RIGHT);\r
84 \r
85         AddOthersToAnchor();\r
86 \r
87     this->GetDlgItem(IDC_PUTTYKEY_AUTOLOAD)->EnableWindow(m_bAutoLoad);\r
88 \r
89         EnableSaveRestore(_T("PushDlg"));\r
90 \r
91         m_RemoteURL.SetURLHistory(TRUE);\r
92         \r
93         CString WorkingDir=g_Git.m_CurrentDir;\r
94         WorkingDir.Replace(_T(':'),_T('_'));\r
95         m_RemoteURL.LoadHistory(CString(_T("Software\\TortoiseGit\\History\\PushURLS\\"))+WorkingDir, _T("url"));\r
96         CString clippath=CAppUtils::GetClipboardLink();\r
97         if(clippath.IsEmpty())\r
98                 m_RemoteURL.SetCurSel(0);\r
99         else\r
100                 m_RemoteURL.SetWindowText(clippath);\r
101 \r
102         m_RemoteURL.EnableWindow(FALSE);\r
103         CheckRadioButton(IDC_RD_REMOTE,IDC_RD_URL,IDC_RD_REMOTE);\r
104 \r
105 \r
106         Refresh();\r
107 \r
108         m_BranchRemote.LoadHistory(CString(_T("Software\\TortoiseGit\\History\\RemoteBranch\\"))+WorkingDir, _T("branch"));\r
109         m_BranchRemote.SetCurSel(0);\r
110 \r
111         //m_BranchRemote.SetWindowTextW(m_BranchSource.GetString());\r
112 \r
113         \r
114         return TRUE;\r
115 }\r
116 \r
117 void CPushDlg::Refresh()\r
118 {\r
119         CString WorkingDir=g_Git.m_CurrentDir;\r
120         WorkingDir.Replace(_T(':'),_T('_'));\r
121 \r
122         CRegString remote(CString(_T("Software\\TortoiseGit\\History\\PushRemote\\")+WorkingDir));\r
123         m_RemoteReg = remote;\r
124         int sel=0;\r
125 \r
126         STRING_VECTOR list;\r
127         m_Remote.Reset();\r
128 \r
129         if(!g_Git.GetRemoteList(list))\r
130         {       \r
131                 for(unsigned int i=0;i<list.size();i++)\r
132                 {\r
133                         m_Remote.AddString(list[i]);\r
134                         if(list[i] == remote)\r
135                                 sel = i;\r
136                 }\r
137         }\r
138         m_Remote.SetCurSel(sel);\r
139 \r
140         int current=0;\r
141         list.clear();\r
142         m_BranchSource.Reset();\r
143         if(!g_Git.GetBranchList(list,&current))\r
144         {\r
145                 for(unsigned int i=0;i<list.size();i++)\r
146                         m_BranchSource.AddString(list[i]);\r
147         }\r
148         m_BranchSource.SetCurSel(current);\r
149 \r
150 }\r
151 // CPushDlg message handlers\r
152 \r
153 void CPushDlg::OnBnClickedRd()\r
154 {\r
155         // TODO: Add your control notification handler code here\r
156         // TODO: Add your control notification handler code here\r
157         if( GetCheckedRadioButton(IDC_RD_REMOTE,IDC_RD_URL) == IDC_RD_REMOTE)\r
158         {\r
159                 m_Remote.EnableWindow(TRUE);\r
160                 m_RemoteURL.EnableWindow(FALSE);;\r
161         }\r
162         if( GetCheckedRadioButton(IDC_RD_REMOTE,IDC_RD_URL) == IDC_RD_URL)\r
163         {\r
164                 m_Remote.EnableWindow(FALSE);\r
165                 m_RemoteURL.EnableWindow(TRUE);\r
166         }\r
167 }\r
168 \r
169 \r
170 void CPushDlg::OnCbnSelchangeBranchSource()\r
171 {\r
172         // TODO: Add your control notification handler code here\r
173         m_BranchRemote.AddString(m_BranchSource.GetString());\r
174 }\r
175 \r
176 void CPushDlg::OnBnClickedOk()\r
177 {\r
178         // TODO: Add your control notification handler code here\r
179         CResizableStandAloneDialog::UpdateData(TRUE);\r
180 \r
181         if( GetCheckedRadioButton(IDC_RD_REMOTE,IDC_RD_URL) == IDC_RD_REMOTE)\r
182         {\r
183                 m_URL=m_Remote.GetString();\r
184         }\r
185         if( GetCheckedRadioButton(IDC_RD_REMOTE,IDC_RD_URL) == IDC_RD_URL)\r
186         {\r
187                 m_URL=m_RemoteURL.GetString();\r
188         }\r
189 \r
190         this->m_BranchRemoteName=m_BranchRemote.GetString();\r
191         this->m_BranchSourceName=m_BranchSource.GetString();\r
192 \r
193         this->m_RemoteURL.SaveHistory();\r
194         this->m_BranchRemote.SaveHistory();\r
195         \r
196         m_RemoteReg = m_Remote.GetString();\r
197 \r
198         CResizableStandAloneDialog::OnOK();\r
199 }\r
200 \r
201 void CPushDlg::OnBnClickedRemoteManage()\r
202 {\r
203     // TODO: Add your control notification handler code here\r
204     CAppUtils::LaunchRemoteSetting();\r
205 }\r
206 \r
207 void CPushDlg::OnBnClickedButtonBrowseSourceBranch()\r
208 {\r
209         if(CBrowseRefsDlg::PickRefForCombo(&m_BranchSource, gPickRef_Head))\r
210                 OnCbnSelchangeBranchSource();\r
211 }\r
212 \r
213 void CPushDlg::OnBnClickedButtonBrowseDestBranch()\r
214 {\r
215         CString remoteBranchName;\r
216         CString remoteName;\r
217         m_BranchRemote.GetWindowText(remoteBranchName);\r
218         remoteName = m_Remote.GetString();\r
219         remoteBranchName = remoteName + '/' + remoteBranchName;\r
220         remoteBranchName = CBrowseRefsDlg::PickRef(false, remoteBranchName, gPickRef_Remote);\r
221         if(remoteBranchName.IsEmpty())\r
222                 return; //Canceled\r
223         remoteBranchName = remoteBranchName.Mid(13);//Strip 'refs/remotes/'\r
224         int slashPlace = remoteBranchName.Find('/');\r
225         remoteName = remoteBranchName.Left(slashPlace);\r
226         remoteBranchName = remoteBranchName.Mid(slashPlace + 1); //Strip remote name (for example 'origin/')\r
227 \r
228         //Select remote\r
229         int remoteSel = m_Remote.FindStringExact(0,remoteName);\r
230         if(remoteSel >= 0)\r
231                 m_Remote.SetCurSel(remoteSel);\r
232 \r
233         //Select branch\r
234         m_BranchRemote.AddString(remoteBranchName);\r
235 }\r
236 \r
237 BOOL CPushDlg::PreTranslateMessage(MSG* pMsg)\r
238 {\r
239         if (pMsg->message == WM_KEYDOWN)\r
240         {\r
241                 switch (pMsg->wParam)\r
242                 {\r
243                 case VK_F5:\r
244                         {\r
245                                 Refresh();\r
246                         }\r
247                         break;\r
248                 }\r
249         }\r
250 \r
251         return CResizableStandAloneDialog::PreTranslateMessage(pMsg);\r
252 }\r