Codejock Forums Homepage
Forum Home Forum Home > Codejock Products > Visual C++ MFC > Command Bars
  New Posts New Posts RSS Feed - Backstage recent file list
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Backstage recent file list

 Post Reply Post Reply
Author
Message
DavidH View Drop Down
Groupie
Groupie


Joined: 24 March 2007
Status: Offline
Points: 59
Post Options Post Options   Thanks (0) Thanks(0)   Quote DavidH Quote  Post ReplyReply Direct Link To This Post Topic: Backstage recent file list
    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.
Back to Top
Fredrik View Drop Down
Senior Member
Senior Member


Joined: 22 June 2005
Status: Offline
Points: 235
Post Options Post Options   Thanks (1) Thanks(1)   Quote Fredrik Quote  Post ReplyReply Direct Link To This Post 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
Back to Top
DavidH View Drop Down
Groupie
Groupie


Joined: 24 March 2007
Status: Offline
Points: 59
Post Options Post Options   Thanks (0) Thanks(0)   Quote DavidH Quote  Post ReplyReply Direct Link To This Post 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.
Back to Top
 Post Reply Post Reply
  Share Topic   

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.04
Copyright ©2001-2021 Web Wiz Ltd.

This page was generated in 0.203 seconds.