Kiln » TortoiseHg » TortoiseHg
Clone URL:  
TortoiseHgCmenu.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
// Copyright (C) 2011 Fog Creek Software // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 2 of the License, or // (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program. If not, see <http://www.gnu.org/licenses/>. #include "stdafx.h" #include "THgShell_h.h" #include "TortoiseUtils.h" #include "StringUtils.h" #include "THgStatus.h" #include "Winstat.h" #include "SysInfo.h" #include "RegistryConfig.h" #include "TortoiseIconBitmap.h" #include "THgVersion.h" #include "TortoiseHgCmenu.h" #include "RunDialog.h" #include "Kiln.h" #include <msi.h> void CTortoiseHgCmenuBase::AddMenuList(UINT idCmd, const CString& strName) { ATLTRACE("AddMenuList: idCmd = %d, name = '%s'\n", idCmd, strName); m_mapMenuId[idCmd] = m_mapMenuDesc[strName]; } void CTortoiseHgCmenuBase::InitMenuMaps(const CMenuDescription *pMenuDescs, int nCount) { if (m_mapMenuDesc.IsEmpty()) { CString strLang; GetRegistryConfig("CMenuLang", strLang); for (int i = 0; i < nCount; i++) { CMenuDescription md = pMenuDescs[i]; if (md.strName.IsEmpty()) { ATLTRACE("**** InitMenuMaps: ignoring entry with empty name\n"); break; } ATLTRACE("InitMenuMaps: adding '%s'\n", (LPCTSTR)md.strName); // Look for translation of menu and help text if (!strLang.IsEmpty()) { GetCMenuTranslation(strLang, md.strName, md.strMenuText, md.strHelpText); } m_mapMenuDesc[md.strName] = md; } } m_mapMenuId.RemoveAll(); } void InsertMenuItemWithIcon1(HMENU hMenu, UINT indexMenu, UINT idCmd, const CStringW& strMenuText, const CString& strIconName) { // MFT_STRING is obsolete and should not be used (replaced by MIIM_STRING // from Win2K onward) MENUITEMINFOW mii; memset(&mii, 0, sizeof(MENUITEMINFOW)); mii.cbSize = sizeof(MENUITEMINFOW); mii.fMask = MIIM_ID | MIIM_STRING; mii.dwTypeData = (LPWSTR)(LPCWSTR)strMenuText; mii.cch = strMenuText.GetLength(); mii.wID = idCmd; if (!strIconName.IsEmpty()) { if (CSysInfo::IsVistaOrLater()) { HBITMAP hBitmap = GetTortoiseIconBitmap(strIconName); if (hBitmap) { mii.fMask |= MIIM_BITMAP; mii.hbmpItem = hBitmap; } else { ATLTRACE(" ***** InsertMenuItemWithIcon1: can't find '%s'\n", (LPCTSTR)strIconName); } } else { HICON hIcon = GetTortoiseIcon(strIconName); if (hIcon) { mii.fMask |= MIIM_BITMAP | MIIM_DATA; mii.dwItemData = (ULONG_PTR)hIcon; mii.hbmpItem = HBMMENU_CALLBACK; } else { ATLTRACE(" ***** InsertMenuItemWithIcon1: can't find '%s'\n", (LPCTSTR)strIconName); } } } ::InsertMenuItemW(hMenu, indexMenu, TRUE, &mii); ATLTRACE(L"InsertMenuItemWithIcon1('%s') finished\n", (LPCWSTR)strMenuText); } void InsertSubMenuItemWithIcon2(HMENU hMenu, HMENU hSubMenu, UINT indexMenu, UINT idCmd, const CStringW& strMenuText, const CString& strIconName) { // MFT_STRING is obsolete and should not be used (replaced by MIIM_STRING // from Win2K onward) MENUITEMINFOW mii; memset(&mii, 0, sizeof(MENUITEMINFOW)); mii.cbSize = sizeof(MENUITEMINFOW); mii.fMask = MIIM_SUBMENU | MIIM_ID | MIIM_STRING; mii.dwTypeData = (LPWSTR)(LPCWSTR)strMenuText; mii.cch = strMenuText.GetLength(); mii.wID = idCmd; mii.hSubMenu = hSubMenu; if (CSysInfo::IsVistaOrLater()) { HBITMAP hBitmap = GetTortoiseIconBitmap(strIconName); if (hBitmap) { mii.fMask |= MIIM_BITMAP; mii.hbmpItem = hBitmap; } else { ATLTRACE(" ***** InsertSubMenuItemWithIcon2: can't find '%s'\n", (LPCTSTR)strIconName); } } else { HICON hIcon = GetTortoiseIcon(strIconName); if (hIcon) { mii.fMask |= MIIM_BITMAP | MIIM_DATA; mii.dwItemData = (ULONG_PTR)hIcon; mii.hbmpItem = HBMMENU_CALLBACK; } else { ATLTRACE(" ***** InsertSubMenuItemWithIcon2: can't find '%s'\n", (LPCTSTR)strIconName); } } ::InsertMenuItemW(hMenu, indexMenu, TRUE, &mii); ATLTRACE(L"InsertMenuItemWithIcon2('%s') finished\n", (LPCWSTR)strMenuText); } void CTortoiseHgCmenuBase::InsertMenuItemByName(HMENU hMenu, const CString& strName, UINT indexMenu, UINT idCmd, UINT idCmdFirst, const CStringW& strPrefix) { const CMenuDescriptionMap::CPair* pPair = m_mapMenuDesc.Lookup(strName); if (pPair == NULL) { ATLTRACE("***** InsertMenuItemByName: can't find menu info for '%s'\n", (LPCTSTR)strName); return; } const CMenuDescription& md = pPair->m_value; AddMenuList(idCmd - idCmdFirst, strName); InsertMenuItemWithIcon1(hMenu, indexMenu, idCmd, strPrefix + md.strMenuText, md.strIconName); } const LPCWSTR TortoiseHgMenuEntryString = L"TortoiseHg"; // returns -1 on error, 0 otherwise int HasTortoiseMenu(HMENU hMenu, bool& bHasMenu) { bHasMenu = false; int nCount = ::GetMenuItemCount(hMenu); if (nCount == -1) { ATLTRACE("***** HasTortoiseMenu: GetMenuItemCount returned -1\n"); return -1; } MENUITEMINFOW mii; for (int i = 0; i < nCount; ++i) { memset(&mii, 0, sizeof(MENUITEMINFOW)); mii.cbSize = sizeof(MENUITEMINFOW); // first GetMenuItemInfoW call: get size of menu item string mii.fMask = MIIM_STRING; BOOL bRes = ::GetMenuItemInfoW(hMenu, i, true, &mii); if (bRes == 0) { ATLTRACE("HasTortoiseMenu: first GetMenuItemInfo returned 0\n"); continue; } if (mii.dwTypeData != MFT_STRING) { // not a string continue; } // allocate buffer for the string CStringW strMenuItemText; LPWSTR lpszBuf = strMenuItemText.GetBuffer(mii.cch + 1); // second GetMenuItemInfoW call: get string into buffer mii.dwTypeData = lpszBuf; ++mii.cch; // size of buffer is one more than length of string bRes = ::GetMenuItemInfoW(hMenu, i, true, &mii); strMenuItemText.ReleaseBuffer(); if (bRes == 0) { ATLTRACE("HasTortoiseMenu: second GetMenuItemInfo returned 0\n"); continue; } if (strMenuItemText == TortoiseHgMenuEntryString) { ATLTRACE("HasTortoiseMenu: FOUND TortoiseHg menu entry\n"); bHasMenu = true; return 0; } } ATLTRACE("HasTortoiseMenu: TortoiseHg menu entry NOT found\n"); return 0; } void CTortoiseHgCmenuBase::TweakMenuForVista(HMENU hMenu) { if (!CSysInfo::IsVistaOrLater()) return; MENUINFO mi; memset(&mi, 0, sizeof(MENUINFO)); mi.cbSize = sizeof(MENUINFO); mi.fMask = MIM_STYLE | MIM_APPLYTOSUBMENUS; mi.dwStyle = MNS_CHECKORBMP; ::SetMenuInfo(hMenu, &mi); } #define ResultFromShort(i) ResultFromScode(MAKE_SCODE(SEVERITY_SUCCESS, 0, (USHORT)(i))) // IContextMenu STDMETHODIMP CTortoiseHgCmenuBase::QueryContextMenu(HMENU hMenu, UINT indexMenu, UINT idCmdFirst, UINT idCmdLast, UINT uFlags) { ATLTRACE("CTortoiseHgCmenuBase::QueryContextMenu\n"); UINT idCmd = idCmdFirst; BOOL bAppendItems = TRUE; if ((uFlags & 0x000F) == CMF_NORMAL) bAppendItems = TRUE; else if (uFlags & CMF_VERBSONLY) bAppendItems = TRUE; else if (uFlags & CMF_EXPLORE) bAppendItems = TRUE; else bAppendItems = FALSE; if (!bAppendItems) return S_OK; bool bHasTHgMenu = false; if (HasTortoiseMenu(hMenu, bHasTHgMenu) == 0 && bHasTHgMenu) { ATLTRACE("CTortoiseHgCmenuBase::QueryContextMenu: " "TortoiseHg menu entry already in menu -> skipping"); return S_OK; } InitMenuMaps(MenuDescList, MenuDescListCount); CString promoted_string = DefaultPromotedString; // default value if key not found GetRegistryConfig("PromotedItems", promoted_string); CAtlList<CString> listPromoted; Tokenize(promoted_string, listPromoted, ","); // Select menu to show bool bFileMenu = !m_listFiles.IsEmpty(); bool bIsHgRepo = false; CString strCwd; if (!m_strFolder.IsEmpty()) { strCwd = m_strFolder; } else if (bFileMenu) { strCwd = m_listFiles.GetHead(); if (!::PathIsDirectory(strCwd)) strCwd = DirName(strCwd); } if (!strCwd.IsEmpty()) { // check if target directory is a Mercurial repository CString strRoot = GetHgRepoRoot(strCwd); bIsHgRepo = !strRoot.IsEmpty(); if (m_listFiles.GetCount() == 1 && strRoot == m_listFiles.GetHead()) { bFileMenu = false; m_strFolder = strCwd; m_listFiles.RemoveAll(); } } if ((uFlags & CMF_EXTENDEDVERBS) == 0) { // shift key is not down if (!bIsHgRepo) { // we are not inside a repo CString strCval; if (GetRegistryConfig("HideMenuOutsideRepo", strCval) != 0 && strCval == "1") { return S_OK; // don't show thg cmenu entries } } } ATLTRACE("CTortoiseHgCmenuBase::QueryContextMenu: bIsHgRepo = %d, bFileMenu = %d\n", bIsHgRepo, bFileMenu); /* We have three menu types: files-selected, no-files-selected, no-repo */ const LPCTSTR* ppszEntries = NULL; int nCount; if (bIsHgRepo) { if (bFileMenu) { ppszEntries = RepoFilesMenu; nCount = RepoFilesMenuCount; } else { ppszEntries = RepoNoFilesMenu; nCount = RepoNoFilesMenuCount; } } else { ppszEntries = NoRepoMenu; nCount = NoRepoMenuCount; } // start building TortoiseHg menus and submenus ::InsertMenu(hMenu, indexMenu++, MF_SEPARATOR | MF_BYPOSITION, 0, NULL); for (int i = 0; i < nCount; i++) { CString strName = ppszEntries[i]; if (listPromoted.Find(strName) != NULL) { if ((strName == "kiln" || strName == "kilnfiles") && !KilnGetUrl(strCwd)) { continue; } InsertMenuItemByName(hMenu, strName, indexMenu++, idCmd++, idCmdFirst, L"Hg "); } } const HMENU hSubMenu = ::CreatePopupMenu(); if (hSubMenu) { UINT indexSubMenu = 0; bool bIsSeparator = true; for (int i = 0; i < nCount; i++) { if (ppszEntries[i] == NULL) { if (!bIsSeparator) { ::InsertMenu(hSubMenu, indexSubMenu++, MF_SEPARATOR | MF_BYPOSITION, 0, NULL); bIsSeparator = true; } } else { CString strName = ppszEntries[i]; if (listPromoted.Find(strName) == NULL) { if ((strName == "kiln" || strName == "kilnfiles") && !KilnGetUrl(strCwd)) { continue; } InsertMenuItemByName(hSubMenu, strName, indexSubMenu++, idCmd++, idCmdFirst, L""); bIsSeparator = false; } } } if (bIsSeparator && indexSubMenu > 0) ::RemoveMenu(hSubMenu, indexSubMenu - 1, MF_BYPOSITION); TweakMenuForVista(hSubMenu); } ATLTRACE(" CTortoiseHgCmenuBase::QueryContextMenu: adding main THG menu\n"); InsertSubMenuItemWithIcon2(hMenu, hSubMenu, indexMenu++, idCmd++, TortoiseHgMenuEntryString, "hg.ico"); ::InsertMenu(hMenu, indexMenu++, MF_SEPARATOR | MF_BYPOSITION, 0, NULL); TweakMenuForVista(hMenu); return ResultFromShort(idCmd - idCmdFirst); } STDMETHODIMP CTortoiseHgCmenuBase::InvokeCommand(LPCMINVOKECOMMANDINFO lpcmi) { ATLTRACE("CTortoiseHgCmenuBase::InvokeCommand"); HRESULT hr = E_INVALIDARG; if (!HIWORD(lpcmi->lpVerb)) { UINT idCmd = LOWORD(lpcmi->lpVerb); ATLTRACE("CTortoiseHgCmenuBase::InvokeCommand: idCmd = %d\n", idCmd); const CMenuIdCmdMap::CPair* p = m_mapMenuId.Lookup(idCmd); if (p != NULL) { RunDialog(lpcmi->hwnd, p->m_value.strName, m_listFiles, m_strFolder); hr = S_OK; } else { ATLTRACE("***** CTortoiseHgCmenuBase::InvokeCommand: action not found " "for idCmd %d\n", idCmd); } } return hr; } STDMETHODIMP CTortoiseHgCmenuBase::GetCommandString(UINT_PTR idCmd, UINT uFlags, UINT FAR *reserved, LPSTR pszName, UINT cchMax) { // see http://msdn.microsoft.com/en-us/library/bb776094%28VS.85%29.aspx HRESULT hr = S_FALSE; const char* psz = ""; const wchar_t* pszw = 0; #ifdef _DEBUG CString strFlags = "?"; switch (uFlags) { case GCS_HELPTEXTW: strFlags = "GCS_HELPTEXTW"; break; case GCS_HELPTEXTA: strFlags = "GCS_HELPTEXTA"; break; case GCS_VALIDATEW: strFlags = "GCS_VALIDATEW"; break; case GCS_VALIDATEA: strFlags = "GCS_VALIDATEA"; break; case GCS_VERBW: strFlags = "GCS_VERBW"; break; case GCS_VERBA: strFlags = "GCS_VERBA"; break; } ATLTRACE("CTortoiseHgCmenuBase::GetCommandString: idCmd = %d, uFlags = %d (%s), " "cchMax = %d\n", idCmd, uFlags, (LPCTSTR)strFlags, cchMax); #endif const CMenuIdCmdMap::CPair* p = m_mapMenuId.Lookup((UINT)idCmd); if (p == NULL) { ATLTRACE("***** CTortoiseHgCmenuBase::GetCommandString: idCmd not found\n"); } else { ATLTRACE("CTortoiseHgCmenuBase::GetCommandString: name = '%s'\n", (LPCTSTR)p->m_value.strName); if (uFlags == GCS_HELPTEXTW) { pszw = p->m_value.strHelpText; hr = S_OK; int nSize = p->m_value.strHelpText.GetLength(); if (nSize >= 40) { ATLTRACE("***** CTortoiseHgCmenuBase::GetCommandString: warning: " "length of help text is %d, which is not reasonably " "short (<40)\n", nSize); } } else if (uFlags == GCS_HELPTEXTA) { // we don't provide ansi help texts psz = ""; hr = S_OK; } else if (uFlags == GCS_VERBW || uFlags == GCS_VERBA) { #if 0 psz = p->m_value.name; #else // bugfix: don't provide verbs ("rename" conflicted with rename of explorer) psz = ""; #endif hr = S_OK; } else if (uFlags == GCS_VALIDATEW || uFlags == GCS_VALIDATEA) { hr = S_OK; } } if (cchMax < 1) { ATLTRACE("CTortoiseHgCmenuBase::GetCommandString: cchMax = %d (is <1)\n", cchMax); return hr; } size_t nSize = 0; if (uFlags & GCS_UNICODE) { LPWSTR lpszDest = (LPWSTR)pszName; CStringW strUnicode = psz; LPCWSTR lpszSrc = pszw ? pszw : strUnicode; wcsncpy_s(lpszDest, cchMax, lpszSrc, cchMax-1); *(lpszDest + cchMax-1) = 0; nSize = wcslen(lpszSrc); ATLTRACE(L"CTortoiseHgCmenuBase::GetCommandString: res = %d, " L"pszName (wide) = '%s'\n", (int)hr, lpszDest); } else { strncpy_s(pszName, cchMax, psz, cchMax-1); *(pszName + cchMax-1) = 0; nSize = strlen(psz); ATLTRACE("CShellExtCMenu::GetCommandString: res = %d, pszName = '%s'\n", (int)hr, psz); } if (nSize > cchMax-1) { ATLTRACE("***** CShellExtCMenu::GetCommandString: string was truncated: " "size = %d, cchMax = %d\n", nSize, cchMax); } return hr; } STDMETHODIMP CTortoiseHgCmenuBase::HandleMenuMsg(UINT uMsg, WPARAM wParam, LPARAM lParam) { LRESULT lResult; return HandleMenuMsg2(uMsg, wParam, lParam, &lResult); } STDMETHODIMP CTortoiseHgCmenuBase::HandleMenuMsg2(UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT* pResult) { // A great tutorial on owner drawn menus in shell extension can be found // here: http://www.codeproject.com/shell/shellextguide7.asp LRESULT lResult; if (!pResult) pResult = &lResult; *pResult = FALSE; switch (uMsg) { case WM_MEASUREITEM: { MEASUREITEMSTRUCT* lpmis = (MEASUREITEMSTRUCT*)lParam; if (lpmis == NULL) break; lpmis->itemWidth += 2; if(lpmis->itemHeight < 16) lpmis->itemHeight = 16; *pResult = TRUE; } break; case WM_DRAWITEM: { DRAWITEMSTRUCT* lpdis = (DRAWITEMSTRUCT*)lParam; if (!lpdis || (lpdis->CtlType != ODT_MENU) || !lpdis->itemData) break; ::DrawIconEx(lpdis->hDC, lpdis->rcItem.left - 16, lpdis->rcItem.top + (lpdis->rcItem.bottom - lpdis->rcItem.top - 16) / 2, (HICON)lpdis->itemData, 16, 16, 0, 0, DI_NORMAL); *pResult = TRUE; } break; default: return S_OK; } return S_OK; } #ifdef _DEBUG void CTortoiseHgCmenuBase::PrintDebugHeader(LPCITEMIDLIST pIDFolder, LPDATAOBJECT pDataObj) { ATLTRACE("CTortoiseHgCmenuBase::Initialize\n"); // get installed MSI product id (for debugging purposes for now) #ifdef _M_X64 LPCTSTR lpszShellExId = "{D5D1E532-CDAD-4FFD-9695-757B8A29B4BA}"; #else LPCTSTR lpszShellExId = "{728E8840-5878-4EA7-918F-281C2697ABB1}"; #endif char szProductId[50]; UINT msires = ::MsiGetProductCode(lpszShellExId, szProductId); ATLTRACE("MSI shellexid: %s\n", lpszShellExId); ATLTRACE("MSI msires: %d", msires); ATLTRACE("MSI installed product id: %s\n", szProductId); DWORD dwBufSize = 300; CAutoVectorPtr<char> buf(new char[dwBufSize]); msires = ::MsiGetProductInfo(szProductId, INSTALLPROPERTY_INSTALLLOCATION, buf, &dwBufSize); if (msires == ERROR_SUCCESS) { ATLTRACE("MSI install location: %s\n", &buf[0]); } else { ATLTRACE("MSI install location: error %d\n", msires); } ATLTRACE(L"---- TortoiseHg shell extension version %s ----", (LPCTSTR)THgVersion); ATLTRACE(" pIDFolder: %p\n", pIDFolder); ATLTRACE(" pDataObj: %p\n", pDataObj); } #endif STDMETHODIMP CTortoiseHgCmenuBase::Initialize(LPCITEMIDLIST pIDFolder, LPDATAOBJECT pDataObj, HKEY hRegKey) { TCHAR szName[MAX_PATH + 1]; #ifdef _DEBUG PrintDebugHeader(pIDFolder, pDataObj); #endif m_strFolder.Empty(); m_listFiles.RemoveAll(); if (pDataObj) { FORMATETC fmt = { CF_HDROP, NULL, DVASPECT_CONTENT, -1, TYMED_HGLOBAL }; STGMEDIUM stg = { TYMED_HGLOBAL }; if (SUCCEEDED(pDataObj->GetData(&fmt, &stg)) && stg.hGlobal) { HDROP hDrop = (HDROP)::GlobalLock(stg.hGlobal); if (hDrop) { UINT uNumFiles = ::DragQueryFile(hDrop, 0xFFFFFFFF, NULL, 0); ATLTRACE(" hDrop uNumFiles = %d\n", uNumFiles); for (UINT i = 0; i < uNumFiles; ++i) { if (::DragQueryFile(hDrop, i, szName, MAX_PATH) > 0) { ATLTRACE(" DragQueryFile [%d] = '%s'\n", i, szName); m_listFiles.AddTail(szName); } } } else { ATLTRACE(" hDrop is NULL\n"); } ::GlobalUnlock(stg.hGlobal); if (stg.pUnkForRelease) { IUnknown* relInterface = (IUnknown*) stg.pUnkForRelease; relInterface->Release(); } } else { ATLTRACE(" pDataObj->GetData failed\n"); } } // if a directory background if (pIDFolder) { ::SHGetPathFromIDList(pIDFolder, szName); ATLTRACE(" Folder '%s'\n", szName); m_strFolder = szName; } // disable context menu if neither the folder nor the files // have been found if (m_strFolder.IsEmpty() && m_listFiles.IsEmpty()) { ATLTRACE(" shell extension not available on this object\n"); return E_FAIL; } else { return S_OK; } } CTortoiseHgCmenuBase::CTortoiseHgCmenuBase() { } CTortoiseHgCmenu::CTortoiseHgCmenu() { }