ToggleFontBold Method

Build 1501 on 14/Nov/2017  This topic last edited on: 20/Sep/2016, at 17:45

Description

Toggle the current font style from not bold to bold and opposite, inserting or removing the >bd 1< tag.

Syntax

Text.ToggleFontBold

Return value

Error code

Context

Text designer commands

See also

EditFontBold Method (Text)

Customizations

Note: the following assumes that in all your formats are available the custom character styles with the tag and style name bold, with the tag and style name italic, and with the tag and style name bolditalic.

You can customize the default action, by adding an override in the CustomTxtDesignerAddIn class of the CustomArticle.vb. Instead to apply the >bd 1< tag, it will apply the >bold< character style:

  <ShellCommand(CanExecute:="Ena_IsEditingArticleText", IsChecked:="Chk_IsToggleFontBoldChecked")>

  Public Overrides Sub ToggleFontBold()

    Dim cMode As Short = 1

    Dim bRestoreSelection As Boolean = False

    Dim oBegSel As Cursor = Nothing

    Dim oEndSel As Cursor = Nothing

    If Text.TestTextSelection Then

      bRestoreSelection = True

      oBegSel = Text.GetCursor(cMode, 3, True)

      oEndSel = Text.GetCursor(cMode, 4, True)

    End If

    if text.testshowcmd then Text.EditBlockNoCmd()

    If Text.TestTextStyle("bolditalic") Then

      Text.setStyleex(false,"italic",false,true)

    ElseIf Text.TestTextStyle("bold") Then

      Text.TxtStyle("")

    ElseIf Text.testtextstyle("italic") Then

      Text.setStyleEx(false,"bolditalic",false,true)

    Else

      Text.SetStyleEx(false,"bold",false,true)

    End If

    If bRestoreSelection Then   ' restore the selection as it was

      If Not oBegSel Is Nothing AndAlso Not oEndSel Is Nothing Then

        Text.CursorTo(oBegSel)

        Text.EditBlockStart()

        Text.CursorTo(oEndSel)

        Text.EditBlockEnd()

      End If

    End If

  End Sub

Note: this script will override the system script and therefore provide for a custom action while editing text on the Articles main tab. In order to have the same customization available also when editing text on page, duplicate the same script also in the CustomPageTxtDesignerAddIn. class of the CustomPage.vb.