OSDN Git Service

Fix File List Del\Add switch problem and enable prevdiff command
[tortoisegit/TortoiseGitJp.git] / src / TortoiseProc / Commands / DropMoveCommand.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 "DropMoveCommand.h"\r
21 \r
22 #include "ProgressDlg.h"\r
23 #include "MessageBox.h"\r
24 #include "SVN.h"\r
25 #include "RenameDlg.h"\r
26 #include "ShellUpdater.h"\r
27 \r
28 bool DropMoveCommand::Execute()\r
29 {\r
30         CString droppath = parser.GetVal(_T("droptarget"));\r
31         if (CTSVNPath(droppath).IsAdminDir())\r
32                 return FALSE;\r
33         SVN svn;\r
34         unsigned long count = 0;\r
35         pathList.RemoveAdminPaths();\r
36         CString sNewName;\r
37         if ((parser.HasKey(_T("rename")))&&(pathList.GetCount()==1))\r
38         {\r
39                 // ask for a new name of the source item\r
40                 do \r
41                 {\r
42                         CRenameDlg renDlg;\r
43                         renDlg.m_windowtitle.LoadString(IDS_PROC_MOVERENAME);\r
44                         renDlg.m_name = pathList[0].GetFileOrDirectoryName();\r
45                         if (renDlg.DoModal() != IDOK)\r
46                         {\r
47                                 return FALSE;\r
48                         }\r
49                         sNewName = renDlg.m_name;\r
50                 } while(sNewName.IsEmpty() || PathFileExists(droppath+_T("\\")+sNewName));\r
51         }\r
52         CProgressDlg progress;\r
53         if (progress.IsValid())\r
54         {\r
55                 progress.SetTitle(IDS_PROC_MOVING);\r
56                 progress.SetAnimation(IDR_MOVEANI);\r
57                 progress.SetTime(true);\r
58                 progress.ShowModeless(CWnd::FromHandle(hwndExplorer));\r
59         }\r
60         for(int nPath = 0; nPath < pathList.GetCount(); nPath++)\r
61         {\r
62                 CTSVNPath destPath;\r
63                 if (sNewName.IsEmpty())\r
64                         destPath = CTSVNPath(droppath+_T("\\")+pathList[nPath].GetFileOrDirectoryName());\r
65                 else\r
66                         destPath = CTSVNPath(droppath+_T("\\")+sNewName);\r
67                 if (destPath.Exists())\r
68                 {\r
69                         CString name = pathList[nPath].GetFileOrDirectoryName();\r
70                         if (!sNewName.IsEmpty())\r
71                                 name = sNewName;\r
72                         progress.Stop();\r
73                         CRenameDlg dlg;\r
74                         dlg.m_name = name;\r
75                         dlg.m_windowtitle.Format(IDS_PROC_NEWNAMEMOVE, (LPCTSTR)name);\r
76                         if (dlg.DoModal() != IDOK)\r
77                         {\r
78                                 return FALSE;\r
79                         }\r
80                         destPath.SetFromWin(droppath+_T("\\")+dlg.m_name);\r
81                 } \r
82                 if (!svn.Move(CTSVNPathList(pathList[nPath]), destPath, FALSE))\r
83                 {\r
84                         if (svn.Err && (svn.Err->apr_err == SVN_ERR_UNVERSIONED_RESOURCE ||\r
85                                 svn.Err->apr_err == SVN_ERR_CLIENT_MODIFIED))\r
86                         {\r
87                                 // file/folder seems to have local modifications. Ask the user if\r
88                                 // a force is requested.\r
89                                 CString temp = svn.GetLastErrorMessage();\r
90                                 CString sQuestion(MAKEINTRESOURCE(IDS_PROC_FORCEMOVE));\r
91                                 temp += _T("\n") + sQuestion;\r
92                                 if (CMessageBox::Show(hwndExplorer, temp, _T("TortoiseSVN"), MB_YESNO)==IDYES)\r
93                                 {\r
94                                         if (!svn.Move(CTSVNPathList(pathList[nPath]), destPath, TRUE))\r
95                                         {\r
96                                                 CMessageBox::Show(hwndExplorer, svn.GetLastErrorMessage(), _T("TortoiseSVN"), MB_ICONERROR);\r
97                                                 return FALSE;           //get out of here\r
98                                         }\r
99                                         CShellUpdater::Instance().AddPathForUpdate(destPath);\r
100                                 }\r
101                         }\r
102                         else\r
103                         {\r
104                                 TRACE(_T("%s\n"), (LPCTSTR)svn.GetLastErrorMessage());\r
105                                 CMessageBox::Show(hwndExplorer, svn.GetLastErrorMessage(), _T("TortoiseSVN"), MB_ICONERROR);\r
106                                 return FALSE;           //get out of here\r
107                         }\r
108                 } \r
109                 else\r
110                         CShellUpdater::Instance().AddPathForUpdate(destPath);\r
111                 count++;\r
112                 if (progress.IsValid())\r
113                 {\r
114                         progress.FormatPathLine(1, IDS_PROC_MOVINGPROG, pathList[nPath].GetWinPath());\r
115                         progress.FormatPathLine(2, IDS_PROC_CPYMVPROG2, destPath.GetWinPath());\r
116                         progress.SetProgress(count, pathList.GetCount());\r
117                 }\r
118                 if ((progress.IsValid())&&(progress.HasUserCancelled()))\r
119                 {\r
120                         CMessageBox::Show(hwndExplorer, IDS_SVN_USERCANCELLED, IDS_APPNAME, MB_ICONINFORMATION);\r
121                         return FALSE;\r
122                 }\r
123         }\r
124         return true;\r
125 }\r