Skip to content

Commit 7fce19d

Browse files
Added public function "IsContextTabEnabled", which returns whether or not a contextual tab is enabled.
1 parent b9249b8 commit 7fce19d

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

Lib/UIRibbon.pas

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,7 @@ TUIRibbon = class(TWinControl, IUIApplication)
207207
/// <param name="pCommandId">The id of the ribbon command.</param>
208208
/// <param name="pContextAvailability">The availability state.</param>
209209
procedure SetContextTabAvailability(const pCommandId: Integer; const pContextAvailability: TUIContextAvailability);
210+
function GetContextTabAvailability(const pCommandId: Integer): TUIContextAvailability;
210211

211212
{ IInterface }
212213
function _AddRef: Integer; stdcall;
@@ -403,6 +404,12 @@ TUIRibbon = class(TWinControl, IUIApplication)
403404
/// <param name="pCommandId">The ID of the context tab.</param>
404405
procedure EnableContextTab(const pCommandId: Integer);
405406

407+
/// <summary>
408+
/// Returns whether or not a ribbon context tab is enabled.
409+
/// </summary>
410+
/// <param name="pCommandId">The ID of the context tab.</param>
411+
function IsContextTabEnabled(const pCommandId: Integer): Boolean;
412+
406413
/// <summary>
407414
/// Hides a ribbon context tab.
408415
/// </summary>
@@ -1104,6 +1111,11 @@ procedure TUIRibbon.InvalidateUICommand(const Command: TUICommand;
11041111
end;
11051112
end;
11061113

1114+
function TUIRibbon.IsContextTabEnabled(const pCommandId: Integer): Boolean;
1115+
begin
1116+
Result := GetContextTabAvailability(pCommandId) in [TUIContextAvailability.caAvailable, TUIContextAvailability.caActive];
1117+
end;
1118+
11071119
function TUIRibbon.GetRecentItems(): TUICommandRecentItems;
11081120
begin
11091121
if not Assigned(fRecentItems) then
@@ -1590,6 +1602,22 @@ procedure TUIRibbon.SetContextTabAvailability(const pCommandId: Integer; const p
15901602
(lCommand as TUICommandContext).Availability := pContextAvailability;
15911603
end;
15921604

1605+
function TUIRibbon.GetContextTabAvailability(const pCommandId: Integer): TUIContextAvailability;
1606+
var
1607+
lCommand: TUICommand;
1608+
begin
1609+
Result := TUIContextAvailability.caNotAvailable;
1610+
//If Ribbons are disabled, exit here.
1611+
if (not Self.Visible) then
1612+
Exit;
1613+
// Get the command with that ID
1614+
if not Self.TryGetCommand(pCommandId, lCommand) then
1615+
Exit;
1616+
// If found, check type, cast and get Availability property.
1617+
if (lCommand.CommandType = TUICommandType.ctContext) then
1618+
Result := (lCommand as TUICommandContext).Availability;
1619+
end;
1620+
15931621
procedure TUIRibbon.SetHighlightColor(const Value: TColor);
15941622
begin
15951623
SetHighlightHsbColor(ColorToHsb(Value));

0 commit comments

Comments
 (0)