Clone
ixen <ixen@copyhandler.com>
committed
on 24 Mar 19
Fixed problem with shell extension not displaying single menu entries (CH-341)
src/ch/MainWnd.cpp (+4 -7)
7 7 *   (version 2) as published by the Free Software Foundation;             *
8 8 *                                                                         *
9 9 *   This program is distributed in the hope that it will be useful,       *
10 10 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
11 11 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
12 12 *   GNU General Public License for more details.                          *
13 13 *                                                                         *
14 14 *   You should have received a copy of the GNU Library General Public     *
15 15 *   License along with this program; if not, write to the                 *
16 16 *   Free Software Foundation, Inc.,                                       *
17 17 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
18 18 ***************************************************************************/
19 19 #include "stdafx.h"
20 20 #include "ch.h"
21 21 #include "MainWnd.h"
22 22
23 23 #include "OptionsDlg.h"
24 24 #include "FolderDialog.h"
25 25 #include "CustomCopyDlg.h"
26 26 #include "AboutDlg.h"
27   #include "ShutdownDlg.h"
28 27 #include "..\common\ipcstructs.h"
29 28 #include "UpdateChecker.h"
30 29 #include "UpdaterDlg.h"
31   #include "FeedbackHandler.h"
32 30 #include "MiniviewDlg.h"
33 31 #include "StatusDlg.h"
34 32 #include "ClipboardMonitor.h"
35   #include <boost/make_shared.hpp>
36 33 #include <boost/shared_array.hpp>
37 34 #include "../common/TShellExtMenuConfig.h"
38 35 #include "../libchcore/TConfig.h"
39 36 #include "FileSupport.h"
40 37 #include "StringHelpers.h"
41 38 #include "../libchcore/TCoreException.h"
42 39 #include "../libchcore/TTaskManagerStatsSnapshot.h"
43 40 #include "../libchcore/TSQLiteSerializerFactory.h"
44 41 #include "TRecentPathsTools.h"
45 42 #include "DirectoryChooser.h"
46 43 #include "FeedbackHandlerFactory.h"
47 44 #include "../libchcore/TTask.h"
48 45 #include "TTaskManagerWrapper.h"
49 46 #include "shortcuts.h"
50 47 #include "CfgProperties.h"
51 48 #include "resource.h"
52 49
53 50 #ifdef _DEBUG
54 51 #define new DEBUG_NEW
55 52 #undef THIS_FILE
 
766 763                                                 }
767 764
768 765                                                 if(GetPropValue<PP_SHSHOWPASTESPECIAL>(rConfig))
769 766                                                 {
770 767                                                         spRootItem->AddChild(std::make_shared<TShellMenuItem>(rResManager.LoadString(IDS_MENUPASTESPECIAL_STRING), rResManager.LoadString(IDS_MENUTIPPASTESPECIAL_STRING),
771 768                                                                 TOperationTypeInfo(TOperationTypeInfo::eOpType_Autodetect, chcore::eOperation_Copy),
772 769                                                                 TSourcePathsInfo(TSourcePathsInfo::eSrcType_Clipboard),
773 770                                                                 TDestinationPathInfo(TDestinationPathInfo::eDstType_InitializeAuto, chcore::TSmartPath()), true));
774 771                                                 }
775 772
776 773                                                 if(GetPropValue<PP_SHSHOWCOPYTO>(rConfig) || GetPropValue<PP_SHSHOWMOVETO>(rConfig) || GetPropValue<PP_SHSHOWCOPYMOVETO>(rConfig))
777 774                                                 {
778 775                                                         // prepare shortcuts for all menu options
779 776                                                         std::vector<CString> vShortcutStrings;
780 777                                                         GetPropValue<PP_SHORTCUTS>(rConfig, vShortcutStrings);
781 778
782 779                                                         bool bRetrieveFreeSpace = GetPropValue<PP_SHSHOWFREESPACE>(rConfig);
783 780
784 781                                                         std::vector<CShortcut> vShortcuts;
785 782
786                                                           BOOST_FOREACH(const CString& strShortcutString, vShortcutStrings)
  783                                                         for(const CString& strShortcutString : vShortcutStrings)
787 784                                                         {
788 785                                                                 CShortcut tShortcut;
789 786                                                                 if(tShortcut.FromString(strShortcutString))
790 787                                                                 {
791 788                                                                         unsigned long long ullSize = 0;
792 789
793 790                                                                         // retrieving free space might fail, but it's not critical - we just won't show the free space
794 791                                                                         if(bRetrieveFreeSpace && GetDynamicFreeSpace(tShortcut.m_strPath, &ullSize, nullptr))
795 792                                                                         {
796 793                                                                                 CString strNameFormat;
797 794                                                                                 strNameFormat.Format(_T("%s (%s)"), tShortcut.m_strName, GetSizeString(ullSize));
798 795
799 796                                                                                 tShortcut.m_strName = strNameFormat;
800 797                                                                         }
801 798
802 799                                                                         vShortcuts.push_back(tShortcut);
803 800                                                                 }
804 801                                                                 else
805 802                                                                         BOOST_ASSERT(false);    // non-critical, but not very nice
806 803                                                         }
807 804
808 805                                                         if(GetPropValue<PP_SHSHOWCOPYTO>(rConfig))
809 806                                                         {
810 807                                                                 std::shared_ptr<TShellMenuItem> menuItem(std::make_shared<TShellMenuItem>(rResManager.LoadString(IDS_MENUCOPYTO_STRING), rResManager.LoadString(IDS_MENUTIPCOPYTO_STRING)));
811                                                                   BOOST_FOREACH(const CShortcut& tShortcut, vShortcuts)
  808                                                                 for(const CShortcut& tShortcut : vShortcuts)
812 809                                                                 {
813 810                                                                         menuItem->AddChild(std::make_shared<TShellMenuItem>((PCTSTR)tShortcut.m_strName, (PCTSTR)tShortcut.m_strPath,
814 811                                                                                 TOperationTypeInfo(TOperationTypeInfo::eOpType_Specified, chcore::eOperation_Copy),
815 812                                                                                 TSourcePathsInfo(TSourcePathsInfo::eSrcType_InitializeAuto),
816 813                                                                                 TDestinationPathInfo(TDestinationPathInfo::eDstType_Specified, chcore::PathFromString((PCTSTR)tShortcut.m_strPath)), false));
817 814                                                                 }
818 815
819 816                                                                 spRootItem->AddChild(menuItem);
820 817
821 818                                                                 // optionally separator
822 819                                                                 if(!vShortcuts.empty())
823 820                                                                         menuItem->AddChild(std::make_shared<TShellMenuItem>());
824 821
825 822                                                                 // "Choose" menu option
826 823                                                                 menuItem->AddChild(std::make_shared<TShellMenuItem>(rResManager.LoadString(IDS_SHELLEXT_CHOOSE_DIR_STRING), rResManager.LoadString(IDS_SHELLEXT_CHOOSE_DIR_TOOLTIP_STRING),
827 824                                                                         TOperationTypeInfo(TOperationTypeInfo::eOpType_Specified, chcore::eOperation_Copy),
828 825                                                                         TSourcePathsInfo(TSourcePathsInfo::eSrcType_InitializeAuto),
829 826                                                                         TDestinationPathInfo(TDestinationPathInfo::eDstType_Choose, chcore::TSmartPath()), false));
830 827                                                         }
831 828
832 829                                                         if(GetPropValue<PP_SHSHOWMOVETO>(rConfig))
833 830                                                         {
834 831                                                                 std::shared_ptr<TShellMenuItem> menuItem(std::make_shared<TShellMenuItem>(rResManager.LoadString(IDS_MENUMOVETO_STRING), rResManager.LoadString(IDS_MENUTIPMOVETO_STRING)));
835                                                                   BOOST_FOREACH(const CShortcut& tShortcut, vShortcuts)
  832                                                                 for(const CShortcut& tShortcut : vShortcuts)
836 833                                                                 {
837 834                                                                         menuItem->AddChild(std::make_shared<TShellMenuItem>((PCTSTR)tShortcut.m_strName, (PCTSTR)tShortcut.m_strPath,
838 835                                                                                 TOperationTypeInfo(TOperationTypeInfo::eOpType_Specified, chcore::eOperation_Move),
839 836                                                                                 TSourcePathsInfo(TSourcePathsInfo::eSrcType_InitializeAuto),
840 837                                                                                 TDestinationPathInfo(TDestinationPathInfo::eDstType_Specified, chcore::PathFromString((PCTSTR)tShortcut.m_strPath)), false));
841 838                                                                 }
842 839
843 840                                                                 spRootItem->AddChild(menuItem);
844 841
845 842                                                                 // optionally separator
846 843                                                                 if(!vShortcuts.empty())
847 844                                                                         menuItem->AddChild(std::make_shared<TShellMenuItem>());
848 845
849 846                                                                 // "Choose" menu option
850 847                                                                 menuItem->AddChild(std::make_shared<TShellMenuItem>(rResManager.LoadString(IDS_SHELLEXT_CHOOSE_DIR_STRING), rResManager.LoadString(IDS_SHELLEXT_CHOOSE_DIR_TOOLTIP_STRING),
851 848                                                                         TOperationTypeInfo(TOperationTypeInfo::eOpType_Specified, chcore::eOperation_Move),
852 849                                                                         TSourcePathsInfo(TSourcePathsInfo::eSrcType_InitializeAuto),
853 850                                                                         TDestinationPathInfo(TDestinationPathInfo::eDstType_Choose, chcore::TSmartPath()), false));
854 851                                                         }
855 852
856 853                                                         if(GetPropValue<PP_SHSHOWCOPYMOVETO>(rConfig))
857 854                                                         {
858 855                                                                 std::shared_ptr<TShellMenuItem> menuItem(std::make_shared<TShellMenuItem>(rResManager.LoadString(IDS_MENUCOPYMOVETOSPECIAL_STRING), rResManager.LoadString(IDS_MENUTIPCOPYMOVETOSPECIAL_STRING)));
859                                                                   BOOST_FOREACH(const CShortcut& tShortcut, vShortcuts)
  856                                                                 for(const CShortcut& tShortcut : vShortcuts)
860 857                                                                 {
861 858                                                                         menuItem->AddChild(std::make_shared<TShellMenuItem>((PCTSTR)tShortcut.m_strName, (PCTSTR)tShortcut.m_strPath,
862 859                                                                                 TOperationTypeInfo(TOperationTypeInfo::eOpType_Specified, chcore::eOperation_Copy),
863 860                                                                                 TSourcePathsInfo(TSourcePathsInfo::eSrcType_InitializeAuto),
864 861                                                                                 TDestinationPathInfo(TDestinationPathInfo::eDstType_Specified, chcore::PathFromString((PCTSTR)tShortcut.m_strPath)), true));
865 862                                                                 }
866 863
867 864                                                                 spRootItem->AddChild(menuItem);
868 865
869 866                                                                 // optionally separator
870 867                                                                 if(!vShortcuts.empty())
871 868                                                                         menuItem->AddChild(std::make_shared<TShellMenuItem>());
872 869
873 870                                                                 // "Choose" menu option
874 871                                                                 menuItem->AddChild(std::make_shared<TShellMenuItem>(rResManager.LoadString(IDS_SHELLEXT_CHOOSE_DIR_STRING), rResManager.LoadString(IDS_SHELLEXT_CHOOSE_DIR_TOOLTIP_STRING),
875 872                                                                         TOperationTypeInfo(TOperationTypeInfo::eOpType_Specified, chcore::eOperation_Copy),
876 873                                                                         TSourcePathsInfo(TSourcePathsInfo::eSrcType_InitializeAuto),
877 874                                                                         TDestinationPathInfo(TDestinationPathInfo::eDstType_Choose, chcore::TSmartPath()), true));
878 875                                                         }
879 876                                                 }