Dropped unused variables
[TortoiseGit.git] / src / TortoiseProc / AddDlg.cpp
blob33fb22a7e9645556363e2366274a2695181aa46e
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2012 - TortoiseGit
4 // Copyright (C) 2003-2008 - TortoiseSVN
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 2
9 // of the License, or (at your option) any later version.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software Foundation,
18 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 #include "stdafx.h"
21 #include "TortoiseProc.h"
22 #include "messagebox.h"
23 #include "DirFileEnum.h"
24 #include "AddDlg.h"
25 //#include "SVNConfig.h"
26 #include "registry.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::GITSLNM_NEEDSREFRESH, OnSVNStatusListCtrlNeedsRefresh)
56 ON_REGISTERED_MESSAGE(CGitStatusListCtrl::GITSLNM_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(GITSLC_COLEXT, _T("AddDlg"), GITSLC_POPALL ^ (GITSLC_POPADD|GITSLC_POPCOMMIT|GITSLC_POPCHANGELISTS), true, true, GITSLC_COLEXT | GITSLC_COLMODIFICATIONDATE | GITSLC_COLSIZE); // 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.SetSelectButton(&m_SelectAll);
71 m_addListCtrl.SetConfirmButton((CButton*)GetDlgItem(IDOK));
72 m_addListCtrl.SetEmptyString(IDS_ERR_NOTHINGTOADD);
73 m_addListCtrl.SetCancelBool(&m_bCancelled);
74 m_addListCtrl.SetBackgroundImage(IDI_ADD_BKG);
75 m_addListCtrl.EnableFileDrop();
77 CString sWindowTitle;
78 GetWindowText(sWindowTitle);
79 CAppUtils::SetWindowTitle(m_hWnd, (g_Git.m_CurrentDir + _T("\\") + m_pathList.GetCommonRoot().GetUIPathString()).TrimRight('\\'), sWindowTitle);
81 AdjustControlSize(IDC_SELECTALL);
82 AdjustControlSize(IDC_INCLUDE_IGNORED);
84 AddAnchor(IDC_ADDLIST, TOP_LEFT, BOTTOM_RIGHT);
85 AddAnchor(IDC_SELECTALL, BOTTOM_LEFT);
86 AddAnchor(IDC_INCLUDE_IGNORED, BOTTOM_LEFT);
87 AddAnchor(IDOK, BOTTOM_RIGHT);
88 AddAnchor(IDCANCEL, BOTTOM_RIGHT);
89 AddAnchor(IDHELP, BOTTOM_RIGHT);
91 if (hWndExplorer)
92 CenterWindow(CWnd::FromHandle(hWndExplorer));
93 EnableSaveRestore(_T("AddDlg"));
95 //first start a thread to obtain the file list with the status without
96 //blocking the dialog
97 if(AfxBeginThread(AddThreadEntry, this) == NULL)
99 CMessageBox::Show(this->m_hWnd, IDS_ERR_THREADSTARTFAILED, IDS_APPNAME, MB_OK | MB_ICONERROR);
101 InterlockedExchange(&m_bThreadRunning, TRUE);
103 return TRUE;
106 void CAddDlg::OnOK()
108 if (m_bThreadRunning)
109 return;
111 // save only the files the user has selected into the path list
112 m_addListCtrl.WriteCheckedNamesToPathList(m_pathList);
114 CResizableStandAloneDialog::OnOK();
117 void CAddDlg::OnCancel()
119 m_bCancelled = true;
120 if (m_bThreadRunning)
121 return;
123 CResizableStandAloneDialog::OnCancel();
126 void CAddDlg::OnBnClickedSelectall()
128 UINT state = (m_SelectAll.GetState() & 0x0003);
129 if (state == BST_INDETERMINATE)
131 // It is not at all useful to manually place the checkbox into the indeterminate state...
132 // We will force this on to the unchecked state
133 state = BST_UNCHECKED;
134 m_SelectAll.SetCheck(state);
136 theApp.DoWaitCursor(1);
137 m_addListCtrl.SelectAll(state == BST_CHECKED);
138 theApp.DoWaitCursor(-1);
141 UINT CAddDlg::AddThreadEntry(LPVOID pVoid)
143 return ((CAddDlg*)pVoid)->AddThread();
146 UINT CAddDlg::AddThread()
148 // get the status of all selected file/folders recursively
149 // and show the ones which the user can add (i.e. the unversioned ones)
150 DialogEnableWindow(IDOK, false);
151 m_bCancelled = false;
152 m_addListCtrl.Clear();
153 if (!m_addListCtrl.GetStatus(&m_pathList, false, m_bIncludeIgnored != FALSE, true))
155 m_addListCtrl.SetEmptyString(m_addListCtrl.GetLastErrorMessage());
157 unsigned int dwShow = GITSLC_SHOWUNVERSIONED | GITSLC_SHOWDIRECTFILES | GITSLC_SHOWREMOVEDANDPRESENT;
158 if (m_bIncludeIgnored)
159 dwShow |= GITSLC_SHOWIGNORED;
160 m_addListCtrl.Show(dwShow);
162 InterlockedExchange(&m_bThreadRunning, FALSE);
163 return 0;
166 void CAddDlg::OnBnClickedHelp()
168 OnHelp();
171 BOOL CAddDlg::PreTranslateMessage(MSG* pMsg)
173 if (pMsg->message == WM_KEYDOWN)
175 switch (pMsg->wParam)
177 case VK_RETURN:
179 if (GetAsyncKeyState(VK_CONTROL)&0x8000)
181 if ( GetDlgItem(IDOK)->IsWindowEnabled() )
183 PostMessage(WM_COMMAND, IDOK);
185 return TRUE;
188 break;
189 case VK_F5:
191 Refresh();
193 break;
197 return CResizableStandAloneDialog::PreTranslateMessage(pMsg);
200 LRESULT CAddDlg::OnSVNStatusListCtrlNeedsRefresh(WPARAM, LPARAM)
202 if(AfxBeginThread(AddThreadEntry, this) == NULL)
204 CMessageBox::Show(this->m_hWnd, IDS_ERR_THREADSTARTFAILED, IDS_APPNAME, MB_OK | MB_ICONERROR);
206 return 0;
209 LRESULT CAddDlg::OnFileDropped(WPARAM, LPARAM lParam)
211 BringWindowToTop();
212 SetForegroundWindow();
213 SetActiveWindow();
214 // if multiple files/folders are dropped
215 // this handler is called for every single item
216 // separately.
217 // To avoid creating multiple refresh threads and
218 // causing crashes, we only add the items to the
219 // list control and start a timer.
220 // When the timer expires, we start the refresh thread,
221 // but only if it isn't already running - otherwise we
222 // restart the timer.
223 CTGitPath path;
224 path.SetFromWin((LPCTSTR)lParam);
226 if (!m_addListCtrl.HasPath(path))
228 if (m_pathList.AreAllPathsFiles())
230 m_pathList.AddPath(path);
231 m_pathList.RemoveDuplicates();
233 else
235 // if the path list contains folders, we have to check whether
236 // our just (maybe) added path is a child of one of those. If it is
237 // a child of a folder already in the list, we must not add it. Otherwise
238 // that path could show up twice in the list.
239 bool bHasParentInList = false;
240 for (int i=0; i<m_pathList.GetCount(); ++i)
242 if (m_pathList[i].IsAncestorOf(path))
244 bHasParentInList = true;
245 break;
248 if (!bHasParentInList)
250 m_pathList.AddPath(path);
251 m_pathList.RemoveDuplicates();
256 // Always start the timer, since the status of an existing item might have changed
257 SetTimer(REFRESHTIMER, 200, NULL);
258 ATLTRACE(_T("Item %s dropped, timer started\n"), path.GetWinPath());
259 return 0;
262 void CAddDlg::Refresh()
264 if (!m_bThreadRunning)
266 if(AfxBeginThread(AddThreadEntry, this) == NULL)
268 CMessageBox::Show(this->m_hWnd, IDS_ERR_THREADSTARTFAILED, IDS_APPNAME, MB_OK | MB_ICONERROR);
270 else
271 InterlockedExchange(&m_bThreadRunning, TRUE);
275 void CAddDlg::OnTimer(UINT_PTR nIDEvent)
277 switch (nIDEvent)
279 case REFRESHTIMER:
280 if (m_bThreadRunning)
282 SetTimer(REFRESHTIMER, 200, NULL);
283 ATLTRACE("Wait some more before refreshing\n");
285 else
287 KillTimer(REFRESHTIMER);
288 ATLTRACE("Refreshing after items dropped\n");
289 OnSVNStatusListCtrlNeedsRefresh(0, 0);
291 break;
293 __super::OnTimer(nIDEvent);
296 void CAddDlg::OnBnClickedIncludeIgnored()
298 UpdateData();
299 Refresh();