Back to Devexpress

TdxRibbonContext.Activate(Boolean) Method

vcl-dxribbon-dot-tdxribboncontext-dot-activate-x28-system-dot-boolean-x29.md

latest3.7 KB
Original Source

TdxRibbonContext.Activate(Boolean) Method

Activates the current context within the Ribbon.

Declaration

delphi
procedure Activate(AActivateFirstTab: Boolean = True);

Parameters

NameType
AActivateFirstTabBoolean

Remarks

If a context’s Visible option is disabled, calling the Activate method automatically enables this option and selects the first tab within the tabs associated with this context.

If the current context is already active, pass False as the AActivateFirstTab parameter to prohibit selecting the first tab and preserve the currently selected tab.

End-users can click a contextual tab label to activate a corresponding context and select the first visible tab associated with this context.

The following code example shows how to activate contextual tabs in response to selection changes in a TRichEdit text editor. This example assumes that two contexts are created within the Ribbon’s Contexts collection at indexes 0 and 1 , respectively. These contexts correspond to the ‘Text Tools’ and ‘Table Tools’ contextual tabs.

delphi
const
  TextToolsContext = 0; // The 'Text Tools' context's index
  TableToolsContext = 1; // The 'Table Tools' context's index
  TableEntryID = '#Table'; // Table identity string
// ...
// The editor's OnSelectionChange event handler
procedure <Form>.EditorSelectionChange(Sender: TObject);
begin
  // ...
  // Check whether a text is selected within the editor
  if Editor.SelLength > 0 then
  begin
    // Activating the 'Text Tools' context. Note that this context has
    // priority over the 'Table Tools' context if both contexts are available
    // simultaneously.
    Ribbon.Contexts[TextToolsContext].Activate(False);
    // Showing the 'Table Tools' contextual tabs if the selection contains the
    // table identity string
    Ribbon.Contexts[TableToolsContext].Visible :=
      Pos(TableEntryID, Editor.SelText) > 0;
  end else
  begin
    Ribbon.Contexts[TextToolsContext].Visible := False;
    Ribbon.Contexts[TableToolsContext].Visible := False;
  end;
end;
cpp
const
  int TextToolsContext = 0; // The 'Text Tools' context's index
  int TableToolsContext = 1; // The 'Table Tools' context's index
  AnsiString TableEntryID = "#Table"; // Table identity string
// ...
// The editor's OnSelectionChange event handler
void __fastcall <Form>::EditorSelectionChange(TObject *Sender)
{
  // ...
  // Check whether a text is selected within the editor
  if (Editor->SelLength > 0) {
    // Activating the 'Text Tools' context. Note that this context has
    // priority over the 'Table Tools' context if both contexts are available
    // simultaneously.
    Ribbon->Contexts->Items[TextToolsContext]->Activate(False);
    // Showing the 'Table Tools' contextual tabs if the selection contains the
    // table identity string
    Ribbon->Contexts->Items[TableToolsContext]->Visible =
      Pos(TableEntryID, Editor->SelText) > 0;
  } else {
    Ribbon->Contexts->Items[TextToolsContext]->Visible = False;
    Ribbon->Contexts->Items[TableToolsContext]->Visible = False;
  }
end;

See Also

TdxRibbonContext Class

TdxRibbonContext Members

dxRibbon Unit