--- /dev/null
+#include "DragDrop.h"
+#include "paths.h"
+#include <boost/scoped_array.hpp>
+
+//
+// OnDropFiles code from CDropEdit
+// Copyright 1997 Chris Losinger
+//
+// shortcut expansion code modified from :
+// CShortcut, 1996 Rob Warner
+//
+
+bool GetDroppedFiles(HDROP dropInfo, std::vector<String>& files)
+{
+// Get the number of pathnames that have been dropped
+ UINT wNumFilesDropped = DragQueryFile(dropInfo, 0xFFFFFFFF, NULL, 0);
+ UINT 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
+ wPathnameSize += 1;
+ boost::scoped_array<TCHAR> npszFile(new TCHAR[wPathnameSize]);
+
+ // Copy the pathname into the buffer
+ DragQueryFile(dropInfo, x, npszFile.get(), wPathnameSize);
+
+ if (x < 3)
+ {
+ files.resize(x + 1);
+ files[x] = npszFile.get();
+ fileCount++;
+ }
+ }
+
+ // Free the memory block containing the dropped-file information
+ DragFinish(dropInfo);
+
+ for (UINT i = 0; i < fileCount; i++)
+ {
+ if (paths_IsShortcut(files[i]))
+ {
+ // if this was a shortcut, we need to expand it to the target path
+ String expandedFile = ExpandShortcut(files[i]);
+
+ // if that worked, we should have a real file name
+ if (!expandedFile.empty())
+ files[i] = expandedFile;
+ }
+ }
+ return true;
+}
--- /dev/null
+#include "UnicodeString.h"
+#include <windows.h>
+#include <vector>
+
+bool GetDroppedFiles(HDROP dropInfo, std::vector<String>& files);
#include "StdAfx.h"
#include "SuperComboBox.h"
+#include "DragDrop.h"
#include <shlwapi.h>
#include <vector>
-#include <boost/scoped_array.hpp>
#ifdef _DEBUG
#define new DEBUG_NEW
//
void CSuperComboBox::OnDropFiles(HDROP dropInfo)
{
- // Get the number of pathnames that have been dropped
- UINT wNumFilesDropped = DragQueryFile(dropInfo, 0xFFFFFFFF, NULL, 0);
-
- CString firstFile;
-
- // get all file names. but we'll only need the first one.
- for (WORD x = 0 ; x < wNumFilesDropped; x++) {
-
- // Get the number of characters required by the file's full pathname
- UINT wPathnameSize = DragQueryFile(dropInfo, x, NULL, 0);
-
- // Allocate memory to contain full pathname & zero byte
- wPathnameSize += 1;
- boost::scoped_array<TCHAR> npszFile(new TCHAR[wPathnameSize]);
-
- // Copy the pathname into the buffer
- DragQueryFile(dropInfo, x, npszFile.get(), wPathnameSize);
-
- // we only care about the first
- if (firstFile==_T(""))
- firstFile=npszFile.get();
- }
-
- // Free the memory block containing the dropped-file information
- DragFinish(dropInfo);
-
- // if this was a shortcut, we need to expand it to the target path
- CString expandedFile = ExpandShortcut(firstFile);
-
- // if that worked, we should have a real file name
- if (!expandedFile.IsEmpty())
- firstFile=expandedFile;
+ std::vector<String> files;
+ GetDroppedFiles(dropInfo, files);
+ if (files.size() == 0)
+ return;
GetParent()->SendMessage(WM_COMMAND, GetDlgCtrlID() +
(CBN_EDITUPDATE << 16), (LPARAM)m_hWnd);
- SetWindowText(firstFile);
+ SetWindowText(files[0].c_str());
GetParent()->SendMessage(WM_COMMAND, GetDlgCtrlID() +
(CBN_EDITCHANGE << 16), (LPARAM)m_hWnd);
}
}
*pResult = 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 CSuperComboBox::ExpandShortcut(CString &inFile)
-{
- CString outFile;
-
- // Make sure we have a path
- ASSERT(!inFile.IsEmpty());
-
- 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))
- {
- WCHAR wsz[MAX_PATH];
-#ifdef _UNICODE
- wcsncpy((wchar_t *)wsz, lpsz, sizeof(wsz)/sizeof(WCHAR));
-#else
- ::MultiByteToWideChar(CP_ACP, 0, lpsz, -1, wsz, MAX_PATH);
-#endif
-
- // Load shortcut
- hres = ppf->Load((LPCOLESTR)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;
-}
// Generated message map functions
protected:
CString m_strCurSel;
- CString ExpandShortcut(CString &inFile);
virtual BOOL OnAddTemplate();
CString m_strAutoAdd;
BOOL m_bMustUninitOLE;
#include <vector>
#include <htmlhelp.h> // From HTMLHelp Workshop (incl. in Platform SDK)
#include <shlwapi.h>
-#include <boost/scoped_array.hpp>
#include "Constants.h"
#include "Merge.h"
#include "UnicodeString.h"
#include "OptionsFont.h"
#include "TFile.h"
#include "JumpList.h"
+#include "DragDrop.h"
#include <Poco/Exception.h>
using std::vector;
}
}
-/////////////////////////////////////////////////////////////////////////////
-//
-// 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);
- PathContext files;
- UINT 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
- wPathnameSize += 1;
- boost::scoped_array<TCHAR> npszFile(new TCHAR[wPathnameSize]);
-
- // Copy the pathname into the buffer
- DragQueryFile(dropInfo, x, npszFile.get(), wPathnameSize);
-
- if (x < 3)
- {
- files.SetSize(x + 1);
- files[x] = npszFile.get();
- fileCount++;
- }
- }
-
- // Free the memory block containing the dropped-file information
- DragFinish(dropInfo);
-
- for (UINT i = 0; i < fileCount; i++)
- {
- if (paths_IsShortcut(files[i]))
- {
- // if this was a shortcut, we need to expand it to the target path
- CString expandedFile = ExpandShortcut(files[i]).c_str();
-
- // if that worked, we should have a real file name
- if (!expandedFile.IsEmpty())
- files[i] = expandedFile;
- }
- }
+ std::vector<String> dropped_files;
+ GetDroppedFiles(dropInfo, dropped_files);
+ PathContext files(dropped_files);
+ const size_t fileCount = files.GetSize();
// If Ctrl pressed, do recursive compare
bool ctrlKey = !!::GetAsyncKeyState(VK_CONTROL);
// Check if they dropped a project file
DWORD dwFlags[3] = {FFILEOPEN_NONE, FFILEOPEN_NONE, FFILEOPEN_NONE};
- if (wNumFilesDropped == 1)
+ if (fileCount == 1)
{
if (theApp.IsProjectFile(files[0].c_str()))
{
</FileConfiguration>\r
</File>\r
<File\r
+ RelativePath=".\Common\DragDrop.cpp">\r
+ <FileConfiguration\r
+ Name="UnicodeRelease|Win32">\r
+ <Tool\r
+ Name="VCCLCompilerTool"\r
+ UsePrecompiledHeader="0"/>\r
+ </FileConfiguration>\r
+ <FileConfiguration\r
+ Name="UnicodeDebug|Win32">\r
+ <Tool\r
+ Name="VCCLCompilerTool"\r
+ UsePrecompiledHeader="0"/>\r
+ </FileConfiguration>\r
+ <FileConfiguration\r
+ Name="Debug|Win32">\r
+ <Tool\r
+ Name="VCCLCompilerTool"\r
+ UsePrecompiledHeader="0"/>\r
+ </FileConfiguration>\r
+ <FileConfiguration\r
+ Name="Release|Win32">\r
+ <Tool\r
+ Name="VCCLCompilerTool"\r
+ UsePrecompiledHeader="0"/>\r
+ </FileConfiguration>\r
+ </File>\r
+ <File\r
RelativePath="EditorFilepathBar.cpp">\r
<FileConfiguration\r
Name="UnicodeRelease|Win32">\r
RelativePath="DirViewColItems.h">\r
</File>\r
<File\r
+ RelativePath=".\Common\DragDrop.h">\r
+ </File>\r
+ <File\r
RelativePath="EditorFilepathBar.h">\r
</File>\r
<File\r
<AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='X64 Release|x64'">%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>\r
<PreprocessorDefinitions Condition="'$(Configuration)|$(Platform)'=='X64 Release|x64'">%(PreprocessorDefinitions)</PreprocessorDefinitions>\r
</ClCompile>\r
+ <ClCompile Include="Common\DragDrop.cpp">\r
+ <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">NotUsing</PrecompiledHeader>\r
+ <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">NotUsing</PrecompiledHeader>\r
+ <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='UnicodeDebug|Win32'">NotUsing</PrecompiledHeader>\r
+ <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='UnicodeRelease|Win32'">NotUsing</PrecompiledHeader>\r
+ <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">NotUsing</PrecompiledHeader>\r
+ <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">NotUsing</PrecompiledHeader>\r
+ <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='UnicodeDebug|x64'">NotUsing</PrecompiledHeader>\r
+ <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='UnicodeRelease|x64'">NotUsing</PrecompiledHeader>\r
+ </ClCompile>\r
<ClCompile Include="Common\ExConverter.cpp">\r
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">NotUsing</PrecompiledHeader>\r
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">NotUsing</PrecompiledHeader>\r
<ClInclude Include="codepage.h" />\r
<ClInclude Include="codepage_detect.h" />\r
<ClInclude Include="ColorButton.h" />\r
+ <ClInclude Include="Common\DragDrop.h" />\r
<ClInclude Include="Common\ExConverter.h" />\r
<ClInclude Include="CompareOptions.h" />\r
<ClInclude Include="CompareStatisticsDlg.h" />\r
<ClCompile Include="OptionsDiffColors.cpp">\r
<Filter>Source Files</Filter>\r
</ClCompile>\r
+ <ClCompile Include="Common\DragDrop.cpp">\r
+ <Filter>GUI\Source Files</Filter>\r
+ </ClCompile>\r
</ItemGroup>\r
<ItemGroup>\r
<ClInclude Include="charsets.h">\r
<ClInclude Include="OptionsDiffColors.h">\r
<Filter>Header Files</Filter>\r
</ClInclude>\r
+ <ClInclude Include="Common\DragDrop.h">\r
+ <Filter>GUI\Header Files</Filter>\r
+ </ClInclude>\r
</ItemGroup>\r
<ItemGroup>\r
<None Include="res\binarydiff.ico">\r
#include <vector>
#include <sys/types.h>
#include <sys/stat.h>
-#include <boost/scoped_array.hpp>
#include "UnicodeString.h"
#include "Merge.h"
#include "OpenDoc.h"
#include "7zCommon.h"
#include "Constants.h"
#include "Picture.h"
+#include "DragDrop.h"
#ifdef _DEBUG
#define new DEBUG_NEW
*/
void COpenView::OnDropFiles(HDROP dropInfo)
{
- // Get the number of pathnames that have been dropped
- UINT wNumFilesDropped = DragQueryFile(dropInfo, 0xFFFFFFFF, NULL, 0);
- CString files[3];
- UINT 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
- wPathnameSize += 1;
- boost::scoped_array<TCHAR> npszFile(new TCHAR[wPathnameSize]);
-
- // Copy the pathname into the buffer
- DragQueryFile(dropInfo, x, npszFile.get(), wPathnameSize);
-
- if (x < 3)
- {
- files[x] = npszFile.get();
- fileCount++;
- }
- }
-
- // Free the memory block containing the dropped-file information
- DragFinish(dropInfo);
-
- for (UINT i = 0; i < fileCount; i++)
- {
- if (paths_IsShortcut((LPCTSTR)files[i]))
- {
- // if this was a shortcut, we need to expand it to the target path
- CString expandedFile = ExpandShortcut((LPCTSTR)files[i]).c_str();
-
- // if that worked, we should have a real file name
- if (!expandedFile.IsEmpty())
- files[i] = expandedFile;
- }
- }
+ std::vector<String> files;
+ GetDroppedFiles(dropInfo, files);
+ const size_t fileCount = files.size();
// Add dropped paths to the dialog
UpdateData(TRUE);
if (fileCount == 3)
{
- m_strPath[0] = files[0];
- m_strPath[1] = files[1];
- m_strPath[2] = files[2];
+ m_strPath[0] = files[0].c_str();
+ m_strPath[1] = files[1].c_str();
+ m_strPath[2] = files[2].c_str();
UpdateData(FALSE);
UpdateButtonStates();
}
else if (fileCount == 2)
{
- m_strPath[0] = files[0];
- m_strPath[1] = files[1];
+ m_strPath[0] = files[0].c_str();
+ m_strPath[1] = files[1].c_str();
UpdateData(FALSE);
UpdateButtonStates();
}
else if (fileCount == 1)
{
if (m_strPath[0].IsEmpty())
- m_strPath[0] = files[0];
+ m_strPath[0] = files[0].c_str();
else if (m_strPath[1].IsEmpty())
- m_strPath[1] = files[0];
+ m_strPath[1] = files[0].c_str();
else if (m_strPath[2].IsEmpty())
- m_strPath[2] = files[0];
+ m_strPath[2] = files[0].c_str();
else
- m_strPath[0] = files[0];
+ m_strPath[0] = files[0].c_str();
UpdateData(FALSE);
UpdateButtonStates();
}
m_path[i].SetPath(paths[i]);
}
+PathContext::PathContext(const std::vector<String> &paths)
+{
+ m_nFiles = paths.size();
+ for (int i = 0; i < paths.size(); i++)
+ m_path[i].SetPath(paths[i]);
+}
+
String PathContext::GetAt(int nIndex) const
{
assert(nIndex < m_nFiles);
#define _PATH_CONTEXT_H_
#include "UnicodeString.h"
+#include <vector>
class PathContext;
PathContext(const String& sLeft, const String& sRight);
PathContext(const String& sLeft, const String& sMiddle, const String& sRight);
PathContext(const PathContext &paths);
+ PathContext(const std::vector<String>& paths);
String GetAt(int nIndex) const;
String& GetElement(int nIndex);