Skip to content

Commit 0da2018

Browse files
committed
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
1 parent 1f57c78 commit 0da2018

File tree

4 files changed

+67
-30
lines changed

4 files changed

+67
-30
lines changed

Src/StartMenu/StartMenuDLL/MenuCommands.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2192,11 +2192,15 @@ void CMenuContainer::ActivateItem( int index, TActivateType type, const POINT *p
21922192

21932193
if (res==CMD_PINSETTING)
21942194
{
2195-
CSearchManager::TItemCategory cat=(CSearchManager::TItemCategory)(item.categoryHash&CSearchManager::CATEGORY_MASK);
2196-
if (cat==CSearchManager::CATEGORY_SETTING)
2197-
CreatePinLink(pItemPidl1,item.name,NULL,0);
2198-
else if (cat==CSearchManager::CATEGORY_METROSETTING)
2199-
CreatePinLink(pItemPidl1,item.name,L"%windir%\\ImmersiveControlPanel\\systemsettings.exe",0);
2195+
CString iconPath;
2196+
if (item.pItemInfo)
2197+
{
2198+
CItemManager::RWLock lock(&g_ItemManager, false, CItemManager::RWLOCK_ITEMS);
2199+
if (_wcsicmp(PathFindExtension(item.pItemInfo->GetPath()), L".settingcontent-ms") == 0)
2200+
iconPath = L"%windir%\\ImmersiveControlPanel\\systemsettings.exe";
2201+
}
2202+
2203+
CreatePinLink(pItemPidl1, item.name, iconPath.IsEmpty() ? nullptr : iconPath.GetString(), 0);
22002204
m_bRefreshItems=true;
22012205
}
22022206

Src/StartMenu/StartMenuDLL/MenuContainer.cpp

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2656,17 +2656,11 @@ int CMenuContainer::AddSearchItems( const std::vector<SearchItem> &items, const
26562656
if (!categoryName.IsEmpty())
26572657
{
26582658
MenuItem item(MENU_SEARCH_CATEGORY);
2659-
if (categoryHash==CSearchManager::CATEGORY_PROGRAM || categoryHash==CSearchManager::CATEGORY_SETTING)
2660-
{
2661-
item.name.Format(L"%s (%d)",categoryName,originalCount);
2662-
}
2663-
else
2664-
{
2665-
item.name=categoryName;
2666-
item.bSplit=(s_Skin.More_bitmap_Size.cx>0);
2667-
}
2659+
item.name.Format(L"%s (%d)",categoryName,originalCount);
26682660
item.nameHash=CalcFNVHash(categoryName);
26692661
item.categoryHash=categoryHash;
2662+
if (categoryHash!=CSearchManager::CATEGORY_PROGRAM || categoryHash!=CSearchManager::CATEGORY_SETTING)
2663+
item.bSplit=(s_Skin.More_bitmap_Size.cx>0);
26702664
m_Items.push_back(item);
26712665
}
26722666
}
@@ -2724,7 +2718,7 @@ bool CMenuContainer::InitSearchItems( void )
27242718
unsigned int runCategoryHash=0;
27252719
CString runCommand;
27262720
CComString runExe;
2727-
if (!bAutoComlpete && !s_bNoRun && s_SearchResults.programs.empty() && s_SearchResults.settings.empty())
2721+
if (!bAutoComlpete && !s_bNoRun && s_SearchResults.programs.empty() && s_SearchResults.settings.empty() && s_SearchResults.metrosettings.empty())
27282722
{
27292723
if (s_bWin7Style)
27302724
m_SearchBox.GetWindowText(runCommand);
@@ -2787,6 +2781,12 @@ bool CMenuContainer::InitSearchItems( void )
27872781
if (m_SearchCategoryHash==CSearchManager::CATEGORY_SETTING)
27882782
selectedCount=(int)s_SearchResults.settings.size();
27892783
}
2784+
if (!s_SearchResults.metrosettings.empty())
2785+
{
2786+
counts.push_back((int)s_SearchResults.metrosettings.size());
2787+
if (m_SearchCategoryHash==CSearchManager::CATEGORY_METROSETTING)
2788+
selectedCount=(int)s_SearchResults.metrosettings.size();
2789+
}
27902790
for (std::list<CSearchManager::SearchCategory>::const_iterator it=s_SearchResults.indexed.begin();it!=s_SearchResults.indexed.end();++it)
27912791
{
27922792
if (!it->items.empty())
@@ -2829,14 +2829,16 @@ bool CMenuContainer::InitSearchItems( void )
28292829

28302830
// add categories
28312831
std::list<CSearchManager::SearchCategory>::const_iterator it=s_SearchResults.indexed.begin();
2832-
for (size_t idx=0;idx<s_SearchResults.indexed.size()+2;idx++)
2832+
for (size_t idx=0;idx<s_SearchResults.indexed.size()+3;idx++)
28332833
{
28342834
items.clear();
28352835
unsigned int categoryHash;
28362836
if (idx==0)
28372837
categoryHash=CSearchManager::CATEGORY_PROGRAM;
28382838
else if (idx==1)
28392839
categoryHash=CSearchManager::CATEGORY_SETTING;
2840+
else if (idx==2)
2841+
categoryHash=CSearchManager::CATEGORY_METROSETTING;
28402842
else
28412843
categoryHash=it->categoryHash;
28422844

@@ -2854,7 +2856,7 @@ bool CMenuContainer::InitSearchItems( void )
28542856
}
28552857
if (count<=0)
28562858
{
2857-
if (idx>=2) ++it;
2859+
if (idx>=3) ++it;
28582860
continue;
28592861
}
28602862

@@ -2880,6 +2882,16 @@ bool CMenuContainer::InitSearchItems( void )
28802882
items.push_back(SearchItem(*it));
28812883
name=FindTranslation(L"Search.CategorySettings",L"Settings");
28822884
}
2885+
else if (idx==2)
2886+
{
2887+
originalCount=(int)s_SearchResults.metrosettings.size();
2888+
if (count>originalCount)
2889+
count=originalCount;
2890+
items.reserve(count);
2891+
for (std::vector<const CItemManager::ItemInfo*>::const_iterator it=s_SearchResults.metrosettings.begin();it!=s_SearchResults.metrosettings.end() && (int)items.size()<count;++it)
2892+
items.push_back(SearchItem(*it));
2893+
name=FindTranslation(L"Search.CategoryPCSettings", L"Modern Settings");
2894+
}
28832895
else
28842896
{
28852897
originalCount=(int)it->items.size();

Src/StartMenu/StartMenuDLL/SearchManager.cpp

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ void CSearchManager::CloseMenu( void )
170170
m_SettingsItems.clear();
171171
m_SettingsHash=FNV_HASH0;
172172
m_bSettingsFound=false;
173+
m_bMetroSettingsFound = false;
173174

174175
m_IndexedItems.clear();
175176
m_AutoCompleteItems.clear();
@@ -310,7 +311,9 @@ bool CSearchManager::AddSearchItem( IShellItem *pItem, const wchar_t *name, int
310311
PROPVARIANT val;
311312
PropVariantInit(&val);
312313
pItem2->GetProperty(PKEY_Keywords,&val);
313-
wchar_t keywords[1024];
314+
if (val.vt==VT_EMPTY)
315+
pItem2->GetProperty(PKEY_HighKeywords,&val);
316+
wchar_t keywords[2048];
314317
int len=0;
315318
if (val.vt==VT_BSTR || val.vt==VT_LPWSTR)
316319
{
@@ -334,7 +337,7 @@ bool CSearchManager::AddSearchItem( IShellItem *pItem, const wchar_t *name, int
334337
}
335338

336339
Lock lock(this,LOCK_DATA);
337-
if (category==CATEGORY_PROGRAM || category==CATEGORY_SETTING)
340+
if (category==CATEGORY_PROGRAM || category==CATEGORY_SETTING || category==CATEGORY_METROSETTING)
338341
{
339342
if (searchRequest.requestId<m_LastProgramsRequestId)
340343
return false;
@@ -345,10 +348,10 @@ bool CSearchManager::AddSearchItem( IShellItem *pItem, const wchar_t *name, int
345348
return false;
346349
}
347350
bool res=true;
348-
if (category==CATEGORY_PROGRAM || category==CATEGORY_SETTING)
351+
if (category==CATEGORY_PROGRAM || category==CATEGORY_SETTING || category==CATEGORY_METROSETTING)
349352
{
350353
std::vector<SearchItem> &items=(category==CATEGORY_PROGRAM)?m_ProgramItems:m_SettingsItems;
351-
if (category==CATEGORY_SETTING)
354+
if (category==CATEGORY_SETTING || category==CATEGORY_METROSETTING)
352355
{
353356
// remove duplicate settings
354357
for (std::vector<SearchItem>::const_iterator it=items.begin();it!=items.end();++it)
@@ -381,6 +384,8 @@ bool CSearchManager::AddSearchItem( IShellItem *pItem, const wchar_t *name, int
381384
}
382385

383386
items.push_back(item);
387+
if (item.category==CATEGORY_METROSETTING)
388+
m_bMetroSettingsFound=true;
384389
}
385390
else if (category==CATEGORY_AUTOCOMPLETE)
386391
{
@@ -409,7 +414,7 @@ void CSearchManager::CollectSearchItems( IShellItem *pFolder, int flags, TItemCa
409414
CComPtr<IShellItem> pChild;
410415
while (pChild=NULL,pEnum->Next(1,&pChild,NULL)==S_OK)
411416
{
412-
if (category==CATEGORY_PROGRAM || category==CATEGORY_SETTING)
417+
if (category==CATEGORY_PROGRAM || category==CATEGORY_SETTING || category==CATEGORY_METROSETTING)
413418
{
414419
if (searchRequest.requestId<m_LastProgramsRequestId)
415420
break;
@@ -428,7 +433,7 @@ void CSearchManager::CollectSearchItems( IShellItem *pFolder, int flags, TItemCa
428433
{
429434
// go into subfolders but not archives or links to folders
430435
CollectSearchItems(pChild,flags,category,searchRequest);
431-
if (category==CATEGORY_PROGRAM || category==CATEGORY_SETTING)
436+
if (category==CATEGORY_PROGRAM || category==CATEGORY_SETTING || category==CATEGORY_METROSETTING)
432437
{
433438
if (searchRequest.requestId<m_LastProgramsRequestId)
434439
break;
@@ -733,6 +738,14 @@ void CSearchManager::SearchThread( void )
733738
if (searchRequest.requestId<m_LastProgramsRequestId)
734739
continue;
735740
}
741+
if (searchRequest.bSearchMetroSettings)
742+
{
743+
CComPtr<IShellItem> pFolder;
744+
if (SUCCEEDED(SHCreateItemFromParsingName(L"shell:::{82E749ED-B971-4550-BAF7-06AA2BF7E836}",NULL,IID_IShellItem,(void**)&pFolder)))
745+
CollectSearchItems(pFolder,(searchRequest.bSearchKeywords?COLLECT_KEYWORDS:0)|COLLECT_NOREFRESH,CATEGORY_METROSETTING,searchRequest);
746+
if (searchRequest.requestId<m_LastProgramsRequestId)
747+
continue;
748+
}
736749
}
737750
bool bRefresh=false;
738751
{
@@ -780,12 +793,12 @@ void CSearchManager::SearchThread( void )
780793
{
781794
std::list<SearchScope> scopeList;
782795

783-
if (searchRequest.bSearchMetroSettings)
796+
if (searchRequest.bSearchMetroSettings && !m_bMetroSettingsFound)
784797
{
785798
scopeList.push_back(SearchScope());
786799
SearchScope &scope=*scopeList.rbegin();
787800
scope.bFiles=true;
788-
scope.name=FindTranslation(L"Search.CategoryPCSettings",L"Settings");
801+
scope.name=FindTranslation(L"Search.CategoryPCSettings",L"Modern Settings");
789802
scope.categoryHash=CATEGORY_METROSETTING;
790803
scope.roots.push_back(L"FILE:");
791804
}
@@ -1240,7 +1253,7 @@ void CSearchManager::SearchThread( void )
12401253
Lock lock(this,LOCK_DATA);
12411254
m_IndexedItems.push_back(SearchCategory());
12421255
pCategory=&*m_IndexedItems.rbegin();
1243-
pCategory->name.Format(L"%s (%d)",it->name,it->resultCount);
1256+
pCategory->name=it->name;
12441257
pCategory->categoryHash=it->categoryHash;
12451258
pCategory->search.Clone(it->search);
12461259
}
@@ -1348,6 +1361,7 @@ void CSearchManager::GetSearchResults( SearchResults &results )
13481361
{
13491362
results.programs.clear();
13501363
results.settings.clear();
1364+
results.metrosettings.clear();
13511365
results.indexed.clear();
13521366
results.autocomplete.clear();
13531367
results.autoCompletePath.Empty();
@@ -1397,14 +1411,19 @@ void CSearchManager::GetSearchResults( SearchResults &results )
13971411
std::vector<SearchItem> &settings=m_bSettingsFound?m_SettingsItems:m_SettingsItemsOld;
13981412
for (std::vector<SearchItem>::iterator it=settings.begin();it!=settings.end();++it)
13991413
{
1400-
int match=(it->category==CATEGORY_SETTING)?it->MatchText(m_SearchText,bSearchSubWord):0;
1414+
int match=(it->category==CATEGORY_SETTING || it->category==CATEGORY_METROSETTING)?it->MatchText(m_SearchText,bSearchSubWord):0;
14011415
it->rank=(it->rank&0xFFFFFFFE)|(match>>1);
14021416
}
14031417
std::sort(settings.begin(),settings.end());
14041418
for (std::vector<SearchItem>::const_iterator it=settings.begin();it!=settings.end();++it)
14051419
{
1406-
if (it->category==CATEGORY_SETTING && it->MatchText(m_SearchText,bSearchSubWord))
1407-
results.settings.push_back(it->pInfo);
1420+
if (it->MatchText(m_SearchText, bSearchSubWord))
1421+
{
1422+
if (it->category==CATEGORY_SETTING)
1423+
results.settings.push_back(it->pInfo);
1424+
if (it->category==CATEGORY_METROSETTING)
1425+
results.metrosettings.push_back(it->pInfo);
1426+
}
14081427
}
14091428
}
14101429

@@ -1423,7 +1442,7 @@ void CSearchManager::GetSearchResults( SearchResults &results )
14231442
results.autocomplete.push_back(it->pInfo);
14241443
}
14251444
}
1426-
results.bResults=(!results.programs.empty() || !results.settings.empty() || !results.indexed.empty() || !results.autocomplete.empty());
1445+
results.bResults=(!results.programs.empty() || !results.settings.empty() || !results.metrosettings.empty() || !results.indexed.empty() || !results.autocomplete.empty());
14271446
results.bSearching=(m_LastCompletedId!=m_LastRequestId);
14281447
}
14291448

Src/StartMenu/StartMenuDLL/SearchManager.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ class CSearchManager
6363
CString autoCompletePath;
6464
std::vector<const CItemManager::ItemInfo*> programs;
6565
std::vector<const CItemManager::ItemInfo*> settings;
66+
std::vector<const CItemManager::ItemInfo*> metrosettings;
6667
std::vector<const CItemManager::ItemInfo*> autocomplete;
6768
std::list<SearchCategory> indexed;
6869
};
@@ -149,6 +150,7 @@ class CSearchManager
149150
unsigned int m_SettingsHashOld;
150151
bool m_bProgramsFound;
151152
bool m_bSettingsFound;
153+
bool m_bMetroSettingsFound = false;
152154
std::vector<SearchItem> m_AutoCompleteItems;
153155
std::list<SearchCategory> m_IndexedItems;
154156
std::vector<ItemRank> m_ItemRanks;

0 commit comments

Comments
 (0)