dropped unused TSVN settings
[TortoiseGit.git] / src / TortoiseProc / AddDlg.cpp
blob9c825018334a2158205ffd34172048ffb7af7fa2
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2011 - 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 "CommonResource.h"
28 #include "AppUtils.h"
30 #define REFRESHTIMER 100
32 IMPLEMENT_DYNAMIC(CAddDlg, CResizableStandAloneDialog)
33 CAddDlg::CAddDlg(CWnd* pParent /*=NULL*/)
34 : CResizableStandAloneDialog(CAddDlg::IDD, pParent)
35 , m_bThreadRunning(FALSE)
36 , m_bCancelled(false)
37 , m_bIncludeIgnored(FALSE)
41 CAddDlg::~CAddDlg()
45 void CAddDlg::DoDataExchange(CDataExchange* pDX)
47 CResizableStandAloneDialog::DoDataExchange(pDX);
48 DDX_Control(pDX, IDC_ADDLIST, m_addListCtrl);
49 DDX_Control(pDX, IDC_SELECTALL, m_SelectAll);
50 DDX_Check(pDX, IDC_INCLUDE_IGNORED, m_bIncludeIgnored);
53 BEGIN_MESSAGE_MAP(CAddDlg, CResizableStandAloneDialog)
54 ON_BN_CLICKED(IDC_SELECTALL, OnBnClickedSelectall)
55 ON_BN_CLICKED(IDHELP, OnBnClickedHelp)
56 ON_REGISTERED_MESSAGE(CGitStatusListCtrl::GITSLNM_NEEDSREFRESH, OnSVNStatusListCtrlNeedsRefresh)
57 ON_REGISTERED_MESSAGE(CGitStatusListCtrl::GITSLNM_ADDFILE, OnFileDropped)
58 ON_WM_TIMER()
59 ON_BN_CLICKED(IDC_INCLUDE_IGNORED, &CAddDlg::OnBnClickedIncludeIgnored)
60 END_MESSAGE_MAP()
63 BOOL CAddDlg::OnInitDialog()
65 CResizableStandAloneDialog::OnInitDialog();
66 CAppUtils::MarkWindowAsUnpinnable(m_hWnd);
68 // initialize the svn status list control
69 m_addListCtrl.Init(GITSLC_COLEXT, _T("AddDlg"), GITSLC_POPALL ^ (GITSLC_POPADD|GITSLC_POPCOMMIT|GITSLC_POPCHANGELISTS)); // adding and committing is useless in the add dialog
70 m_addListCtrl.SetIgnoreRemoveOnly(); // when ignoring, don't add the parent folder since we're in the add dialog
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 CString sWindowTitle;
79 GetWindowText(sWindowTitle);
80 CAppUtils::SetWindowTitle(m_hWnd, (g_Git.m_CurrentDir + _T("\\") + m_pathList.GetCommonRoot().GetUIPathString()).TrimRight('\\'), sWindowTitle);
82 AdjustControlSize(IDC_SELECTALL);
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);
90 if (hWndExplorer)
91 CenterWindow(CWnd::FromHandle(hWndExplorer));
92 EnableSaveRestore(_T("AddDlg"));
94 //first start a thread to obtain the file list with the status without
95 //blocking the dialog
96 if(AfxBeginThread(AddThreadEntry, this) == NULL)
98 CMessageBox::Show(this->m_hWnd, IDS_ERR_THREADSTARTFAILED, IDS_APPNAME, MB_OK | MB_ICONERROR);
100 InterlockedExchange(&m_bThreadRunning, TRUE);
102 return TRUE;
105 void CAddDlg::OnOK()
107 if (m_bThreadRunning)
108 return;
110 // save only the files the user has selected into the path list
111 m_addListCtrl.WriteCheckedNamesToPathList(m_pathList);
113 CResizableStandAloneDialog::OnOK();
116 void CAddDlg::OnCancel()
118 m_bCancelled = true;
119 if (m_bThreadRunning)
120 return;
122 CResizableStandAloneDialog::OnCancel();
125 void CAddDlg::OnBnClickedSelectall()
127 UINT state = (m_SelectAll.GetState() & 0x0003);
128 if (state == BST_INDETERMINATE)
130 // It is not at all useful to manually place the checkbox into the indeterminate state...
131 // We will force this on to the unchecked state
132 state = BST_UNCHECKED;
133 m_SelectAll.SetCheck(state);
135 theApp.DoWaitCursor(1);
136 m_addListCtrl.SelectAll(state == BST_CHECKED);
137 theApp.DoWaitCursor(-1);
140 UINT CAddDlg::AddThreadEntry(LPVOID pVoid)
142 return ((CAddDlg*)pVoid)->AddThread();
145 UINT CAddDlg::AddThread()
147 // get the status of all selected file/folders recursively
148 // and show the ones which the user can add (i.e. the unversioned ones)
149 DialogEnableWindow(IDOK, false);
150 m_bCancelled = false;
151 m_addListCtrl.Clear();
152 if (!m_addListCtrl.GetStatus(&m_pathList, false, m_bIncludeIgnored != FALSE, true, true))
154 m_addListCtrl.SetEmptyString(m_addListCtrl.GetLastErrorMessage());
156 unsigned int dwShow = GITSLC_SHOWUNVERSIONED | GITSLC_SHOWDIRECTFILES | GITSLC_SHOWREMOVEDANDPRESENT;
157 if (m_bIncludeIgnored)
158 dwShow |= GITSLC_SHOWIGNORED;
159 m_addListCtrl.Show(dwShow);
161 InterlockedExchange(&m_bThreadRunning, FALSE);
162 return 0;
165 void CAddDlg::OnBnClickedHelp()
167 OnHelp();
170 BOOL CAddDlg::PreTranslateMessage(MSG* pMsg)
172 if (pMsg->message == WM_KEYDOWN)
174 switch (pMsg->wParam)
176 case VK_RETURN:
178 if (GetAsyncKeyState(VK_CONTROL)&0x8000)
180 if ( GetDlgItem(IDOK)->IsWindowEnabled() )
182 PostMessage(WM_COMMAND, IDOK);
184 return TRUE;
187 break;
188 case VK_F5:
190 Refresh();
192 break;
196 return CResizableStandAloneDialog::PreTranslateMessage(pMsg);
199 LRESULT CAddDlg::OnSVNStatusListCtrlNeedsRefresh(WPARAM, LPARAM)
201 if(AfxBeginThread(AddThreadEntry, this) == NULL)
203 CMessageBox::Show(this->m_hWnd, IDS_ERR_THREADSTARTFAILED, IDS_APPNAME, MB_OK | MB_ICONERROR);
205 return 0;
208 LRESULT CAddDlg::OnFileDropped(WPARAM, LPARAM lParam)
210 BringWindowToTop();
211 SetForegroundWindow();
212 SetActiveWindow();
213 // if multiple files/folders are dropped
214 // this handler is called for every single item
215 // separately.
216 // To avoid creating multiple refresh threads and
217 // causing crashes, we only add the items to the
218 // list control and start a timer.
219 // When the timer expires, we start the refresh thread,
220 // but only if it isn't already running - otherwise we
221 // restart the timer.
222 CTGitPath path;
223 path.SetFromWin((LPCTSTR)lParam);
225 if (!m_addListCtrl.HasPath(path))
227 if (m_pathList.AreAllPathsFiles())
229 m_pathList.AddPath(path);
230 m_pathList.RemoveDuplicates();
232 else
234 // if the path list contains folders, we have to check whether
235 // our just (maybe) added path is a child of one of those. If it is
236 // a child of a folder already in the list, we must not add it. Otherwise
237 // that path could show up twice in the list.
238 bool bHasParentInList = false;
239 for (int i=0; i<m_pathList.GetCount(); ++i)
241 if (m_pathList[i].IsAncestorOf(path))
243 bHasParentInList = true;
244 break;
247 if (!bHasParentInList)
249 m_pathList.AddPath(path);
250 m_pathList.RemoveDuplicates();
255 // Always start the timer, since the status of an existing item might have changed
256 SetTimer(REFRESHTIMER, 200, NULL);
257 ATLTRACE(_T("Item %s dropped, timer started\n"), path.GetWinPath());
258 return 0;
261 void CAddDlg::Refresh()
263 if (!m_bThreadRunning)
265 if(AfxBeginThread(AddThreadEntry, this) == NULL)
267 CMessageBox::Show(this->m_hWnd, IDS_ERR_THREADSTARTFAILED, IDS_APPNAME, MB_OK | MB_ICONERROR);
269 else
270 InterlockedExchange(&m_bThreadRunning, TRUE);
274 void CAddDlg::OnTimer(UINT_PTR nIDEvent)
276 switch (nIDEvent)
278 case REFRESHTIMER:
279 if (m_bThreadRunning)
281 SetTimer(REFRESHTIMER, 200, NULL);
282 ATLTRACE("Wait some more before refreshing\n");
284 else
286 KillTimer(REFRESHTIMER);
287 ATLTRACE("Refreshing after items dropped\n");
288 OnSVNStatusListCtrlNeedsRefresh(0, 0);
290 break;
292 __super::OnTimer(nIDEvent);
295 void CAddDlg::OnBnClickedIncludeIgnored()
297 UpdateData();
298 Refresh();