Update diff del rename ignore document.
[TortoiseGit.git] / src / TortoiseProc / ChangedDlg.cpp
blobd671b39bb07eca6064b917c44189d1ca1bfbe495
1 // TortoiseSVN - a Windows shell extension for easy version control
3 // Copyright (C) 2003-2008 - TortoiseSVN
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 2
8 // of the License, or (at your option) any later version.
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software Foundation,
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 #include "stdafx.h"
20 #include "TortoiseProc.h"
21 #include "ChangedDlg.h"
22 #include "messagebox.h"
23 #include "cursor.h"
24 #include ".\changeddlg.h"
26 #include "GitStatusListCtrl.h"
28 #include "CommonResource.h"
30 IMPLEMENT_DYNAMIC(CChangedDlg, CResizableStandAloneDialog)
31 CChangedDlg::CChangedDlg(CWnd* pParent /*=NULL*/)
32 : CResizableStandAloneDialog(CChangedDlg::IDD, pParent)
33 , m_bShowUnversioned(FALSE)
34 , m_iShowUnmodified(0)
35 , m_bBlock(FALSE)
36 , m_bCanceled(false)
37 , m_bShowIgnored(FALSE)
38 , m_bShowExternals(TRUE)
39 , m_bShowUserProps(FALSE)
41 m_bRemote = FALSE;
44 CChangedDlg::~CChangedDlg()
48 void CChangedDlg::DoDataExchange(CDataExchange* pDX)
50 CResizableStandAloneDialog::DoDataExchange(pDX);
51 DDX_Control(pDX, IDC_CHANGEDLIST, m_FileListCtrl);
52 DDX_Check(pDX, IDC_SHOWUNVERSIONED, m_bShowUnversioned);
53 DDX_Check(pDX, IDC_SHOWUNMODIFIED, m_iShowUnmodified);
54 DDX_Check(pDX, IDC_SHOWIGNORED, m_bShowIgnored);
55 // DDX_Check(pDX, IDC_SHOWEXTERNALS, m_bShowExternals);
56 // DDX_Check(pDX, IDC_SHOWUSERPROPS, m_bShowUserProps);
60 BEGIN_MESSAGE_MAP(CChangedDlg, CResizableStandAloneDialog)
61 ON_BN_CLICKED(IDC_CHECKREPO, OnBnClickedCheckrepo)
62 ON_BN_CLICKED(IDC_SHOWUNVERSIONED, OnBnClickedShowunversioned)
63 ON_BN_CLICKED(IDC_SHOWUNMODIFIED, OnBnClickedShowUnmodified)
64 // ON_BN_CLICKED(IDC_SHOWUSERPROPS, OnBnClickedShowUserProps)
65 ON_REGISTERED_MESSAGE(CGitStatusListCtrl::SVNSLNM_NEEDSREFRESH, OnSVNStatusListCtrlNeedsRefresh)
66 ON_REGISTERED_MESSAGE(CGitStatusListCtrl::SVNSLNM_ITEMCOUNTCHANGED, OnSVNStatusListCtrlItemCountChanged)
67 ON_BN_CLICKED(IDC_SHOWIGNORED, &CChangedDlg::OnBnClickedShowignored)
68 ON_BN_CLICKED(IDC_REFRESH, &CChangedDlg::OnBnClickedRefresh)
69 // ON_BN_CLICKED(IDC_SHOWEXTERNALS, &CChangedDlg::OnBnClickedShowexternals)
70 END_MESSAGE_MAP()
72 BOOL CChangedDlg::OnInitDialog()
74 CResizableStandAloneDialog::OnInitDialog();
76 GetWindowText(m_sTitle);
78 m_tooltips.Create(this);
80 m_regAddBeforeCommit = CRegDWORD(_T("Software\\TortoiseGit\\AddBeforeCommit"), TRUE);
81 m_bShowUnversioned = m_regAddBeforeCommit;
82 UpdateData(FALSE);
84 m_FileListCtrl.Init(SVNSLC_COLEXT | SVNSLC_COLSTATUS, _T("ChangedDlg"),
85 SVNSLC_POPALL, false);
86 m_FileListCtrl.SetCancelBool(&m_bCanceled);
87 m_FileListCtrl.SetBackgroundImage(IDI_CFM_BKG);
88 m_FileListCtrl.SetEmptyString(IDS_REPOSTATUS_EMPTYFILELIST);
90 AdjustControlSize(IDC_SHOWUNVERSIONED);
91 AdjustControlSize(IDC_SHOWUNMODIFIED);
92 AdjustControlSize(IDC_SHOWIGNORED);
93 // AdjustControlSize(IDC_SHOWEXTERNALS);
94 // AdjustControlSize(IDC_SHOWUSERPROPS);
96 AddAnchor(IDC_CHANGEDLIST, TOP_LEFT, BOTTOM_RIGHT);
97 AddAnchor(IDC_SUMMARYTEXT, BOTTOM_LEFT, BOTTOM_RIGHT);
98 AddAnchor(IDC_SHOWUNVERSIONED, BOTTOM_LEFT);
99 AddAnchor(IDC_SHOWUNMODIFIED, BOTTOM_LEFT);
100 AddAnchor(IDC_SHOWIGNORED, BOTTOM_LEFT);
101 // AddAnchor(IDC_SHOWEXTERNALS, BOTTOM_LEFT);
102 // AddAnchor(IDC_SHOWUSERPROPS, BOTTOM_LEFT);
103 AddAnchor(IDC_INFOLABEL, BOTTOM_RIGHT);
104 AddAnchor(IDC_REFRESH, BOTTOM_RIGHT);
105 AddAnchor(IDC_CHECKREPO, BOTTOM_RIGHT);
106 AddAnchor(IDOK, BOTTOM_RIGHT);
107 // SetPromptParentWindow(m_hWnd);
108 if (hWndExplorer)
109 CenterWindow(CWnd::FromHandle(hWndExplorer));
110 EnableSaveRestore(_T("ChangedDlg"));
112 m_bRemote = !!(DWORD)CRegDWORD(_T("Software\\TortoiseGit\\CheckRepo"), FALSE);
114 // first start a thread to obtain the status without
115 // blocking the dialog
116 if (AfxBeginThread(ChangedStatusThreadEntry, this)==NULL)
118 CMessageBox::Show(NULL, IDS_ERR_THREADSTARTFAILED, IDS_APPNAME, MB_OK | MB_ICONERROR);
121 return TRUE;
124 UINT CChangedDlg::ChangedStatusThreadEntry(LPVOID pVoid)
126 return ((CChangedDlg*)pVoid)->ChangedStatusThread();
129 UINT CChangedDlg::ChangedStatusThread()
131 InterlockedExchange(&m_bBlock, TRUE);
132 m_bCanceled = false;
133 SetDlgItemText(IDOK, CString(MAKEINTRESOURCE(IDS_MSGBOX_CANCEL)));
134 DialogEnableWindow(IDC_REFRESH, FALSE);
135 DialogEnableWindow(IDC_CHECKREPO, FALSE);
136 DialogEnableWindow(IDC_SHOWUNVERSIONED, FALSE);
137 DialogEnableWindow(IDC_SHOWUNMODIFIED, FALSE);
138 DialogEnableWindow(IDC_SHOWIGNORED, FALSE);
139 DialogEnableWindow(IDC_SHOWUSERPROPS, FALSE);
140 CString temp;
141 m_FileListCtrl.Clear();
142 if (!m_FileListCtrl.GetStatus(&m_pathList, m_bRemote, m_bShowIgnored != FALSE, m_bShowUnversioned,m_bShowUserProps != FALSE))
144 if (!m_FileListCtrl.GetLastErrorMessage().IsEmpty())
145 m_FileListCtrl.SetEmptyString(m_FileListCtrl.GetLastErrorMessage());
147 DWORD dwShow = SVNSLC_SHOWVERSIONEDBUTNORMALANDEXTERNALS | SVNSLC_SHOWLOCKS | SVNSLC_SHOWSWITCHED | SVNSLC_SHOWINCHANGELIST;
148 dwShow |= m_bShowUnversioned ? SVNSLC_SHOWUNVERSIONED : 0;
149 dwShow |= m_iShowUnmodified ? SVNSLC_SHOWNORMAL : 0;
150 dwShow |= m_bShowIgnored ? SVNSLC_SHOWIGNORED : 0;
151 dwShow |= m_bShowExternals ? SVNSLC_SHOWEXTERNAL | SVNSLC_SHOWINEXTERNALS | SVNSLC_SHOWEXTERNALFROMDIFFERENTREPO : 0;
152 m_FileListCtrl.Show(dwShow);
153 UpdateStatistics();
156 CTGitPath commonDir = m_FileListCtrl.GetCommonDirectory(false);
157 bool bSingleFile = ((m_pathList.GetCount()==1)&&(!m_pathList[0].IsDirectory()));
158 if (bSingleFile)
159 SetWindowText(m_sTitle + _T(" - ") + m_pathList[0].GetWinPathString());
160 else
161 SetWindowText(m_sTitle + _T(" - ") + commonDir.GetWinPathString());
163 SetDlgItemText(IDOK, CString(MAKEINTRESOURCE(IDS_MSGBOX_OK)));
164 DialogEnableWindow(IDC_REFRESH, TRUE);
165 DialogEnableWindow(IDC_CHECKREPO, TRUE);
166 DialogEnableWindow(IDC_SHOWUNVERSIONED, !bSingleFile);
167 DialogEnableWindow(IDC_SHOWUNMODIFIED, !bSingleFile);
168 DialogEnableWindow(IDC_SHOWIGNORED, !bSingleFile);
169 DialogEnableWindow(IDC_SHOWUSERPROPS, TRUE);
170 InterlockedExchange(&m_bBlock, FALSE);
171 // revert the remote flag back to the default
172 m_bRemote = !!(DWORD)CRegDWORD(_T("Software\\TortoiseGit\\CheckRepo"), FALSE);
173 RefreshCursor();
174 return 0;
177 void CChangedDlg::OnOK()
179 if (m_bBlock)
181 m_bCanceled = true;
182 return;
184 __super::OnOK();
187 void CChangedDlg::OnCancel()
189 if (m_bBlock)
191 m_bCanceled = true;
192 return;
194 __super::OnCancel();
197 void CChangedDlg::OnBnClickedCheckrepo()
199 m_bRemote = TRUE;
200 if (AfxBeginThread(ChangedStatusThreadEntry, this)==NULL)
202 CMessageBox::Show(NULL, IDS_ERR_THREADSTARTFAILED, IDS_APPNAME, MB_OK | MB_ICONERROR);
206 DWORD CChangedDlg::UpdateShowFlags()
208 DWORD dwShow = m_FileListCtrl.GetShowFlags();
209 if (m_bShowUnversioned)
210 dwShow |= SVNSLC_SHOWUNVERSIONED;
211 else
212 dwShow &= ~SVNSLC_SHOWUNVERSIONED;
213 if (m_iShowUnmodified)
214 dwShow |= SVNSLC_SHOWNORMAL;
215 else
216 dwShow &= ~SVNSLC_SHOWNORMAL;
217 if (m_bShowIgnored)
218 dwShow |= SVNSLC_SHOWIGNORED;
219 else
220 dwShow &= ~SVNSLC_SHOWIGNORED;
221 if (m_bShowExternals)
222 dwShow |= SVNSLC_SHOWEXTERNAL | SVNSLC_SHOWINEXTERNALS | SVNSLC_SHOWEXTERNALFROMDIFFERENTREPO;
223 else
224 dwShow &= ~(SVNSLC_SHOWEXTERNAL | SVNSLC_SHOWINEXTERNALS | SVNSLC_SHOWEXTERNALFROMDIFFERENTREPO);
226 return dwShow;
229 void CChangedDlg::OnBnClickedShowunversioned()
231 UpdateData();
232 m_FileListCtrl.Show(UpdateShowFlags());
233 m_regAddBeforeCommit = m_bShowUnversioned;
234 UpdateStatistics();
237 void CChangedDlg::OnBnClickedShowUnmodified()
239 UpdateData();
240 m_FileListCtrl.Show(UpdateShowFlags());
241 m_regAddBeforeCommit = m_bShowUnversioned;
242 UpdateStatistics();
245 void CChangedDlg::OnBnClickedShowignored()
247 UpdateData();
248 if (AfxBeginThread(ChangedStatusThreadEntry, this)==NULL)
250 CMessageBox::Show(NULL, IDS_ERR_THREADSTARTFAILED, IDS_APPNAME, MB_OK | MB_ICONERROR);
254 void CChangedDlg::OnBnClickedShowexternals()
256 UpdateData();
257 m_FileListCtrl.Show(UpdateShowFlags());
258 UpdateStatistics();
261 void CChangedDlg::OnBnClickedShowUserProps()
263 UpdateData();
264 if (AfxBeginThread(ChangedStatusThreadEntry, this)==NULL)
266 CMessageBox::Show(NULL, IDS_ERR_THREADSTARTFAILED, IDS_APPNAME, MB_OK | MB_ICONERROR);
270 LRESULT CChangedDlg::OnSVNStatusListCtrlNeedsRefresh(WPARAM, LPARAM)
272 if (AfxBeginThread(ChangedStatusThreadEntry, this)==NULL)
274 CMessageBox::Show(NULL, IDS_ERR_THREADSTARTFAILED, IDS_APPNAME, MB_OK | MB_ICONERROR);
276 return 0;
279 LRESULT CChangedDlg::OnSVNStatusListCtrlItemCountChanged(WPARAM, LPARAM)
281 UpdateStatistics();
282 return 0;
285 BOOL CChangedDlg::PreTranslateMessage(MSG* pMsg)
287 m_tooltips.RelayEvent(pMsg);
288 if (pMsg->message == WM_KEYDOWN)
290 switch (pMsg->wParam)
292 case VK_F5:
294 if (m_bBlock)
295 return CResizableStandAloneDialog::PreTranslateMessage(pMsg);
296 if (AfxBeginThread(ChangedStatusThreadEntry, this)==NULL)
298 CMessageBox::Show(NULL, IDS_ERR_THREADSTARTFAILED, IDS_APPNAME, MB_OK | MB_ICONERROR);
301 break;
305 return CResizableStandAloneDialog::PreTranslateMessage(pMsg);
308 void CChangedDlg::OnBnClickedRefresh()
310 if (!m_bBlock)
312 if (AfxBeginThread(ChangedStatusThreadEntry, this)==NULL)
314 CMessageBox::Show(NULL, IDS_ERR_THREADSTARTFAILED, IDS_APPNAME, MB_OK | MB_ICONERROR);
319 void CChangedDlg::UpdateStatistics()
321 CString temp;
322 #if 0
323 LONG lMin, lMax;
325 m_FileListCtrl.GetMinMaxRevisions(lMin, lMax, true, false);
326 if (LONG(m_FileListCtrl.m_HeadRev) >= 0)
328 temp.Format(IDS_REPOSTATUS_HEADREV, lMin, lMax, LONG(m_FileListCtrl.m_HeadRev));
329 SetDlgItemText(IDC_SUMMARYTEXT, temp);
331 else
333 temp.Format(IDS_REPOSTATUS_WCINFO, lMin, lMax);
334 SetDlgItemText(IDC_SUMMARYTEXT, temp);
336 #endif
337 temp = m_FileListCtrl.GetStatisticsString();
338 temp.Replace(_T(" = "), _T("="));
339 temp.Replace(_T("\n"), _T(", "));
340 SetDlgItemText(IDC_INFOLABEL, temp);