pulled latest translations from Transifex
[TortoiseGit.git] / src / TortoiseProc / AddDlg.cpp
blob63562b88d5eee5d2c44bd48d267529c7b013123d
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 "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)); // 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);
83 AddAnchor(IDC_ADDLIST, TOP_LEFT, BOTTOM_RIGHT);
84 AddAnchor(IDC_SELECTALL, BOTTOM_LEFT);
85 AddAnchor(IDC_INCLUDE_IGNORED, BOTTOM_LEFT);
86 AddAnchor(IDOK, BOTTOM_RIGHT);
87 AddAnchor(IDCANCEL, BOTTOM_RIGHT);
88 AddAnchor(IDHELP, BOTTOM_RIGHT);
89 if (hWndExplorer)
90 CenterWindow(CWnd::FromHandle(hWndExplorer));
91 EnableSaveRestore(_T("AddDlg"));
93 //first start a thread to obtain the file list with the status without
94 //blocking the dialog
95 if(AfxBeginThread(AddThreadEntry, this) == NULL)
97 CMessageBox::Show(this->m_hWnd, IDS_ERR_THREADSTARTFAILED, IDS_APPNAME, MB_OK | MB_ICONERROR);
99 InterlockedExchange(&m_bThreadRunning, TRUE);
101 return TRUE;
104 void CAddDlg::OnOK()
106 if (m_bThreadRunning)
107 return;
109 // save only the files the user has selected into the path list
110 m_addListCtrl.WriteCheckedNamesToPathList(m_pathList);
112 CResizableStandAloneDialog::OnOK();
115 void CAddDlg::OnCancel()
117 m_bCancelled = true;
118 if (m_bThreadRunning)
119 return;
121 CResizableStandAloneDialog::OnCancel();
124 void CAddDlg::OnBnClickedSelectall()
126 UINT state = (m_SelectAll.GetState() & 0x0003);
127 if (state == BST_INDETERMINATE)
129 // It is not at all useful to manually place the checkbox into the indeterminate state...
130 // We will force this on to the unchecked state
131 state = BST_UNCHECKED;
132 m_SelectAll.SetCheck(state);
134 theApp.DoWaitCursor(1);
135 m_addListCtrl.SelectAll(state == BST_CHECKED);
136 theApp.DoWaitCursor(-1);
139 UINT CAddDlg::AddThreadEntry(LPVOID pVoid)
141 return ((CAddDlg*)pVoid)->AddThread();
144 UINT CAddDlg::AddThread()
146 // get the status of all selected file/folders recursively
147 // and show the ones which the user can add (i.e. the unversioned ones)
148 DialogEnableWindow(IDOK, false);
149 m_bCancelled = false;
150 m_addListCtrl.Clear();
151 if (!m_addListCtrl.GetStatus(&m_pathList, false, m_bIncludeIgnored != FALSE, true, true))
153 m_addListCtrl.SetEmptyString(m_addListCtrl.GetLastErrorMessage());
155 unsigned int dwShow = GITSLC_SHOWUNVERSIONED | GITSLC_SHOWDIRECTFILES | GITSLC_SHOWREMOVEDANDPRESENT;
156 if (m_bIncludeIgnored)
157 dwShow |= GITSLC_SHOWIGNORED;
158 m_addListCtrl.Show(dwShow);
160 InterlockedExchange(&m_bThreadRunning, FALSE);
161 return 0;
164 void CAddDlg::OnBnClickedHelp()
166 OnHelp();
169 BOOL CAddDlg::PreTranslateMessage(MSG* pMsg)
171 if (pMsg->message == WM_KEYDOWN)
173 switch (pMsg->wParam)
175 case VK_RETURN:
177 if (GetAsyncKeyState(VK_CONTROL)&0x8000)
179 if ( GetDlgItem(IDOK)->IsWindowEnabled() )
181 PostMessage(WM_COMMAND, IDOK);
183 return TRUE;
186 break;
187 case VK_F5:
189 Refresh();
191 break;
195 return CResizableStandAloneDialog::PreTranslateMessage(pMsg);
198 LRESULT CAddDlg::OnSVNStatusListCtrlNeedsRefresh(WPARAM, LPARAM)
200 if(AfxBeginThread(AddThreadEntry, this) == NULL)
202 CMessageBox::Show(this->m_hWnd, IDS_ERR_THREADSTARTFAILED, IDS_APPNAME, MB_OK | MB_ICONERROR);
204 return 0;
207 LRESULT CAddDlg::OnFileDropped(WPARAM, LPARAM lParam)
209 BringWindowToTop();
210 SetForegroundWindow();
211 SetActiveWindow();
212 // if multiple files/folders are dropped
213 // this handler is called for every single item
214 // separately.
215 // To avoid creating multiple refresh threads and
216 // causing crashes, we only add the items to the
217 // list control and start a timer.
218 // When the timer expires, we start the refresh thread,
219 // but only if it isn't already running - otherwise we
220 // restart the timer.
221 CTGitPath path;
222 path.SetFromWin((LPCTSTR)lParam);
224 if (!m_addListCtrl.HasPath(path))
226 if (m_pathList.AreAllPathsFiles())
228 m_pathList.AddPath(path);
229 m_pathList.RemoveDuplicates();
231 else
233 // if the path list contains folders, we have to check whether
234 // our just (maybe) added path is a child of one of those. If it is
235 // a child of a folder already in the list, we must not add it. Otherwise
236 // that path could show up twice in the list.
237 bool bHasParentInList = false;
238 for (int i=0; i<m_pathList.GetCount(); ++i)
240 if (m_pathList[i].IsAncestorOf(path))
242 bHasParentInList = true;
243 break;
246 if (!bHasParentInList)
248 m_pathList.AddPath(path);
249 m_pathList.RemoveDuplicates();
254 // Always start the timer, since the status of an existing item might have changed
255 SetTimer(REFRESHTIMER, 200, NULL);
256 ATLTRACE(_T("Item %s dropped, timer started\n"), path.GetWinPath());
257 return 0;
260 void CAddDlg::Refresh()
262 if (!m_bThreadRunning)
264 if(AfxBeginThread(AddThreadEntry, this) == NULL)
266 CMessageBox::Show(this->m_hWnd, IDS_ERR_THREADSTARTFAILED, IDS_APPNAME, MB_OK | MB_ICONERROR);
268 else
269 InterlockedExchange(&m_bThreadRunning, TRUE);
273 void CAddDlg::OnTimer(UINT_PTR nIDEvent)
275 switch (nIDEvent)
277 case REFRESHTIMER:
278 if (m_bThreadRunning)
280 SetTimer(REFRESHTIMER, 200, NULL);
281 ATLTRACE("Wait some more before refreshing\n");
283 else
285 KillTimer(REFRESHTIMER);
286 ATLTRACE("Refreshing after items dropped\n");
287 OnSVNStatusListCtrlNeedsRefresh(0, 0);
289 break;
291 __super::OnTimer(nIDEvent);
294 void CAddDlg::OnBnClickedIncludeIgnored()
296 UpdateData();
297 Refresh();