Drop "SVN" from string resource IDs
[TortoiseGit.git] / src / TortoiseProc / Commands / DropMoveCommand.cpp
blobcd95fafa3ed9d780fc02d45a7472c491c9bb0f59
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2009,2011-2014 - TortoiseGit
4 // Copyright (C) 2007-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 "DropMoveCommand.h"
23 #include "SysProgressDlg.h"
24 #include "MessageBox.h"
25 #include "Git.h"
26 #include "RenameDlg.h"
27 #include "ShellUpdater.h"
29 bool DropMoveCommand::Execute()
31 CString droppath = parser.GetVal(_T("droptarget"));
32 CString ProjectTop;
33 if (!CTGitPath(droppath).HasAdminDir(&ProjectTop))
34 return FALSE;
36 if (ProjectTop != g_Git.m_CurrentDir )
38 CMessageBox::Show(NULL,_T("Target and source must be the same git repository"),_T("TortoiseGit"),MB_OK);
39 return FALSE;
42 if (ProjectTop.GetLength() == 3 && ProjectTop.Mid(1, 2) == _T(":\\")) // working tree root is directly on a drive
43 droppath = droppath.Right(droppath.GetLength() - ProjectTop.GetLength());
44 else
45 droppath = droppath.Right(droppath.GetLength() - ProjectTop.GetLength() - 1);
46 if (!droppath.IsEmpty())
47 droppath += L"\\";
49 unsigned long count = 0;
50 pathList.RemoveAdminPaths();
51 CString sNewName;
53 if ((parser.HasKey(_T("rename")))&&(pathList.GetCount()==1))
55 // ask for a new name of the source item
58 CRenameDlg renDlg;
59 renDlg.m_windowtitle.LoadString(IDS_PROC_MOVERENAME);
60 renDlg.m_name = pathList[0].GetFileOrDirectoryName();
61 if (renDlg.DoModal() != IDOK)
63 return FALSE;
65 sNewName = renDlg.m_name;
66 } while(sNewName.IsEmpty() || PathFileExists(droppath + sNewName));
68 CSysProgressDlg progress;
69 if (progress.IsValid())
71 progress.SetTitle(IDS_PROC_MOVING);
72 progress.SetAnimation(IDR_MOVEANI);
73 progress.SetTime(true);
74 progress.ShowModeless(CWnd::FromHandle(hwndExplorer));
76 for (int nPath = 0; nPath < pathList.GetCount(); ++nPath)
78 CTGitPath destPath;
79 if (sNewName.IsEmpty())
80 destPath = CTGitPath(droppath + pathList[nPath].GetFileOrDirectoryName());
81 else
82 destPath = CTGitPath(droppath + sNewName);
83 if (destPath.Exists())
85 CString name = pathList[nPath].GetFileOrDirectoryName();
86 if (!sNewName.IsEmpty())
87 name = sNewName;
88 progress.Stop();
89 CRenameDlg dlg;
90 dlg.m_name = name;
91 dlg.m_windowtitle.Format(IDS_PROC_NEWNAMEMOVE, (LPCTSTR)name);
92 if (dlg.DoModal() != IDOK)
94 return FALSE;
96 destPath.SetFromWin(droppath + dlg.m_name);
98 CString cmd,out;
100 cmd.Format(_T("git.exe mv -- \"%s\" \"%s\""),pathList[nPath].GetGitPathString(),destPath.GetGitPathString());
101 if (g_Git.Run(cmd, &out, CP_UTF8))
103 if (CMessageBox::Show(hwndExplorer, out, _T("TortoiseGit"), 2, IDI_EXCLAMATION, CString(MAKEINTRESOURCE(IDS_IGNOREBUTTON)), CString(MAKEINTRESOURCE(IDS_ABORTBUTTON))) == 1)
105 #if 0
106 if (!svn.Move(CTSVNPathList(pathList[nPath]), destPath, TRUE))
108 CMessageBox::Show(hwndExplorer, svn.GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR);
109 return FALSE; //get out of here
111 CShellUpdater::Instance().AddPathForUpdate(destPath);
112 #endif
114 else
116 CMessageBox::Show(hwndExplorer, IDS_USERCANCELLED, IDS_APPNAME, MB_ICONERROR);
117 return FALSE; //get out of here
120 else
121 CShellUpdater::Instance().AddPathForUpdate(destPath);
122 ++count;
123 if (progress.IsValid())
125 progress.FormatPathLine(1, IDS_PROC_MOVINGPROG, pathList[nPath].GetWinPath());
126 progress.FormatPathLine(2, IDS_PROC_CPYMVPROG2, destPath.GetWinPath());
127 progress.SetProgress(count, pathList.GetCount());
129 if ((progress.IsValid())&&(progress.HasUserCancelled()))
131 CMessageBox::Show(hwndExplorer, IDS_USERCANCELLED, IDS_APPNAME, MB_ICONINFORMATION);
132 return FALSE;
135 return true;