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.
20 #include "TortoiseProc.h"
21 #include "ChangedDlg.h"
22 #include "messagebox.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)
37 , m_bShowIgnored(FALSE
)
38 , m_bShowExternals(TRUE
)
39 , m_bShowUserProps(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)
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
;
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);
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
);
124 UINT
CChangedDlg::ChangedStatusThreadEntry(LPVOID pVoid
)
126 return ((CChangedDlg
*)pVoid
)->ChangedStatusThread();
129 UINT
CChangedDlg::ChangedStatusThread()
131 InterlockedExchange(&m_bBlock
, TRUE
);
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
);
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
);
156 CTGitPath commonDir
= m_FileListCtrl
.GetCommonDirectory(false);
157 bool bSingleFile
= ((m_pathList
.GetCount()==1)&&(!m_pathList
[0].IsDirectory()));
159 SetWindowText(m_sTitle
+ _T(" - ") + m_pathList
[0].GetWinPathString());
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
);
177 void CChangedDlg::OnOK()
187 void CChangedDlg::OnCancel()
197 void CChangedDlg::OnBnClickedCheckrepo()
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
;
212 dwShow
&= ~SVNSLC_SHOWUNVERSIONED
;
213 if (m_iShowUnmodified
)
214 dwShow
|= SVNSLC_SHOWNORMAL
;
216 dwShow
&= ~SVNSLC_SHOWNORMAL
;
218 dwShow
|= SVNSLC_SHOWIGNORED
;
220 dwShow
&= ~SVNSLC_SHOWIGNORED
;
221 if (m_bShowExternals
)
222 dwShow
|= SVNSLC_SHOWEXTERNAL
| SVNSLC_SHOWINEXTERNALS
| SVNSLC_SHOWEXTERNALFROMDIFFERENTREPO
;
224 dwShow
&= ~(SVNSLC_SHOWEXTERNAL
| SVNSLC_SHOWINEXTERNALS
| SVNSLC_SHOWEXTERNALFROMDIFFERENTREPO
);
229 void CChangedDlg::OnBnClickedShowunversioned()
232 m_FileListCtrl
.Show(UpdateShowFlags());
233 m_regAddBeforeCommit
= m_bShowUnversioned
;
237 void CChangedDlg::OnBnClickedShowUnmodified()
240 m_FileListCtrl
.Show(UpdateShowFlags());
241 m_regAddBeforeCommit
= m_bShowUnversioned
;
245 void CChangedDlg::OnBnClickedShowignored()
248 if (AfxBeginThread(ChangedStatusThreadEntry
, this)==NULL
)
250 CMessageBox::Show(NULL
, IDS_ERR_THREADSTARTFAILED
, IDS_APPNAME
, MB_OK
| MB_ICONERROR
);
254 void CChangedDlg::OnBnClickedShowexternals()
257 m_FileListCtrl
.Show(UpdateShowFlags());
261 void CChangedDlg::OnBnClickedShowUserProps()
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
);
279 LRESULT
CChangedDlg::OnSVNStatusListCtrlItemCountChanged(WPARAM
, LPARAM
)
285 BOOL
CChangedDlg::PreTranslateMessage(MSG
* pMsg
)
287 m_tooltips
.RelayEvent(pMsg
);
288 if (pMsg
->message
== WM_KEYDOWN
)
290 switch (pMsg
->wParam
)
295 return CResizableStandAloneDialog::PreTranslateMessage(pMsg
);
296 if (AfxBeginThread(ChangedStatusThreadEntry
, this)==NULL
)
298 CMessageBox::Show(NULL
, IDS_ERR_THREADSTARTFAILED
, IDS_APPNAME
, MB_OK
| MB_ICONERROR
);
305 return CResizableStandAloneDialog::PreTranslateMessage(pMsg
);
308 void CChangedDlg::OnBnClickedRefresh()
312 if (AfxBeginThread(ChangedStatusThreadEntry
, this)==NULL
)
314 CMessageBox::Show(NULL
, IDS_ERR_THREADSTARTFAILED
, IDS_APPNAME
, MB_OK
| MB_ICONERROR
);
319 void CChangedDlg::UpdateStatistics()
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
);
333 temp
.Format(IDS_REPOSTATUS_WCINFO
, lMin
, lMax
);
334 SetDlgItemText(IDC_SUMMARYTEXT
, temp
);
337 temp
= m_FileListCtrl
.GetStatisticsString();
338 temp
.Replace(_T(" = "), _T("="));
339 temp
.Replace(_T("\n"), _T(", "));
340 SetDlgItemText(IDC_INFOLABEL
, temp
);