OSDN Git Service

Show Ignore Sub Menu
[tortoisegit/TortoiseGitJp.git] / TortoiseProc / Commands / DropCopyCommand.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 "DropCopyCommand.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 "ShellUpdater.h"\r
28 \r
29 bool DropCopyCommand::Execute()\r
30 {\r
31         CString sDroppath = parser.GetVal(_T("droptarget"));\r
32         if (CTSVNPath(sDroppath).IsAdminDir())\r
33                 return FALSE;\r
34         SVN svn;\r
35         unsigned long count = 0;\r
36         CString sNewName;\r
37         pathList.RemoveAdminPaths();\r
38         if ((parser.HasKey(_T("rename")))&&(pathList.GetCount()==1))\r
39         {\r
40                 // ask for a new name of the source item\r
41                 do \r
42                 {\r
43                         CRenameDlg renDlg;\r
44                         renDlg.m_windowtitle.LoadString(IDS_PROC_COPYRENAME);\r
45                         renDlg.m_name = pathList[0].GetFileOrDirectoryName();\r
46                         if (renDlg.DoModal() != IDOK)\r
47                         {\r
48                                 return FALSE;\r
49                         }\r
50                         sNewName = renDlg.m_name;\r
51                 } while(sNewName.IsEmpty() || PathFileExists(sDroppath+_T("\\")+sNewName));\r
52         }\r
53         CProgressDlg progress;\r
54         progress.SetTitle(IDS_PROC_COPYING);\r
55         progress.SetAnimation(IDR_MOVEANI);\r
56         progress.SetTime(true);\r
57         progress.ShowModeless(CWnd::FromHandle(hwndExplorer));\r
58         for(int nPath = 0; nPath < pathList.GetCount(); nPath++)\r
59         {\r
60                 const CTSVNPath& sourcePath = pathList[nPath];\r
61 \r
62                 CTSVNPath fullDropPath(sDroppath);\r
63                 if (sNewName.IsEmpty())\r
64                         fullDropPath.AppendPathString(sourcePath.GetFileOrDirectoryName());\r
65                 else\r
66                         fullDropPath.AppendPathString(sNewName);\r
67 \r
68                 // Check for a drop-on-to-ourselves\r
69                 if (sourcePath.IsEquivalentTo(fullDropPath))\r
70                 {\r
71                         // Offer a rename\r
72                         progress.Stop();\r
73                         CRenameDlg dlg;\r
74                         dlg.m_windowtitle.Format(IDS_PROC_NEWNAMECOPY, (LPCTSTR)sourcePath.GetUIFileOrDirectoryName());\r
75                         if (dlg.DoModal() != IDOK)\r
76                         {\r
77                                 return FALSE;\r
78                         }\r
79                         // rebuild the progress dialog\r
80                         progress.EnsureValid();\r
81                         progress.SetTitle(IDS_PROC_COPYING);\r
82                         progress.SetAnimation(IDR_MOVEANI);\r
83                         progress.SetTime(true);\r
84                         progress.SetProgress(count, pathList.GetCount());\r
85                         progress.ShowModeless(CWnd::FromHandle(hwndExplorer));\r
86                         // Rebuild the destination path, with the new name\r
87                         fullDropPath.SetFromUnknown(sDroppath);\r
88                         fullDropPath.AppendPathString(dlg.m_name);\r
89                 } \r
90                 if (!svn.Copy(CTSVNPathList(sourcePath), fullDropPath, SVNRev::REV_WC, SVNRev()))\r
91                 {\r
92                         TRACE(_T("%s\n"), (LPCTSTR)svn.GetLastErrorMessage());\r
93                         CMessageBox::Show(hwndExplorer, svn.GetLastErrorMessage(), _T("TortoiseSVN"), MB_ICONERROR);\r
94                         return FALSE;           //get out of here\r
95                 }\r
96                 else\r
97                         CShellUpdater::Instance().AddPathForUpdate(fullDropPath);\r
98                 count++;\r
99                 if (progress.IsValid())\r
100                 {\r
101                         progress.FormatPathLine(1, IDS_PROC_COPYINGPROG, sourcePath.GetWinPath());\r
102                         progress.FormatPathLine(2, IDS_PROC_CPYMVPROG2, fullDropPath.GetWinPath());\r
103                         progress.SetProgress(count, pathList.GetCount());\r
104                 }\r
105                 if ((progress.IsValid())&&(progress.HasUserCancelled()))\r
106                 {\r
107                         CMessageBox::Show(hwndExplorer, IDS_SVN_USERCANCELLED, IDS_APPNAME, MB_ICONINFORMATION);\r
108                         return false;\r
109                 }\r
110         }\r
111         return true;\r
112 }\r