Multi Commander Support Forum

Multi Commander => SDK => Topic started by: ice-man on July 21, 2013, 13:33:36

Title: Get all items and select some of them
Post by: ice-man on July 21, 2013, 13:33:36
I been playing around a bit with the SDK.

In one of the sample plugins you have an example on how to get all selected items.

But if I want to get all items and then set some of them as selected. How do I do that ?


Title: Re: Get all items and select some of them
Post by: Mathias (Author) on July 21, 2013, 13:54:25
Use the AM_GETFILESITEMS and AM_SELECTFILEITEMS message

This code will get all items in the current source view and then select every second item.

Quote
IFileItemCollection* pFileItems = m_pAppInterface->CreateFileItemCollection();
IFileItemCollection* pFileItemsSelected = m_pAppInterface->CreateFileItemCollection();
m_pAppInterface->SendMessageToSource( AM_GETFILEITEMS, (WPARAM)pFileItems, MF_ALL);
 
 DWORD nCount = pFileItems->Count();
 for(DWORD n = 0; n < nCount; ++n)
 {
   IFileItem* pItem = pFileItems->GetAt(n);
   if(pItem && n % 2)
  {
     pFileItemsSelected->Add(pItem);
   }
 }

 m_pAppInterface->SendMessageToSource( AM_SELECTFILEITEMS, (WPARAM)pFileItemsSelected, 1); // 0 for Unselect, 1 for Select
 pFileItemsSelected->Release();
 pFileItems->Release();
(Will add this to the SDK Sample project)