OSDN Git Service

0d5c108809923abe33e1e889d20ed781dddc3e6a
[tortoisegit/TortoiseGitJp.git] / src / TortoiseProc / SyncDlg.cpp
1 // TortoiseGit - a Windows shell extension for easy version control\r
2 \r
3 // Copyright (C) 2008-2009 - TortoiseGit\r
4 \r
5 // This program is free software; you can redistribute it and/or\r
6 // modify it under the terms of the GNU General Public License\r
7 // as published by the Free Software Foundation; either version 2\r
8 // of the License, or (at your option) any later version.\r
9 \r
10 // This program is distributed in the hope that it will be useful,\r
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of\r
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
13 // GNU General Public License for more details.\r
14 \r
15 // You should have received a copy of the GNU General Public License\r
16 // along with this program; if not, write to the Free Software Foundation,\r
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.\r
18 //\r
19 \r
20 // SyncDlg.cpp : implementation file\r
21 //\r
22 \r
23 #include "stdafx.h"\r
24 #include "TortoiseProc.h"\r
25 #include "SyncDlg.h"\r
26 \r
27 \r
28 // CSyncDlg dialog\r
29 \r
30 IMPLEMENT_DYNAMIC(CSyncDlg, CResizableStandAloneDialog)\r
31 \r
32 CSyncDlg::CSyncDlg(CWnd* pParent /*=NULL*/)\r
33         : CResizableStandAloneDialog(CSyncDlg::IDD, pParent)\r
34         , m_bAutoLoadPuttyKey(FALSE)\r
35 {\r
36         m_pTooltip=&this->m_tooltips;\r
37 }\r
38 \r
39 CSyncDlg::~CSyncDlg()\r
40 {\r
41 }\r
42 \r
43 void CSyncDlg::DoDataExchange(CDataExchange* pDX)\r
44 {\r
45         CDialog::DoDataExchange(pDX);\r
46         DDX_Check(pDX, IDC_CHECK_PUTTY_KEY, m_bAutoLoadPuttyKey);\r
47         DDX_Control(pDX, IDC_COMBOBOXEX_URL, m_ctrlURL);\r
48         DDX_Control(pDX, IDC_BUTTON_TABCTRL, m_ctrlDumyButton);\r
49         DDX_Control(pDX, IDC_BUTTON_PULL, m_ctrlPull);\r
50         DDX_Control(pDX, IDC_BUTTON_PUSH, m_ctrlPush);\r
51         DDX_Control(pDX, IDC_STATIC_STATUS, m_ctrlStatus);\r
52         DDX_Control(pDX, IDC_PROGRESS_SYNC, m_ctrlProgress);\r
53         DDX_Control(pDX, IDC_ANIMATE_SYNC, m_ctrlAnimate);\r
54 \r
55         BRANCH_COMBOX_DDX;\r
56 }\r
57 \r
58 \r
59 BEGIN_MESSAGE_MAP(CSyncDlg, CResizableStandAloneDialog)\r
60         ON_BN_CLICKED(IDC_BUTTON_PULL, &CSyncDlg::OnBnClickedButtonPull)\r
61         ON_BN_CLICKED(IDC_BUTTON_PUSH, &CSyncDlg::OnBnClickedButtonPush)\r
62         ON_BN_CLICKED(IDC_BUTTON_APPLY, &CSyncDlg::OnBnClickedButtonApply)\r
63         ON_BN_CLICKED(IDC_BUTTON_EMAIL, &CSyncDlg::OnBnClickedButtonEmail)\r
64         ON_BN_CLICKED(IDC_BUTTON_MANAGE, &CSyncDlg::OnBnClickedButtonManage)\r
65         BRANCH_COMBOX_EVENT\r
66         ON_NOTIFY(CBEN_ENDEDIT, IDC_COMBOBOXEX_URL, &CSyncDlg::OnCbenEndeditComboboxexUrl)\r
67         ON_CBN_EDITCHANGE(IDC_COMBOBOXEX_URL, &CSyncDlg::OnCbnEditchangeComboboxexUrl)\r
68 END_MESSAGE_MAP()\r
69 \r
70 \r
71 // CSyncDlg message handlers\r
72 \r
73 void CSyncDlg::OnBnClickedButtonPull()\r
74 {\r
75         // TODO: Add your control notification handler code here\r
76         this->m_regPullButton =this->m_ctrlPull.GetCurrentEntry();\r
77 }\r
78 \r
79 void CSyncDlg::OnBnClickedButtonPush()\r
80 {\r
81         // TODO: Add your control notification handler code here\r
82         this->m_regPushButton=this->m_ctrlPush.GetCurrentEntry();\r
83 \r
84 }\r
85 \r
86 void CSyncDlg::OnBnClickedButtonApply()\r
87 {\r
88         // TODO: Add your control notification handler code here\r
89 }\r
90 \r
91 void CSyncDlg::OnBnClickedButtonEmail()\r
92 {\r
93         // TODO: Add your control notification handler code here\r
94 }\r
95 \r
96 BOOL CSyncDlg::OnInitDialog()\r
97 {\r
98         CResizableStandAloneDialog::OnInitDialog();\r
99 \r
100         //Create Tabctrl\r
101         CWnd *pwnd=this->GetDlgItem(IDC_BUTTON_TABCTRL);\r
102         CRect rectDummy;\r
103         pwnd->GetWindowRect(&rectDummy);\r
104         this->ScreenToClient(rectDummy);\r
105 \r
106         if (!m_ctrlTabCtrl.Create(CMFCTabCtrl::STYLE_FLAT, rectDummy, this, IDC_SYNC_TAB))\r
107         {\r
108                 TRACE0("Failed to create output tab window\n");\r
109                 return FALSE;      // fail to create\r
110         }\r
111         m_ctrlTabCtrl.SetResizeMode(CMFCTabCtrl::RESIZE_NO);\r
112 \r
113         DWORD dwStyle =LVS_REPORT | LVS_SHOWSELALWAYS | LVS_ALIGNLEFT | LVS_OWNERDATA | WS_BORDER | WS_TABSTOP;\r
114 \r
115         if( !m_OutLogList.Create(dwStyle,rectDummy,&m_ctrlTabCtrl,IDC_OUT_LOGLIST))\r
116         {\r
117                 TRACE0("Failed to create output commits window\n");\r
118                 return FALSE;      // fail to create\r
119 \r
120         }\r
121         m_ctrlTabCtrl.InsertTab(&m_OutLogList,_T("Out Commits"),0);\r
122 \r
123         m_OutLogList.InsertGitColumn();\r
124 \r
125         dwStyle = LVS_REPORT | LVS_SHOWSELALWAYS | LVS_ALIGNLEFT | WS_BORDER | WS_TABSTOP |LVS_SINGLESEL |WS_CHILD | WS_VISIBLE;\r
126         \r
127         if( !m_OutChangeFileList.Create(dwStyle,rectDummy,&m_ctrlTabCtrl,IDC_OUT_CHANGELIST))\r
128         {\r
129                 TRACE0("Failed to create output change files window\n");\r
130                 return FALSE;      // fail to create\r
131         }\r
132         m_ctrlTabCtrl.InsertTab(&m_OutChangeFileList,_T("Out ChangeList"),1);\r
133 \r
134         m_OutChangeFileList.Init(SVNSLC_COLEXT | SVNSLC_COLSTATUS |SVNSLC_COLADD|SVNSLC_COLDEL , _T("RebaseDlg"),(SVNSLC_POPALL ^ SVNSLC_POPCOMMIT),false);\r
135 \r
136         this->m_tooltips.Create(this);\r
137 \r
138         AddAnchor(IDC_SYNC_TAB,TOP_LEFT,BOTTOM_RIGHT);\r
139 \r
140         AddAnchor(IDC_GROUP_INFO,TOP_LEFT,TOP_RIGHT);\r
141         AddAnchor(IDC_COMBOBOXEX_URL,TOP_LEFT,TOP_RIGHT);\r
142         AddAnchor(IDC_BUTTON_MANAGE,TOP_RIGHT);\r
143         AddAnchor(IDC_BUTTON_PULL,BOTTOM_LEFT);\r
144         AddAnchor(IDC_BUTTON_PUSH,BOTTOM_LEFT);\r
145         AddAnchor(IDC_BUTTON_APPLY,BOTTOM_LEFT);\r
146         AddAnchor(IDC_BUTTON_EMAIL,BOTTOM_LEFT);\r
147         AddAnchor(IDC_PROGRESS_SYNC,BOTTOM_LEFT,BOTTOM_RIGHT);\r
148         AddAnchor(IDOK,BOTTOM_RIGHT);\r
149         AddAnchor(IDHELP,BOTTOM_RIGHT);\r
150         AddAnchor(IDC_STATIC_STATUS,BOTTOM_LEFT);\r
151         AddAnchor(IDC_ANIMATE_SYNC,TOP_RIGHT);\r
152         \r
153         BRANCH_COMBOX_ADD_ANCHOR();\r
154 \r
155         CString WorkingDir=g_Git.m_CurrentDir;\r
156         WorkingDir.Replace(_T(':'),_T('_'));\r
157         m_RegKeyRemoteBranch = CString(_T("Software\\TortoiseGit\\History\\SyncBranch\\"))+WorkingDir;\r
158 \r
159 \r
160         this->AddOthersToAnchor();\r
161         // TODO:  Add extra initialization here\r
162 \r
163         this->m_ctrlPush.AddEntry(CString(_T("Push")));\r
164         this->m_ctrlPush.AddEntry(CString(_T("Push tags")));\r
165         this->m_ctrlPush.AddEntry(CString(_T("Push All")));\r
166 \r
167         this->m_ctrlPull.AddEntry(CString(_T("&Pull")));\r
168         this->m_ctrlPull.AddEntry(CString(_T("&Fetch")));\r
169         this->m_ctrlPull.AddEntry(CString(_T("Fetch&&Rebase")));\r
170 \r
171         \r
172         WorkingDir.Replace(_T(':'),_T('_'));\r
173 \r
174         CString regkey ;\r
175         regkey.Format(_T("Software\\TortoiseGit\\TortoiseProc\\Sync\\%s"),WorkingDir);\r
176 \r
177         this->m_regPullButton = CRegDWORD(regkey+_T("\\Pull"),0);\r
178         this->m_regPushButton = CRegDWORD(regkey+_T("\\Push"),0);\r
179 \r
180         this->m_ctrlPull.SetCurrentEntry(this->m_regPullButton);\r
181         this->m_ctrlPush.SetCurrentEntry(this->m_regPushButton);\r
182 \r
183         CString str;\r
184         this->GetWindowText(str);\r
185         str += _T(" - ") + g_Git.m_CurrentDir;\r
186         this->SetWindowText(str);\r
187 \r
188         EnableSaveRestore(_T("SyncDlg"));\r
189 \r
190         this->LoadBranchInfo();\r
191 \r
192         \r
193         return TRUE;  // return TRUE unless you set the focus to a control\r
194         // EXCEPTION: OCX Property Pages should return FALSE\r
195 }\r
196 \r
197 void CSyncDlg::OnBnClickedButtonManage()\r
198 {\r
199         // TODO: Add your control notification handler code here\r
200         CAppUtils::LaunchRemoteSetting();\r
201 }\r
202 \r
203 BOOL CSyncDlg::PreTranslateMessage(MSG* pMsg)\r
204 {\r
205         // TODO: Add your specialized code here and/or call the base class\r
206         m_tooltips.RelayEvent(pMsg);\r
207         return __super::PreTranslateMessage(pMsg);\r
208 }\r
209 void CSyncDlg::FetchOutList()\r
210 {\r
211         m_OutChangeFileList.Clear();\r
212         this->m_OutLogList.Clear();\r
213 \r
214         CString remote;\r
215         this->m_ctrlURL.GetWindowText(remote);\r
216         CString remotebranch;\r
217         this->m_ctrlRemoteBranch.GetWindowText(remotebranch);\r
218         remotebranch=remote+_T("/")+remotebranch;\r
219 \r
220         if(IsURL())\r
221         {\r
222                 CString str;\r
223                 str=_T("Don't know what will push befause you enter URL");\r
224                 m_OutLogList.ShowText(str);\r
225                 this->m_ctrlTabCtrl.ShowTab(m_OutChangeFileList.GetDlgCtrlID()-1,FALSE);\r
226                 m_OutLocalBranch.Empty();\r
227                 m_OutRemoteBranch.Empty();\r
228                 return ;\r
229         \r
230         }else if(g_Git.GetHash(remotebranch).GetLength()<40)\r
231         {\r
232                 CString str;\r
233                 str.Format(_T("Don't know what will push befause unkown \"%s\""),remotebranch);\r
234                 m_OutLogList.ShowText(str);\r
235                 this->m_ctrlTabCtrl.ShowTab(m_OutChangeFileList.GetDlgCtrlID()-1,FALSE);\r
236                 m_OutLocalBranch.Empty();\r
237                 m_OutRemoteBranch.Empty();\r
238                 return ;\r
239         }\r
240         else\r
241         {\r
242                 CString localbranch;\r
243                 localbranch=this->m_ctrlLocalBranch.GetString();\r
244 \r
245                 if(localbranch != m_OutLocalBranch && m_OutRemoteBranch != remotebranch)\r
246                 {\r
247                         m_OutLogList.ClearText();\r
248                         m_OutLogList.FillGitLog(NULL,CGit::     LOG_INFO_STAT| CGit::LOG_INFO_FILESTATE | CGit::LOG_INFO_SHOW_MERGEDFILE,\r
249                                 &remotebranch,&localbranch);\r
250                 }\r
251                 this->m_OutLocalBranch=localbranch;\r
252                 this->m_OutRemoteBranch=remotebranch;\r
253         }\r
254 \r
255 }\r
256 \r
257 bool CSyncDlg::IsURL()\r
258 {\r
259         CString str;\r
260         this->m_ctrlURL.GetWindowText(str);\r
261         if(str.Find(_T('\\'))>=0 || str.Find(_T('/'))>=0)\r
262                 return true;\r
263         else\r
264                 return false;\r
265 }\r
266 void CSyncDlg::OnCbenEndeditComboboxexUrl(NMHDR *pNMHDR, LRESULT *pResult)\r
267 {\r
268         // TODO: Add your control notification handler code here\r
269         *pResult = 0;\r
270 }\r
271 \r
272 void CSyncDlg::OnCbnEditchangeComboboxexUrl()\r
273 {\r
274         this->FetchOutList();\r
275         // TODO: Add your control notification handler code here\r
276 }\r