MCPcopy Create free account
hub / github.com/clechasseur/pathcopycopy / QueryContextMenu

Method QueryContextMenu

PathCopyCopy/src/PathCopyCopyContextMenuExt.cpp:297–526  ·  view source on GitHub ↗

IContextMenu::QueryContextMenu Invoked by the shell to populate a contextual menu. We need to use this opportunity to add our menu items. @param p_hMenu Handle to the contextual menu to populate. @param p_Index Index in the menu where to add items. @param p_FirstCmdId First available command ID for our commands. @param p_LastCmdId Last available command ID for our commands. @param p_Flags Flags

Source from the content-addressed store, hash-verified

295// used, plus one; otherwise, an error code.
296//
297[[gsl::suppress(c.128)]]
298STDMETHODIMP CPathCopyCopyContextMenuExt::QueryContextMenu(
299 HMENU p_hMenu,
300 UINT p_Index,
301 UINT p_FirstCmdId,
302 UINT p_LastCmdId,
303 UINT p_Flags)
304{
305 HRESULT hRes = S_OK;
306
307 try {
308 if (p_hMenu == nullptr) {
309 hRes = E_INVALIDARG;
310 } else {
311 // Make sure this menu hasn't been modified by another instance.
312 CPathCopyCopyContextMenuExt* pOtherInstance = nullptr;
313 {
314 std::lock_guard<std::mutex> lock(s_ExtToMenusLock);
315 auto it = std::find_if(s_vExtToMenus.begin(), s_vExtToMenus.end(), [&](const auto& extToMenu) {
316 return extToMenu.second == p_hMenu;
317 });
318 if (it != s_vExtToMenus.end()) {
319 pOtherInstance = it->first;
320 }
321 }
322
323 // Do not add items if the default action is chosen, if we have no files,
324 // if menu has been modified by another instance or if this is a menu for
325 // a shortcut (.lnk) file and we want to copy true .lnk paths (in such a
326 // case, another instance is coming after us to do the job).
327 bool skipBecauseOfLnk = false;
328 if ((p_Flags & CMF_VERBSONLY) != 0) {
329 skipBecauseOfLnk = GetSettings().GetTrueLnkPaths();
330 }
331 if (m_vFiles.empty() || (p_Flags & CMF_DEFAULTONLY) != 0 || pOtherInstance != nullptr || skipBecauseOfLnk) {
332 hRes = E_FAIL;
333 } else {
334 UINT cmdId = p_FirstCmdId;
335 UINT position = p_Index;
336
337 // Fetch reference to settings.
338 PCC::Settings& rSettings = GetSettings();
339
340 // Get all plugins in default order. Do not include temp pipeline plugins.
341 m_vspPluginsInDefaultOrder = PCC::PluginsRegistry::GetPluginsInDefaultOrder(
342 &rSettings, &rSettings, PCC::PipelinePluginsOptions::FetchPipelinePlugins);
343
344 // Get set of all plugins from the above vector.
345 m_sspAllPlugins.insert(m_vspPluginsInDefaultOrder.cbegin(), m_vspPluginsInDefaultOrder.cend());
346
347 // Create plugin provider object wrapping our set of all plugins.
348 m_spPluginProvider = std::make_shared<PCC::AllPluginsProvider>(m_sspAllPlugins);
349
350 // Provide each plugin with settings object and plugin provider, since some require this to work.
351 for (const PCC::PluginSP& spPlugin : m_sspAllPlugins) {
352 spPlugin->SetSettings(&rSettings);
353 spPlugin->SetPluginProvider(m_spPluginProvider.get());
354 }

Callers

nothing calls this directly

Calls 15

GetTrueLnkPathsMethod · 0.80
emptyMethod · 0.80
SetSettingsMethod · 0.80
SetPluginProviderMethod · 0.80
GetUsePreviewModeMethod · 0.80
GetDropRedundantWordsMethod · 0.80
GetAlwaysShowSubmenuMethod · 0.80
GetKnownPluginsMethod · 0.80
GetCtrlKeyPluginMethod · 0.80

Tested by

no test coverage detected