1 // TortoiseSVN - a Windows shell extension for easy version control
\r
3 // Copyright (C) 2007-2008 - TortoiseSVN
\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
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
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
20 #include "DropMoveCommand.h"
\r
22 #include "SysProgressDlg.h"
\r
23 #include "MessageBox.h"
\r
25 #include "RenameDlg.h"
\r
26 #include "ShellUpdater.h"
\r
27 #include "commonresource.h"
\r
29 bool DropMoveCommand::Execute()
\r
31 CString droppath = parser.GetVal(_T("droptarget"));
\r
33 if (CTGitPath(droppath).HasAdminDir(&ProjectTop))
\r
36 if (ProjectTop != g_Git.m_CurrentDir )
\r
38 CMessageBox::Show(NULL,_T("Target and source must be the same git repository"),_T("TortoiseGit"),MB_OK);
\r
42 droppath.Right(droppath.GetLength()-ProjectTop.GetLength()-1);
\r
44 unsigned long count = 0;
\r
45 pathList.RemoveAdminPaths();
\r
48 if ((parser.HasKey(_T("rename")))&&(pathList.GetCount()==1))
\r
50 // ask for a new name of the source item
\r
54 renDlg.m_windowtitle.LoadString(IDS_PROC_MOVERENAME);
\r
55 renDlg.m_name = pathList[0].GetFileOrDirectoryName();
\r
56 if (renDlg.DoModal() != IDOK)
\r
60 sNewName = renDlg.m_name;
\r
61 } while(sNewName.IsEmpty() || PathFileExists(droppath+_T("\\")+sNewName));
\r
63 CSysProgressDlg progress;
\r
64 if (progress.IsValid())
\r
66 progress.SetTitle(IDS_PROC_MOVING);
\r
67 progress.SetAnimation(IDR_MOVEANI);
\r
68 progress.SetTime(true);
\r
69 progress.ShowModeless(CWnd::FromHandle(hwndExplorer));
\r
71 for(int nPath = 0; nPath < pathList.GetCount(); nPath++)
\r
74 if (sNewName.IsEmpty())
\r
75 destPath = CTGitPath(droppath+_T("\\")+pathList[nPath].GetFileOrDirectoryName());
\r
77 destPath = CTGitPath(droppath+_T("\\")+sNewName);
\r
78 if (destPath.Exists())
\r
80 CString name = pathList[nPath].GetFileOrDirectoryName();
\r
81 if (!sNewName.IsEmpty())
\r
86 dlg.m_windowtitle.Format(IDS_PROC_NEWNAMEMOVE, (LPCTSTR)name);
\r
87 if (dlg.DoModal() != IDOK)
\r
91 destPath.SetFromWin(droppath+_T("\\")+dlg.m_name);
\r
95 cmd.Format(_T("git.exe mv \"%s\" \"%s\""),pathList[nPath].GetGitPathString(),destPath.GetGitPathString());
\r
96 if(g_Git.Run(cmd,&out,CP_OEMCP))
\r
98 if (CMessageBox::Show(hwndExplorer, out, _T("TortoiseGit"), MB_YESNO)==IDYES)
\r
101 if (!svn.Move(CTSVNPathList(pathList[nPath]), destPath, TRUE))
\r
103 CMessageBox::Show(hwndExplorer, svn.GetLastErrorMessage(), _T("TortoiseSVN"), MB_ICONERROR);
\r
104 return FALSE; //get out of here
\r
106 CShellUpdater::Instance().AddPathForUpdate(destPath);
\r
111 //TRACE(_T("%s\n"), (LPCTSTR)svn.GetLastErrorMessage());
\r
112 CMessageBox::Show(hwndExplorer, _T("Cancel"), _T("TortoiseGit"), MB_ICONERROR);
\r
113 return FALSE; //get out of here
\r
117 CShellUpdater::Instance().AddPathForUpdate(destPath);
\r
119 if (progress.IsValid())
\r
121 progress.FormatPathLine(1, IDS_PROC_MOVINGPROG, pathList[nPath].GetWinPath());
\r
122 progress.FormatPathLine(2, IDS_PROC_CPYMVPROG2, destPath.GetWinPath());
\r
123 progress.SetProgress(count, pathList.GetCount());
\r
125 if ((progress.IsValid())&&(progress.HasUserCancelled()))
\r
127 CMessageBox::Show(hwndExplorer, IDS_SVN_USERCANCELLED, IDS_APPNAME, MB_ICONINFORMATION);
\r