Adding dynamic controls to TadxRibbonSplitButton

Add-in Express™ Support Service
That's what is more important than anything else

Adding dynamic controls to TadxRibbonSplitButton
Adding to TadxRibbonSplitButton causes entire ribbon group hidden 
Brian Post




Posts: 84
Joined: 2007-09-06
RibbonSplitButtons behave like CommandBarPopups.

I have the following code to add to an existing splitbutton. ShowMessage displays a message box with the correct # of controls. The entire Ribbongroup get hidden or disabled. I just need to be able to add TadxRibbonButton to these.

procedure TadxOfficeAddin.UpdateQuickSaveStatus(splitButton: TadxRibbonSplitButton);
var
menu: TadxRibbonMenu;
begin
if (splitButton = Nil) then
Exit;

menu := splitButton.Controls.Items[0].AsRibbonMenu;
if (menu.Controls.Count > 0) then
begin
splitButton.ScreenTip := TOOLTIP_HAS_FOLDERS;
splitButton.Enabled := True;
end
else
begin
splitButton.ScreenTip := TOOLTIP_NO_FOLDERS;
splitButton.Enabled := False;
end;
end;

procedure TadxOfficeAddin.ReplaceQuickSaveItems(splitButton: TadxRibbonSplitButton; const GUID: string);
var
i: integer;
menu: TadxRibbonMenu;
tempControl: TadxRibbonCustomControl;
tempButton: TadxRibbonButton;
tempFolder : TDMFolder;
begin
if (splitButton = Nil) then
Exit;

menu := splitButton.Controls.Items[0].AsRibbonMenu;
if (Assigned(Menu)) then
ShowMessage(Format('Menu %d', [menu.Controls.Count]));

while (menu.Controls.Count > 0) do
begin
menu.Controls.Delete(menu.Controls.Count - 1);
end;
//Exit;

// Add the new buttons
for i:=0 to FFolderButtonList.Count-1 do
begin
if (i > MAX_FOLDERS_ALLOWED) then
break;
tempFolder := FFolderButtonList.Objects[i] as TDMFolder;
tempControl := menu.Controls.Add();
tempControl.DisplayName := tempFolder.Path;
{splitButton.Co
tempButton := tempControl.AsRibbonButton;
With tempButton do
begin
Id := MakeTag(GUID, FOLDER_TAG_PREFIX+tempFolder.ID);
Caption := GetShortFolderPath(StringReplace(tempFolder.Path,'\\','',
[rfReplaceAll, rfIgnoreCase]),g_MaxPathLen);
ScreenTip := tempFolder.Path;
Enabled := True;
Visible := True;
Glyph := FFolderGlyph;
//OnClick := QuickSaveOnClick;
end;
}
end;

UpdateQuickSaveStatus(splitButton);
end;

Cheers, Brian
Posted 19 Sep, 2007 23:47:24 Top
Brian Post




Posts: 84
Joined: 2007-09-06
As a .Net post mentions unable to dynamically add to RibbonMenu.

Ok found out that I can't dynamically add/remove items from TadxRibbonSplitButton. So I changed it to hide or show & change existing buttons. I have noticed that I can't reassign the Id property of my buttons added to my split button. If I do the entire ribbon group is not displayed.

Is there any point on startup where I can add extra buttons to my designer splitbutton, i.e TAddinModule.OnRibbonBeforeCreate? We have a registry entry where they specify the # of quick save buttons.

Should I be able to change the button Id or is there another non-visible to the user string property?

Cheers, Brian
Posted 20 Sep, 2007 00:25:53 Top
Dmitry Kostochko


Add-in Express team


Posts: 2875
Joined: 2004-04-05
Hi Brian,

Yes, you are correct, the 'splitButton' ribbon control doesn't support adding/removing buttons dynamically. I'd suggest using a standalone TadxRibbonMenu control with Dynamic := True, handle the TadxRibbonMenu.OnCreate event and populate the Controls collection.

Is there any point on startup where I can add extra buttons to my designer splitbutton, i.e TAddinModule.OnRibbonBeforeCreate?


You can use this event.

Should I be able to change the button Id or is there another non-visible to the user string property?


The Id property cannot be changed at run-time. You can try using the TadxRibbonButton.Description property.

Posted 20 Sep, 2007 05:25:41 Top