Extend static functions in CAppUtils with a window handle parameter
[TortoiseGit.git] / src / TortoiseProc / Commands / PasteMoveCommand.cpp
blob4b7853a0536b58f1a1d38f28e9822bd559f45278
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008, 2012-2013, 2015-2017 - TortoiseGit
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 "PasteMoveCommand.h"
22 #include "SysProgressDlg.h"
23 #include "MessageBox.h"
24 #include "Git.h"
25 #include "RenameDlg.h"
26 #include "ShellUpdater.h"
28 bool PasteMoveCommand::Execute()
30 CString sDroppath = parser.GetVal(L"droptarget");
31 CTGitPath dropPath(sDroppath);
32 if (dropPath.IsAdminDir())
33 return FALSE;
35 if(!dropPath.HasAdminDir(&g_Git.m_CurrentDir))
36 return FALSE;
38 unsigned long count = 0;
39 orgPathList.RemoveAdminPaths();
40 CString sNewName;
41 CSysProgressDlg progress;
42 progress.SetTitle(IDS_PROC_MOVING);
43 progress.SetTime(true);
44 progress.ShowModeless(CWnd::FromHandle(hwndExplorer));
45 for (int nPath = 0; nPath < orgPathList.GetCount(); ++nPath)
47 CTGitPath destPath;
48 if (sNewName.IsEmpty())
49 destPath = CTGitPath(sDroppath + L'\\' + orgPathList[nPath].GetFileOrDirectoryName());
50 else
51 destPath = CTGitPath(sDroppath + L'\\' + sNewName);
52 if (destPath.Exists())
54 CString name = orgPathList[nPath].GetFileOrDirectoryName();
55 if (!sNewName.IsEmpty())
56 name = sNewName;
57 progress.Stop();
58 CRenameDlg dlg;
59 dlg.m_name = name;
60 dlg.m_windowtitle.Format(IDS_PROC_NEWNAMEMOVE, (LPCTSTR)name);
61 if (dlg.DoModal() != IDOK)
62 return FALSE;
63 destPath.SetFromWin(sDroppath + L'\\' + dlg.m_name);
65 CString top;
66 orgPathList[nPath].HasAdminDir(&top);
67 //git_wc_status_kind s = status.GetAllStatus(orgPathList[nPath]);
68 //if (s == git_wc_status_none || s == git_wc_status_unversioned || s == git_wc_status_ignored || top.CompareNoCase(g_Git.m_CurrentDir) != 0)
69 if (false)
71 // source file is unversioned: move the file to the target, then add it
72 MoveFile(orgPathList[nPath].GetWinPath(), destPath.GetWinPath());
73 CString cmd,output;
74 cmd.Format(L"git.exe add -- \"%s\"", destPath.GetWinPath());
75 if (g_Git.Run(cmd, &output, CP_UTF8))
76 //if (!Git.Add(CTGitorgPathList(destPath), &props, Git_depth_infinity, true, false, true))
78 TRACE(L"%s\n", (LPCTSTR)output);
79 CMessageBox::Show(hwndExplorer, output, L"TortoiseGit", MB_ICONERROR);
80 return FALSE; //get out of here
82 CShellUpdater::Instance().AddPathForUpdate(destPath);
84 else
86 CString cmd,output;
87 cmd.Format(L"git.exe mv \"%s\" \"%s\"", (LPCTSTR)orgPathList[nPath].GetGitPathString(), (LPCTSTR)destPath.GetGitPathString());
88 if (g_Git.Run(cmd, &output, CP_UTF8))
89 //if (!Git.Move(CTGitorgPathList(orgPathList[nPath]), destPath, FALSE))
91 #if 0
92 if (Git.Err && (Git.Err->apr_err == Git_ERR_UNVERSIONED_RESOURCE ||
93 Git.Err->apr_err == Git_ERR_CLIENT_MODIFIED))
95 // file/folder seems to have local modifications. Ask the user if
96 // a force is requested.
97 CString temp = Git.GetLastErrorMessage();
98 CString sQuestion(MAKEINTRESOURCE(IDS_PROC_FORCEMOVE));
99 temp += L'\n' + sQuestion;
100 if (CMessageBox::Show(hwndExplorer, temp, L"TortoiseGit", MB_YESNO) == IDYES)
102 if (!Git.Move(CTGitPathList(pathList[nPath]), destPath, TRUE))
104 CMessageBox::Show(hwndExplorer, Git.GetLastErrorMessage(), L"TortoiseGit", MB_ICONERROR);
105 return FALSE; //get out of here
107 CShellUpdater::Instance().AddPathForUpdate(destPath);
110 else
111 #endif
113 TRACE(L"%s\n", (LPCTSTR)output);
114 CMessageBox::Show(hwndExplorer, output, L"TortoiseGit", MB_ICONERROR);
115 return FALSE; //get out of here
118 else
119 CShellUpdater::Instance().AddPathForUpdate(destPath);
121 ++count;
122 if (progress.IsValid())
124 progress.FormatPathLine(1, IDS_PROC_MOVINGPROG, orgPathList[nPath].GetWinPath());
125 progress.FormatPathLine(2, IDS_PROC_CPYMVPROG2, destPath.GetWinPath());
126 progress.SetProgress(count, orgPathList.GetCount());
128 if ((progress.IsValid())&&(progress.HasUserCancelled()))
130 CMessageBox::Show(hwndExplorer, IDS_USERCANCELLED, IDS_APPNAME, MB_ICONINFORMATION);
131 return FALSE;
134 return true;