OSDN Git Service

Show Ignore Sub Menu
[tortoisegit/TortoiseGitJp.git] / src / TortoiseProc / Commands / RemoveCommand.cpp
1 // TortoiseSVN - a Windows shell extension for easy version control\r
2 \r
3 // Copyright (C) 2007-2008 - TortoiseSVN\r
4 \r
5 // This program is free software; you can redistribute it and/or\r
6 // modify it under the terms of the GNU General Public License\r
7 // as published by the Free Software Foundation; either version 2\r
8 // of the License, or (at your option) any later version.\r
9 \r
10 // This program is distributed in the hope that it will be useful,\r
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of\r
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
13 // GNU General Public License for more details.\r
14 \r
15 // You should have received a copy of the GNU General Public License\r
16 // along with this program; if not, write to the Free Software Foundation,\r
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.\r
18 //\r
19 #include "StdAfx.h"\r
20 #include "RemoveCommand.h"\r
21 \r
22 #include "MessageBox.h"\r
23 #include "ProgressDlg.h"\r
24 #include "SVN.h"\r
25 #include "InputLogDlg.h"\r
26 #include "ShellUpdater.h"\r
27 \r
28 bool RemoveCommand::Execute()\r
29 {\r
30         bool bRet = false;\r
31         // removing items from a working copy is done item-by-item so we\r
32         // have a chance to show a progress bar\r
33         //\r
34         // removing items from an URL in the repository requires that we\r
35         // ask the user for a log message.\r
36         BOOL bForce = FALSE;\r
37         SVN svn;\r
38         if ((pathList.GetCount())&&(SVN::PathIsURL(pathList[0])))\r
39         {\r
40                 // Delete using URL's, not wc paths\r
41                 svn.SetPromptApp(&theApp);\r
42                 CInputLogDlg dlg;\r
43                 CString sUUID;\r
44                 svn.GetRepositoryRootAndUUID(pathList[0], sUUID);\r
45                 dlg.SetUUID(sUUID);\r
46                 CString sHint;\r
47                 if (pathList.GetCount() == 1)\r
48                         sHint.Format(IDS_INPUT_REMOVEONE, (LPCTSTR)pathList[0].GetSVNPathString());\r
49                 else\r
50                         sHint.Format(IDS_INPUT_REMOVEMORE, pathList.GetCount());\r
51                 dlg.SetActionText(sHint);\r
52                 if (dlg.DoModal()==IDOK)\r
53                 {\r
54                         if (!svn.Remove(pathList, TRUE, parser.HasKey(_T("keep")), dlg.GetLogMessage()))\r
55                         {\r
56                                 CMessageBox::Show(hwndExplorer, svn.GetLastErrorMessage(), _T("TortoiseSVN"), MB_ICONERROR);\r
57                                 return FALSE;\r
58                         }\r
59                         return true;\r
60                 }\r
61                 return FALSE;\r
62         }\r
63         else\r
64         {\r
65                 for(int nPath = 0; nPath < pathList.GetCount(); nPath++)\r
66                 {\r
67                         TRACE(_T("remove file %s\n"), (LPCTSTR)pathList[nPath].GetUIPathString());\r
68                         // even though SVN::Remove takes a list of paths to delete at once\r
69                         // we delete each item individually so we can prompt the user\r
70                         // if something goes wrong or unversioned/modified items are\r
71                         // to be deleted\r
72                         CTSVNPathList removePathList(pathList[nPath]);\r
73                         if (bForce)\r
74                         {\r
75                                 CTSVNPath delPath = removePathList[0];\r
76                                 delPath.Delete(true);\r
77                         }\r
78                         if (!svn.Remove(removePathList, bForce, parser.HasKey(_T("keep"))))\r
79                         {\r
80                                 if ((svn.Err->apr_err == SVN_ERR_UNVERSIONED_RESOURCE) ||\r
81                                         (svn.Err->apr_err == SVN_ERR_CLIENT_MODIFIED))\r
82                                 {\r
83                                         CString msg, yes, no, yestoall;\r
84                                         if (pathList[nPath].IsDirectory())\r
85                                         {\r
86                                                 msg.Format(IDS_PROC_REMOVEFORCEFOLDER, pathList[nPath].GetWinPath());\r
87                                         }\r
88                                         else\r
89                                         {\r
90                                                 msg.Format(IDS_PROC_REMOVEFORCE, (LPCTSTR)svn.GetLastErrorMessage());\r
91                                         }\r
92                                         yes.LoadString(IDS_MSGBOX_YES);\r
93                                         no.LoadString(IDS_MSGBOX_NO);\r
94                                         yestoall.LoadString(IDS_PROC_YESTOALL);\r
95                                         UINT ret = CMessageBox::Show(hwndExplorer, msg, _T("TortoiseSVN"), 2, IDI_ERROR, yes, no, yestoall);\r
96                                         if (ret == 3)\r
97                                                 bForce = TRUE;\r
98                                         if ((ret == 1)||(ret==3))\r
99                                         {\r
100                                                 CTSVNPath delPath = removePathList[0];\r
101                                                 delPath.Delete(true);\r
102                                                 if (!svn.Remove(removePathList, TRUE, parser.HasKey(_T("keep"))))\r
103                                                 {\r
104                                                         CMessageBox::Show(hwndExplorer, svn.GetLastErrorMessage(), _T("TortoiseSVN"), MB_ICONERROR);\r
105                                                 }\r
106                                                 else\r
107                                                         bRet = true;\r
108                                         }\r
109                                 }\r
110                                 else\r
111                                         CMessageBox::Show(hwndExplorer, svn.GetLastErrorMessage(), _T("TortoiseSVN"), MB_ICONERROR);\r
112                         }\r
113                 }\r
114         }\r
115         if (bRet)\r
116                 CShellUpdater::Instance().AddPathsForUpdate(pathList);\r
117         return bRet;\r
118 }\r