OSDN Git Service

Add Paste Command at shell extension.
authorFrank Li <lznuaa@gmail.com>
Fri, 25 Sep 2009 02:12:21 +0000 (10:12 +0800)
committerFrank Li <lznuaa@gmail.com>
Fri, 25 Sep 2009 02:12:21 +0000 (10:12 +0800)
Copy and paste file is okay. But there are problems when including directory.
Cut and paste working.

Signed-off-by: Frank Li <lznuaa@gmail.com>
src/TortoiseProc/Commands/Command.cpp
src/TortoiseProc/Commands/PasteCopyCommand.cpp
src/TortoiseProc/Commands/PasteMoveCommand.cpp
src/TortoiseProc/TortoiseProc.vcproj
src/TortoiseShell/ContextMenu.cpp
src/TortoiseShell/Globals.h

index 3e15b96..4e3a1ea 100644 (file)
@@ -66,6 +66,8 @@
 #include "SVNRebaseCommand.h"\r
 #include "SyncCommand.h"\r
 #include "UpdateCheckCommand.h"\r
+#include "PasteCopyCommand.h"\r
+#include "PasteMoveCommand.h"\r
 \r
 #if 0\r
 \r
@@ -91,8 +93,6 @@
 \r
 \r
 #include "MergeAllCommand.h"\r
-#include "PasteCopyCommand.h"\r
-#include "PasteMoveCommand.h"\r
 \r
 #include "PropertiesCommand.h"\r
 #include "RebuildIconCacheCommand.h"\r
@@ -386,6 +386,10 @@ Command * CommandServer::GetCommand(const CString& sCmd)
                return new SyncCommand;\r
        case cmdUpdateCheck:\r
                return new UpdateCheckCommand;\r
+       case cmdPasteCopy:\r
+               return new PasteCopyCommand;\r
+       case cmdPasteMove:\r
+               return new PasteMoveCommand;\r
 \r
 #if 0\r
 \r
@@ -412,10 +416,6 @@ Command * CommandServer::GetCommand(const CString& sCmd)
                return new LockCommand;\r
        case cmdMergeAll:\r
                return new MergeAllCommand;\r
-       case cmdPasteCopy:\r
-               return new PasteCopyCommand;\r
-       case cmdPasteMove:\r
-               return new PasteMoveCommand;\r
        case cmdPrevDiff:\r
                return new PrevDiffCommand;\r
        case cmdProperties:\r
index 3d7577e..0f90dc4 100644 (file)
 #include "StdAfx.h"\r
 #include "PasteCopyCommand.h"\r
 \r
-#include "SVNProgressDlg.h"\r
 #include "ProgressDlg.h"\r
+#include "SysProgressDlg.h"\r
 #include "MessageBox.h"\r
 #include "RenameDlg.h"\r
-#include "SVN.h"\r
-#include "SVNStatus.h"\r
+#include "Git.h"\r
+#include "GitStatus.h"\r
 #include "ShellUpdater.h"\r
+#include "ProjectProperties.h"\r
+#include "CommonResource.h"\r
 \r
 bool PasteCopyCommand::Execute()\r
 {\r
        CString sDroppath = parser.GetVal(_T("droptarget"));\r
-       CTSVNPath dropPath(sDroppath);\r
+       CTGitPath dropPath(sDroppath);\r
        ProjectProperties props;\r
        props.ReadProps(dropPath);\r
        if (dropPath.IsAdminDir())\r
                return FALSE;\r
-       SVN svn;\r
-       SVNStatus status;\r
+\r
+       if(!dropPath.HasAdminDir(&g_Git.m_CurrentDir))\r
+               return FALSE;\r
+       //SVN svn;\r
+       //SVNStatus status;\r
        unsigned long count = 0;\r
        CString sNewName;\r
-       pathList.RemoveAdminPaths();\r
-       CProgressDlg progress;\r
+       orgPathList.RemoveAdminPaths();\r
+       CSysProgressDlg progress;\r
        progress.SetTitle(IDS_PROC_COPYING);\r
        progress.SetAnimation(IDR_MOVEANI);\r
        progress.SetTime(true);\r
        progress.ShowModeless(CWnd::FromHandle(hwndExplorer));\r
-       for(int nPath = 0; nPath < pathList.GetCount(); nPath++)\r
+       for(int nPath = 0; nPath < orgPathList.GetCount(); nPath++)\r
        {\r
-               const CTSVNPath& sourcePath = pathList[nPath];\r
+               const CTGitPath& sourcePath = orgPathList[nPath];\r
 \r
-               CTSVNPath fullDropPath = dropPath;\r
+               CTGitPath fullDropPath = dropPath;\r
                if (sNewName.IsEmpty())\r
                        fullDropPath.AppendPathString(sourcePath.GetFileOrDirectoryName());\r
                else\r
@@ -71,44 +76,46 @@ bool PasteCopyCommand::Execute()
                        progress.SetTitle(IDS_PROC_COPYING);\r
                        progress.SetAnimation(IDR_MOVEANI);\r
                        progress.SetTime(true);\r
-                       progress.SetProgress(count, pathList.GetCount());\r
+                       progress.SetProgress(count, orgPathList.GetCount());\r
                        progress.ShowModeless(CWnd::FromHandle(hwndExplorer));\r
                        // Rebuild the destination path, with the new name\r
                        fullDropPath.SetFromUnknown(sDroppath);\r
                        fullDropPath.AppendPathString(dlg.m_name);\r
                }\r
 \r
-               svn_wc_status_kind s = status.GetAllStatus(sourcePath);\r
-               if ((s == svn_wc_status_none)||(s == svn_wc_status_unversioned)||(s == svn_wc_status_ignored))\r
+               //svn_wc_status_kind s = status.GetAllStatus(sourcePath);\r
+               //if ((s == svn_wc_status_none)||(s == svn_wc_status_unversioned)||(s == svn_wc_status_ignored))\r
                {\r
                        // source file is unversioned: move the file to the target, then add it\r
                        CopyFile(sourcePath.GetWinPath(), fullDropPath.GetWinPath(), FALSE);\r
-                       if (!svn.Add(CTSVNPathList(fullDropPath), &props, svn_depth_infinity, true, false, true))\r
-                       {\r
-                               TRACE(_T("%s\n"), (LPCTSTR)svn.GetLastErrorMessage());\r
-                               CMessageBox::Show(hwndExplorer, svn.GetLastErrorMessage(), _T("TortoiseSVN"), MB_ICONERROR);\r
-                               return FALSE;           //get out of here\r
-                       }\r
-                       else\r
-                               CShellUpdater::Instance().AddPathForUpdate(fullDropPath);\r
-               }\r
-               else\r
-               {\r
-                       if (!svn.Copy(CTSVNPathList(sourcePath), fullDropPath, SVNRev::REV_WC, SVNRev()))\r
+                       CString cmd,output;\r
+                       cmd.Format(_T("git.exe add \"%s\""),fullDropPath.GetWinPath());\r
+                       if( g_Git.Run(cmd,&output,CP_ACP))\r
                        {\r
-                               TRACE(_T("%s\n"), (LPCTSTR)svn.GetLastErrorMessage());\r
-                               CMessageBox::Show(hwndExplorer, svn.GetLastErrorMessage(), _T("TortoiseSVN"), MB_ICONERROR);\r
+                               TRACE(_T("%s\n"), (LPCTSTR)output);\r
+                               CMessageBox::Show(hwndExplorer, output, _T("TortoiseGit"), MB_ICONERROR);\r
                                return FALSE;           //get out of here\r
                        }\r
                        else\r
                                CShellUpdater::Instance().AddPathForUpdate(fullDropPath);\r
                }\r
+               //else\r
+               //{\r
+               //      if (!svn.Copy(CTSVNPathList(sourcePath), fullDropPath, SVNRev::REV_WC, SVNRev()))\r
+               //      {\r
+               //              TRACE(_T("%s\n"), (LPCTSTR)svn.GetLastErrorMessage());\r
+               //              CMessageBox::Show(hwndExplorer, svn.GetLastErrorMessage(), _T("TortoiseSVN"), MB_ICONERROR);\r
+               //              return FALSE;           //get out of here\r
+               //      }\r
+               //      else\r
+               //              CShellUpdater::Instance().AddPathForUpdate(fullDropPath);\r
+               //}\r
                count++;\r
                if (progress.IsValid())\r
                {\r
                        progress.FormatPathLine(1, IDS_PROC_COPYINGPROG, sourcePath.GetWinPath());\r
                        progress.FormatPathLine(2, IDS_PROC_CPYMVPROG2, fullDropPath.GetWinPath());\r
-                       progress.SetProgress(count, pathList.GetCount());\r
+                       progress.SetProgress(count, orgPathList.GetCount());\r
                }\r
                if ((progress.IsValid())&&(progress.HasUserCancelled()))\r
                {\r
index 34ac2fa..6e72fc1 100644 (file)
@@ -1,6 +1,6 @@
-// TortoiseSVN - a Windows shell extension for easy version control\r
+// TortoiseGit - a Windows shell extension for easy version control\r
 \r
-// Copyright (C) 2008 - TortoiseSVN\r
+// Copyright (C) 2008 - TortoiseGit\r
 \r
 // This program is free software; you can redistribute it and/or\r
 // modify it under the terms of the GNU General Public License\r
 #include "StdAfx.h"\r
 #include "PasteMoveCommand.h"\r
 \r
-#include "ProgressDlg.h"\r
+#include "SysProgressDlg.h"\r
 #include "MessageBox.h"\r
-#include "SVN.h"\r
-#include "SVNStatus.h"\r
+#include "Git.h"\r
+#include "GitStatus.h"\r
 #include "RenameDlg.h"\r
 #include "ShellUpdater.h"\r
+#include "ProjectProperties.h"\r
+#include "CommonResource.h"\r
 \r
 bool PasteMoveCommand::Execute()\r
 {\r
        CString sDroppath = parser.GetVal(_T("droptarget"));\r
-       CTSVNPath dropPath(sDroppath);\r
+       CTGitPath dropPath(sDroppath);\r
        ProjectProperties props;\r
        props.ReadProps(dropPath);\r
        if (dropPath.IsAdminDir())\r
                return FALSE;\r
-       SVN svn;\r
-       SVNStatus status;\r
+\r
+       if(!dropPath.HasAdminDir(&g_Git.m_CurrentDir))\r
+               return FALSE;\r
+\r
+       GitStatus status;\r
        unsigned long count = 0;\r
-       pathList.RemoveAdminPaths();\r
+       orgPathList.RemoveAdminPaths();\r
        CString sNewName;\r
-       CProgressDlg progress;\r
+       CSysProgressDlg progress;\r
        progress.SetTitle(IDS_PROC_MOVING);\r
        progress.SetAnimation(IDR_MOVEANI);\r
        progress.SetTime(true);\r
        progress.ShowModeless(CWnd::FromHandle(hwndExplorer));\r
-       for(int nPath = 0; nPath < pathList.GetCount(); nPath++)\r
+       for(int nPath = 0; nPath < orgPathList.GetCount(); nPath++)\r
        {\r
-               CTSVNPath destPath;\r
+               CTGitPath destPath;\r
                if (sNewName.IsEmpty())\r
-                       destPath = CTSVNPath(sDroppath+_T("\\")+pathList[nPath].GetFileOrDirectoryName());\r
+                       destPath = CTGitPath(sDroppath+_T("\\")+orgPathList[nPath].GetFileOrDirectoryName());\r
                else\r
-                       destPath = CTSVNPath(sDroppath+_T("\\")+sNewName);\r
+                       destPath = CTGitPath(sDroppath+_T("\\")+sNewName);\r
                if (destPath.Exists())\r
                {\r
-                       CString name = pathList[nPath].GetFileOrDirectoryName();\r
+                       CString name = orgPathList[nPath].GetFileOrDirectoryName();\r
                        if (!sNewName.IsEmpty())\r
                                name = sNewName;\r
                        progress.Stop();\r
@@ -66,45 +71,56 @@ bool PasteMoveCommand::Execute()
                        }\r
                        destPath.SetFromWin(sDroppath+_T("\\")+dlg.m_name);\r
                }\r
-               svn_wc_status_kind s = status.GetAllStatus(pathList[nPath]);\r
-               if ((s == svn_wc_status_none)||(s == svn_wc_status_unversioned)||(s == svn_wc_status_ignored))\r
+               CString top;\r
+               top.Empty();\r
+               orgPathList[nPath].HasAdminDir(&top);\r
+               git_wc_status_kind s = status.GetAllStatus(orgPathList[nPath]);\r
+               if ((s == git_wc_status_none)||(s == git_wc_status_unversioned)||(s == git_wc_status_ignored)||top != g_Git.m_CurrentDir)\r
                {\r
                        // source file is unversioned: move the file to the target, then add it\r
-                       MoveFile(pathList[nPath].GetWinPath(), destPath.GetWinPath());\r
-                       if (!svn.Add(CTSVNPathList(destPath), &props, svn_depth_infinity, true, false, true))\r
+                       MoveFile(orgPathList[nPath].GetWinPath(), destPath.GetWinPath());\r
+                       CString cmd,output;\r
+                       cmd.Format(_T("git.exe add \"%s\""),destPath.GetWinPath());\r
+                       if(g_Git.Run(cmd,&output,CP_ACP))\r
+                       //if (!Git.Add(CTGitorgPathList(destPath), &props, Git_depth_infinity, true, false, true))\r
                        {\r
-                               TRACE(_T("%s\n"), (LPCTSTR)svn.GetLastErrorMessage());\r
-                               CMessageBox::Show(hwndExplorer, svn.GetLastErrorMessage(), _T("TortoiseSVN"), MB_ICONERROR);\r
+                               TRACE(_T("%s\n"), output);\r
+                               CMessageBox::Show(hwndExplorer, output, _T("TortoiseGit"), MB_ICONERROR);\r
                                return FALSE;           //get out of here\r
                        }\r
                        CShellUpdater::Instance().AddPathForUpdate(destPath);\r
                }\r
                else\r
                {\r
-                       if (!svn.Move(CTSVNPathList(pathList[nPath]), destPath, FALSE))\r
+                       CString cmd,output;\r
+                       cmd.Format(_T("git.exe mv \"%s\" \"%s\""),orgPathList[nPath].GetGitPathString(),destPath.GetGitPathString());\r
+                       if(g_Git.Run(cmd,&output,CP_ACP))\r
+                       //if (!Git.Move(CTGitorgPathList(orgPathList[nPath]), destPath, FALSE))\r
                        {\r
-                               if (svn.Err && (svn.Err->apr_err == SVN_ERR_UNVERSIONED_RESOURCE ||\r
-                                       svn.Err->apr_err == SVN_ERR_CLIENT_MODIFIED))\r
+#if 0\r
+                               if (Git.Err && (Git.Err->apr_err == Git_ERR_UNVERSIONED_RESOURCE ||\r
+                                       Git.Err->apr_err == Git_ERR_CLIENT_MODIFIED))\r
                                {\r
                                        // file/folder seems to have local modifications. Ask the user if\r
                                        // a force is requested.\r
-                                       CString temp = svn.GetLastErrorMessage();\r
+                                       CString temp = Git.GetLastErrorMessage();\r
                                        CString sQuestion(MAKEINTRESOURCE(IDS_PROC_FORCEMOVE));\r
                                        temp += _T("\n") + sQuestion;\r
-                                       if (CMessageBox::Show(hwndExplorer, temp, _T("TortoiseSVN"), MB_YESNO)==IDYES)\r
+                                       if (CMessageBox::Show(hwndExplorer, temp, _T("TortoiseGit"), MB_YESNO)==IDYES)\r
                                        {\r
-                                               if (!svn.Move(CTSVNPathList(pathList[nPath]), destPath, TRUE))\r
+                                               if (!Git.Move(CTGitPathList(pathList[nPath]), destPath, TRUE))\r
                                                {\r
-                                                       CMessageBox::Show(hwndExplorer, svn.GetLastErrorMessage(), _T("TortoiseSVN"), MB_ICONERROR);\r
+                                                       CMessageBox::Show(hwndExplorer, Git.GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR);\r
                                                        return FALSE;           //get out of here\r
                                                }\r
                                                CShellUpdater::Instance().AddPathForUpdate(destPath);\r
                                        }\r
                                }\r
                                else\r
+#endif\r
                                {\r
-                                       TRACE(_T("%s\n"), (LPCTSTR)svn.GetLastErrorMessage());\r
-                                       CMessageBox::Show(hwndExplorer, svn.GetLastErrorMessage(), _T("TortoiseSVN"), MB_ICONERROR);\r
+                                       TRACE(_T("%s\n"), (LPCTSTR)output);\r
+                                       CMessageBox::Show(hwndExplorer, output, _T("TortoiseGit"), MB_ICONERROR);\r
                                        return FALSE;           //get out of here\r
                                }\r
                        } \r
@@ -114,9 +130,9 @@ bool PasteMoveCommand::Execute()
                count++;\r
                if (progress.IsValid())\r
                {\r
-                       progress.FormatPathLine(1, IDS_PROC_MOVINGPROG, pathList[nPath].GetWinPath());\r
+                       progress.FormatPathLine(1, IDS_PROC_MOVINGPROG, orgPathList[nPath].GetWinPath());\r
                        progress.FormatPathLine(2, IDS_PROC_CPYMVPROG2, destPath.GetWinPath());\r
-                       progress.SetProgress(count, pathList.GetCount());\r
+                       progress.SetProgress(count, orgPathList.GetCount());\r
                }\r
                if ((progress.IsValid())&&(progress.HasUserCancelled()))\r
                {\r
index d03b238..28f0c99 100644 (file)
                                >\r
                        </File>\r
                        <File\r
-                               RelativePath=".\copy.ico"\r
+                               RelativePath="..\Resources\copy.ico"\r
                                >\r
                        </File>\r
                        <File\r
-                               RelativePath="..\Resources\copy.ico"\r
+                               RelativePath=".\copy.ico"\r
                                >\r
                        </File>\r
                        <File\r
                                >\r
                        </File>\r
                        <File\r
-                               RelativePath="..\Resources\explorer.ico"\r
+                               RelativePath=".\explorer.ico"\r
                                >\r
                        </File>\r
                        <File\r
-                               RelativePath=".\explorer.ico"\r
+                               RelativePath="..\Resources\explorer.ico"\r
                                >\r
                        </File>\r
                        <File\r
                                >\r
                        </File>\r
                        <File\r
-                               RelativePath=".\newfolder.ico"\r
+                               RelativePath="..\Resources\newfolder.ico"\r
                                >\r
                        </File>\r
                        <File\r
-                               RelativePath="..\Resources\newfolder.ico"\r
+                               RelativePath=".\newfolder.ico"\r
                                >\r
                        </File>\r
                        <File\r
                                >\r
                        </File>\r
                        <File\r
-                               RelativePath=".\refresh.ico"\r
+                               RelativePath="..\Resources\refresh.ico"\r
                                >\r
                        </File>\r
                        <File\r
-                               RelativePath="..\Resources\refresh.ico"\r
+                               RelativePath=".\refresh.ico"\r
                                >\r
                        </File>\r
                        <File\r
                                >\r
                        </File>\r
                        <File\r
-                               RelativePath="..\Resources\save.ico"\r
+                               RelativePath=".\save.ico"\r
                                >\r
                        </File>\r
                        <File\r
-                               RelativePath=".\save.ico"\r
+                               RelativePath="..\Resources\save.ico"\r
                                >\r
                        </File>\r
                        <File\r
                                >\r
                        </File>\r
                        <File\r
-                               RelativePath=".\up.ico"\r
+                               RelativePath="..\Resources\up.ico"\r
                                >\r
                        </File>\r
                        <File\r
-                               RelativePath="..\Resources\up.ico"\r
+                               RelativePath=".\up.ico"\r
                                >\r
                        </File>\r
                        <File\r
                                        >\r
                                </File>\r
                        </Filter>\r
+                       <Filter\r
+                               Name="Paste"\r
+                               >\r
+                               <File\r
+                                       RelativePath=".\Commands\PasteCopyCommand.cpp"\r
+                                       >\r
+                               </File>\r
+                               <File\r
+                                       RelativePath=".\Commands\PasteMoveCommand.cpp"\r
+                                       >\r
+                               </File>\r
+                       </Filter>\r
                </Filter>\r
                <Filter\r
                        Name="Utility Dialogs"\r
index 3ce2c55..83ae0e2 100644 (file)
@@ -234,8 +234,8 @@ CShellExt::MenuInfo CShellExt::menuInfo[] =
 //     ITEMIS_INSVN, 0, ITEMIS_FOLDERINSVN, 0, 0, 0, 0, 0 },\r
 \r
        { ShellSeparator, 0, 0, 0, 0, 0, 0, 0, 0},\r
-//     { ShellMenuClipPaste,                                   MENUCLIPPASTE,          IDI_CLIPPASTE,                  IDS_MENUCLIPPASTE,                      IDS_MENUDESCCLIPPASTE,\r
-//     ITEMIS_INSVN|ITEMIS_FOLDER|ITEMIS_PATHINCLIPBOARD, 0, 0, 0, 0, 0, 0, 0 },\r
+       { ShellMenuClipPaste,                                   MENUCLIPPASTE,          IDI_CLIPPASTE,                  IDS_MENUCLIPPASTE,                      IDS_MENUDESCCLIPPASTE,\r
+       ITEMIS_INSVN|ITEMIS_FOLDER|ITEMIS_PATHINCLIPBOARD, 0, 0, 0, 0, 0, 0, 0 },\r
 \r
        { ShellSeparator, 0, 0, 0, 0, 0, 0, 0, 0},\r
 \r
index 08ca6d8..85b07d9 100644 (file)
@@ -52,7 +52,7 @@
 #define MENUDELUNVERSIONED     0x0000000080000000\r
 #define MENUMERGEALL           0x0000000100000000\r
 #define MENUPREVDIFF           0x0000000200000000\r
-//#define MENUCLIPPASTE                0x0000000400000000\r
+#define MENUCLIPPASTE          0x0000000400000000\r
 #define MENUPULL                       0x0000000800000000\r
 #define MENUPUSH                       0x0000001000000000\r
 #define MENUCLONE           0x0000002000000000\r