Print Page | Close Window

Backstage recent file list

Printed From: Codejock Forums
Category: Codejock Products
Forum Name: Command Bars
Forum Description: Topics Related to Codejock Command Bars
URL: http://forum.codejock.com/forum_posts.asp?TID=21854
Printed Date: 24 November 2024 at 5:28pm
Software Version: Web Wiz Forums 12.04 - http://www.webwizforums.com


Topic: Backstage recent file list
Posted By: DavidH
Subject: Backstage recent file list
Date Posted: 21 August 2013 at 10:34am
Is it possible to catch a right-mouse click on an item in the recent file list in the backstage area of the ribbon?

I ask this as I'd like to add a context menu allowing the user to remove the item from the list, or to delete the document the item is pointing to.

David.



Replies:
Posted By: Fredrik
Date Posted: 28 August 2013 at 7:37am
Try something like this (with necessary changes of course): 

BEGIN_MESSAGE_MAP(BackstagePageRecent, CXTPRibbonBackstagePage)
   ON_MESSAGE(WM_XTP_CONTROLRBUTTONUP, &BackstagePageRecent::OnRecentFileListRClick)
END_MESSAGE_MAP()

LRESULT BackstagePageRecent::OnRecentFileListRClick(WPARAM, LPARAM lParam)
{
   if ((CXTPControl*) lParam != mRecentFileListBox.GetGallery())
      return FALSE;

   CXTPControlGalleryItem* pItem = mRecentFileListBox.GetGallery()->GetItem(mRecentFileListBox.GetGallery()->GetSelectedItem());

   if (!pItem)
      return FALSE;

   CXTPRecentFileList* pRecentFileList = theApp.GetRecentFileList(); //- theApp = same as AfxGetApp()->GetRecentFileList
   CXTPRecentFileListItem* pRecentFileListItem = NULL; 
   int nSelectedIndex = 0; 

   // The recent file list in CXTPRecentFileListBox is currently protected. This loop is for finding which CXTPRecentFileListItem was clicked.
   for (int nIndex = 0; nIndex < pRecentFileList->m_nSize; ++nIndex)
   {
      CXTPRecentFileListItem* pTmpItem = dynamic_cast<CXTPRecentFileListItem*>(pRecentFileList->GetItem(nIndex));
      if (!pTmpItem)
         break;

      if (pItem->GetData() == (DWORD_PTR) pTmpItem)
      {
         pRecentFileListItem = pTmpItem;
         nSelectedIndex = nIndex;
         break;
      }
   }

   if (pRecentFileListItem)
   {
      CMenu oMenu;
      VERIFY(oMenu.CreatePopupMenu());

      oMenu.AppendMenu(MF_STRING, 1, _T("&Open"));
      oMenu.AppendMenu(MF_STRING, 2, _T("&Copy path to clipboard"));
      if (!pRecentFileListItem->IsPinned())
         oMenu.AppendMenu(MF_STRING, 3, _T("&Pin to list"));
      else
         oMenu.AppendMenu(MF_STRING, 3, _T("&Unpin from list"));
      oMenu.AppendMenu(MF_STRING, 4, _T("&Remove from list"));
      oMenu.AppendMenu(MF_STRING, 5, _T("Cl&ear unpinned documents"));

      CPoint pos;
      GetCursorPos(&pos);

      int nMenuResult = UmMenu::TrackPopupMenu(&oMenu, 
         TPM_NONOTIFY | TPM_RETURNCMD | TPM_LEFTALIGN |TPM_RIGHTBUTTON, 
         pos.x, pos.y, this, NULL);

      switch (nMenuResult)
      {
      case 1:
 // -- Add code to close the backstage page and open the file
         break;
      case 2:
 // -- Add code to copy to clipboard
         break;
      case 3:
         pRecentFileListItem->SetPinned(!pRecentFileListItem->IsPinned());
         pRecentFileList->WriteList();
         mRecentFileListBox.BuildItems();
         break;
      case 4:
         pRecentFileList->Remove(nSelectedIndex);
         pRecentFileList->WriteList();
         //OnSetActive(); // -- Add code to hide the list if it is empty here
         break;     
      case 5:
         for (int nIndex = pRecentFileList->GetCount(); nIndex >= 0; --nIndex)
         {
            CXTPRecentFileListItem* pTmpItem = dynamic_cast<CXTPRecentFileListItem*>(pRecentFileList->GetItem(nIndex));
            if (!pTmpItem)
               continue;

            if (!pTmpItem->IsPinned())
               pRecentFileList->Remove(nIndex);
         }
         pRecentFileList->WriteList();
         OnSetActive(); // -- Add code to hide the list if it is empty here
         break;
      default:
         return FALSE;
      }

      return TRUE; 
   }

   return FALSE;
}

Maybe someone at CodeJock sees this and have suggestions how to make the code simpler - right now the way how to find which CXTPRecentFileListItem is clicked is just a big hack.


-------------
Windows 10, Visual Studio 20157, Toolkit Pro 18.3.0


Posted By: DavidH
Date Posted: 04 September 2013 at 11:51am
Hi Fredrik,

I'm sorry that I only found your reply today. It's great!
I need to make some tweaks, for instance to keep the clicked row highlighted, but wow, very helpful.

David.



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.04 - http://www.webwizforums.com
Copyright ©2001-2021 Web Wiz Ltd. - https://www.webwiz.net