make add dialog show ignored files
[TortoiseGit.git] / src / TortoiseProc / AddDlg.cpp
blob618bcbe1bf46671e33241002a087004a691dd30e
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 "messagebox.h"
22 #include "DirFileEnum.h"
23 #include "AddDlg.h"
24 //#include "SVNConfig.h"
25 #include "Registry.h"
26 #include "CommonResource.h"
27 #include "AppUtils.h"
29 #define REFRESHTIMER 100
31 IMPLEMENT_DYNAMIC(CAddDlg, CResizableStandAloneDialog)
32 CAddDlg::CAddDlg(CWnd* pParent /*=NULL*/)
33 : CResizableStandAloneDialog(CAddDlg::IDD, pParent)
34 , m_bThreadRunning(FALSE)
35 , m_bCancelled(false)
36 , m_bIncludeIgnored(FALSE)
40 CAddDlg::~CAddDlg()
44 void CAddDlg::DoDataExchange(CDataExchange* pDX)
46 CResizableStandAloneDialog::DoDataExchange(pDX);
47 DDX_Control(pDX, IDC_ADDLIST, m_addListCtrl);
48 DDX_Control(pDX, IDC_SELECTALL, m_SelectAll);
49 DDX_Check(pDX, IDC_INCLUDE_IGNORED, m_bIncludeIgnored);
52 BEGIN_MESSAGE_MAP(CAddDlg, CResizableStandAloneDialog)
53 ON_BN_CLICKED(IDC_SELECTALL, OnBnClickedSelectall)
54 ON_BN_CLICKED(IDHELP, OnBnClickedHelp)
55 ON_REGISTERED_MESSAGE(CGitStatusListCtrl::SVNSLNM_NEEDSREFRESH, OnSVNStatusListCtrlNeedsRefresh)
56 ON_REGISTERED_MESSAGE(CGitStatusListCtrl::SVNSLNM_ADDFILE, OnFileDropped)
57 ON_WM_TIMER()
58 ON_BN_CLICKED(IDC_INCLUDE_IGNORED, &CAddDlg::OnBnClickedIncludeIgnored)
59 END_MESSAGE_MAP()
62 BOOL CAddDlg::OnInitDialog()
64 CResizableStandAloneDialog::OnInitDialog();
65 CAppUtils::MarkWindowAsUnpinnable(m_hWnd);
67 // initialize the svn status list control
68 m_addListCtrl.Init(SVNSLC_COLEXT, _T("AddDlg"), SVNSLC_POPALL ^ (SVNSLC_POPADD|SVNSLC_POPCOMMIT|SVNSLC_POPCHANGELISTS)); // adding and committing is useless in the add dialog
69 m_addListCtrl.SetIgnoreRemoveOnly(); // when ignoring, don't add the parent folder since we're in the add dialog
70 m_addListCtrl.SetUnversionedRecurse(true); // recurse into unversioned folders - user might want to add those too
71 m_addListCtrl.SetSelectButton(&m_SelectAll);
72 m_addListCtrl.SetConfirmButton((CButton*)GetDlgItem(IDOK));
73 m_addListCtrl.SetEmptyString(IDS_ERR_NOTHINGTOADD);
74 m_addListCtrl.SetCancelBool(&m_bCancelled);
75 m_addListCtrl.SetBackgroundImage(IDI_ADD_BKG);
76 m_addListCtrl.EnableFileDrop();
78 AdjustControlSize(IDC_SELECTALL);
80 AddAnchor(IDC_ADDLIST, TOP_LEFT, BOTTOM_RIGHT);
81 AddAnchor(IDC_SELECTALL, BOTTOM_LEFT);
82 AddAnchor(IDC_INCLUDE_IGNORED, BOTTOM_LEFT);
83 AddAnchor(IDOK, BOTTOM_RIGHT);
84 AddAnchor(IDCANCEL, BOTTOM_RIGHT);
85 AddAnchor(IDHELP, BOTTOM_RIGHT);
86 if (hWndExplorer)
87 CenterWindow(CWnd::FromHandle(hWndExplorer));
88 EnableSaveRestore(_T("AddDlg"));
90 //first start a thread to obtain the file list with the status without
91 //blocking the dialog
92 if(AfxBeginThread(AddThreadEntry, this) == NULL)
94 CMessageBox::Show(this->m_hWnd, IDS_ERR_THREADSTARTFAILED, IDS_APPNAME, MB_OK | MB_ICONERROR);
96 InterlockedExchange(&m_bThreadRunning, TRUE);
98 return TRUE;
101 void CAddDlg::OnOK()
103 if (m_bThreadRunning)
104 return;
106 // save only the files the user has selected into the path list
107 m_addListCtrl.WriteCheckedNamesToPathList(m_pathList);
109 CResizableStandAloneDialog::OnOK();
112 void CAddDlg::OnCancel()
114 m_bCancelled = true;
115 if (m_bThreadRunning)
116 return;
118 CResizableStandAloneDialog::OnCancel();
121 void CAddDlg::OnBnClickedSelectall()
123 UINT state = (m_SelectAll.GetState() & 0x0003);
124 if (state == BST_INDETERMINATE)
126 // It is not at all useful to manually place the checkbox into the indeterminate state...
127 // We will force this on to the unchecked state
128 state = BST_UNCHECKED;
129 m_SelectAll.SetCheck(state);
131 theApp.DoWaitCursor(1);
132 m_addListCtrl.SelectAll(state == BST_CHECKED);
133 theApp.DoWaitCursor(-1);
136 UINT CAddDlg::AddThreadEntry(LPVOID pVoid)
138 return ((CAddDlg*)pVoid)->AddThread();
141 UINT CAddDlg::AddThread()
143 // get the status of all selected file/folders recursively
144 // and show the ones which the user can add (i.e. the unversioned ones)
145 DialogEnableWindow(IDOK, false);
146 m_bCancelled = false;
147 m_addListCtrl.Clear();
148 if (!m_addListCtrl.GetStatus(&m_pathList, false, m_bIncludeIgnored != FALSE, true, true))
150 m_addListCtrl.SetEmptyString(m_addListCtrl.GetLastErrorMessage());
152 unsigned int dwShow = SVNSLC_SHOWUNVERSIONED | SVNSLC_SHOWDIRECTFILES | SVNSLC_SHOWREMOVEDANDPRESENT;
153 if (m_bIncludeIgnored)
154 dwShow |= SVNSLC_SHOWIGNORED;
155 m_addListCtrl.Show(dwShow);
157 InterlockedExchange(&m_bThreadRunning, FALSE);
158 return 0;
161 void CAddDlg::OnBnClickedHelp()
163 OnHelp();
166 BOOL CAddDlg::PreTranslateMessage(MSG* pMsg)
168 if (pMsg->message == WM_KEYDOWN)
170 switch (pMsg->wParam)
172 case VK_RETURN:
174 if (GetAsyncKeyState(VK_CONTROL)&0x8000)
176 if ( GetDlgItem(IDOK)->IsWindowEnabled() )
178 PostMessage(WM_COMMAND, IDOK);
180 return TRUE;
183 break;
184 case VK_F5:
186 Refresh();
188 break;
192 return CResizableStandAloneDialog::PreTranslateMessage(pMsg);
195 LRESULT CAddDlg::OnSVNStatusListCtrlNeedsRefresh(WPARAM, LPARAM)
197 if(AfxBeginThread(AddThreadEntry, this) == NULL)
199 CMessageBox::Show(this->m_hWnd, IDS_ERR_THREADSTARTFAILED, IDS_APPNAME, MB_OK | MB_ICONERROR);
201 return 0;
204 LRESULT CAddDlg::OnFileDropped(WPARAM, LPARAM lParam)
206 BringWindowToTop();
207 SetForegroundWindow();
208 SetActiveWindow();
209 // if multiple files/folders are dropped
210 // this handler is called for every single item
211 // separately.
212 // To avoid creating multiple refresh threads and
213 // causing crashes, we only add the items to the
214 // list control and start a timer.
215 // When the timer expires, we start the refresh thread,
216 // but only if it isn't already running - otherwise we
217 // restart the timer.
218 CTGitPath path;
219 path.SetFromWin((LPCTSTR)lParam);
221 if (!m_addListCtrl.HasPath(path))
223 if (m_pathList.AreAllPathsFiles())
225 m_pathList.AddPath(path);
226 m_pathList.RemoveDuplicates();
228 else
230 // if the path list contains folders, we have to check whether
231 // our just (maybe) added path is a child of one of those. If it is
232 // a child of a folder already in the list, we must not add it. Otherwise
233 // that path could show up twice in the list.
234 bool bHasParentInList = false;
235 for (int i=0; i<m_pathList.GetCount(); ++i)
237 if (m_pathList[i].IsAncestorOf(path))
239 bHasParentInList = true;
240 break;
243 if (!bHasParentInList)
245 m_pathList.AddPath(path);
246 m_pathList.RemoveDuplicates();
251 // Always start the timer, since the status of an existing item might have changed
252 SetTimer(REFRESHTIMER, 200, NULL);
253 ATLTRACE(_T("Item %s dropped, timer started\n"), path.GetWinPath());
254 return 0;
257 void CAddDlg::Refresh()
259 if (!m_bThreadRunning)
261 if(AfxBeginThread(AddThreadEntry, this) == NULL)
263 CMessageBox::Show(this->m_hWnd, IDS_ERR_THREADSTARTFAILED, IDS_APPNAME, MB_OK | MB_ICONERROR);
265 else
266 InterlockedExchange(&m_bThreadRunning, TRUE);
270 void CAddDlg::OnTimer(UINT_PTR nIDEvent)
272 switch (nIDEvent)
274 case REFRESHTIMER:
275 if (m_bThreadRunning)
277 SetTimer(REFRESHTIMER, 200, NULL);
278 ATLTRACE("Wait some more before refreshing\n");
280 else
282 KillTimer(REFRESHTIMER);
283 ATLTRACE("Refreshing after items dropped\n");
284 OnSVNStatusListCtrlNeedsRefresh(0, 0);
286 break;
288 __super::OnTimer(nIDEvent);
291 void CAddDlg::OnBnClickedIncludeIgnored()
293 UpdateData();
294 Refresh();