From 0da20180ac440f4fc9a65985d075c859601e88bc Mon Sep 17 00:00:00 2001 From: ge0rdi Date: Sun, 23 Aug 2020 16:20:55 +0200 Subject: [PATCH] Search modern settings using our new shell folder Use our modern settings shell folder (`shell:::{82E749ED-B971-4550-BAF7-06AA2BF7E836}`) to search (enumerate) modern settings. Fixes #57 --- Src/StartMenu/StartMenuDLL/MenuCommands.cpp | 14 +++--- Src/StartMenu/StartMenuDLL/MenuContainer.cpp | 36 ++++++++++------ Src/StartMenu/StartMenuDLL/SearchManager.cpp | 45 ++++++++++++++------ Src/StartMenu/StartMenuDLL/SearchManager.h | 2 + 4 files changed, 67 insertions(+), 30 deletions(-) diff --git a/Src/StartMenu/StartMenuDLL/MenuCommands.cpp b/Src/StartMenu/StartMenuDLL/MenuCommands.cpp index 843d5c4..bd89335 100644 --- a/Src/StartMenu/StartMenuDLL/MenuCommands.cpp +++ b/Src/StartMenu/StartMenuDLL/MenuCommands.cpp @@ -2192,11 +2192,15 @@ void CMenuContainer::ActivateItem( int index, TActivateType type, const POINT *p if (res==CMD_PINSETTING) { - CSearchManager::TItemCategory cat=(CSearchManager::TItemCategory)(item.categoryHash&CSearchManager::CATEGORY_MASK); - if (cat==CSearchManager::CATEGORY_SETTING) - CreatePinLink(pItemPidl1,item.name,NULL,0); - else if (cat==CSearchManager::CATEGORY_METROSETTING) - CreatePinLink(pItemPidl1,item.name,L"%windir%\\ImmersiveControlPanel\\systemsettings.exe",0); + CString iconPath; + if (item.pItemInfo) + { + CItemManager::RWLock lock(&g_ItemManager, false, CItemManager::RWLOCK_ITEMS); + if (_wcsicmp(PathFindExtension(item.pItemInfo->GetPath()), L".settingcontent-ms") == 0) + iconPath = L"%windir%\\ImmersiveControlPanel\\systemsettings.exe"; + } + + CreatePinLink(pItemPidl1, item.name, iconPath.IsEmpty() ? nullptr : iconPath.GetString(), 0); m_bRefreshItems=true; } diff --git a/Src/StartMenu/StartMenuDLL/MenuContainer.cpp b/Src/StartMenu/StartMenuDLL/MenuContainer.cpp index c8d5f88..a362c4d 100644 --- a/Src/StartMenu/StartMenuDLL/MenuContainer.cpp +++ b/Src/StartMenu/StartMenuDLL/MenuContainer.cpp @@ -2656,17 +2656,11 @@ int CMenuContainer::AddSearchItems( const std::vector &items, const if (!categoryName.IsEmpty()) { MenuItem item(MENU_SEARCH_CATEGORY); - if (categoryHash==CSearchManager::CATEGORY_PROGRAM || categoryHash==CSearchManager::CATEGORY_SETTING) - { - item.name.Format(L"%s (%d)",categoryName,originalCount); - } - else - { - item.name=categoryName; - item.bSplit=(s_Skin.More_bitmap_Size.cx>0); - } + item.name.Format(L"%s (%d)",categoryName,originalCount); item.nameHash=CalcFNVHash(categoryName); item.categoryHash=categoryHash; + if (categoryHash!=CSearchManager::CATEGORY_PROGRAM || categoryHash!=CSearchManager::CATEGORY_SETTING) + item.bSplit=(s_Skin.More_bitmap_Size.cx>0); m_Items.push_back(item); } } @@ -2724,7 +2718,7 @@ bool CMenuContainer::InitSearchItems( void ) unsigned int runCategoryHash=0; CString runCommand; CComString runExe; - if (!bAutoComlpete && !s_bNoRun && s_SearchResults.programs.empty() && s_SearchResults.settings.empty()) + if (!bAutoComlpete && !s_bNoRun && s_SearchResults.programs.empty() && s_SearchResults.settings.empty() && s_SearchResults.metrosettings.empty()) { if (s_bWin7Style) m_SearchBox.GetWindowText(runCommand); @@ -2787,6 +2781,12 @@ bool CMenuContainer::InitSearchItems( void ) if (m_SearchCategoryHash==CSearchManager::CATEGORY_SETTING) selectedCount=(int)s_SearchResults.settings.size(); } + if (!s_SearchResults.metrosettings.empty()) + { + counts.push_back((int)s_SearchResults.metrosettings.size()); + if (m_SearchCategoryHash==CSearchManager::CATEGORY_METROSETTING) + selectedCount=(int)s_SearchResults.metrosettings.size(); + } for (std::list::const_iterator it=s_SearchResults.indexed.begin();it!=s_SearchResults.indexed.end();++it) { if (!it->items.empty()) @@ -2829,7 +2829,7 @@ bool CMenuContainer::InitSearchItems( void ) // add categories std::list::const_iterator it=s_SearchResults.indexed.begin(); - for (size_t idx=0;idxcategoryHash; @@ -2854,7 +2856,7 @@ bool CMenuContainer::InitSearchItems( void ) } if (count<=0) { - if (idx>=2) ++it; + if (idx>=3) ++it; continue; } @@ -2880,6 +2882,16 @@ bool CMenuContainer::InitSearchItems( void ) items.push_back(SearchItem(*it)); name=FindTranslation(L"Search.CategorySettings",L"Settings"); } + else if (idx==2) + { + originalCount=(int)s_SearchResults.metrosettings.size(); + if (count>originalCount) + count=originalCount; + items.reserve(count); + for (std::vector::const_iterator it=s_SearchResults.metrosettings.begin();it!=s_SearchResults.metrosettings.end() && (int)items.size()items.size(); diff --git a/Src/StartMenu/StartMenuDLL/SearchManager.cpp b/Src/StartMenu/StartMenuDLL/SearchManager.cpp index a275a4e..1296667 100644 --- a/Src/StartMenu/StartMenuDLL/SearchManager.cpp +++ b/Src/StartMenu/StartMenuDLL/SearchManager.cpp @@ -170,6 +170,7 @@ void CSearchManager::CloseMenu( void ) m_SettingsItems.clear(); m_SettingsHash=FNV_HASH0; m_bSettingsFound=false; + m_bMetroSettingsFound = false; m_IndexedItems.clear(); m_AutoCompleteItems.clear(); @@ -310,7 +311,9 @@ bool CSearchManager::AddSearchItem( IShellItem *pItem, const wchar_t *name, int PROPVARIANT val; PropVariantInit(&val); pItem2->GetProperty(PKEY_Keywords,&val); - wchar_t keywords[1024]; + if (val.vt==VT_EMPTY) + pItem2->GetProperty(PKEY_HighKeywords,&val); + wchar_t keywords[2048]; int len=0; if (val.vt==VT_BSTR || val.vt==VT_LPWSTR) { @@ -334,7 +337,7 @@ bool CSearchManager::AddSearchItem( IShellItem *pItem, const wchar_t *name, int } Lock lock(this,LOCK_DATA); - if (category==CATEGORY_PROGRAM || category==CATEGORY_SETTING) + if (category==CATEGORY_PROGRAM || category==CATEGORY_SETTING || category==CATEGORY_METROSETTING) { if (searchRequest.requestId &items=(category==CATEGORY_PROGRAM)?m_ProgramItems:m_SettingsItems; - if (category==CATEGORY_SETTING) + if (category==CATEGORY_SETTING || category==CATEGORY_METROSETTING) { // remove duplicate settings for (std::vector::const_iterator it=items.begin();it!=items.end();++it) @@ -381,6 +384,8 @@ bool CSearchManager::AddSearchItem( IShellItem *pItem, const wchar_t *name, int } items.push_back(item); + if (item.category==CATEGORY_METROSETTING) + m_bMetroSettingsFound=true; } else if (category==CATEGORY_AUTOCOMPLETE) { @@ -409,7 +414,7 @@ void CSearchManager::CollectSearchItems( IShellItem *pFolder, int flags, TItemCa CComPtr pChild; while (pChild=NULL,pEnum->Next(1,&pChild,NULL)==S_OK) { - if (category==CATEGORY_PROGRAM || category==CATEGORY_SETTING) + if (category==CATEGORY_PROGRAM || category==CATEGORY_SETTING || category==CATEGORY_METROSETTING) { if (searchRequest.requestId pFolder; + if (SUCCEEDED(SHCreateItemFromParsingName(L"shell:::{82E749ED-B971-4550-BAF7-06AA2BF7E836}",NULL,IID_IShellItem,(void**)&pFolder))) + CollectSearchItems(pFolder,(searchRequest.bSearchKeywords?COLLECT_KEYWORDS:0)|COLLECT_NOREFRESH,CATEGORY_METROSETTING,searchRequest); + if (searchRequest.requestId scopeList; - if (searchRequest.bSearchMetroSettings) + if (searchRequest.bSearchMetroSettings && !m_bMetroSettingsFound) { scopeList.push_back(SearchScope()); SearchScope &scope=*scopeList.rbegin(); scope.bFiles=true; - scope.name=FindTranslation(L"Search.CategoryPCSettings",L"Settings"); + scope.name=FindTranslation(L"Search.CategoryPCSettings",L"Modern Settings"); scope.categoryHash=CATEGORY_METROSETTING; scope.roots.push_back(L"FILE:"); } @@ -1240,7 +1253,7 @@ void CSearchManager::SearchThread( void ) Lock lock(this,LOCK_DATA); m_IndexedItems.push_back(SearchCategory()); pCategory=&*m_IndexedItems.rbegin(); - pCategory->name.Format(L"%s (%d)",it->name,it->resultCount); + pCategory->name=it->name; pCategory->categoryHash=it->categoryHash; pCategory->search.Clone(it->search); } @@ -1348,6 +1361,7 @@ void CSearchManager::GetSearchResults( SearchResults &results ) { results.programs.clear(); results.settings.clear(); + results.metrosettings.clear(); results.indexed.clear(); results.autocomplete.clear(); results.autoCompletePath.Empty(); @@ -1397,14 +1411,19 @@ void CSearchManager::GetSearchResults( SearchResults &results ) std::vector &settings=m_bSettingsFound?m_SettingsItems:m_SettingsItemsOld; for (std::vector::iterator it=settings.begin();it!=settings.end();++it) { - int match=(it->category==CATEGORY_SETTING)?it->MatchText(m_SearchText,bSearchSubWord):0; + int match=(it->category==CATEGORY_SETTING || it->category==CATEGORY_METROSETTING)?it->MatchText(m_SearchText,bSearchSubWord):0; it->rank=(it->rank&0xFFFFFFFE)|(match>>1); } std::sort(settings.begin(),settings.end()); for (std::vector::const_iterator it=settings.begin();it!=settings.end();++it) { - if (it->category==CATEGORY_SETTING && it->MatchText(m_SearchText,bSearchSubWord)) - results.settings.push_back(it->pInfo); + if (it->MatchText(m_SearchText, bSearchSubWord)) + { + if (it->category==CATEGORY_SETTING) + results.settings.push_back(it->pInfo); + if (it->category==CATEGORY_METROSETTING) + results.metrosettings.push_back(it->pInfo); + } } } @@ -1423,7 +1442,7 @@ void CSearchManager::GetSearchResults( SearchResults &results ) results.autocomplete.push_back(it->pInfo); } } - results.bResults=(!results.programs.empty() || !results.settings.empty() || !results.indexed.empty() || !results.autocomplete.empty()); + results.bResults=(!results.programs.empty() || !results.settings.empty() || !results.metrosettings.empty() || !results.indexed.empty() || !results.autocomplete.empty()); results.bSearching=(m_LastCompletedId!=m_LastRequestId); } diff --git a/Src/StartMenu/StartMenuDLL/SearchManager.h b/Src/StartMenu/StartMenuDLL/SearchManager.h index 3234127..c521eec 100644 --- a/Src/StartMenu/StartMenuDLL/SearchManager.h +++ b/Src/StartMenu/StartMenuDLL/SearchManager.h @@ -63,6 +63,7 @@ public: CString autoCompletePath; std::vector programs; std::vector settings; + std::vector metrosettings; std::vector autocomplete; std::list indexed; }; @@ -149,6 +150,7 @@ private: unsigned int m_SettingsHashOld; bool m_bProgramsFound; bool m_bSettingsFound; + bool m_bMetroSettingsFound = false; std::vector m_AutoCompleteItems; std::list m_IndexedItems; std::vector m_ItemRanks;