Skip to content

Commit

Permalink
Support "drag & drop" from Visual Studio Solution Explorer.
Browse files Browse the repository at this point in the history
  • Loading branch information
zufuliu committed Aug 18, 2018
1 parent b26b4f3 commit d208446
Showing 1 changed file with 34 additions and 1 deletion.
35 changes: 34 additions & 1 deletion scintilla/win32/ScintillaWin.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@
#include <shlobj.h>
#include <shellapi.h>

/*
CF_VSSTGPROJECTITEMS, CF_VSREFPROJECTITEMS
https://docs.microsoft.com/en-us/visualstudio/extensibility/ux-guidelines/application-patterns-for-visual-studio
*/
#define EnableDrop_VisualStudioProjectItem 1

#if !defined(DISABLE_D2D)
#define USE_D2D 1
#endif
Expand Down Expand Up @@ -272,6 +278,11 @@ class ScintillaWin :
CLIPFORMAT cfLineSelect;
CLIPFORMAT cfVSLineTag;

#if EnableDrop_VisualStudioProjectItem
CLIPFORMAT cfVSStgProjectItem;
CLIPFORMAT cfVSRefProjectItem;
#endif

// supported drag & drop format
std::vector<CLIPFORMAT> dropFormat;

Expand Down Expand Up @@ -464,7 +475,16 @@ ScintillaWin::ScintillaWin(HWND hwnd) {
cfVSLineTag = static_cast<CLIPFORMAT>(
::RegisterClipboardFormat(TEXT("VisualStudioEditorOperationsLineCutCopyClipboardTag")));

#if EnableDrop_VisualStudioProjectItem
cfVSStgProjectItem = static_cast<CLIPFORMAT>(::RegisterClipboardFormat(TEXT("CF_VSSTGPROJECTITEMS")));
cfVSRefProjectItem = static_cast<CLIPFORMAT>(::RegisterClipboardFormat(TEXT("CF_VSREFPROJECTITEMS")));
#endif

dropFormat.push_back(CF_HDROP);
#if EnableDrop_VisualStudioProjectItem
dropFormat.push_back(cfVSStgProjectItem);
dropFormat.push_back(cfVSRefProjectItem);
#endif
// text format comes last
dropFormat.push_back(CF_UNICODETEXT);
dropFormat.push_back(CF_TEXT);
Expand Down Expand Up @@ -3156,11 +3176,24 @@ STDMETHODIMP ScintillaWin::Drop(LPDATAOBJECT pIDataSource, DWORD grfKeyState,
hr = pIDataSource->GetData(&fmtu, &medium);
if (SUCCEEDED(hr) && medium.hGlobal) {
// File Drop
if (fmt == CF_HDROP) {
if (fmt == CF_HDROP
#if EnableDrop_VisualStudioProjectItem
|| fmt == cfVSStgProjectItem || fmt == cfVSRefProjectItem
#endif
) {
fileDrop = true;
WCHAR pathDropped[1024];
if (::DragQueryFileW(static_cast<HDROP>(medium.hGlobal), 0, pathDropped, sizeof(pathDropped)/sizeof(WCHAR)) > 0) {
WCHAR *p = pathDropped;
#if EnableDrop_VisualStudioProjectItem
if (fmt == cfVSStgProjectItem || fmt == cfVSRefProjectItem) {
// {UUID}|Solution\Project.[xx]proj|path
WCHAR *t = StrRChrW(p, NULL, L'|');
if (t) {
p = t + 1;
}
}
#endif
// Convert UTF-16 to UTF-8
const std::wstring_view wsv(p);
const size_t dataLen = UTF8Length(wsv);
Expand Down

0 comments on commit d208446

Please sign in to comment.