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:
@@ -214,6 +214,8 @@ private:
|
|||||||
wxString m_title;
|
wxString m_title;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
typedef wxVector<wxJumpListCategory*> wxJumpListCategories;
|
||||||
|
|
||||||
class WXDLLIMPEXP_CORE wxJumpList
|
class WXDLLIMPEXP_CORE wxJumpList
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@@ -227,10 +229,11 @@ public:
|
|||||||
|
|
||||||
const wxJumpListCategory* GetFrequentCategory();
|
const wxJumpListCategory* GetFrequentCategory();
|
||||||
const wxJumpListCategory* GetRecentCategory();
|
const wxJumpListCategory* GetRecentCategory();
|
||||||
const wxVector<wxJumpListCategory*>& GetCustomCategories();
|
const wxJumpListCategories& GetCustomCategories();
|
||||||
|
|
||||||
void AddCategory(wxJumpListCategory * catalog);
|
void AddCategory(wxJumpListCategory * catalog);
|
||||||
wxJumpListCategory* RemoveCategory(const wxString& title);
|
wxJumpListCategory* RemoveCategory(const wxString& title);
|
||||||
|
void DeleteCategory(const wxString& title);
|
||||||
|
|
||||||
void Update();
|
void Update();
|
||||||
|
|
||||||
@@ -238,6 +241,7 @@ private:
|
|||||||
bool BeginUpdate();
|
bool BeginUpdate();
|
||||||
bool CommitUpdate();
|
bool CommitUpdate();
|
||||||
void AddTasksToDestinationList();
|
void AddTasksToDestinationList();
|
||||||
|
void AddCustomCategoriesToDestionationList();
|
||||||
void LoadKnownCategory(const wxString& title);
|
void LoadKnownCategory(const wxString& title);
|
||||||
|
|
||||||
ICustomDestinationList *m_destinationList;
|
ICustomDestinationList *m_destinationList;
|
||||||
@@ -246,7 +250,7 @@ private:
|
|||||||
wxScopedPtr<wxJumpListCategory> m_tasks;
|
wxScopedPtr<wxJumpListCategory> m_tasks;
|
||||||
wxScopedPtr<wxJumpListCategory> m_frequent;
|
wxScopedPtr<wxJumpListCategory> m_frequent;
|
||||||
wxScopedPtr<wxJumpListCategory> m_recent;
|
wxScopedPtr<wxJumpListCategory> m_recent;
|
||||||
wxVector<wxJumpListCategory*> m_customCategories;
|
wxJumpListCategories m_customCategories;
|
||||||
bool m_recent_visible;
|
bool m_recent_visible;
|
||||||
bool m_frequent_visible;
|
bool m_frequent_visible;
|
||||||
};
|
};
|
||||||
|
@@ -161,6 +161,19 @@ bool MyApp::OnInit()
|
|||||||
jumpList.GetTasks()->Append(item2);
|
jumpList.GetTasks()->Append(item2);
|
||||||
jumpList.ShowRecentCategory();
|
jumpList.ShowRecentCategory();
|
||||||
jumpList.ShowFrequentCategory();
|
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();
|
jumpList.Update();
|
||||||
|
|
||||||
const wxJumpListCategory* category = jumpList.GetFrequentCategory();
|
const wxJumpListCategory* category = jumpList.GetFrequentCategory();
|
||||||
|
@@ -364,7 +364,8 @@ bool AddShellLink(IObjectCollection *collection, const wxJumpListItem& item)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( item.GetType() == wxJUMP_LIST_TASK )
|
if ( item.GetType() == wxJUMP_LIST_TASK ||
|
||||||
|
item.GetType() == wxJUMP_LIST_DESTIONATION )
|
||||||
{
|
{
|
||||||
if ( !item.GetFilePath().IsEmpty() )
|
if ( !item.GetFilePath().IsEmpty() )
|
||||||
shellLink->SetPath(item.GetFilePath().wc_str());
|
shellLink->SetPath(item.GetFilePath().wc_str());
|
||||||
@@ -389,7 +390,8 @@ bool AddShellLink(IObjectCollection *collection, const wxJumpListItem& item)
|
|||||||
}
|
}
|
||||||
|
|
||||||
PROPVARIANT pv;
|
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);
|
hr = InitPropVariantFromString(item.GetTitle().wc_str(), &pv);
|
||||||
if ( SUCCEEDED(hr) )
|
if ( SUCCEEDED(hr) )
|
||||||
@@ -474,6 +476,29 @@ wxJumpListItem* GetItemFromIShellItem(IShellItem *shellItem)
|
|||||||
return item;
|
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
|
} // namespace
|
||||||
|
|
||||||
IMPLEMENT_DYNAMIC_CLASS(wxThumbBarButton, wxObject)
|
IMPLEMENT_DYNAMIC_CLASS(wxThumbBarButton, wxObject)
|
||||||
@@ -1040,6 +1065,13 @@ wxJumpList::~wxJumpList()
|
|||||||
{
|
{
|
||||||
if ( m_destinationList )
|
if ( m_destinationList )
|
||||||
m_destinationList->Release();
|
m_destinationList->Release();
|
||||||
|
|
||||||
|
for ( wxJumpListCategories::iterator it = m_customCategories.begin();
|
||||||
|
it != m_customCategories.end();
|
||||||
|
++it )
|
||||||
|
{
|
||||||
|
delete *it;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxJumpList::Update()
|
void wxJumpList::Update()
|
||||||
@@ -1048,6 +1080,7 @@ void wxJumpList::Update()
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
AddTasksToDestinationList();
|
AddTasksToDestinationList();
|
||||||
|
AddCustomCategoriesToDestionationList();
|
||||||
if ( m_recent_visible )
|
if ( m_recent_visible )
|
||||||
m_destinationList->AppendKnownCategory(KDC_RECENT);
|
m_destinationList->AppendKnownCategory(KDC_RECENT);
|
||||||
if ( m_frequent_visible )
|
if ( m_frequent_visible )
|
||||||
@@ -1101,7 +1134,7 @@ const wxJumpListCategory* wxJumpList::GetRecentCategory()
|
|||||||
return m_recent.get();
|
return m_recent.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
const wxVector<wxJumpListCategory*>& wxJumpList::GetCustomCategories()
|
const wxJumpListCategories& wxJumpList::GetCustomCategories()
|
||||||
{
|
{
|
||||||
return m_customCategories;
|
return m_customCategories;
|
||||||
}
|
}
|
||||||
@@ -1113,7 +1146,7 @@ void wxJumpList::AddCategory(wxJumpListCategory *catalog)
|
|||||||
|
|
||||||
wxJumpListCategory* wxJumpList::RemoveCategory(const wxString& title)
|
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 != m_customCategories.end();
|
||||||
++it )
|
++it )
|
||||||
{
|
{
|
||||||
@@ -1127,6 +1160,13 @@ wxJumpListCategory* wxJumpList::RemoveCategory(const wxString& title)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void wxJumpList::DeleteCategory(const wxString& title)
|
||||||
|
{
|
||||||
|
wxJumpListCategory* category = RemoveCategory(title);
|
||||||
|
if ( category )
|
||||||
|
delete category;
|
||||||
|
}
|
||||||
|
|
||||||
bool wxJumpList::BeginUpdate()
|
bool wxJumpList::BeginUpdate()
|
||||||
{
|
{
|
||||||
if ( m_destinationList == NULL )
|
if ( m_destinationList == NULL )
|
||||||
@@ -1147,27 +1187,9 @@ bool wxJumpList::CommitUpdate()
|
|||||||
|
|
||||||
void wxJumpList::AddTasksToDestinationList()
|
void wxJumpList::AddTasksToDestinationList()
|
||||||
{
|
{
|
||||||
IObjectArray* objectArray;
|
IObjectCollection* collection = CreateObjectCollection();
|
||||||
IObjectCollection* collection;
|
if ( !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;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
hr = collection->QueryInterface(wxIID_IObjectArray,
|
|
||||||
reinterpret_cast<void**>(&(objectArray)));
|
|
||||||
|
|
||||||
const wxJumpListItems& tasks = m_tasks->GetItems();
|
const wxJumpListItems& tasks = m_tasks->GetItems();
|
||||||
for ( wxJumpListItems::const_iterator it = tasks.begin();
|
for ( wxJumpListItems::const_iterator it = tasks.begin();
|
||||||
@@ -1176,12 +1198,33 @@ void wxJumpList::AddTasksToDestinationList()
|
|||||||
{
|
{
|
||||||
AddShellLink(collection, *(*it));
|
AddShellLink(collection, *(*it));
|
||||||
}
|
}
|
||||||
m_destinationList->AddUserTasks(objectArray);
|
m_destinationList->AddUserTasks(collection);
|
||||||
|
|
||||||
objectArray->Release();
|
|
||||||
collection->Release();
|
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)
|
void wxJumpList::LoadKnownCategory(const wxString& title)
|
||||||
{
|
{
|
||||||
IApplicationDocumentLists *docList = 0;
|
IApplicationDocumentLists *docList = 0;
|
||||||
|
Reference in New Issue
Block a user