OSDN Git Service

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