Also move context menu logic into separate classes
[TortoiseGit.git] / src / TortoiseProc / ProgressCommands / RevertProgressCommand.cpp
blob4f7222b1ac55272d1a869e76b08baca135aa4a89
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2009-2014 - TortoiseGit
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 "RevertProgressCommand.h"
21 #include "ShellUpdater.h"
22 #include "AppUtils.h"
24 bool RevertProgressCommand::Run(CGitProgressList* list, CString& sWindowTitle, int& m_itemCountTotal, int& m_itemCount)
26 list->SetWindowTitle(IDS_PROGRS_TITLE_REVERT, g_Git.CombinePath(m_targetPathList.GetCommonRoot().GetUIPathString()), sWindowTitle);
27 list->SetBackgroundImage(IDI_REVERT_BKG);
29 m_itemCountTotal = 2 * m_targetPathList.GetCount();
30 CTGitPathList delList;
31 for (m_itemCount = 0; m_itemCount < m_targetPathList.GetCount(); ++m_itemCount)
33 CTGitPath path;
34 int action;
35 path.SetFromWin(g_Git.CombinePath(m_targetPathList[m_itemCount]));
36 action = m_targetPathList[m_itemCount].m_Action;
37 /* rename file can't delete because it needs original file*/
38 if ((!(action & CTGitPath::LOGACTIONS_ADDED)) &&
39 (!(action & CTGitPath::LOGACTIONS_REPLACED)))
40 delList.AddPath(path);
42 if (DWORD(CRegDWORD(_T("Software\\TortoiseGit\\RevertWithRecycleBin"), TRUE)))
43 delList.DeleteAllFiles(true);
45 list->ReportCmd(CString(MAKEINTRESOURCE(IDS_PROGRS_CMD_REVERT)));
46 for (int i = 0; i < m_targetPathList.GetCount(); ++i)
48 CString err;
49 if (g_Git.Revert(_T("HEAD"), (CTGitPath&)m_targetPathList[i], err))
51 list->ReportError(_T("Revert failed:\n") + err);
52 return false;
54 list->AddNotify(new CGitProgressList::WC_File_NotificationData(m_targetPathList[i], CGitProgressList::WC_File_NotificationData::git_wc_notify_revert));
55 ++m_itemCount;
57 if (list->IsCancelled() == TRUE)
59 list->ReportUserCanceled();
60 return false;
64 CShellUpdater::Instance().AddPathsForUpdate(m_targetPathList);
66 return true;