Skip to content

Commit

Permalink
Added public function "IsContextTabEnabled", which returns whether or…
Browse files Browse the repository at this point in the history
… not a contextual tab is enabled.
  • Loading branch information
SaschaSchaefer committed Jun 15, 2022
1 parent b9249b8 commit 7fce19d
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions Lib/UIRibbon.pas
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ TUIRibbon = class(TWinControl, IUIApplication)
/// <param name="pCommandId">The id of the ribbon command.</param>
/// <param name="pContextAvailability">The availability state.</param>
procedure SetContextTabAvailability(const pCommandId: Integer; const pContextAvailability: TUIContextAvailability);
function GetContextTabAvailability(const pCommandId: Integer): TUIContextAvailability;

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

/// <summary>
/// Returns whether or not a ribbon context tab is enabled.
/// </summary>
/// <param name="pCommandId">The ID of the context tab.</param>
function IsContextTabEnabled(const pCommandId: Integer): Boolean;

/// <summary>
/// Hides a ribbon context tab.
/// </summary>
Expand Down Expand Up @@ -1104,6 +1111,11 @@ procedure TUIRibbon.InvalidateUICommand(const Command: TUICommand;
end;
end;

function TUIRibbon.IsContextTabEnabled(const pCommandId: Integer): Boolean;
begin
Result := GetContextTabAvailability(pCommandId) in [TUIContextAvailability.caAvailable, TUIContextAvailability.caActive];
end;

function TUIRibbon.GetRecentItems(): TUICommandRecentItems;
begin
if not Assigned(fRecentItems) then
Expand Down Expand Up @@ -1590,6 +1602,22 @@ procedure TUIRibbon.SetContextTabAvailability(const pCommandId: Integer; const p
(lCommand as TUICommandContext).Availability := pContextAvailability;
end;

function TUIRibbon.GetContextTabAvailability(const pCommandId: Integer): TUIContextAvailability;
var
lCommand: TUICommand;
begin
Result := TUIContextAvailability.caNotAvailable;
//If Ribbons are disabled, exit here.
if (not Self.Visible) then
Exit;
// Get the command with that ID
if not Self.TryGetCommand(pCommandId, lCommand) then
Exit;
// If found, check type, cast and get Availability property.
if (lCommand.CommandType = TUICommandType.ctContext) then
Result := (lCommand as TUICommandContext).Availability;
end;

procedure TUIRibbon.SetHighlightColor(const Value: TColor);
begin
SetHighlightHsbColor(ColorToHsb(Value));
Expand Down

0 comments on commit 7fce19d

Please sign in to comment.