OSDN Git Service

Share resource file between TortoiseGitBlame and TortoiseProc
[tortoisegit/TortoiseGitJp.git] / src / TortoiseProc / ChangedDlg.cpp
1 // TortoiseSVN - a Windows shell extension for easy version control\r
2 \r
3 // Copyright (C) 2003-2008 - TortoiseSVN\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 #include "stdafx.h"\r
20 #include "TortoiseProc.h"\r
21 #include "ChangedDlg.h"\r
22 #include "messagebox.h"\r
23 #include "cursor.h"\r
24 #include ".\changeddlg.h"\r
25 \r
26 #include "GitStatusListCtrl.h"\r
27 \r
28 #include "CommonResource.h"\r
29 \r
30 IMPLEMENT_DYNAMIC(CChangedDlg, CResizableStandAloneDialog)\r
31 CChangedDlg::CChangedDlg(CWnd* pParent /*=NULL*/)\r
32         : CResizableStandAloneDialog(CChangedDlg::IDD, pParent)\r
33         , m_bShowUnversioned(FALSE)\r
34         , m_iShowUnmodified(0)\r
35         , m_bBlock(FALSE)\r
36         , m_bCanceled(false)\r
37         , m_bShowIgnored(FALSE)\r
38         , m_bShowExternals(TRUE)\r
39     , m_bShowUserProps(FALSE)\r
40 {\r
41         m_bRemote = FALSE;\r
42 }\r
43 \r
44 CChangedDlg::~CChangedDlg()\r
45 {\r
46 }\r
47 \r
48 void CChangedDlg::DoDataExchange(CDataExchange* pDX)\r
49 {\r
50         CResizableStandAloneDialog::DoDataExchange(pDX);\r
51         DDX_Control(pDX, IDC_CHANGEDLIST, m_FileListCtrl);\r
52         DDX_Check(pDX, IDC_SHOWUNVERSIONED, m_bShowUnversioned);\r
53         DDX_Check(pDX, IDC_SHOWUNMODIFIED, m_iShowUnmodified);\r
54         DDX_Check(pDX, IDC_SHOWIGNORED, m_bShowIgnored);\r
55 //      DDX_Check(pDX, IDC_SHOWEXTERNALS, m_bShowExternals);\r
56 //      DDX_Check(pDX, IDC_SHOWUSERPROPS, m_bShowUserProps);\r
57 }\r
58 \r
59 \r
60 BEGIN_MESSAGE_MAP(CChangedDlg, CResizableStandAloneDialog)\r
61         ON_BN_CLICKED(IDC_CHECKREPO, OnBnClickedCheckrepo)\r
62         ON_BN_CLICKED(IDC_SHOWUNVERSIONED, OnBnClickedShowunversioned)\r
63         ON_BN_CLICKED(IDC_SHOWUNMODIFIED, OnBnClickedShowUnmodified)\r
64 //    ON_BN_CLICKED(IDC_SHOWUSERPROPS, OnBnClickedShowUserProps)\r
65         ON_REGISTERED_MESSAGE(CGitStatusListCtrl::SVNSLNM_NEEDSREFRESH, OnSVNStatusListCtrlNeedsRefresh)\r
66         ON_REGISTERED_MESSAGE(CGitStatusListCtrl::SVNSLNM_ITEMCOUNTCHANGED, OnSVNStatusListCtrlItemCountChanged)\r
67         ON_BN_CLICKED(IDC_SHOWIGNORED, &CChangedDlg::OnBnClickedShowignored)\r
68         ON_BN_CLICKED(IDC_REFRESH, &CChangedDlg::OnBnClickedRefresh)\r
69 //      ON_BN_CLICKED(IDC_SHOWEXTERNALS, &CChangedDlg::OnBnClickedShowexternals)\r
70 END_MESSAGE_MAP()\r
71 \r
72 BOOL CChangedDlg::OnInitDialog()\r
73 {\r
74         CResizableStandAloneDialog::OnInitDialog();\r
75         \r
76         GetWindowText(m_sTitle);\r
77 \r
78         m_tooltips.Create(this);\r
79 \r
80         m_regAddBeforeCommit = CRegDWORD(_T("Software\\TortoiseGit\\AddBeforeCommit"), TRUE);\r
81         m_bShowUnversioned = m_regAddBeforeCommit;\r
82         UpdateData(FALSE);\r
83 \r
84         m_FileListCtrl.Init(SVNSLC_COLEXT | SVNSLC_COLSTATUS, _T("ChangedDlg"),\r
85                                                 SVNSLC_POPALL, false);\r
86         m_FileListCtrl.SetCancelBool(&m_bCanceled);\r
87         m_FileListCtrl.SetBackgroundImage(IDI_CFM_BKG);\r
88         m_FileListCtrl.SetEmptyString(IDS_REPOSTATUS_EMPTYFILELIST);\r
89         \r
90         AdjustControlSize(IDC_SHOWUNVERSIONED);\r
91         AdjustControlSize(IDC_SHOWUNMODIFIED);\r
92         AdjustControlSize(IDC_SHOWIGNORED);\r
93 //      AdjustControlSize(IDC_SHOWEXTERNALS);\r
94 //    AdjustControlSize(IDC_SHOWUSERPROPS);\r
95 \r
96         AddAnchor(IDC_CHANGEDLIST, TOP_LEFT, BOTTOM_RIGHT);\r
97         AddAnchor(IDC_SUMMARYTEXT, BOTTOM_LEFT, BOTTOM_RIGHT);\r
98         AddAnchor(IDC_SHOWUNVERSIONED, BOTTOM_LEFT);\r
99         AddAnchor(IDC_SHOWUNMODIFIED, BOTTOM_LEFT);\r
100         AddAnchor(IDC_SHOWIGNORED, BOTTOM_LEFT);\r
101 //      AddAnchor(IDC_SHOWEXTERNALS, BOTTOM_LEFT);\r
102 //      AddAnchor(IDC_SHOWUSERPROPS, BOTTOM_LEFT);\r
103         AddAnchor(IDC_INFOLABEL, BOTTOM_RIGHT);\r
104         AddAnchor(IDC_REFRESH, BOTTOM_RIGHT);\r
105         AddAnchor(IDC_CHECKREPO, BOTTOM_RIGHT);\r
106         AddAnchor(IDOK, BOTTOM_RIGHT);\r
107 //      SetPromptParentWindow(m_hWnd);\r
108         if (hWndExplorer)\r
109                 CenterWindow(CWnd::FromHandle(hWndExplorer));\r
110         EnableSaveRestore(_T("ChangedDlg"));\r
111 \r
112         m_bRemote = !!(DWORD)CRegDWORD(_T("Software\\TortoiseGit\\CheckRepo"), FALSE);\r
113         \r
114         // first start a thread to obtain the status without\r
115         // blocking the dialog\r
116         if (AfxBeginThread(ChangedStatusThreadEntry, this)==NULL)\r
117         {\r
118                 CMessageBox::Show(NULL, IDS_ERR_THREADSTARTFAILED, IDS_APPNAME, MB_OK | MB_ICONERROR);\r
119         }\r
120 \r
121         return TRUE;\r
122 }\r
123 \r
124 UINT CChangedDlg::ChangedStatusThreadEntry(LPVOID pVoid)\r
125 {\r
126         return ((CChangedDlg*)pVoid)->ChangedStatusThread();\r
127 }\r
128 \r
129 UINT CChangedDlg::ChangedStatusThread()\r
130 {\r
131         InterlockedExchange(&m_bBlock, TRUE);\r
132         m_bCanceled = false;\r
133         SetDlgItemText(IDOK, CString(MAKEINTRESOURCE(IDS_MSGBOX_CANCEL)));\r
134         DialogEnableWindow(IDC_REFRESH, FALSE);\r
135         DialogEnableWindow(IDC_CHECKREPO, FALSE);\r
136         DialogEnableWindow(IDC_SHOWUNVERSIONED, FALSE);\r
137         DialogEnableWindow(IDC_SHOWUNMODIFIED, FALSE);\r
138         DialogEnableWindow(IDC_SHOWIGNORED, FALSE);\r
139     DialogEnableWindow(IDC_SHOWUSERPROPS, FALSE);\r
140         CString temp;\r
141         if (!m_FileListCtrl.GetStatus(m_pathList, m_bRemote, m_bShowIgnored != FALSE, m_bShowUnversioned,m_bShowUserProps != FALSE))\r
142         {\r
143                 if (!m_FileListCtrl.GetLastErrorMessage().IsEmpty())\r
144                         m_FileListCtrl.SetEmptyString(m_FileListCtrl.GetLastErrorMessage());\r
145         }\r
146         DWORD dwShow = SVNSLC_SHOWVERSIONEDBUTNORMALANDEXTERNALS | SVNSLC_SHOWLOCKS | SVNSLC_SHOWSWITCHED | SVNSLC_SHOWINCHANGELIST;\r
147         dwShow |= m_bShowUnversioned ? SVNSLC_SHOWUNVERSIONED : 0;\r
148         dwShow |= m_iShowUnmodified ? SVNSLC_SHOWNORMAL : 0;\r
149         dwShow |= m_bShowIgnored ? SVNSLC_SHOWIGNORED : 0;\r
150         dwShow |= m_bShowExternals ? SVNSLC_SHOWEXTERNAL | SVNSLC_SHOWINEXTERNALS | SVNSLC_SHOWEXTERNALFROMDIFFERENTREPO : 0;\r
151         m_FileListCtrl.Show(dwShow);\r
152         UpdateStatistics();\r
153 \r
154 \r
155         CTGitPath commonDir = m_FileListCtrl.GetCommonDirectory(false);\r
156         bool bSingleFile = ((m_pathList.GetCount()==1)&&(!m_pathList[0].IsDirectory()));\r
157         if (bSingleFile)\r
158                 SetWindowText(m_sTitle + _T(" - ") + m_pathList[0].GetWinPathString());\r
159         else\r
160                 SetWindowText(m_sTitle + _T(" - ") + commonDir.GetWinPathString());\r
161 \r
162         SetDlgItemText(IDOK, CString(MAKEINTRESOURCE(IDS_MSGBOX_OK)));\r
163         DialogEnableWindow(IDC_REFRESH, TRUE);\r
164         DialogEnableWindow(IDC_CHECKREPO, TRUE);\r
165         DialogEnableWindow(IDC_SHOWUNVERSIONED, !bSingleFile);\r
166         DialogEnableWindow(IDC_SHOWUNMODIFIED, !bSingleFile);\r
167         DialogEnableWindow(IDC_SHOWIGNORED, !bSingleFile);\r
168     DialogEnableWindow(IDC_SHOWUSERPROPS, TRUE);\r
169         InterlockedExchange(&m_bBlock, FALSE);\r
170         // revert the remote flag back to the default\r
171         m_bRemote = !!(DWORD)CRegDWORD(_T("Software\\TortoiseGit\\CheckRepo"), FALSE);\r
172         RefreshCursor();\r
173         return 0;\r
174 }\r
175 \r
176 void CChangedDlg::OnOK()\r
177 {\r
178         if (m_bBlock)\r
179         {\r
180                 m_bCanceled = true;\r
181                 return;\r
182         }\r
183         __super::OnOK();\r
184 }\r
185 \r
186 void CChangedDlg::OnCancel()\r
187 {\r
188         if (m_bBlock)\r
189         {\r
190                 m_bCanceled = true;\r
191                 return;\r
192         }\r
193         __super::OnCancel();\r
194 }\r
195 \r
196 void CChangedDlg::OnBnClickedCheckrepo()\r
197 {\r
198         m_bRemote = TRUE;\r
199         if (AfxBeginThread(ChangedStatusThreadEntry, this)==NULL)\r
200         {\r
201                 CMessageBox::Show(NULL, IDS_ERR_THREADSTARTFAILED, IDS_APPNAME, MB_OK | MB_ICONERROR);\r
202         }\r
203 }\r
204 \r
205 DWORD CChangedDlg::UpdateShowFlags()\r
206 {\r
207         DWORD dwShow = m_FileListCtrl.GetShowFlags();\r
208         if (m_bShowUnversioned)\r
209                 dwShow |= SVNSLC_SHOWUNVERSIONED;\r
210         else\r
211                 dwShow &= ~SVNSLC_SHOWUNVERSIONED;\r
212         if (m_iShowUnmodified)\r
213                 dwShow |= SVNSLC_SHOWNORMAL;\r
214         else\r
215                 dwShow &= ~SVNSLC_SHOWNORMAL;\r
216         if (m_bShowIgnored)\r
217                 dwShow |= SVNSLC_SHOWIGNORED;\r
218         else\r
219                 dwShow &= ~SVNSLC_SHOWIGNORED;\r
220         if (m_bShowExternals)\r
221                 dwShow |= SVNSLC_SHOWEXTERNAL | SVNSLC_SHOWINEXTERNALS | SVNSLC_SHOWEXTERNALFROMDIFFERENTREPO;\r
222         else\r
223                 dwShow &= ~(SVNSLC_SHOWEXTERNAL | SVNSLC_SHOWINEXTERNALS | SVNSLC_SHOWEXTERNALFROMDIFFERENTREPO);\r
224 \r
225         return dwShow;\r
226 }\r
227 \r
228 void CChangedDlg::OnBnClickedShowunversioned()\r
229 {\r
230         UpdateData();\r
231         m_FileListCtrl.Show(UpdateShowFlags());\r
232         m_regAddBeforeCommit = m_bShowUnversioned;\r
233         UpdateStatistics();\r
234 }\r
235 \r
236 void CChangedDlg::OnBnClickedShowUnmodified()\r
237 {\r
238         UpdateData();\r
239         m_FileListCtrl.Show(UpdateShowFlags());\r
240         m_regAddBeforeCommit = m_bShowUnversioned;\r
241         UpdateStatistics();\r
242 }\r
243 \r
244 void CChangedDlg::OnBnClickedShowignored()\r
245 {\r
246         UpdateData();\r
247         if (AfxBeginThread(ChangedStatusThreadEntry, this)==NULL)\r
248         {\r
249                 CMessageBox::Show(NULL, IDS_ERR_THREADSTARTFAILED, IDS_APPNAME, MB_OK | MB_ICONERROR);\r
250         }\r
251 }\r
252 \r
253 void CChangedDlg::OnBnClickedShowexternals()\r
254 {\r
255         UpdateData();\r
256         m_FileListCtrl.Show(UpdateShowFlags());\r
257         UpdateStatistics();\r
258 }\r
259 \r
260 void CChangedDlg::OnBnClickedShowUserProps()\r
261 {\r
262         UpdateData();\r
263         if (AfxBeginThread(ChangedStatusThreadEntry, this)==NULL)\r
264         {\r
265                 CMessageBox::Show(NULL, IDS_ERR_THREADSTARTFAILED, IDS_APPNAME, MB_OK | MB_ICONERROR);\r
266         }\r
267 }\r
268 \r
269 LRESULT CChangedDlg::OnSVNStatusListCtrlNeedsRefresh(WPARAM, LPARAM)\r
270 {\r
271         if (AfxBeginThread(ChangedStatusThreadEntry, this)==NULL)\r
272         {\r
273                 CMessageBox::Show(NULL, IDS_ERR_THREADSTARTFAILED, IDS_APPNAME, MB_OK | MB_ICONERROR);\r
274         }\r
275         return 0;\r
276 }\r
277 \r
278 LRESULT CChangedDlg::OnSVNStatusListCtrlItemCountChanged(WPARAM, LPARAM)\r
279 {\r
280         UpdateStatistics();\r
281         return 0;\r
282 }\r
283 \r
284 BOOL CChangedDlg::PreTranslateMessage(MSG* pMsg)\r
285 {\r
286         m_tooltips.RelayEvent(pMsg);\r
287         if (pMsg->message == WM_KEYDOWN)\r
288         {\r
289                 switch (pMsg->wParam)\r
290                 {\r
291                 case VK_F5:\r
292                         {\r
293                                 if (m_bBlock)\r
294                                         return CResizableStandAloneDialog::PreTranslateMessage(pMsg);\r
295                                 if (AfxBeginThread(ChangedStatusThreadEntry, this)==NULL)\r
296                                 {\r
297                                         CMessageBox::Show(NULL, IDS_ERR_THREADSTARTFAILED, IDS_APPNAME, MB_OK | MB_ICONERROR);\r
298                                 }\r
299                         }\r
300                         break;\r
301                 }\r
302         }\r
303 \r
304         return CResizableStandAloneDialog::PreTranslateMessage(pMsg);\r
305 }\r
306 \r
307 void CChangedDlg::OnBnClickedRefresh()\r
308 {\r
309         if (!m_bBlock)\r
310         {\r
311                 if (AfxBeginThread(ChangedStatusThreadEntry, this)==NULL)\r
312                 {\r
313                         CMessageBox::Show(NULL, IDS_ERR_THREADSTARTFAILED, IDS_APPNAME, MB_OK | MB_ICONERROR);\r
314                 }\r
315         }\r
316 }\r
317 \r
318 void CChangedDlg::UpdateStatistics()\r
319 {\r
320         CString temp;\r
321 #if 0\r
322         LONG lMin, lMax;\r
323         \r
324         m_FileListCtrl.GetMinMaxRevisions(lMin, lMax, true, false);\r
325         if (LONG(m_FileListCtrl.m_HeadRev) >= 0)\r
326         {\r
327                 temp.Format(IDS_REPOSTATUS_HEADREV, lMin, lMax, LONG(m_FileListCtrl.m_HeadRev));\r
328                 SetDlgItemText(IDC_SUMMARYTEXT, temp);\r
329         }\r
330         else\r
331         {\r
332                 temp.Format(IDS_REPOSTATUS_WCINFO, lMin, lMax);\r
333                 SetDlgItemText(IDC_SUMMARYTEXT, temp);\r
334         }\r
335 #endif\r
336         temp = m_FileListCtrl.GetStatisticsString();\r
337         temp.Replace(_T(" = "), _T("="));\r
338         temp.Replace(_T("\n"), _T(", "));\r
339         SetDlgItemText(IDC_INFOLABEL, temp);\r
340 \r
341 }\r
342 \r
343 \r