Implement jump list feature: adding custom categories.

Author: Chaobin Zhang

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@77617 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Bryan Petty
2014-09-10 14:54:08 +00:00
parent dc51580b1a
commit 30015f9cfe
3 changed files with 89 additions and 29 deletions

View File

@@ -214,6 +214,8 @@ private:
wxString m_title;
};
typedef wxVector<wxJumpListCategory*> wxJumpListCategories;
class WXDLLIMPEXP_CORE wxJumpList
{
public:
@@ -227,10 +229,11 @@ public:
const wxJumpListCategory* GetFrequentCategory();
const wxJumpListCategory* GetRecentCategory();
const wxVector<wxJumpListCategory*>& GetCustomCategories();
const wxJumpListCategories& GetCustomCategories();
void AddCategory(wxJumpListCategory * catalog);
wxJumpListCategory* RemoveCategory(const wxString& title);
void DeleteCategory(const wxString& title);
void Update();
@@ -238,6 +241,7 @@ private:
bool BeginUpdate();
bool CommitUpdate();
void AddTasksToDestinationList();
void AddCustomCategoriesToDestionationList();
void LoadKnownCategory(const wxString& title);
ICustomDestinationList *m_destinationList;
@@ -246,7 +250,7 @@ private:
wxScopedPtr<wxJumpListCategory> m_tasks;
wxScopedPtr<wxJumpListCategory> m_frequent;
wxScopedPtr<wxJumpListCategory> m_recent;
wxVector<wxJumpListCategory*> m_customCategories;
wxJumpListCategories m_customCategories;
bool m_recent_visible;
bool m_frequent_visible;
};

View File

@@ -161,6 +161,19 @@ bool MyApp::OnInit()
jumpList.GetTasks()->Append(item2);
jumpList.ShowRecentCategory();
jumpList.ShowFrequentCategory();
wxJumpListItem* item3 = new wxJumpListItem(
wxJUMP_LIST_DESTIONATION,
wxT("Custom Item - Help"),
wxStandardPaths::Get().GetExecutablePath(),
wxT("--help"),
wxT("Test Custom Category."),
wxStandardPaths::Get().GetExecutablePath(),
0);
wxJumpListCategory* customCategory = new wxJumpListCategory(wxT("Custom"));
customCategory->Append(item3);
jumpList.AddCategory(customCategory);
jumpList.Update();
const wxJumpListCategory* category = jumpList.GetFrequentCategory();

View File

@@ -364,7 +364,8 @@ bool AddShellLink(IObjectCollection *collection, const wxJumpListItem& item)
return false;
}
if ( item.GetType() == wxJUMP_LIST_TASK )
if ( item.GetType() == wxJUMP_LIST_TASK ||
item.GetType() == wxJUMP_LIST_DESTIONATION )
{
if ( !item.GetFilePath().IsEmpty() )
shellLink->SetPath(item.GetFilePath().wc_str());
@@ -389,7 +390,8 @@ bool AddShellLink(IObjectCollection *collection, const wxJumpListItem& item)
}
PROPVARIANT pv;
if ( item.GetType() == wxJUMP_LIST_TASK )
if ( item.GetType() == wxJUMP_LIST_TASK ||
item.GetType() == wxJUMP_LIST_DESTIONATION )
{
hr = InitPropVariantFromString(item.GetTitle().wc_str(), &pv);
if ( SUCCEEDED(hr) )
@@ -474,6 +476,29 @@ wxJumpListItem* GetItemFromIShellItem(IShellItem *shellItem)
return item;
}
IObjectCollection* CreateObjectCollection()
{
IObjectCollection* collection;
HRESULT hr;
hr = CoCreateInstance
(
wxCLSID_EnumerableObjectCollection,
NULL,
CLSCTX_INPROC,
wxIID_IObjectCollection,
reinterpret_cast<void**>(&(collection))
);
if ( FAILED(hr) )
{
wxLogApiError("CoCreateInstance(wxCLSID_EnumerableObjectCollection)",
hr);
return NULL;
}
return collection;
}
} // namespace
IMPLEMENT_DYNAMIC_CLASS(wxThumbBarButton, wxObject)
@@ -1040,6 +1065,13 @@ wxJumpList::~wxJumpList()
{
if ( m_destinationList )
m_destinationList->Release();
for ( wxJumpListCategories::iterator it = m_customCategories.begin();
it != m_customCategories.end();
++it )
{
delete *it;
}
}
void wxJumpList::Update()
@@ -1048,6 +1080,7 @@ void wxJumpList::Update()
return;
AddTasksToDestinationList();
AddCustomCategoriesToDestionationList();
if ( m_recent_visible )
m_destinationList->AppendKnownCategory(KDC_RECENT);
if ( m_frequent_visible )
@@ -1101,7 +1134,7 @@ const wxJumpListCategory* wxJumpList::GetRecentCategory()
return m_recent.get();
}
const wxVector<wxJumpListCategory*>& wxJumpList::GetCustomCategories()
const wxJumpListCategories& wxJumpList::GetCustomCategories()
{
return m_customCategories;
}
@@ -1113,7 +1146,7 @@ void wxJumpList::AddCategory(wxJumpListCategory *catalog)
wxJumpListCategory* wxJumpList::RemoveCategory(const wxString& title)
{
for ( wxVector<wxJumpListCategory*>::iterator it = m_customCategories.begin();
for ( wxJumpListCategories::iterator it = m_customCategories.begin();
it != m_customCategories.end();
++it )
{
@@ -1127,6 +1160,13 @@ wxJumpListCategory* wxJumpList::RemoveCategory(const wxString& title)
return NULL;
}
void wxJumpList::DeleteCategory(const wxString& title)
{
wxJumpListCategory* category = RemoveCategory(title);
if ( category )
delete category;
}
bool wxJumpList::BeginUpdate()
{
if ( m_destinationList == NULL )
@@ -1147,27 +1187,9 @@ bool wxJumpList::CommitUpdate()
void wxJumpList::AddTasksToDestinationList()
{
IObjectArray* objectArray;
IObjectCollection* collection;
HRESULT hr;
hr = CoCreateInstance
(
wxCLSID_EnumerableObjectCollection,
NULL,
CLSCTX_INPROC,
wxIID_IObjectCollection,
reinterpret_cast<void**>(&(collection))
);
if ( FAILED(hr) )
{
wxLogApiError("CoCreateInstance(wxCLSID_EnumerableObjectCollection)",
hr);
IObjectCollection* collection = CreateObjectCollection();
if ( !collection )
return;
}
hr = collection->QueryInterface(wxIID_IObjectArray,
reinterpret_cast<void**>(&(objectArray)));
const wxJumpListItems& tasks = m_tasks->GetItems();
for ( wxJumpListItems::const_iterator it = tasks.begin();
@@ -1176,12 +1198,33 @@ void wxJumpList::AddTasksToDestinationList()
{
AddShellLink(collection, *(*it));
}
m_destinationList->AddUserTasks(objectArray);
objectArray->Release();
m_destinationList->AddUserTasks(collection);
collection->Release();
}
void wxJumpList::AddCustomCategoriesToDestionationList()
{
for ( wxJumpListCategories::iterator iter = m_customCategories.begin();
iter != m_customCategories.end();
++iter )
{
IObjectCollection* collection = CreateObjectCollection();
if ( !collection )
continue;
const wxJumpListItems& tasks = (*iter)->GetItems();
for ( wxJumpListItems::const_iterator it = tasks.begin();
it != tasks.end();
++it )
{
AddShellLink(collection, *(*it));
}
m_destinationList->AppendCategory((*iter)->GetTitle().wc_str(),
collection);
collection->Release();
}
}
void wxJumpList::LoadKnownCategory(const wxString& title)
{
IApplicationDocumentLists *docList = 0;