Includes cleanup
[TortoiseGit.git] / src / TortoiseProc / Commands / PasteCopyCommand.cpp
blobd58e13815b2c4c880854dd5514d68ae255e7129d
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2009, 2011-2013, 2015 - TortoiseGit
4 // Copyright (C) 2008 - TortoiseSVN
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 2
9 // of the License, or (at your option) any later version.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software Foundation,
18 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 #include "stdafx.h"
21 #include "PasteCopyCommand.h"
23 #include "SysProgressDlg.h"
24 #include "MessageBox.h"
25 #include "RenameDlg.h"
26 #include "Git.h"
27 #include "GitStatus.h"
28 #include "ShellUpdater.h"
30 bool PasteCopyCommand::Execute()
32 CString sDroppath = parser.GetVal(_T("droptarget"));
33 CTGitPath dropPath(sDroppath);
34 if (dropPath.IsAdminDir())
35 return FALSE;
37 if(!dropPath.HasAdminDir(&g_Git.m_CurrentDir))
38 return FALSE;
39 //SVN svn;
40 //SVNStatus status;
41 unsigned long count = 0;
42 CString sNewName;
43 orgPathList.RemoveAdminPaths();
44 CSysProgressDlg progress;
45 progress.SetTitle(IDS_PROC_COPYING);
46 progress.SetAnimation(IDR_MOVEANI);
47 progress.SetTime(true);
48 progress.ShowModeless(CWnd::FromHandle(hwndExplorer));
49 for (int nPath = 0; nPath < orgPathList.GetCount(); ++nPath)
51 const CTGitPath& sourcePath = orgPathList[nPath];
53 CTGitPath fullDropPath = dropPath;
54 if (sNewName.IsEmpty())
55 fullDropPath.AppendPathString(sourcePath.GetFileOrDirectoryName());
56 else
57 fullDropPath.AppendPathString(sNewName);
59 // Check for a drop-on-to-ourselves
60 if (sourcePath.IsEquivalentTo(fullDropPath))
62 // Offer a rename
63 progress.Stop();
64 CRenameDlg dlg;
65 dlg.m_windowtitle.Format(IDS_PROC_NEWNAMECOPY, (LPCTSTR)sourcePath.GetUIFileOrDirectoryName());
66 if (dlg.DoModal() != IDOK)
68 return FALSE;
70 // rebuild the progress dialog
71 progress.EnsureValid();
72 progress.SetTitle(IDS_PROC_COPYING);
73 progress.SetAnimation(IDR_MOVEANI);
74 progress.SetTime(true);
75 progress.SetProgress(count, orgPathList.GetCount());
76 progress.ShowModeless(CWnd::FromHandle(hwndExplorer));
77 // Rebuild the destination path, with the new name
78 fullDropPath.SetFromUnknown(sDroppath);
79 fullDropPath.AppendPathString(dlg.m_name);
82 //svn_wc_status_kind s = status.GetAllStatus(sourcePath);
83 //if ((s == svn_wc_status_none)||(s == svn_wc_status_unversioned)||(s == svn_wc_status_ignored))
85 // source file is unversioned: move the file to the target, then add it
86 CopyFile(sourcePath.GetWinPath(), fullDropPath.GetWinPath(), FALSE);
87 CString cmd,output;
88 cmd.Format(_T("git.exe add -- \"%s\""),fullDropPath.GetWinPath());
89 if (g_Git.Run(cmd, &output, CP_UTF8))
91 TRACE(_T("%s\n"), (LPCTSTR)output);
92 CMessageBox::Show(hwndExplorer, output, _T("TortoiseGit"), MB_ICONERROR);
93 return FALSE; //get out of here
95 else
96 CShellUpdater::Instance().AddPathForUpdate(fullDropPath);
98 //else
99 //{
100 // if (!svn.Copy(CTSVNPathList(sourcePath), fullDropPath, SVNRev::REV_WC, SVNRev()))
101 // {
102 // TRACE(_T("%s\n"), (LPCTSTR)svn.GetLastErrorMessage());
103 // CMessageBox::Show(hwndExplorer, svn.GetLastErrorMessage(), _T("TortoiseSVN"), MB_ICONERROR);
104 // return FALSE; //get out of here
105 // }
106 // else
107 // CShellUpdater::Instance().AddPathForUpdate(fullDropPath);
109 ++count;
110 if (progress.IsValid())
112 progress.FormatPathLine(1, IDS_PROC_COPYINGPROG, sourcePath.GetWinPath());
113 progress.FormatPathLine(2, IDS_PROC_CPYMVPROG2, fullDropPath.GetWinPath());
114 progress.SetProgress(count, orgPathList.GetCount());
116 if ((progress.IsValid())&&(progress.HasUserCancelled()))
118 CMessageBox::Show(hwndExplorer, IDS_SVN_USERCANCELLED, IDS_APPNAME, MB_ICONINFORMATION);
119 return false;
122 return true;