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 "messagebox.h"
22 #include "ResolveDlg.h"
23 #include "CommonResource.h"
25 #define REFRESHTIMER 100
27 IMPLEMENT_DYNAMIC(CResolveDlg
, CResizableStandAloneDialog
)
28 CResolveDlg::CResolveDlg(CWnd
* pParent
/*=NULL*/)
29 : CResizableStandAloneDialog(CResolveDlg::IDD
, pParent
)
30 , m_bThreadRunning(FALSE
)
35 CResolveDlg::~CResolveDlg()
39 void CResolveDlg::DoDataExchange(CDataExchange
* pDX
)
41 CResizableStandAloneDialog::DoDataExchange(pDX
);
42 DDX_Control(pDX
, IDC_RESOLVELIST
, m_resolveListCtrl
);
43 DDX_Control(pDX
, IDC_SELECTALL
, m_SelectAll
);
47 BEGIN_MESSAGE_MAP(CResolveDlg
, CResizableStandAloneDialog
)
48 ON_BN_CLICKED(IDC_SELECTALL
, OnBnClickedSelectall
)
49 ON_BN_CLICKED(IDHELP
, OnBnClickedHelp
)
50 ON_REGISTERED_MESSAGE(CGitStatusListCtrl::SVNSLNM_NEEDSREFRESH
, OnSVNStatusListCtrlNeedsRefresh
)
51 ON_REGISTERED_MESSAGE(CGitStatusListCtrl::SVNSLNM_ADDFILE
, OnFileDropped
)
55 BOOL
CResolveDlg::OnInitDialog()
57 CResizableStandAloneDialog::OnInitDialog();
59 m_resolveListCtrl
.Init(SVNSLC_COLEXT
| SVNSLC_COLTEXTSTATUS
| SVNSLC_COLPROPSTATUS
, _T("ResolveDlg"), SVNSLC_POPALL
^ (SVNSLC_POPIGNORE
|SVNSLC_POPADD
|SVNSLC_POPCOMMIT
));
60 m_resolveListCtrl
.SetConfirmButton((CButton
*)GetDlgItem(IDOK
));
61 m_resolveListCtrl
.SetSelectButton(&m_SelectAll
);
62 m_resolveListCtrl
.SetCancelBool(&m_bCancelled
);
63 m_resolveListCtrl
.SetBackgroundImage(IDI_RESOLVE_BKG
);
64 m_resolveListCtrl
.EnableFileDrop();
66 AdjustControlSize(IDC_SELECTALL
);
68 AddAnchor(IDC_RESOLVELIST
, TOP_LEFT
, BOTTOM_RIGHT
);
69 AddAnchor(IDC_SELECTALL
, BOTTOM_LEFT
);
70 AddAnchor(IDOK
, BOTTOM_RIGHT
);
71 AddAnchor(IDCANCEL
, BOTTOM_RIGHT
);
72 AddAnchor(IDHELP
, BOTTOM_RIGHT
);
74 CenterWindow(CWnd::FromHandle(hWndExplorer
));
75 EnableSaveRestore(_T("ResolveDlg"));
77 // first start a thread to obtain the file list with the status without
78 // blocking the dialog
79 if(AfxBeginThread(ResolveThreadEntry
, this) == NULL
)
81 CMessageBox::Show(this->m_hWnd
, IDS_ERR_THREADSTARTFAILED
, IDS_APPNAME
, MB_OK
| MB_ICONERROR
);
83 InterlockedExchange(&m_bThreadRunning
, TRUE
);
88 void CResolveDlg::OnOK()
93 //save only the files the user has selected into the path list
94 m_resolveListCtrl
.WriteCheckedNamesToPathList(m_pathList
);
96 CResizableStandAloneDialog::OnOK();
99 void CResolveDlg::OnCancel()
102 if (m_bThreadRunning
)
105 CResizableStandAloneDialog::OnCancel();
108 void CResolveDlg::OnBnClickedSelectall()
110 UINT state
= (m_SelectAll
.GetState() & 0x0003);
111 if (state
== BST_INDETERMINATE
)
113 // It is not at all useful to manually place the checkbox into the indeterminate state...
114 // We will force this on to the unchecked state
115 state
= BST_UNCHECKED
;
116 m_SelectAll
.SetCheck(state
);
118 theApp
.DoWaitCursor(1);
119 m_resolveListCtrl
.SelectAll(state
== BST_CHECKED
);
120 theApp
.DoWaitCursor(-1);
123 UINT
CResolveDlg::ResolveThreadEntry(LPVOID pVoid
)
125 return ((CResolveDlg
*)pVoid
)->ResolveThread();
127 UINT
CResolveDlg::ResolveThread()
129 // get the status of all selected file/folders recursively
130 // and show the ones which are in conflict
131 DialogEnableWindow(IDOK
, false);
133 m_bCancelled
= false;
135 if (!m_resolveListCtrl
.GetStatus(&m_pathList
))
137 m_resolveListCtrl
.SetEmptyString(m_resolveListCtrl
.GetLastErrorMessage());
139 m_resolveListCtrl
.Show(SVNSLC_SHOWCONFLICTED
|SVNSLC_SHOWINEXTERNALS
, SVNSLC_SHOWCONFLICTED
);
141 InterlockedExchange(&m_bThreadRunning
, FALSE
);
145 void CResolveDlg::OnBnClickedHelp()
150 BOOL
CResolveDlg::PreTranslateMessage(MSG
* pMsg
)
152 if (pMsg
->message
== WM_KEYDOWN
)
154 switch (pMsg
->wParam
)
158 if (GetAsyncKeyState(VK_CONTROL
)&0x8000)
160 if ( GetDlgItem(IDOK
)->IsWindowEnabled() )
162 PostMessage(WM_COMMAND
, IDOK
);
170 if (!m_bThreadRunning
)
172 if(AfxBeginThread(ResolveThreadEntry
, this) == NULL
)
174 CMessageBox::Show(this->m_hWnd
, IDS_ERR_THREADSTARTFAILED
, IDS_APPNAME
, MB_OK
| MB_ICONERROR
);
177 InterlockedExchange(&m_bThreadRunning
, TRUE
);
184 return CResizableStandAloneDialog::PreTranslateMessage(pMsg
);
187 LRESULT
CResolveDlg::OnSVNStatusListCtrlNeedsRefresh(WPARAM
, LPARAM
)
189 if(AfxBeginThread(ResolveThreadEntry
, this) == NULL
)
191 CMessageBox::Show(this->m_hWnd
, IDS_ERR_THREADSTARTFAILED
, IDS_APPNAME
, MB_OK
| MB_ICONERROR
);
196 LRESULT
CResolveDlg::OnFileDropped(WPARAM
, LPARAM lParam
)
199 SetForegroundWindow();
201 // if multiple files/folders are dropped
202 // this handler is called for every single item
204 // To avoid creating multiple refresh threads and
205 // causing crashes, we only add the items to the
206 // list control and start a timer.
207 // When the timer expires, we start the refresh thread,
208 // but only if it isn't already running - otherwise we
209 // restart the timer.
211 path
.SetFromWin((LPCTSTR
)lParam
);
213 if (!m_resolveListCtrl
.HasPath(path
))
215 if (m_pathList
.AreAllPathsFiles())
217 m_pathList
.AddPath(path
);
218 m_pathList
.RemoveDuplicates();
222 // if the path list contains folders, we have to check whether
223 // our just (maybe) added path is a child of one of those. If it is
224 // a child of a folder already in the list, we must not add it. Otherwise
225 // that path could show up twice in the list.
226 bool bHasParentInList
= false;
227 for (int i
=0; i
<m_pathList
.GetCount(); ++i
)
229 if (m_pathList
[i
].IsAncestorOf(path
))
231 bHasParentInList
= true;
235 if (!bHasParentInList
)
237 m_pathList
.AddPath(path
);
238 m_pathList
.RemoveDuplicates();
243 // Always start the timer, since the status of an existing item might have changed
244 SetTimer(REFRESHTIMER
, 200, NULL
);
245 ATLTRACE(_T("Item %s dropped, timer started\n"), path
.GetWinPath());
249 void CResolveDlg::OnTimer(UINT_PTR nIDEvent
)
254 if (m_bThreadRunning
)
256 SetTimer(REFRESHTIMER
, 200, NULL
);
257 ATLTRACE("Wait some more before refreshing\n");
261 KillTimer(REFRESHTIMER
);
262 ATLTRACE("Refreshing after items dropped\n");
263 OnSVNStatusListCtrlNeedsRefresh(0, 0);
267 __super::OnTimer(nIDEvent
);