Use processdlg to format patch.
[TortoiseGit.git] / src / TortoiseProc / Commands / PasteMoveCommand.cpp
blob34ac2fab91dd121ea92efc0faf91cf36716aa99c
1 // TortoiseSVN - a Windows shell extension for easy version control
3 // Copyright (C) 2008 - TortoiseSVN
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 2
8 // of the License, or (at your option) any later version.
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software Foundation,
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 #include "StdAfx.h"
20 #include "PasteMoveCommand.h"
22 #include "ProgressDlg.h"
23 #include "MessageBox.h"
24 #include "SVN.h"
25 #include "SVNStatus.h"
26 #include "RenameDlg.h"
27 #include "ShellUpdater.h"
29 bool PasteMoveCommand::Execute()
31 CString sDroppath = parser.GetVal(_T("droptarget"));
32 CTSVNPath dropPath(sDroppath);
33 ProjectProperties props;
34 props.ReadProps(dropPath);
35 if (dropPath.IsAdminDir())
36 return FALSE;
37 SVN svn;
38 SVNStatus status;
39 unsigned long count = 0;
40 pathList.RemoveAdminPaths();
41 CString sNewName;
42 CProgressDlg progress;
43 progress.SetTitle(IDS_PROC_MOVING);
44 progress.SetAnimation(IDR_MOVEANI);
45 progress.SetTime(true);
46 progress.ShowModeless(CWnd::FromHandle(hwndExplorer));
47 for(int nPath = 0; nPath < pathList.GetCount(); nPath++)
49 CTSVNPath destPath;
50 if (sNewName.IsEmpty())
51 destPath = CTSVNPath(sDroppath+_T("\\")+pathList[nPath].GetFileOrDirectoryName());
52 else
53 destPath = CTSVNPath(sDroppath+_T("\\")+sNewName);
54 if (destPath.Exists())
56 CString name = pathList[nPath].GetFileOrDirectoryName();
57 if (!sNewName.IsEmpty())
58 name = sNewName;
59 progress.Stop();
60 CRenameDlg dlg;
61 dlg.m_name = name;
62 dlg.m_windowtitle.Format(IDS_PROC_NEWNAMEMOVE, (LPCTSTR)name);
63 if (dlg.DoModal() != IDOK)
65 return FALSE;
67 destPath.SetFromWin(sDroppath+_T("\\")+dlg.m_name);
69 svn_wc_status_kind s = status.GetAllStatus(pathList[nPath]);
70 if ((s == svn_wc_status_none)||(s == svn_wc_status_unversioned)||(s == svn_wc_status_ignored))
72 // source file is unversioned: move the file to the target, then add it
73 MoveFile(pathList[nPath].GetWinPath(), destPath.GetWinPath());
74 if (!svn.Add(CTSVNPathList(destPath), &props, svn_depth_infinity, true, false, true))
76 TRACE(_T("%s\n"), (LPCTSTR)svn.GetLastErrorMessage());
77 CMessageBox::Show(hwndExplorer, svn.GetLastErrorMessage(), _T("TortoiseSVN"), MB_ICONERROR);
78 return FALSE; //get out of here
80 CShellUpdater::Instance().AddPathForUpdate(destPath);
82 else
84 if (!svn.Move(CTSVNPathList(pathList[nPath]), destPath, FALSE))
86 if (svn.Err && (svn.Err->apr_err == SVN_ERR_UNVERSIONED_RESOURCE ||
87 svn.Err->apr_err == SVN_ERR_CLIENT_MODIFIED))
89 // file/folder seems to have local modifications. Ask the user if
90 // a force is requested.
91 CString temp = svn.GetLastErrorMessage();
92 CString sQuestion(MAKEINTRESOURCE(IDS_PROC_FORCEMOVE));
93 temp += _T("\n") + sQuestion;
94 if (CMessageBox::Show(hwndExplorer, temp, _T("TortoiseSVN"), MB_YESNO)==IDYES)
96 if (!svn.Move(CTSVNPathList(pathList[nPath]), destPath, TRUE))
98 CMessageBox::Show(hwndExplorer, svn.GetLastErrorMessage(), _T("TortoiseSVN"), MB_ICONERROR);
99 return FALSE; //get out of here
101 CShellUpdater::Instance().AddPathForUpdate(destPath);
104 else
106 TRACE(_T("%s\n"), (LPCTSTR)svn.GetLastErrorMessage());
107 CMessageBox::Show(hwndExplorer, svn.GetLastErrorMessage(), _T("TortoiseSVN"), MB_ICONERROR);
108 return FALSE; //get out of here
111 else
112 CShellUpdater::Instance().AddPathForUpdate(destPath);
114 count++;
115 if (progress.IsValid())
117 progress.FormatPathLine(1, IDS_PROC_MOVINGPROG, pathList[nPath].GetWinPath());
118 progress.FormatPathLine(2, IDS_PROC_CPYMVPROG2, destPath.GetWinPath());
119 progress.SetProgress(count, pathList.GetCount());
121 if ((progress.IsValid())&&(progress.HasUserCancelled()))
123 CMessageBox::Show(hwndExplorer, IDS_SVN_USERCANCELLED, IDS_APPNAME, MB_ICONINFORMATION);
124 return FALSE;
127 return true;