GotoTxt Method (Article)

Build 1501 on 14/Nov/2017  This topic last edited on: 22/Mar/2016, at 17:07

Description

Edits the specified text.

Available in Ted and Fred.

Syntax

object.GotoTxt (nIdx, bSrc), bOnly*

object

Required. Object name. Returned by Ted.GetActiveArticle.

nIdx

Index of the text to edit, ranging from 0 = first text in the article to NTxts-1 = last text in the article. If nIdx is outside this range a run-time error is raised. To get the idx of the current element, use GetCurTxtIdx.

bSrc

If true the text is edited in a source window, if false in the WYSIWYG window

bOnly

THIS PARAMETER IS AVAILABLE ONLY IN TED, NOT IN FRED

If true the command fails if the window required by the bSrc parameters is not available

if false and the required window type is not availabe the other type is used - e.g. if bSrc=false (i.e. request WYSIWYG editing) and bOnly=false there is no WYSIWYG window the specified text is edited in a source window.

Remarks

If the text is already being edited GotoTxt just sets the focus to its editing window, otherwise it opens an editing window for the text and then sets the focus. See also GotoNode and GotoTxtEx to open the element in the specified mode (r/o, r/w).

Example

This script edit the current text element.

If Ted.HasActiveArticle Then

  dim objArticle = Ted.GetActiveArticle

  objArticle.GotoTxt (objArticle.GetCurTxtIdx,True,False)

End If

This script opens in the source panel all text elements, and puts the cursor in the first element. It won't work in Fred, as there it's impossible to open more element than one in the source panel.

If Ted.HasActiveArticle Then  

  dim objArt = Ted.GetActiveArticle  

  dim nIdx as Integer = objArt.GetCurTxtIdx 

  dim i as Integer 

  For i=0 To objArt.NTxts-1  

    objArt.GotoTxt (i,True,False)

  Next  

  If nIdx >= 0 Then   

    objArt.Gototxt (nIdx,True,False)

  Else  

    If objArt.NTxts > 0 Then  

      objArt.GotoTxt (0,True,False)

    End If  

  End If  

  objArt.GotoTxt (0,True,False)

End If   

This script edits the head element.

 

If Ted.HasActiveArticle Then

  dim objArt = Ted.GetActiveArticle

  dim strTypeName as String = "head"

  dim nIdx as Integer = -1

  dim i as Integer = 0

  While i < objArt.NTxts And nIdx < 0

    dim objNode = objArt.GetTxtNode(i)

    If objNode.TypeName = strTypeName Then

      nIdx = i

    End If

    i = i+1

  End While

  If nIdx >= 0 Then 

    objArt.Gototxt (nIdx,True,False)

  Else 

    MsgBox ("The article does not contain a " & strTypeName & " element")

  End If

End If

This script closes the current element and edits the next element.

 

If Ted.HasActiveArticle Then

  dim objArt = Ted.GetActiveArticle

  dim nIdx as Integer = objArt.GetCurTxtIdx

  If nIdx < 0 Then

    If objArt.NTxts > 0 Then

      nIdx = 0

    End If

  Else

    If objArt.CloseTxt(nIdx,False) <> 0 Then

      nIdx = -1

    Else 

      nIdx = nIdx + 1

      If nIdx >= objArt.NTxts Then

        nIdx = 0

      End If 

    End If

  End If

 

  If nIdx >= 0 Then

    objArt.GotoTxt (nIdx,True,False)

  End If  

End If

Context

Article object