Cleanup
[TortoiseGit.git] / src / TortoiseProc / Commands / DropMoveCommand.cpp
blob0756b0e1bd154911184b05f9d4bf33c4e63253af
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2007-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 "DropMoveCommand.h"
22 #include "SysProgressDlg.h"
23 #include "MessageBox.h"
24 #include "Git.h"
25 #include "RenameDlg.h"
26 #include "ShellUpdater.h"
28 bool DropMoveCommand::Execute()
30 CString droppath = parser.GetVal(_T("droptarget"));
31 CString ProjectTop;
32 if (!CTGitPath(droppath).HasAdminDir(&ProjectTop))
33 return FALSE;
35 if (ProjectTop != g_Git.m_CurrentDir )
37 CMessageBox::Show(NULL,_T("Target and source must be the same git repository"),_T("TortoiseGit"),MB_OK);
38 return FALSE;
41 droppath = droppath.Right(droppath.GetLength()-ProjectTop.GetLength()-1);
43 unsigned long count = 0;
44 pathList.RemoveAdminPaths();
45 CString sNewName;
47 if ((parser.HasKey(_T("rename")))&&(pathList.GetCount()==1))
49 // ask for a new name of the source item
52 CRenameDlg renDlg;
53 renDlg.m_windowtitle.LoadString(IDS_PROC_MOVERENAME);
54 renDlg.m_name = pathList[0].GetFileOrDirectoryName();
55 if (renDlg.DoModal() != IDOK)
57 return FALSE;
59 sNewName = renDlg.m_name;
60 } while(sNewName.IsEmpty() || PathFileExists(droppath+_T("\\")+sNewName));
62 CSysProgressDlg progress;
63 if (progress.IsValid())
65 progress.SetTitle(IDS_PROC_MOVING);
66 progress.SetAnimation(IDR_MOVEANI);
67 progress.SetTime(true);
68 progress.ShowModeless(CWnd::FromHandle(hwndExplorer));
70 for(int nPath = 0; nPath < pathList.GetCount(); nPath++)
72 CTGitPath destPath;
73 if (sNewName.IsEmpty())
74 destPath = CTGitPath(droppath+_T("\\")+pathList[nPath].GetFileOrDirectoryName());
75 else
76 destPath = CTGitPath(droppath+_T("\\")+sNewName);
77 if (destPath.Exists())
79 CString name = pathList[nPath].GetFileOrDirectoryName();
80 if (!sNewName.IsEmpty())
81 name = sNewName;
82 progress.Stop();
83 CRenameDlg dlg;
84 dlg.m_name = name;
85 dlg.m_windowtitle.Format(IDS_PROC_NEWNAMEMOVE, (LPCTSTR)name);
86 if (dlg.DoModal() != IDOK)
88 return FALSE;
90 destPath.SetFromWin(droppath+_T("\\")+dlg.m_name);
92 CString cmd,out;
94 cmd.Format(_T("git.exe mv -- \"%s\" \"%s\""),pathList[nPath].GetGitPathString(),destPath.GetGitPathString());
95 if (g_Git.Run(cmd, &out, CP_UTF8))
97 if (CMessageBox::Show(hwndExplorer, out, _T("TortoiseGit"), MB_YESNO)==IDYES)
99 #if 0
100 if (!svn.Move(CTSVNPathList(pathList[nPath]), destPath, TRUE))
102 CMessageBox::Show(hwndExplorer, svn.GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR);
103 return FALSE; //get out of here
105 CShellUpdater::Instance().AddPathForUpdate(destPath);
106 #endif
108 else
110 //TRACE(_T("%s\n"), (LPCTSTR)svn.GetLastErrorMessage());
111 CMessageBox::Show(hwndExplorer, _T("Cancel"), _T("TortoiseGit"), MB_ICONERROR);
112 return FALSE; //get out of here
115 else
116 CShellUpdater::Instance().AddPathForUpdate(destPath);
117 count++;
118 if (progress.IsValid())
120 progress.FormatPathLine(1, IDS_PROC_MOVINGPROG, pathList[nPath].GetWinPath());
121 progress.FormatPathLine(2, IDS_PROC_CPYMVPROG2, destPath.GetWinPath());
122 progress.SetProgress(count, pathList.GetCount());
124 if ((progress.IsValid())&&(progress.HasUserCancelled()))
126 CMessageBox::Show(hwndExplorer, IDS_SVN_USERCANCELLED, IDS_APPNAME, MB_ICONINFORMATION);
127 return FALSE;
130 return true;