| 26 | #include "ShellUpdater.h" |
| 27 | |
| 28 | bool DropCopyCommand::Execute() |
| 29 | { |
| 30 | CString sDroppath = parser.GetVal(L"droptarget"); |
| 31 | if (CTGitPath(sDroppath).IsAdminDir()) |
| 32 | { |
| 33 | MessageBox(GetExplorerHWND(), L"Can't drop to .git repository directory\n", L"TortoiseGit", MB_OK | MB_ICONERROR); |
| 34 | return FALSE; |
| 35 | } |
| 36 | unsigned long count = 0; |
| 37 | |
| 38 | CString sNewName; |
| 39 | pathList.RemoveAdminPaths(); |
| 40 | if (parser.HasKey(L"rename") && pathList.GetCount() == 1) |
| 41 | { |
| 42 | // ask for a new name of the source item |
| 43 | CRenameDlg renDlg; |
| 44 | renDlg.SetInputValidator([&](const int /*nID*/, const CString& input) -> CString |
| 45 | { |
| 46 | if (PathFileExists(sDroppath + L'\\' + input)) |
| 47 | return CString(static_cast<LPCWSTR>(CFormatMessageWrapper(ERROR_FILE_EXISTS))); |
| 48 | |
| 49 | return{}; |
| 50 | }); |
| 51 | renDlg.m_sBaseDir = sDroppath; |
| 52 | renDlg.m_windowtitle.LoadString(IDS_PROC_COPYRENAME); |
| 53 | renDlg.m_name = pathList[0].GetFileOrDirectoryName(); |
| 54 | if (renDlg.DoModal() != IDOK) |
| 55 | return FALSE; |
| 56 | sNewName = renDlg.m_name; |
| 57 | } |
| 58 | CSysProgressDlg progress; |
| 59 | progress.SetTitle(IDS_PROC_COPYING); |
| 60 | progress.SetTime(true); |
| 61 | progress.ShowModeless(CWnd::FromHandle(GetExplorerHWND())); |
| 62 | for (int nPath = 0; nPath < pathList.GetCount(); ++nPath) |
| 63 | { |
| 64 | const CTGitPath& sourcePath = orgPathList[nPath]; |
| 65 | |
| 66 | CTGitPath fullDropPath(sDroppath); |
| 67 | |
| 68 | if (sNewName.IsEmpty()) |
| 69 | fullDropPath.AppendPathString(sourcePath.GetFileOrDirectoryName()); |
| 70 | else |
| 71 | fullDropPath.AppendPathString(sNewName); |
| 72 | |
| 73 | // Check for a drop-on-to-ourselves |
| 74 | if (sourcePath.IsEquivalentTo(fullDropPath)) |
| 75 | { |
| 76 | // Offer a rename |
| 77 | progress.Stop(); |
| 78 | CRenameDlg dlg; |
| 79 | dlg.SetInputValidator([&](const int /*nID*/, const CString& input) -> CString |
| 80 | { |
| 81 | CTGitPath newPath(sDroppath); |
| 82 | newPath.AppendPathString(input); |
| 83 | if (newPath.Exists()) |
| 84 | return CString(static_cast<LPCWSTR>(CFormatMessageWrapper(ERROR_FILE_EXISTS))); |
| 85 |
nothing calls this directly
no test coverage detected