Kiln » TortoiseHg » TortoiseHg
Clone URL:  
Pushed to one repository · View In Graph Contained in tip

fogcreek shellext: added function to construct a list of selected files

Changeset cf4b87c14212

Parent 11daa31b29f1

by David Golub

Changes to 2 files · Browse files at cf4b87c14212 Showing diff from parent 11daa31b29f1 Diff from another changeset...

 
73
74
75
 
 
76
77
78
 
80
81
82
83
 
84
85
86
 
87
88
 
89
90
 
91
92
93
94
 
95
96
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
97
98
99
 
73
74
75
76
77
78
79
80
 
82
83
84
 
85
86
87
 
88
89
 
90
91
 
92
93
94
95
 
96
97
 
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
@@ -73,6 +73,8 @@
  {   if (KeyShortcutList[i].wKey == wParam && KeyShortcutList[i].wFlags == wFlags)   { + CAtlList<CString> listFiles; + g_pObject->GetSelectedFiles(listFiles);   }   }   } @@ -80,20 +82,53 @@
  return ::CallNextHookEx(g_pObject->m_hHook, code, wParam, lParam);  }   -HRESULT CTortoiseHgKeyboard::GetActiveShellView(IShellView** ppSV) +bool CTortoiseHgKeyboard::GetActiveShellView(IShellView** ppSV)  {   CComQIPtr<IWebBrowser2> spWB = m_spUnkSite; - if (spWB == NULL) return E_FAIL; + if (spWB == NULL) return false;   CComPtr<IDispatch> spApp; - if (FAILED(spWB->get_Application(&spApp))) return E_FAIL; + if (FAILED(spWB->get_Application(&spApp))) return false;   CComQIPtr<IServiceProvider> spSP = spApp; - if (spSP == NULL) return E_FAIL; + if (spSP == NULL) return false;   CComPtr<IShellBrowser> spSB;   if (FAILED(spSP->QueryService(SID_STopLevelBrowser, IID_IShellBrowser, (void**)&spSB)))   { - return E_FAIL; + return false;   } - return spSB->QueryActiveShellView(ppSV); + return SUCCEEDED(spSB->QueryActiveShellView(ppSV)); +} + +bool CTortoiseHgKeyboard::GetSelectedFiles(CAtlList<CString>& listFiles) +{ + // Get the active shell view object. + CComPtr<IShellView> spSV; + if (!GetActiveShellView(&spSV)) return false; + + // Obtain the current selection as an IDataObject. + CComPtr<IDataObject> spDO; + if (FAILED(spSV->GetItemObject(SVGIO_SELECTION, IID_IDataObject, (void**)&spDO))) + { + return false; + } + + // Obtain a drop handle from the IDataObject. + FORMATETC fmt = { CF_HDROP, NULL, DVASPECT_CONTENT, -1, TYMED_HGLOBAL }; + STGMEDIUM stg; + stg.tymed = TYMED_HGLOBAL; + if (FAILED(spDO->GetData(&fmt, &stg))) return false; + + // Enumerate through the files and add each one to the list. + HDROP hDrop = (HDROP)::GlobalLock(stg.hGlobal); + UINT uNumFiles = ::DragQueryFile(hDrop, (UINT)-1, NULL, 0); + for (UINT i = 0; i < uNumFiles; i++) + { + TCHAR szPath[MAX_PATH]; + ::DragQueryFile(hDrop, i, szPath, MAX_PATH); + listFiles.AddTail(szPath); + } + ::GlobalUnlock(stg.hGlobal); + ::ReleaseStgMedium(&stg); + return true;  }    CTortoiseHgKeyboard::CTortoiseHgKeyboard() :
 
37
38
39
40
 
 
41
42
43
 
37
38
39
 
40
41
42
43
44
@@ -37,7 +37,8 @@
  STDMETHOD(SetSite)(IUnknown* pUnkSite);    private: - HRESULT GetActiveShellView(IShellView** ppSV); + bool GetActiveShellView(IShellView** ppSV); + bool GetSelectedFiles(CAtlList<CString>& listFiles);     static LRESULT CALLBACK HookProc(int code, WPARAM wParam, LPARAM lParam);  };