OSDN Git Service

PATCH: [ 699893 ] Add drag&drop of files/paths to main window
authorKimmo Varis <kimmov@gmail.com>
Sun, 9 Mar 2003 19:55:04 +0000 (19:55 +0000)
committerKimmo Varis <kimmov@gmail.com>
Sun, 9 Mar 2003 19:55:04 +0000 (19:55 +0000)
Src/MainFrm.cpp
Src/MainFrm.h
Src/Merge.cpp
Src/paths.cpp
Src/paths.h
Src/readme.txt

index 91cd22f..81fa8d0 100644 (file)
@@ -49,6 +49,7 @@
 #include "PropSyntax.h"
 #include "ssapi.h"      // BSP - Includes for Visual Source Safe COM interface
 #include "multimon.h"
+#include "paths.h"
 
 #ifdef _DEBUG
 #define new DEBUG_NEW
@@ -94,7 +95,7 @@ BEGIN_MESSAGE_MAP(CMainFrame, CMDIFrameWnd)
        ON_WM_CLOSE()
        ON_COMMAND(ID_VIEW_WHITESPACE, OnViewWhitespace)
        ON_UPDATE_COMMAND_UI(ID_VIEW_WHITESPACE, OnUpdateViewWhitespace)
-
+       ON_WM_DROPFILES()
        //}}AFX_MSG_MAP
 END_MESSAGE_MAP()
 
@@ -1423,3 +1424,66 @@ void CMainFrame::ConvertPathToSlashes(LPTSTR path)
        while (ptr != NULL);
 }
 
+/////////////////////////////////////////////////////////////////////////////
+//
+//     OnDropFiles code from CDropEdit
+//     Copyright 1997 Chris Losinger
+//
+//     shortcut expansion code modified from :
+//     CShortcut, 1996 Rob Warner
+//
+void CMainFrame::OnDropFiles(HDROP dropInfo)
+{
+       // Get the number of pathnames that have been dropped
+       UINT wNumFilesDropped = DragQueryFile(dropInfo, 0xFFFFFFFF, NULL, 0);
+       CString files[2];
+       int fileCount = 0;
+
+       // get all file names. but we'll only need the first one.
+       for (WORD x = 0 ; x < wNumFilesDropped; x++)
+       {
+               // Get the number of bytes required by the file's full pathname
+               UINT wPathnameSize = DragQueryFile(dropInfo, x, NULL, 0);
+
+               // Allocate memory to contain full pathname & zero byte
+               char * npszFile = (char *) LocalAlloc(LPTR, wPathnameSize += 1);
+
+               // If not enough memory, skip this one
+               if (npszFile == NULL) continue;
+
+               // Copy the pathname into the buffer
+               DragQueryFile(dropInfo, x, npszFile, wPathnameSize);
+
+               if (x < 2)
+               {
+                       files[x] = npszFile;
+                       fileCount++;
+               }
+               // clean up
+               LocalFree(npszFile);
+       }
+
+       // Free the memory block containing the dropped-file information
+       DragFinish(dropInfo);
+
+       for (int i = 0; i < fileCount; i++)
+       {
+               // if this was a shortcut, we need to expand it to the target path
+               CString expandedFile = ExpandShortcut(files[i]);
+
+               // if that worked, we should have a real file name
+               if (expandedFile != _T("")) 
+                       files[i] = expandedFile;
+       }
+
+       if (m_pMergeDoc != NULL)
+       {
+               // Save files and update dirview status if needed
+               if (!m_pMergeDoc->SaveHelper())
+                       return;
+       }
+       
+       // If Ctrl pressed, do recursive compare
+       BOOL ctrlKey = ::GetAsyncKeyState(VK_CONTROL);
+       DoFileOpen(files[0], files[1], ctrlKey);
+}
index b16c91e..d6b1cc4 100644 (file)
@@ -159,6 +159,7 @@ protected:
        afx_msg void OnClose();
        afx_msg void OnViewWhitespace();
        afx_msg void OnUpdateViewWhitespace(CCmdUI* pCmdUI);
+       afx_msg void OnDropFiles(HDROP dropInfo);
 
        //}}AFX_MSG
        DECLARE_MESSAGE_MAP()
index 6d8f14d..1d8ce85 100644 (file)
@@ -159,6 +159,8 @@ BOOL CMergeApp::InitInstance()
        if (!pMainFrame->LoadFrame(IDR_MAINFRAME))
                return FALSE;
        m_pMainWnd = pMainFrame;
+       // Enable drag&drop files
+       pMainFrame->ModifyStyleEx(NULL, WS_EX_ACCEPTFILES);
 
        pMainFrame->m_hMenuDefault=pMainFrame->NewDefaultMenu();
 
index 990dd96..90aef42 100644 (file)
@@ -191,3 +191,58 @@ TCHAR paths_GetCurrentDrive()
        return curdir[0];
 }
 
+//////////////////////////////////////////////////////////////////
+//     use IShellLink to expand the shortcut
+//     returns the expanded file, or "" on error
+//
+//     original code was part of CShortcut 
+//     1996 by Rob Warner
+//     rhwarner@southeast.net
+//     http://users.southeast.net/~rhwarner
+CString ExpandShortcut(CString &inFile)
+{
+       CString outFile = "";
+
+    // Make sure we have a path
+    ASSERT(inFile != _T(""));
+
+    IShellLink* psl;
+    HRESULT hres;
+    LPTSTR lpsz = inFile.GetBuffer(MAX_PATH);
+
+    // Create instance for shell link
+    hres = ::CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER,
+        IID_IShellLink, (LPVOID*) &psl);
+    if (SUCCEEDED(hres))
+    {
+        // Get a pointer to the persist file interface
+        IPersistFile* ppf;
+        hres = psl->QueryInterface(IID_IPersistFile, (LPVOID*) &ppf);
+        if (SUCCEEDED(hres))
+        {
+            // Make sure it's ANSI
+            WORD wsz[MAX_PATH];
+            ::MultiByteToWideChar(CP_ACP, 0, lpsz, -1, wsz, MAX_PATH);
+
+            // Load shortcut
+            hres = ppf->Load(wsz, STGM_READ);
+            if (SUCCEEDED(hres)) {
+                               WIN32_FIND_DATA wfd;
+                               // find the path from that
+                               HRESULT hres = psl->GetPath(outFile.GetBuffer(MAX_PATH), 
+                                                               MAX_PATH,
+                                                               &wfd, 
+                                                               SLGP_UNCPRIORITY);
+
+                               outFile.ReleaseBuffer();
+            }
+            ppf->Release();
+        }
+        psl->Release();
+    }
+
+       inFile.ReleaseBuffer();
+
+       // if this fails, outFile == ""
+    return outFile;
+}
index 954b3ee..8ab883e 100644 (file)
@@ -7,5 +7,6 @@ PATH_EXISTENCE paths_DoesPathExist(LPCTSTR szPath);
 void paths_normalize(CString & sPath);
 CString paths_GetLongPath(const CString & sPath);
 TCHAR paths_GetCurrentDrive();
+CString ExpandShortcut(CString &inFile);
 
 #endif // paths_h_included
index bbe2701..0132c92 100644 (file)
@@ -1,6 +1,9 @@
 2003-03-09 Kimmo
  PATCH: [ 699839 ] Add same binaries to dir compare status
   WinMerge: MainFrm.h MainFrm.cpp
+ PATCH: [ 699893 ] Add drag&drop of files/paths to main window
+  Note: Press down Ctrl when dropping dirs for recursive compare
+  WinMerge: MainFrm.h MainFrm.cpp Merge.cpp paths.h paths.cpp
 
 2003-03-07 Perry
  PATCH: [ 699580 ] Fix paths.cpp