OSDN Git Service

Share resource file between TortoiseGitBlame and TortoiseProc
[tortoisegit/TortoiseGitJp.git] / src / TortoiseProc / Commands / PasteCopyCommand.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 "PasteCopyCommand.h"\r
21 \r
22 #include "SVNProgressDlg.h"\r
23 #include "ProgressDlg.h"\r
24 #include "MessageBox.h"\r
25 #include "RenameDlg.h"\r
26 #include "SVN.h"\r
27 #include "SVNStatus.h"\r
28 #include "ShellUpdater.h"\r
29 \r
30 bool PasteCopyCommand::Execute()\r
31 {\r
32         CString sDroppath = parser.GetVal(_T("droptarget"));\r
33         CTSVNPath dropPath(sDroppath);\r
34         ProjectProperties props;\r
35         props.ReadProps(dropPath);\r
36         if (dropPath.IsAdminDir())\r
37                 return FALSE;\r
38         SVN svn;\r
39         SVNStatus status;\r
40         unsigned long count = 0;\r
41         CString sNewName;\r
42         pathList.RemoveAdminPaths();\r
43         CProgressDlg progress;\r
44         progress.SetTitle(IDS_PROC_COPYING);\r
45         progress.SetAnimation(IDR_MOVEANI);\r
46         progress.SetTime(true);\r
47         progress.ShowModeless(CWnd::FromHandle(hwndExplorer));\r
48         for(int nPath = 0; nPath < pathList.GetCount(); nPath++)\r
49         {\r
50                 const CTSVNPath& sourcePath = pathList[nPath];\r
51 \r
52                 CTSVNPath fullDropPath = dropPath;\r
53                 if (sNewName.IsEmpty())\r
54                         fullDropPath.AppendPathString(sourcePath.GetFileOrDirectoryName());\r
55                 else\r
56                         fullDropPath.AppendPathString(sNewName);\r
57 \r
58                 // Check for a drop-on-to-ourselves\r
59                 if (sourcePath.IsEquivalentTo(fullDropPath))\r
60                 {\r
61                         // Offer a rename\r
62                         progress.Stop();\r
63                         CRenameDlg dlg;\r
64                         dlg.m_windowtitle.Format(IDS_PROC_NEWNAMECOPY, (LPCTSTR)sourcePath.GetUIFileOrDirectoryName());\r
65                         if (dlg.DoModal() != IDOK)\r
66                         {\r
67                                 return FALSE;\r
68                         }\r
69                         // rebuild the progress dialog\r
70                         progress.EnsureValid();\r
71                         progress.SetTitle(IDS_PROC_COPYING);\r
72                         progress.SetAnimation(IDR_MOVEANI);\r
73                         progress.SetTime(true);\r
74                         progress.SetProgress(count, pathList.GetCount());\r
75                         progress.ShowModeless(CWnd::FromHandle(hwndExplorer));\r
76                         // Rebuild the destination path, with the new name\r
77                         fullDropPath.SetFromUnknown(sDroppath);\r
78                         fullDropPath.AppendPathString(dlg.m_name);\r
79                 }\r
80 \r
81                 svn_wc_status_kind s = status.GetAllStatus(sourcePath);\r
82                 if ((s == svn_wc_status_none)||(s == svn_wc_status_unversioned)||(s == svn_wc_status_ignored))\r
83                 {\r
84                         // source file is unversioned: move the file to the target, then add it\r
85                         CopyFile(sourcePath.GetWinPath(), fullDropPath.GetWinPath(), FALSE);\r
86                         if (!svn.Add(CTSVNPathList(fullDropPath), &props, svn_depth_infinity, true, false, true))\r
87                         {\r
88                                 TRACE(_T("%s\n"), (LPCTSTR)svn.GetLastErrorMessage());\r
89                                 CMessageBox::Show(hwndExplorer, svn.GetLastErrorMessage(), _T("TortoiseSVN"), MB_ICONERROR);\r
90                                 return FALSE;           //get out of here\r
91                         }\r
92                         else\r
93                                 CShellUpdater::Instance().AddPathForUpdate(fullDropPath);\r
94                 }\r
95                 else\r
96                 {\r
97                         if (!svn.Copy(CTSVNPathList(sourcePath), fullDropPath, SVNRev::REV_WC, SVNRev()))\r
98                         {\r
99                                 TRACE(_T("%s\n"), (LPCTSTR)svn.GetLastErrorMessage());\r
100                                 CMessageBox::Show(hwndExplorer, svn.GetLastErrorMessage(), _T("TortoiseSVN"), MB_ICONERROR);\r
101                                 return FALSE;           //get out of here\r
102                         }\r
103                         else\r
104                                 CShellUpdater::Instance().AddPathForUpdate(fullDropPath);\r
105                 }\r
106                 count++;\r
107                 if (progress.IsValid())\r
108                 {\r
109                         progress.FormatPathLine(1, IDS_PROC_COPYINGPROG, sourcePath.GetWinPath());\r
110                         progress.FormatPathLine(2, IDS_PROC_CPYMVPROG2, fullDropPath.GetWinPath());\r
111                         progress.SetProgress(count, pathList.GetCount());\r
112                 }\r
113                 if ((progress.IsValid())&&(progress.HasUserCancelled()))\r
114                 {\r
115                         CMessageBox::Show(hwndExplorer, IDS_SVN_USERCANCELLED, IDS_APPNAME, MB_ICONINFORMATION);\r
116                         return false;\r
117                 }\r
118         }\r
119         return true;\r
120 }