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