Skip to content

Commit 483e5f7

Browse files
Recent Programs: Show as a list, with rows per column
The Recent Programs item can show the recent programs as a list in its own place in the menu (Show as a list in the item editor, setting FLAT_LIST), instead of as a sub-menu. In the Classic two-column menu that puts the recent list wherever the user wants it, for example in a column of its own after a column break, and Rows per column lets it continue in the next column, like the Pinned programs item. - The item is a placeholder, replaced once all other items are added (InsertRecentProgramLists), because GetRecentPrograms skips programs that are already in the main menu. Any Recent Programs item already turns off the recent programs that the RecentPrograms setting adds to the main menu (MENU_NORECENT), so they never show twice. - The list takes the icon size of the pane it is in (IsInSecondPane). - Sorting by name or in reverse used to reorder only the first block of recent programs, in one column. Every block is sorted now, and each program takes a place the layout gave the list, so a list that runs over several columns keeps its shape. - Rows per column is enabled for the Recent Programs item only while Show as a list is checked, since a sub-menu has no rows. - GetRecentProgramCount and SetJumplistFlags are the code InitItems already had, moved into helpers so the list can use them too.
1 parent 02ec52d commit 483e5f7

7 files changed

Lines changed: 161 additions & 61 deletions

File tree

‎Src/Lib/SettingsUIHelper.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ struct CTreeItem
243243
CString icon;
244244
CString iconD;
245245
unsigned int settings;
246-
int rows; // rows per column of a Pinned programs list (0 - no limit)
246+
int rows; // rows per column of a Pinned programs or Recent Programs list (0 - no limit)
247247
const CStdCommand *pStdCommand; // always valid
248248

249249
CTreeItem( void ) { settings=0; rows=0; pStdCommand=NULL; }

‎Src/StartMenu/StartMenuDLL/CustomMenu.cpp‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,7 @@ static unsigned int ParseItemSettings( const wchar_t *name )
200200
if (_wcsicmp(token,L"NOEXTENSIONS")==0) settings|=StdMenuItem::MENU_NOEXTENSIONS;
201201
if (_wcsicmp(token,L"INLINE")==0) settings|=StdMenuItem::MENU_INLINE;
202202
if (_wcsicmp(token,L"SPLIT")==0) settings|=StdMenuItem::MENU_SPLIT_BUTTON;
203+
if (_wcsicmp(token,L"FLAT_LIST")==0) settings|=StdMenuItem::MENU_FLAT_LIST;
203204
}
204205
return settings;
205206
}

‎Src/StartMenu/StartMenuDLL/MenuContainer.cpp‎

Lines changed: 110 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1198,11 +1198,12 @@ void CMenuContainer::AddStandardItems( bool bPlacePinned )
11981198
item.bInlineFirst=bInlineFirst;
11991199
bAlignBottom=bInlineFirst=false;
12001200

1201-
if (pStdItem->id==MENU_PINNED_PROGRAMS)
1201+
bool bPinned=(pStdItem->id==MENU_PINNED_PROGRAMS);
1202+
if (bPinned || IsRecentProgramList(pStdItem))
12021203
{
1203-
// a placeholder, replaced once all other items are known (PlacePinnedPrograms).
1204+
// a placeholder, replaced once all other items are known (InsertRecentProgramLists, PlacePinnedPrograms).
12041205
// only the Classic main menu can place its pinned programs
1205-
if (pInlineParent || m_bSubMenu || s_bWin7Style)
1206+
if (pInlineParent || (bPinned && (m_bSubMenu || s_bWin7Style)))
12061207
continue;
12071208
m_Items.insert(m_Items.begin()+menuIdx,1,item);
12081209
menuIdx++;
@@ -1514,10 +1515,48 @@ void CMenuContainer::AddStandardItems( bool bPlacePinned )
15141515
menuIdx++;
15151516
}
15161517
}
1518+
InsertRecentProgramLists();
15171519
PlacePinnedPrograms(bPlacePinned);
15181520
}
15191521
}
15201522

1523+
// The number of recent programs to show
1524+
int CMenuContainer::GetRecentProgramCount( void )
1525+
{
1526+
// the sign of MaxRecentPrograms only picks the order
1527+
int count=GetSettingInt(L"MaxRecentPrograms");
1528+
if (count<0) count=-count;
1529+
if (count>MRU_PROGRAMS_COUNT) count=MRU_PROGRAMS_COUNT;
1530+
return count;
1531+
}
1532+
1533+
// Lets the items that have a jump list open it as a split sub-menu
1534+
void CMenuContainer::SetJumplistFlags( std::vector<MenuItem> &items )
1535+
{
1536+
for (std::vector<MenuItem>::iterator it=items.begin();it!=items.end();++it)
1537+
{
1538+
MenuItem &item=*it;
1539+
if (!item.bLink || item.bFolder || !item.pItem1) continue;
1540+
CItemManager::RWLock lock(&g_ItemManager,false,CItemManager::RWLOCK_ITEMS);
1541+
item.bFolder=(!item.pItemInfo->GetAppid().IsEmpty() && HasJumplist(item.pItemInfo->GetAppid()));
1542+
item.bHasJumpList=item.bFolder;
1543+
item.bSplit=item.bFolder;
1544+
}
1545+
}
1546+
1547+
// Whether the item at index gets the second-pane look, going by the column breaks before it (for items added before the layout)
1548+
bool CMenuContainer::IsInSecondPane( int index )
1549+
{
1550+
int breaks=0, count=0;
1551+
for (int i=1;i<(int)m_Items.size();i++)
1552+
{
1553+
if (!m_Items[i].bBreak || m_Items[i].bOverflow) continue; // overflow columns never change the panes
1554+
count++;
1555+
if (i<=index) breaks++;
1556+
}
1557+
return IsSecondPaneAfterBreaks(breaks,count);
1558+
}
1559+
15211560
// Passes a placeholder's column break and bottom alignment to the item that takes its place
15221561
void CMenuContainer::InheritColumnFlags( const MenuItem &placeholder, MenuItem &item )
15231562
{
@@ -1536,6 +1575,42 @@ void CMenuContainer::SetOverflowBreaks( std::vector<MenuItem> &items, int first,
15361575
}
15371576
}
15381577

1578+
// Whether the item is a Recent Programs item shown as a list (MENU_FLAT_LIST)
1579+
bool CMenuContainer::IsRecentProgramList( const StdMenuItem *pStdItem )
1580+
{
1581+
return pStdItem && pStdItem->id==MENU_RECENT_PROGRAMS && (pStdItem->settings&StdMenuItem::MENU_FLAT_LIST);
1582+
}
1583+
1584+
// The recent programs that take the place of the Recent Programs item at index, with their overflow breaks
1585+
void CMenuContainer::GetRecentProgramList( int index, std::vector<MenuItem> &items )
1586+
{
1587+
int count=GetRecentProgramCount();
1588+
if (count>0)
1589+
GetRecentPrograms(items,count,IsInSecondPane(index));
1590+
if (!m_bSubMenu && GetSettingBool(L"EnableJumplists"))
1591+
SetJumplistFlags(items);
1592+
SetOverflowBreaks(items,0,(int)items.size(),m_Items[index].pStdItem->rows);
1593+
}
1594+
1595+
// Replaces each Recent Programs item shown as a list by the recent programs themselves
1596+
void CMenuContainer::InsertRecentProgramLists( void )
1597+
{
1598+
// this runs after all other items are added, because GetRecentPrograms skips programs that are already in the main menu
1599+
for (int i=0;i<(int)m_Items.size();i++)
1600+
{
1601+
if (!IsRecentProgramList(m_Items[i].pStdItem))
1602+
continue;
1603+
std::vector<MenuItem> items;
1604+
GetRecentProgramList(i,items);
1605+
MenuItem copy=m_Items[i];
1606+
m_Items.erase(m_Items.begin()+i);
1607+
m_Items.insert(m_Items.begin()+i,items.begin(),items.end());
1608+
if (i<(int)m_Items.size())
1609+
InheritColumnFlags(copy,m_Items[i]);
1610+
i+=(int)items.size()-1; // continue after the inserted items
1611+
}
1612+
}
1613+
15391614
// Removes the Pinned Programs placeholders and remembers where the first one was (m_PinnedPosition)
15401615
void CMenuContainer::PlacePinnedPrograms( bool bSetPosition )
15411616
{
@@ -1837,12 +1912,13 @@ static bool IgnoreUserAssistItem(const UserAssistItem& uaItem)
18371912
return false;
18381913
}
18391914

1840-
void CMenuContainer::GetRecentPrograms( std::vector<MenuItem> &items, int maxCount )
1915+
void CMenuContainer::GetRecentPrograms( std::vector<MenuItem> &items, int maxCount, bool bSecondPane )
18411916
{
18421917
bool bShowMetro=GetSettingBool(L"RecentMetroApps");
18431918
const std::vector<MenuItem> &mainItems=s_Menus[0]->m_Items;
18441919

1845-
int iconSizeFlag=(!m_bSubMenu && s_Skin.Main_icon_size==MenuSkin::ICON_SIZE_LARGE)?CItemManager::INFO_LARGE_ICON:CItemManager::INFO_SMALL_ICON;
1920+
MenuSkin::TIconSize mainIconSize=bSecondPane?s_Skin.Main2_icon_size:s_Skin.Main_icon_size;
1921+
int iconSizeFlag=(!m_bSubMenu && mainIconSize==MenuSkin::ICON_SIZE_LARGE)?CItemManager::INFO_LARGE_ICON:CItemManager::INFO_SMALL_ICON;
18461922
if (s_RecentPrograms==RECENT_PROGRAMS_RECENT)
18471923
{
18481924
for (int i=0;i<MRU_PROGRAMS_COUNT;i++)
@@ -2790,10 +2866,7 @@ void CMenuContainer::InitItems( void )
27902866

27912867
if (m_Options&CONTAINER_RECENT)
27922868
{
2793-
int nRecent=GetSettingInt(L"MaxRecentPrograms");
2794-
if (nRecent<0)
2795-
nRecent=-nRecent;
2796-
if (nRecent>MRU_PROGRAMS_COUNT) nRecent=MRU_PROGRAMS_COUNT;
2869+
int nRecent=GetRecentProgramCount();
27972870
if (nRecent>0)
27982871
{
27992872
// prepend recent programs
@@ -2817,19 +2890,7 @@ void CMenuContainer::InitItems( void )
28172890
}
28182891

28192892
if (!m_bSubMenu && GetSettingBool(L"EnableJumplists"))
2820-
{
2821-
for (std::vector<MenuItem>::iterator it=m_Items.begin();it!=m_Items.end();++it)
2822-
{
2823-
MenuItem &item=*it;
2824-
if (item.bLink && !item.bFolder && item.pItem1)
2825-
{
2826-
CItemManager::RWLock lock(&g_ItemManager,false,CItemManager::RWLOCK_ITEMS);
2827-
item.bFolder=(!item.pItemInfo->GetAppid().IsEmpty() && HasJumplist(item.pItemInfo->GetAppid()));
2828-
item.bHasJumpList=item.bFolder;
2829-
item.bSplit=item.bFolder;
2830-
}
2831-
}
2832-
}
2893+
SetJumplistFlags(m_Items);
28332894

28342895
m_ScrollCount=(int)m_Items.size();
28352896
if (m_ScrollCount>0 && m_Items[m_ScrollCount-1].id==MENU_PROGRAMS_TREE)
@@ -3302,21 +3363,20 @@ void CMenuContainer::InitWindowInternal( bool bDontShrink, const POINT &corner,
33023363
bool bRecentReverse=GetSettingInt(L"MaxRecentPrograms")<0;
33033364
bool bRecentByName=GetSettingBool(L"RecentSortName");
33043365

3305-
int firstRecent=-1, lastRecent=-1;
3366+
// the layout is done in MRU order, and each block of recent programs is put in display order after it.
3367+
// every Recent Programs item shown as a list adds a block of its own
3368+
std::vector<std::pair<int,int>> recentBlocks; // [first,last) of each block
33063369
if ((bRecentReverse || bRecentByName) && (!m_bSubMenu || (m_Options&CONTAINER_RECENT)))
33073370
{
33083371
for (int i=0;i<(int)m_Items.size();i++)
33093372
{
3310-
if (m_Items[i].id==MENU_RECENT)
3311-
{
3312-
if (firstRecent==-1) firstRecent=i;
3313-
lastRecent=i+1;
3314-
}
3315-
else if (firstRecent!=-1)
3316-
break;
3373+
if (m_Items[i].id!=MENU_RECENT) continue;
3374+
int first=i;
3375+
while (i<(int)m_Items.size() && m_Items[i].id==MENU_RECENT)
3376+
i++;
3377+
std::sort(m_Items.begin()+first,m_Items.begin()+i,MenuItem::MruOrderComparator());
3378+
recentBlocks.push_back(std::make_pair(first,i));
33173379
}
3318-
if (firstRecent>=0)
3319-
std::sort(m_Items.begin()+firstRecent,m_Items.begin()+lastRecent,MenuItem::MruOrderComparator());
33203380
}
33213381

33223382
m_bTwoColumns=(!m_bSubMenu && s_Skin.TwoColumns);
@@ -3476,7 +3536,7 @@ void CMenuContainer::InitWindowInternal( bool bDontShrink, const POINT &corner,
34763536
int y=0;
34773537
int maxw=0;
34783538
int index=m_bSecondPaneFirst?1:0;
3479-
int overflowTop=0; // where the pinned programs start, so their overflow columns line up with them
3539+
int overflowTop=0; // where the current list starts, so its overflow columns line up with it
34803540
for (int k=0;k<(int)order.size();k++)
34813541
{
34823542
int i=order[k];
@@ -3503,7 +3563,9 @@ void CMenuContainer::InitWindowInternal( bool bDontShrink, const POINT &corner,
35033563
else
35043564
index=GetPaneOfNewColumn(column,index,lastBreak<0 || k==lastBreak);
35053565
}
3506-
if (i==0 && m_ScrollCount>0)
3566+
bool bPinnedStart=(i==0 && m_ScrollCount>0);
3567+
bool bRecentStart=(item.id==MENU_RECENT && (k==0 || m_Items[order[k-1]].id!=MENU_RECENT));
3568+
if (bPinnedStart || bRecentStart)
35073569
overflowTop=y;
35083570
item.bNew=false;
35093571
if (m_bTwoColumns && i<m_OriginalCount && s_MenuMode!=MODE_NORMAL && (i<=m_SearchIndex-m_SearchItemCount || i>m_SearchIndex) && item.id!=MENU_SHUTDOWN_BUTTON)
@@ -4192,11 +4254,17 @@ void CMenuContainer::InitWindowInternal( bool bDontShrink, const POINT &corner,
41924254
}
41934255
}
41944256

4195-
if (firstRecent>=0)
4257+
for (std::vector<std::pair<int,int>>::const_iterator block=recentBlocks.begin();block!=recentBlocks.end();++block)
41964258
{
4197-
// reorder recent items
4198-
int top=m_Items[firstRecent].itemRect.top;
4199-
int firstRow=m_Items[firstRecent].row;
4259+
// reorder recent items. they take the places the layout gave them in MRU order, which may span several columns
4260+
int firstRecent=block->first, lastRecent=block->second;
4261+
struct Place { RECT rect; int row, column; };
4262+
std::vector<Place> places;
4263+
for (int i=firstRecent;i<lastRecent;i++)
4264+
{
4265+
Place place={m_Items[i].itemRect,m_Items[i].row,m_Items[i].column};
4266+
places.push_back(place);
4267+
}
42004268
if (bRecentByName)
42014269
std::sort(m_Items.begin()+firstRecent,m_Items.begin()+lastRecent,MenuItem::MruNameComparator());
42024270

@@ -4232,12 +4300,10 @@ void CMenuContainer::InitWindowInternal( bool bDontShrink, const POINT &corner,
42324300
std::reverse(m_Items.begin()+firstRecent,m_Items.begin()+lastRecent);
42334301
for (int i=firstRecent;i<lastRecent;i++)
42344302
{
4235-
RECT &rc=m_Items[i].itemRect;
4236-
int h=rc.bottom-rc.top;
4237-
rc.top=top;
4238-
top+=h;
4239-
rc.bottom=top;
4240-
m_Items[i].row=firstRow-firstRecent+i;
4303+
const Place &place=places[i-firstRecent];
4304+
m_Items[i].itemRect=place.rect;
4305+
m_Items[i].row=place.row;
4306+
m_Items[i].column=place.column;
42414307
}
42424308
}
42434309
}

‎Src/StartMenu/StartMenuDLL/MenuContainer.h‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ struct StdMenuItem
115115
const wchar_t *iconPath;
116116
const wchar_t *link;
117117
unsigned int settings;
118-
int rows; // Pinned programs list: rows per column before the list continues in the next column (0 - no limit)
118+
int rows; // Pinned programs and Recent Programs lists: rows per column before the list continues in the next column (0 - no limit)
119119
const StdMenuItem *submenu;
120120
CString labelString, tipString; // additional storage for the strings
121121

@@ -138,6 +138,7 @@ struct StdMenuItem
138138
MENU_SPLIT_BUTTON = 0x002000, // the item is drawn as a split button
139139
MENU_ITEM_DISABLED = 0x004000, // the item is disabled
140140
MENU_NORECENT = 0x008000, // don't show recent items in the root menu (because a sub-menu uses MENU_RECENT_ITEMS)
141+
MENU_FLAT_LIST = 0x010000, // show the recent programs as a list in place of the item, instead of a sub-menu
141142

142143
// style
143144
MENU_STYLE_CLASSIC1 = 0x100000,
@@ -713,9 +714,15 @@ class CMenuContainer: public IDropTarget, public IFrameworkInputPaneHandler, pub
713714
};
714715

715716
int AddSearchItems( const std::vector<SearchItem> &items, const CString &categoryName, unsigned int categoryHash, int originalCount );
716-
void GetRecentPrograms( std::vector<MenuItem> &items, int maxCount );
717+
void GetRecentPrograms( std::vector<MenuItem> &items, int maxCount, bool bSecondPane=false );
718+
static int GetRecentProgramCount( void );
719+
static void SetJumplistFlags( std::vector<MenuItem> &items );
720+
bool IsInSecondPane( int index );
717721
static void InheritColumnFlags( const MenuItem &placeholder, MenuItem &item );
718722
static void SetOverflowBreaks( std::vector<MenuItem> &items, int first, int last, int rows );
723+
static bool IsRecentProgramList( const StdMenuItem *pStdItem );
724+
void GetRecentProgramList( int index, std::vector<MenuItem> &items );
725+
void InsertRecentProgramLists( void );
719726
void PlacePinnedPrograms( bool bSetPosition );
720727
void MovePinnedPadding( void );
721728
void GetLayoutOrder( std::vector<int> &order );

0 commit comments

Comments
 (0)