1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2009, 2011-2017 - 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.
21 #include "DropMoveCommand.h"
23 #include "SysProgressDlg.h"
24 #include "MessageBox.h"
26 #include "RenameDlg.h"
27 #include "ShellUpdater.h"
29 bool DropMoveCommand::Execute()
31 CString droppath
= parser
.GetVal(L
"droptarget");
33 if (!CTGitPath(droppath
).HasAdminDir(&ProjectTop
))
36 if (g_Git
.m_CurrentDir
.CompareNoCase(ProjectTop
) != 0)
38 CMessageBox::Show(hwndExplorer
, IDS_ERR_MUSTBESAMEWT
, IDS_APPNAME
, MB_OK
| MB_ICONEXCLAMATION
);
42 if (ProjectTop
.GetLength() == 3 && ProjectTop
.Mid(1, 2) == L
":\\") // working tree root is directly on a drive
43 droppath
= droppath
.Right(droppath
.GetLength() - ProjectTop
.GetLength());
45 droppath
= droppath
.Right(droppath
.GetLength() - ProjectTop
.GetLength() - 1);
46 if (!droppath
.IsEmpty())
49 unsigned long count
= 0;
50 pathList
.RemoveAdminPaths();
53 if (parser
.HasKey(L
"rename") && pathList
.GetCount() == 1)
55 // ask for a new name of the source item
57 renDlg
.SetRenameRequired(pathList
[0].GetContainingDirectory().IsEquivalentToWithoutCase(droppath
));
58 renDlg
.SetInputValidator([&](const int /*nID*/, const CString
& input
) -> CString
60 if (PathFileExists(g_Git
.CombinePath(droppath
+ L
'\\' + input
)))
61 return CString(CFormatMessageWrapper(ERROR_FILE_EXISTS
));
65 renDlg
.m_sBaseDir
= g_Git
.CombinePath(droppath
);
66 renDlg
.m_windowtitle
.LoadString(IDS_PROC_MOVERENAME
);
67 renDlg
.m_name
= pathList
[0].GetFileOrDirectoryName();
68 if (renDlg
.DoModal() != IDOK
)
70 sNewName
= renDlg
.m_name
;
72 CSysProgressDlg progress
;
73 if (progress
.IsValid())
75 progress
.SetTitle(IDS_PROC_MOVING
);
76 progress
.SetAnimation(IDR_MOVEANI
);
77 progress
.SetTime(true);
78 progress
.ShowModeless(CWnd::FromHandle(hwndExplorer
));
80 for (int nPath
= 0; nPath
< pathList
.GetCount(); ++nPath
)
83 if (sNewName
.IsEmpty())
84 destPath
= CTGitPath(droppath
+ pathList
[nPath
].GetFileOrDirectoryName());
86 destPath
= CTGitPath(droppath
+ sNewName
);
87 if (destPath
.Exists())
91 CString name
= destPath
.GetFileOrDirectoryName();
94 dlg
.SetInputValidator([&](const int /*nID*/, const CString
& input
) -> CString
96 if (PathFileExists(g_Git
.CombinePath(droppath
+ L
'\\' + input
)))
97 return CString(CFormatMessageWrapper(ERROR_FILE_EXISTS
));
101 dlg
.m_sBaseDir
= g_Git
.CombinePath(destPath
);
103 dlg
.m_windowtitle
.Format(IDS_PROC_NEWNAMEMOVE
, (LPCTSTR
)name
);
104 if (dlg
.DoModal() != IDOK
)
107 // rebuild the progress dialog
108 progress
.EnsureValid();
109 progress
.SetTitle(IDS_PROC_MOVING
);
110 progress
.SetAnimation(IDR_MOVEANI
);
111 progress
.SetTime(true);
112 progress
.SetProgress(count
, pathList
.GetCount());
113 progress
.ShowModeless(CWnd::FromHandle(hwndExplorer
));
115 // Rebuild the destination path, with the new name
116 destPath
.SetFromUnknown(droppath
);
117 destPath
.AppendPathString(dlg
.m_name
);
121 cmd
.Format(L
"git.exe mv -- \"%s\" \"%s\"", (LPCTSTR
)pathList
[nPath
].GetGitPathString(), (LPCTSTR
)destPath
.GetGitPathString());
122 if (g_Git
.Run(cmd
, &out
, CP_UTF8
))
124 if (CMessageBox::Show(hwndExplorer
, out
, L
"TortoiseGit", 2, IDI_EXCLAMATION
, CString(MAKEINTRESOURCE(IDS_IGNOREBUTTON
)), CString(MAKEINTRESOURCE(IDS_ABORTBUTTON
))) == 1)
127 if (!svn
.Move(CTSVNPathList(pathList
[nPath
]), destPath
, TRUE
))
129 CMessageBox::Show(hwndExplorer
, svn
.GetLastErrorMessage(), L
"TortoiseGit", MB_ICONERROR
);
130 return FALSE
; //get out of here
132 CShellUpdater::Instance().AddPathForUpdate(destPath
);
137 CMessageBox::Show(hwndExplorer
, IDS_USERCANCELLED
, IDS_APPNAME
, MB_ICONERROR
);
138 return FALSE
; //get out of here
142 CShellUpdater::Instance().AddPathForUpdate(destPath
);
144 if (progress
.IsValid())
146 progress
.FormatPathLine(1, IDS_PROC_MOVINGPROG
, pathList
[nPath
].GetWinPath());
147 progress
.FormatPathLine(2, IDS_PROC_CPYMVPROG2
, destPath
.GetWinPath());
148 progress
.SetProgress(count
, pathList
.GetCount());
150 if ((progress
.IsValid())&&(progress
.HasUserCancelled()))
152 CMessageBox::Show(hwndExplorer
, IDS_USERCANCELLED
, IDS_APPNAME
, MB_ICONINFORMATION
);