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 "DirFileEnum.h"
\r
24 //#include "SVNConfig.h"
\r
25 #include "Registry.h"
\r
27 #define REFRESHTIMER 100
\r
29 IMPLEMENT_DYNAMIC(CAddDlg, CResizableStandAloneDialog)
\r
30 CAddDlg::CAddDlg(CWnd* pParent /*=NULL*/)
\r
31 : CResizableStandAloneDialog(CAddDlg::IDD, pParent)
\r
32 , m_bThreadRunning(FALSE)
\r
33 , m_bCancelled(false)
\r
41 void CAddDlg::DoDataExchange(CDataExchange* pDX)
\r
43 CResizableStandAloneDialog::DoDataExchange(pDX);
\r
44 DDX_Control(pDX, IDC_ADDLIST, m_addListCtrl);
\r
45 DDX_Control(pDX, IDC_SELECTALL, m_SelectAll);
\r
48 BEGIN_MESSAGE_MAP(CAddDlg, CResizableStandAloneDialog)
\r
49 ON_BN_CLICKED(IDC_SELECTALL, OnBnClickedSelectall)
\r
50 ON_BN_CLICKED(IDHELP, OnBnClickedHelp)
\r
51 ON_REGISTERED_MESSAGE(CGitStatusListCtrl::SVNSLNM_NEEDSREFRESH, OnSVNStatusListCtrlNeedsRefresh)
\r
52 ON_REGISTERED_MESSAGE(CGitStatusListCtrl::SVNSLNM_ADDFILE, OnFileDropped)
\r
57 BOOL CAddDlg::OnInitDialog()
\r
59 CResizableStandAloneDialog::OnInitDialog();
\r
61 // initialize the svn status list control
\r
62 m_addListCtrl.Init(SVNSLC_COLEXT, _T("AddDlg"), SVNSLC_POPALL ^ (SVNSLC_POPADD|SVNSLC_POPCOMMIT|SVNSLC_POPCHANGELISTS)); // adding and committing is useless in the add dialog
\r
63 m_addListCtrl.SetIgnoreRemoveOnly(); // when ignoring, don't add the parent folder since we're in the add dialog
\r
64 m_addListCtrl.SetUnversionedRecurse(true); // recurse into unversioned folders - user might want to add those too
\r
65 m_addListCtrl.SetSelectButton(&m_SelectAll);
\r
66 m_addListCtrl.SetConfirmButton((CButton*)GetDlgItem(IDOK));
\r
67 m_addListCtrl.SetEmptyString(IDS_ERR_NOTHINGTOADD);
\r
68 m_addListCtrl.SetCancelBool(&m_bCancelled);
\r
69 m_addListCtrl.SetBackgroundImage(IDI_ADD_BKG);
\r
70 m_addListCtrl.EnableFileDrop();
\r
72 AdjustControlSize(IDC_SELECTALL);
\r
74 AddAnchor(IDC_ADDLIST, TOP_LEFT, BOTTOM_RIGHT);
\r
75 AddAnchor(IDC_SELECTALL, BOTTOM_LEFT);
\r
76 AddAnchor(IDOK, BOTTOM_RIGHT);
\r
77 AddAnchor(IDCANCEL, BOTTOM_RIGHT);
\r
78 AddAnchor(IDHELP, BOTTOM_RIGHT);
\r
80 CenterWindow(CWnd::FromHandle(hWndExplorer));
\r
81 EnableSaveRestore(_T("AddDlg"));
\r
83 //first start a thread to obtain the file list with the status without
\r
84 //blocking the dialog
\r
85 if(AfxBeginThread(AddThreadEntry, this) == NULL)
\r
87 CMessageBox::Show(this->m_hWnd, IDS_ERR_THREADSTARTFAILED, IDS_APPNAME, MB_OK | MB_ICONERROR);
\r
89 InterlockedExchange(&m_bThreadRunning, TRUE);
\r
94 void CAddDlg::OnOK()
\r
96 if (m_bThreadRunning)
\r
99 // save only the files the user has selected into the path list
\r
100 m_addListCtrl.WriteCheckedNamesToPathList(m_pathList);
\r
102 CResizableStandAloneDialog::OnOK();
\r
105 void CAddDlg::OnCancel()
\r
107 m_bCancelled = true;
\r
108 if (m_bThreadRunning)
\r
111 CResizableStandAloneDialog::OnCancel();
\r
114 void CAddDlg::OnBnClickedSelectall()
\r
116 UINT state = (m_SelectAll.GetState() & 0x0003);
\r
117 if (state == BST_INDETERMINATE)
\r
119 // It is not at all useful to manually place the checkbox into the indeterminate state...
\r
120 // We will force this on to the unchecked state
\r
121 state = BST_UNCHECKED;
\r
122 m_SelectAll.SetCheck(state);
\r
124 theApp.DoWaitCursor(1);
\r
125 m_addListCtrl.SelectAll(state == BST_CHECKED);
\r
126 theApp.DoWaitCursor(-1);
\r
129 UINT CAddDlg::AddThreadEntry(LPVOID pVoid)
\r
131 return ((CAddDlg*)pVoid)->AddThread();
\r
134 UINT CAddDlg::AddThread()
\r
136 // get the status of all selected file/folders recursively
\r
137 // and show the ones which the user can add (i.e. the unversioned ones)
\r
138 DialogEnableWindow(IDOK, false);
\r
139 m_bCancelled = false;
\r
140 if (!m_addListCtrl.GetStatus(m_pathList))
\r
142 m_addListCtrl.SetEmptyString(m_addListCtrl.GetLastErrorMessage());
\r
144 m_addListCtrl.Show(SVNSLC_SHOWUNVERSIONED | SVNSLC_SHOWDIRECTFILES | SVNSLC_SHOWREMOVEDANDPRESENT,
\r
145 SVNSLC_SHOWUNVERSIONED | SVNSLC_SHOWDIRECTFILES | SVNSLC_SHOWREMOVEDANDPRESENT);
\r
147 InterlockedExchange(&m_bThreadRunning, FALSE);
\r
151 void CAddDlg::OnBnClickedHelp()
\r
156 BOOL CAddDlg::PreTranslateMessage(MSG* pMsg)
\r
158 if (pMsg->message == WM_KEYDOWN)
\r
160 switch (pMsg->wParam)
\r
164 if (GetAsyncKeyState(VK_CONTROL)&0x8000)
\r
166 if ( GetDlgItem(IDOK)->IsWindowEnabled() )
\r
168 PostMessage(WM_COMMAND, IDOK);
\r
176 if (!m_bThreadRunning)
\r
178 if(AfxBeginThread(AddThreadEntry, this) == NULL)
\r
180 CMessageBox::Show(this->m_hWnd, IDS_ERR_THREADSTARTFAILED, IDS_APPNAME, MB_OK | MB_ICONERROR);
\r
183 InterlockedExchange(&m_bThreadRunning, TRUE);
\r
190 return CResizableStandAloneDialog::PreTranslateMessage(pMsg);
\r
193 LRESULT CAddDlg::OnSVNStatusListCtrlNeedsRefresh(WPARAM, LPARAM)
\r
195 if(AfxBeginThread(AddThreadEntry, this) == NULL)
\r
197 CMessageBox::Show(this->m_hWnd, IDS_ERR_THREADSTARTFAILED, IDS_APPNAME, MB_OK | MB_ICONERROR);
\r
202 LRESULT CAddDlg::OnFileDropped(WPARAM, LPARAM lParam)
\r
204 BringWindowToTop();
\r
205 SetForegroundWindow();
\r
207 // if multiple files/folders are dropped
\r
208 // this handler is called for every single item
\r
210 // To avoid creating multiple refresh threads and
\r
211 // causing crashes, we only add the items to the
\r
212 // list control and start a timer.
\r
213 // When the timer expires, we start the refresh thread,
\r
214 // but only if it isn't already running - otherwise we
\r
215 // restart the timer.
\r
217 path.SetFromWin((LPCTSTR)lParam);
\r
219 if (!m_addListCtrl.HasPath(path))
\r
221 if (m_pathList.AreAllPathsFiles())
\r
223 m_pathList.AddPath(path);
\r
224 m_pathList.RemoveDuplicates();
\r
228 // if the path list contains folders, we have to check whether
\r
229 // our just (maybe) added path is a child of one of those. If it is
\r
230 // a child of a folder already in the list, we must not add it. Otherwise
\r
231 // that path could show up twice in the list.
\r
232 bool bHasParentInList = false;
\r
233 for (int i=0; i<m_pathList.GetCount(); ++i)
\r
235 if (m_pathList[i].IsAncestorOf(path))
\r
237 bHasParentInList = true;
\r
241 if (!bHasParentInList)
\r
243 m_pathList.AddPath(path);
\r
244 m_pathList.RemoveDuplicates();
\r
249 // Always start the timer, since the status of an existing item might have changed
\r
250 SetTimer(REFRESHTIMER, 200, NULL);
\r
251 ATLTRACE(_T("Item %s dropped, timer started\n"), path.GetWinPath());
\r
255 void CAddDlg::OnTimer(UINT_PTR nIDEvent)
\r
260 if (m_bThreadRunning)
\r
262 SetTimer(REFRESHTIMER, 200, NULL);
\r
263 ATLTRACE("Wait some more before refreshing\n");
\r
267 KillTimer(REFRESHTIMER);
\r
268 ATLTRACE("Refreshing after items dropped\n");
\r
269 OnSVNStatusListCtrlNeedsRefresh(0, 0);
\r
273 __super::OnTimer(nIDEvent);
\r