tags:

views:

127

answers:

1

I can easly add a MRF list to A TRibbon recent items list but how do you add the same list to a ribbon item set as a dropdownbutton? The dropdown item is ActionBars[2].Items[1].

var
ARecentFilesList: TStringList;
ACI: TActionClientItem;
if FileExists( ARecentFilesFilename ) then
begin
  ARecentFilesList.LoadFromFile( ARecentFilesFilename );
  for i := 0 to ARecentFilesList.Count - 1 do
  begin
    // add filename to Ribbon Recent Items
    Ribbon1.AddRecentItem( ARecentFilesList.Strings[ i ] );
    //add the file name to dropdown button collection
    //add MostRecentFiles to ActionBars[2].Items[1]
    //ACI := TActionClientItem.Create( );
    //ACI.Caption := ARecentFilesList.Strings[ i ];
  end;
end;

Thanks,

Bill

A: 

As with much of the actionbar controls, it is not as intuitive as you'd like. The basic structure on the ribbon is like this:

  • Each ribbon has tabs.
  • Each tab has groups.
  • Each group has a series of controls.
  • Each control has a TActionClient associated with it.
  • Each TActionClient can have other TActionClient objects associated with it, either as ContextItems or Items. And the more you repeat this level, the deeper the nested menus.

So your strategy then, is to get your hands on the TActionClient that represents the button you'd like to add your items to. On my simple test app, I grabbed the first control on the first group - your logic may need to be more advanced.

var
  ActionClient: TActionClient;
  ChildItem: TActionClientItem;
begin
// Does the same as Ribbon1.AddRecentItem('C:\MyFile.txt');

  ActionClient := RibbonGroup1.ActionControls[0].ActionClient;

  ChildItem := ActionClient.Items.Add;
  ChildItem.Action := ActionThanOpensAFile;
  ChildItem.Caption := 'C:\MyFile.txt';
end;

Note that I assign the caption of my menu item after I assigned the action - this is because the action replaces the caption (and other properties too) of the client it is associated with.

Cobus Kruger
thank-you very much... I managed to get one filename added to the control (in my case the second control of the first group) from open file. Now to figure out how to add items from a string list ( already available ) and to figure out which item is selected to get the filename to reopen the file.
Bill Miller
I managed to add ActionClientItems at run time from a stringlist... see my most recent post for question on how to get the selected ActionClientItem?
Bill Miller
I like Nat's answer there - It may be possible to find it in another way, but creating an action per file is probably best. I added some comments in there too.
Cobus Kruger