Index: src/ch/MainWnd.cpp =================================================================== diff -u -N -r772856340344b3c47cda9c4d6f75931f7c99e927 -r3c248d4f6d0fdb1e487cc868b2f0b219eec37ef4 --- src/ch/MainWnd.cpp (.../MainWnd.cpp) (revision 772856340344b3c47cda9c4d6f75931f7c99e927) +++ src/ch/MainWnd.cpp (.../MainWnd.cpp) (revision 3c248d4f6d0fdb1e487cc868b2f0b219eec37ef4) @@ -33,8 +33,6 @@ #include #include "../common/TShellExtMenuConfig.h" #include "../libchcore/TConfig.h" -#include "FileSupport.h" -#include "StringHelpers.h" #include "../libchcore/TCoreException.h" #include "../libchcore/TTaskManagerStatsSnapshot.h" #include "../libchcore/TSQLiteSerializerFactory.h" @@ -699,7 +697,6 @@ try { chcore::TConfig& rConfig = GetConfig(); - ictranslate::CResourceManager& rResManager = GetResManager(); TShellExtMenuConfig cfgShellExt; @@ -710,179 +707,19 @@ cfgShellExt.SetInterceptKeyboardActions(GetPropValue(rConfig)); cfgShellExt.SetInterceptCtxMenuActions(GetPropValue(rConfig)); - TShellMenuItemPtr spRootItem = cfgShellExt.GetCommandRoot(); + cfgShellExt.GetFormatter()->SetValues( + GetResManager().LoadString(IDS_BYTE_STRING), + GetResManager().LoadString(IDS_KBYTE_STRING), + GetResManager().LoadString(IDS_MBYTE_STRING), + GetResManager().LoadString(IDS_GBYTE_STRING), + GetResManager().LoadString(IDS_TBYTE_STRING) + ); - // what kind of menu ? - switch(wParam) - { - case eLocation_DragAndDropMenu: - { - bool bAddedAnyOption = false; - if(GetPropValue(rConfig)) - { - spRootItem->AddChild(std::make_shared(rResManager.LoadString(IDS_MENUCOPY_STRING), rResManager.LoadString(IDS_MENUTIPCOPY_STRING), - TOperationTypeInfo(TOperationTypeInfo::eOpType_Specified, chcore::eOperation_Copy), - TSourcePathsInfo(TSourcePathsInfo::eSrcType_InitializeIDataObject), - TDestinationPathInfo(TDestinationPathInfo::eDstType_InitializePidlFolder, chcore::TSmartPath()), false, chcore::eOperation_Copy)); - bAddedAnyOption = true; - } + cfgShellExt.SetShowFreeSpace(GetPropValue(rConfig)); - if(GetPropValue(rConfig)) - { - spRootItem->AddChild(std::make_shared(rResManager.LoadString(IDS_MENUMOVE_STRING), rResManager.LoadString(IDS_MENUTIPMOVE_STRING), - TOperationTypeInfo(TOperationTypeInfo::eOpType_Specified, chcore::eOperation_Move), - TSourcePathsInfo(TSourcePathsInfo::eSrcType_InitializeIDataObject), - TDestinationPathInfo(TDestinationPathInfo::eDstType_InitializePidlFolder, chcore::TSmartPath()), false, chcore::eOperation_Move)); - bAddedAnyOption = true; - } + PrepareDragAndDropMenuItems(cfgShellExt); + PrepareNormalMenuItems(cfgShellExt); - if(GetPropValue(rConfig)) - { - spRootItem->AddChild(std::make_shared(rResManager.LoadString(IDS_MENUCOPYMOVESPECIAL_STRING), rResManager.LoadString(IDS_MENUTIPCOPYMOVESPECIAL_STRING), - TOperationTypeInfo(TOperationTypeInfo::eOpType_Autodetect, chcore::eOperation_Copy), - TSourcePathsInfo(TSourcePathsInfo::eSrcType_InitializeIDataObject), - TDestinationPathInfo(TDestinationPathInfo::eDstType_InitializePidlFolder, chcore::TSmartPath()), true)); - bAddedAnyOption = true; - } - - if(bAddedAnyOption) - { - // insert separator as an addition to other items - spRootItem->AddChild(std::make_shared()); - } - break; - } - - case eLocation_ContextMenu: - { - if(GetPropValue(rConfig)) - { - spRootItem->AddChild(std::make_shared(rResManager.LoadString(IDS_MENUPASTE_STRING), rResManager.LoadString(IDS_MENUTIPPASTE_STRING), - TOperationTypeInfo(TOperationTypeInfo::eOpType_Autodetect, chcore::eOperation_Copy), - TSourcePathsInfo(TSourcePathsInfo::eSrcType_Clipboard), - TDestinationPathInfo(TDestinationPathInfo::eDstType_InitializeAuto, chcore::TSmartPath()), false)); - } - - if(GetPropValue(rConfig)) - { - spRootItem->AddChild(std::make_shared(rResManager.LoadString(IDS_MENUPASTESPECIAL_STRING), rResManager.LoadString(IDS_MENUTIPPASTESPECIAL_STRING), - TOperationTypeInfo(TOperationTypeInfo::eOpType_Autodetect, chcore::eOperation_Copy), - TSourcePathsInfo(TSourcePathsInfo::eSrcType_Clipboard), - TDestinationPathInfo(TDestinationPathInfo::eDstType_InitializeAuto, chcore::TSmartPath()), true)); - } - - if(GetPropValue(rConfig) || GetPropValue(rConfig) || GetPropValue(rConfig)) - { - // prepare shortcuts for all menu options - std::vector vShortcutStrings; - GetPropValue(rConfig, vShortcutStrings); - - bool bRetrieveFreeSpace = GetPropValue(rConfig); - - std::vector vShortcuts; - - for(const CString& strShortcutString : vShortcutStrings) - { - CShortcut tShortcut; - if(tShortcut.FromString(strShortcutString)) - { - unsigned long long ullSize = 0; - - // retrieving free space might fail, but it's not critical - we just won't show the free space - if(bRetrieveFreeSpace && GetDynamicFreeSpace(tShortcut.m_strPath, &ullSize, nullptr)) - { - CString strNameFormat; - strNameFormat.Format(_T("%s (%s)"), tShortcut.m_strName, GetSizeString(ullSize)); - - tShortcut.m_strName = strNameFormat; - } - - vShortcuts.push_back(tShortcut); - } - else - BOOST_ASSERT(false); // non-critical, but not very nice - } - - if(GetPropValue(rConfig)) - { - std::shared_ptr menuItem(std::make_shared(rResManager.LoadString(IDS_MENUCOPYTO_STRING), rResManager.LoadString(IDS_MENUTIPCOPYTO_STRING))); - for(const CShortcut& tShortcut : vShortcuts) - { - menuItem->AddChild(std::make_shared((PCTSTR)tShortcut.m_strName, (PCTSTR)tShortcut.m_strPath, - TOperationTypeInfo(TOperationTypeInfo::eOpType_Specified, chcore::eOperation_Copy), - TSourcePathsInfo(TSourcePathsInfo::eSrcType_InitializeAuto), - TDestinationPathInfo(TDestinationPathInfo::eDstType_Specified, chcore::PathFromString((PCTSTR)tShortcut.m_strPath)), false)); - } - - spRootItem->AddChild(menuItem); - - // optionally separator - if(!vShortcuts.empty()) - menuItem->AddChild(std::make_shared()); - - // "Choose" menu option - menuItem->AddChild(std::make_shared(rResManager.LoadString(IDS_SHELLEXT_CHOOSE_DIR_STRING), rResManager.LoadString(IDS_SHELLEXT_CHOOSE_DIR_TOOLTIP_STRING), - TOperationTypeInfo(TOperationTypeInfo::eOpType_Specified, chcore::eOperation_Copy), - TSourcePathsInfo(TSourcePathsInfo::eSrcType_InitializeAuto), - TDestinationPathInfo(TDestinationPathInfo::eDstType_Choose, chcore::TSmartPath()), false)); - } - - if(GetPropValue(rConfig)) - { - std::shared_ptr menuItem(std::make_shared(rResManager.LoadString(IDS_MENUMOVETO_STRING), rResManager.LoadString(IDS_MENUTIPMOVETO_STRING))); - for(const CShortcut& tShortcut : vShortcuts) - { - menuItem->AddChild(std::make_shared((PCTSTR)tShortcut.m_strName, (PCTSTR)tShortcut.m_strPath, - TOperationTypeInfo(TOperationTypeInfo::eOpType_Specified, chcore::eOperation_Move), - TSourcePathsInfo(TSourcePathsInfo::eSrcType_InitializeAuto), - TDestinationPathInfo(TDestinationPathInfo::eDstType_Specified, chcore::PathFromString((PCTSTR)tShortcut.m_strPath)), false)); - } - - spRootItem->AddChild(menuItem); - - // optionally separator - if(!vShortcuts.empty()) - menuItem->AddChild(std::make_shared()); - - // "Choose" menu option - menuItem->AddChild(std::make_shared(rResManager.LoadString(IDS_SHELLEXT_CHOOSE_DIR_STRING), rResManager.LoadString(IDS_SHELLEXT_CHOOSE_DIR_TOOLTIP_STRING), - TOperationTypeInfo(TOperationTypeInfo::eOpType_Specified, chcore::eOperation_Move), - TSourcePathsInfo(TSourcePathsInfo::eSrcType_InitializeAuto), - TDestinationPathInfo(TDestinationPathInfo::eDstType_Choose, chcore::TSmartPath()), false)); - } - - if(GetPropValue(rConfig)) - { - std::shared_ptr menuItem(std::make_shared(rResManager.LoadString(IDS_MENUCOPYMOVETOSPECIAL_STRING), rResManager.LoadString(IDS_MENUTIPCOPYMOVETOSPECIAL_STRING))); - for(const CShortcut& tShortcut : vShortcuts) - { - menuItem->AddChild(std::make_shared((PCTSTR)tShortcut.m_strName, (PCTSTR)tShortcut.m_strPath, - TOperationTypeInfo(TOperationTypeInfo::eOpType_Specified, chcore::eOperation_Copy), - TSourcePathsInfo(TSourcePathsInfo::eSrcType_InitializeAuto), - TDestinationPathInfo(TDestinationPathInfo::eDstType_Specified, chcore::PathFromString((PCTSTR)tShortcut.m_strPath)), true)); - } - - spRootItem->AddChild(menuItem); - - // optionally separator - if(!vShortcuts.empty()) - menuItem->AddChild(std::make_shared()); - - // "Choose" menu option - menuItem->AddChild(std::make_shared(rResManager.LoadString(IDS_SHELLEXT_CHOOSE_DIR_STRING), rResManager.LoadString(IDS_SHELLEXT_CHOOSE_DIR_TOOLTIP_STRING), - TOperationTypeInfo(TOperationTypeInfo::eOpType_Specified, chcore::eOperation_Copy), - TSourcePathsInfo(TSourcePathsInfo::eSrcType_InitializeAuto), - TDestinationPathInfo(TDestinationPathInfo::eDstType_Choose, chcore::TSmartPath()), true)); - } - } - - break; - } - - default: - ASSERT(false); // unhandled case - } - chcore::TConfig cfgStorage; chcore::TString wstrData; @@ -957,6 +794,160 @@ return CWnd::WindowProc(message, wParam, lParam); } +void CMainWnd::PrepareDragAndDropMenuItems(TShellExtMenuConfig &cfgShellExt) const +{ + chcore::TConfig& rConfig = GetConfig(); + ictranslate::CResourceManager& rResManager = GetResManager(); + + TShellMenuItemPtr spDragAndDropRootItem = cfgShellExt.GetDragAndDropRoot(); + bool bAddedAnyOption = false; + if(GetPropValue(rConfig)) + { + spDragAndDropRootItem->AddChild(std::make_shared(rResManager.LoadString(IDS_MENUCOPY_STRING), rResManager.LoadString(IDS_MENUTIPCOPY_STRING), + TOperationTypeInfo(TOperationTypeInfo::eOpType_Specified, chcore::eOperation_Copy), + TSourcePathsInfo(TSourcePathsInfo::eSrcType_InitializeIDataObject), + TDestinationPathInfo(TDestinationPathInfo::eDstType_InitializePidlFolder, chcore::TSmartPath()), false, chcore::eOperation_Copy)); + bAddedAnyOption = true; + } + + if(GetPropValue(rConfig)) + { + spDragAndDropRootItem->AddChild(std::make_shared(rResManager.LoadString(IDS_MENUMOVE_STRING), rResManager.LoadString(IDS_MENUTIPMOVE_STRING), + TOperationTypeInfo(TOperationTypeInfo::eOpType_Specified, chcore::eOperation_Move), + TSourcePathsInfo(TSourcePathsInfo::eSrcType_InitializeIDataObject), + TDestinationPathInfo(TDestinationPathInfo::eDstType_InitializePidlFolder, chcore::TSmartPath()), false, chcore::eOperation_Move)); + bAddedAnyOption = true; + } + + if(GetPropValue(rConfig)) + { + spDragAndDropRootItem->AddChild(std::make_shared(rResManager.LoadString(IDS_MENUCOPYMOVESPECIAL_STRING), rResManager.LoadString(IDS_MENUTIPCOPYMOVESPECIAL_STRING), + TOperationTypeInfo(TOperationTypeInfo::eOpType_Autodetect, chcore::eOperation_Copy), + TSourcePathsInfo(TSourcePathsInfo::eSrcType_InitializeIDataObject), + TDestinationPathInfo(TDestinationPathInfo::eDstType_InitializePidlFolder, chcore::TSmartPath()), true)); + bAddedAnyOption = true; + } + + if(bAddedAnyOption) + { + // insert separator as an addition to other items + spDragAndDropRootItem->AddChild(std::make_shared()); + } +} + +void CMainWnd::PrepareNormalMenuItems(TShellExtMenuConfig &cfgShellExt) const +{ + chcore::TConfig& rConfig = GetConfig(); + ictranslate::CResourceManager& rResManager = GetResManager(); + + TShellMenuItemPtr spNormalRootItem = cfgShellExt.GetNormalRoot(); + + if(GetPropValue(rConfig)) + { + spNormalRootItem->AddChild(std::make_shared(rResManager.LoadString(IDS_MENUPASTE_STRING), rResManager.LoadString(IDS_MENUTIPPASTE_STRING), + TOperationTypeInfo(TOperationTypeInfo::eOpType_Autodetect, chcore::eOperation_Copy), + TSourcePathsInfo(TSourcePathsInfo::eSrcType_Clipboard), + TDestinationPathInfo(TDestinationPathInfo::eDstType_InitializeAuto, chcore::TSmartPath()), false)); + } + + if(GetPropValue(rConfig)) + { + spNormalRootItem->AddChild(std::make_shared(rResManager.LoadString(IDS_MENUPASTESPECIAL_STRING), rResManager.LoadString(IDS_MENUTIPPASTESPECIAL_STRING), + TOperationTypeInfo(TOperationTypeInfo::eOpType_Autodetect, chcore::eOperation_Copy), + TSourcePathsInfo(TSourcePathsInfo::eSrcType_Clipboard), + TDestinationPathInfo(TDestinationPathInfo::eDstType_InitializeAuto, chcore::TSmartPath()), true)); + } + + if(GetPropValue(rConfig) || GetPropValue(rConfig) || GetPropValue(rConfig)) + { + // prepare shortcuts for all menu options + std::vector vShortcutStrings; + GetPropValue(rConfig, vShortcutStrings); + + std::vector vShortcuts; + + for(const CString& strShortcutString : vShortcutStrings) + { + CShortcut tShortcut; + if(tShortcut.FromString(strShortcutString)) + vShortcuts.push_back(tShortcut); + else + BOOST_ASSERT(false); // non-critical, but not very nice + } + + if(GetPropValue(rConfig)) + { + std::shared_ptr menuItem(std::make_shared(rResManager.LoadString(IDS_MENUCOPYTO_STRING), rResManager.LoadString(IDS_MENUTIPCOPYTO_STRING))); + for(const CShortcut& tShortcut : vShortcuts) + { + menuItem->AddChild(std::make_shared((PCTSTR)tShortcut.m_strName, (PCTSTR)tShortcut.m_strPath, + TOperationTypeInfo(TOperationTypeInfo::eOpType_Specified, chcore::eOperation_Copy), + TSourcePathsInfo(TSourcePathsInfo::eSrcType_InitializeAuto), + TDestinationPathInfo(TDestinationPathInfo::eDstType_Specified, chcore::PathFromString((PCTSTR)tShortcut.m_strPath)), false)); + } + + spNormalRootItem->AddChild(menuItem); + + // optionally separator + if(!vShortcuts.empty()) + menuItem->AddChild(std::make_shared()); + + // "Choose" menu option + menuItem->AddChild(std::make_shared(rResManager.LoadString(IDS_SHELLEXT_CHOOSE_DIR_STRING), rResManager.LoadString(IDS_SHELLEXT_CHOOSE_DIR_TOOLTIP_STRING), + TOperationTypeInfo(TOperationTypeInfo::eOpType_Specified, chcore::eOperation_Copy), + TSourcePathsInfo(TSourcePathsInfo::eSrcType_InitializeAuto), + TDestinationPathInfo(TDestinationPathInfo::eDstType_Choose, chcore::TSmartPath()), false)); + } + + if(GetPropValue(rConfig)) + { + std::shared_ptr menuItem(std::make_shared(rResManager.LoadString(IDS_MENUMOVETO_STRING), rResManager.LoadString(IDS_MENUTIPMOVETO_STRING))); + for(const CShortcut& tShortcut : vShortcuts) + { + menuItem->AddChild(std::make_shared((PCTSTR)tShortcut.m_strName, (PCTSTR)tShortcut.m_strPath, + TOperationTypeInfo(TOperationTypeInfo::eOpType_Specified, chcore::eOperation_Move), + TSourcePathsInfo(TSourcePathsInfo::eSrcType_InitializeAuto), + TDestinationPathInfo(TDestinationPathInfo::eDstType_Specified, chcore::PathFromString((PCTSTR)tShortcut.m_strPath)), false)); + } + + spNormalRootItem->AddChild(menuItem); + + // optionally separator + if(!vShortcuts.empty()) + menuItem->AddChild(std::make_shared()); + + // "Choose" menu option + menuItem->AddChild(std::make_shared(rResManager.LoadString(IDS_SHELLEXT_CHOOSE_DIR_STRING), rResManager.LoadString(IDS_SHELLEXT_CHOOSE_DIR_TOOLTIP_STRING), + TOperationTypeInfo(TOperationTypeInfo::eOpType_Specified, chcore::eOperation_Move), + TSourcePathsInfo(TSourcePathsInfo::eSrcType_InitializeAuto), + TDestinationPathInfo(TDestinationPathInfo::eDstType_Choose, chcore::TSmartPath()), false)); + } + + if(GetPropValue(rConfig)) + { + std::shared_ptr menuItem(std::make_shared(rResManager.LoadString(IDS_MENUCOPYMOVETOSPECIAL_STRING), rResManager.LoadString(IDS_MENUTIPCOPYMOVETOSPECIAL_STRING))); + for(const CShortcut& tShortcut : vShortcuts) + { + menuItem->AddChild(std::make_shared((PCTSTR)tShortcut.m_strName, (PCTSTR)tShortcut.m_strPath, + TOperationTypeInfo(TOperationTypeInfo::eOpType_Specified, chcore::eOperation_Copy), + TSourcePathsInfo(TSourcePathsInfo::eSrcType_InitializeAuto), + TDestinationPathInfo(TDestinationPathInfo::eDstType_Specified, chcore::PathFromString((PCTSTR)tShortcut.m_strPath)), true)); + } + + spNormalRootItem->AddChild(menuItem); + + // optionally separator + if(!vShortcuts.empty()) + menuItem->AddChild(std::make_shared()); + + // "Choose" menu option + menuItem->AddChild(std::make_shared(rResManager.LoadString(IDS_SHELLEXT_CHOOSE_DIR_STRING), rResManager.LoadString(IDS_SHELLEXT_CHOOSE_DIR_TOOLTIP_STRING), + TOperationTypeInfo(TOperationTypeInfo::eOpType_Specified, chcore::eOperation_Copy), + TSourcePathsInfo(TSourcePathsInfo::eSrcType_InitializeAuto), + TDestinationPathInfo(TDestinationPathInfo::eDstType_Choose, chcore::TSmartPath()), true)); + } + } +} void CMainWnd::OnAppAbout() { CAboutDlg *pdlg=new CAboutDlg;