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.
21 #include "TortoiseProc.h"
22 #include "messagebox.h"
23 #include "DirFileEnum.h"
25 //#include "SVNConfig.h"
27 #include "CommonResource.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
)
37 , m_bIncludeIgnored(FALSE
)
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
)
59 ON_BN_CLICKED(IDC_INCLUDE_IGNORED
, &CAddDlg::OnBnClickedIncludeIgnored
)
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();
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
);
91 CenterWindow(CWnd::FromHandle(hWndExplorer
));
92 EnableSaveRestore(_T("AddDlg"));
94 //first start a thread to obtain the file list with the status without
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
);
107 if (m_bThreadRunning
)
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()
119 if (m_bThreadRunning
)
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
);
165 void CAddDlg::OnBnClickedHelp()
170 BOOL
CAddDlg::PreTranslateMessage(MSG
* pMsg
)
172 if (pMsg
->message
== WM_KEYDOWN
)
174 switch (pMsg
->wParam
)
178 if (GetAsyncKeyState(VK_CONTROL
)&0x8000)
180 if ( GetDlgItem(IDOK
)->IsWindowEnabled() )
182 PostMessage(WM_COMMAND
, IDOK
);
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
);
208 LRESULT
CAddDlg::OnFileDropped(WPARAM
, LPARAM lParam
)
211 SetForegroundWindow();
213 // if multiple files/folders are dropped
214 // this handler is called for every single item
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.
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();
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;
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());
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
);
270 InterlockedExchange(&m_bThreadRunning
, TRUE
);
274 void CAddDlg::OnTimer(UINT_PTR nIDEvent
)
279 if (m_bThreadRunning
)
281 SetTimer(REFRESHTIMER
, 200, NULL
);
282 ATLTRACE("Wait some more before refreshing\n");
286 KillTimer(REFRESHTIMER
);
287 ATLTRACE("Refreshing after items dropped\n");
288 OnSVNStatusListCtrlNeedsRefresh(0, 0);
292 __super::OnTimer(nIDEvent
);
295 void CAddDlg::OnBnClickedIncludeIgnored()