The document object gives you access to the current document. All you have to do is type "Document." and all the properties and methods are displayed in an auto completion list.
All methods in the Document object are listed below.
NOTE! A text string is a single quote string in Pascal script, but double quote string in C++, Basic and JScript.
E.g.
HighlightText('Lorem ipsum') in Pascal script
HighlightText("Lorem ipsum") in C++ script.
Properties
CanRedo
Syntax
CanRedo: Boolean (read-only)
Description
True if changes can be re-done.
CanUndo
Syntax
CanUndo: Boolean (read-only)
Description
True if changes can be undone.
Example
// C++ script
if (Document.CanUndo) {
// some useful code
}
CodePage
Syntax
CodePage: Integer
Description
Read or change the code page (encoding) of the current document.
Example
// C++ script
Document.CodePage = 65001; // Change the encoding to UTF-8
Document.UseBOM = true;
Document.NewlineFormat = "Windows";
CursorX
Syntax
CursorX: Integer
Description
Get or set the text cursor character position starting with 0.
CursorY
Syntax
CursorY: Integer
Description
Get or set the text cursor line position starting with 0.
FileName
Syntax
FileName: String (read-only)
Description
Get the file name and complete path of the current document.
HighlighterAtCursor
Syntax
HighlighterAtCursor: String (read-only)
Description
Get the name of the highlighter used at the text cursor position. The name returned is always in lower case.
LineCount
Syntax
LineCount: Integer (read-only)
Description
Number of lines in the document.
Lines
Syntax
Lines[Index: Integer]: String
Description
Get or set the text of a line.
Modified
Syntax
Modified: Boolean (read-only)
Description
True if the document has changed since it was last saved.
NewlineFormat
Syntax
NewlineFormat: string
Description
Read or change the newline format (linefeeds) used in the current document. If you change the newline format of a document all current linefeeds are changed.
Available formats are "Windows", "Unix" or "Mac". When you read the property you may get a string containing the word "Mixed", e.g. "MixedWindows", "MixedUnix" or "MixedMac". This indicates that the linefeeds in the document are mixed but most of them are Windows, Unix or Mac linefeeds.
Example
// C++ script
Document.NewlineFormat = "Unix"; // Set all linefeeds to LF (Unix linefeeds)
SelLength
Syntax
SelLength: Integer
Description
Get or set the length of the current selection.
SelStart
Syntax
SelStart: Integer
Description
Get or set the start of the current selection.
SelText
Syntax
SelText: String
Description
Get or set the text in the current selection.
Example
// PascalScript
var
s: String;
begin
Document.CursorLineStart(false); // Move cursor to the beginning of the line
Document.CursorWordRight(true); // Select the first word
s := Document.SelText; // Get the selected word
...
end.
Text
Syntax
Text: String
Description
Get or set the document text.
UseBOM
Syntax
UseBOM: Boolean
Description
Read or set the UseBOM property. A BOM is usually written to a Unicode file for easy identification.
Set this property if you want to save the current document to a Unicode file and add a BOM at the beginning of the file.
Example
// C++ script
Document.CodePage = 65001; // Set encoding to UTF-8
Document.UseBOM = true;
Wordwrap
Syntax
Wordwrap: Boolean
Description
Get or set wordwrap mode. Could be used at the beginning of a script to ensure that the document is not word wrapped.
Methods
AddSelectionToMultiSelection
Syntax
AddSelectionToMultiSelection(bRedraw: Boolean);
Description
Use after a selection is made, e.g. SetSelection(). This will add the selected block to the multi selection list and allow you to make another selection.
Example
Document.SelectLine(10);
Document.AddSelectionToMultiSelection(False);
Document.SelectLine(12);
BeginUndo
Syntax
BeginUndo()
Description
Create an undo start point for a complex script action. Use "EndUndo()" to create the end undo point.
When a user press undo - all operations between BeginUndo and EndUndo will be undone.
Example
Document.BeginUndo();
for (int i = 0; i < 10; i++)
Document.DeleteLine(0);
Document.EndUndo();
BeginUpdate
Syntax
BeginUpdate()
Description
Turn off screen updating for the current document. To turn it on again, use EndUpdate().
Clear
Syntax
Clear()
Description
Clear the current document.
Close
Syntax
bool Close(bool bDiscardChanges = false)
Description
Close the current document. The user may be prompted to save the document first, if bDiscardChanges is false. If bDiscardChanges is set to true the document is just closed and all changes since the last save are lost.
When the document is closed the function returns true. Otherwise false.
Example
Document.Close(); // Close document and display prompt if modified
Document.Close(true); // Close document without saving even if modified
CopyToClipboard
Syntax
CopyToClipboard()
Description
Copy selection to the clipboard.
CursorLeft, CursorRight, CursorWordLeft, CursorWordRight, CursorDown, CursorUp, CursorPageDown, CursorPageUp, CursorDocStart, CursorDocEnd, CursorLineStart, CursorLineEnd
Syntax
Cursor...(bSelect: Boolean)
Description
Position the cursor. If bSelect is True then the current selection is extended to the new position.
Example
Document.CursorLineStart(False);
Document.CursorLineEnd(True); // Move the cursor to the end of line and select from the previous position.
CutToClipboard
Syntax
CutToClipboard()
Description
Cut selection to the clipboard.
DeleteBlankLines
Syntax
DeleteBlankLines()
Description
Delete all blank lines in a selection.
DeleteCurrentLine
Syntax
bool DeleteCurrentLine()
Description
Delete the current line in the document. The current line is where the text cursor is located.
DuplicateLineNTimes
Syntax
DuplicateLineNTimes(const nr: Integer)
Description
Duplicate the current line nr times.
EndUndo
Syntax
EndUndo()
Description
Create an undo end point. Use "BeginUndo()" to start the undo action.
When a user press undo - all operations between BeginUndo and EndUndo will be undone.
Example
Document.BeginUndo();
for (int i = 0; i < 10; i++)
Document.DeleteLine(0);
Document.EndUndo();
EndUpdate
Syntax
EndUpdate()
Description
Turn on screen updating for the current document and update and refresh the display.
ExitMultiEditMode
Syntax
ExitMultiEditMode()
Description
Clear all multiple selections.
FindAt
Syntax
FindAt(line: Integer; wSub: string; nfrom: Integer; bCase: Boolean): Integer
int FindAt(int line; String wSub; int nfrom; bool bCase)
Description
Find a character or sub string on a given line, in the document. The return value is > 0 if something is found, else return value is 0. (Pascal) Strings and lines always start at position 1.
Example
// Find "https://" at line 0 from position 1 on the line. (Strings always start at 1)
int n = Document.FindAt(0, "https://", 1, false);
FindRegExAt
Syntax
FindRegExAt(line: Integer; wSub: String; nfrom: Integer; var wx: String): Integer
int FindRegExAt(int line; String wSub; int nfrom; String &wx)
Description
Find an expression on a given line in the document. The return value is > 0 if something is found, else return value is 0. (Pascal) Strings and lines always start at position 1.
FoldAll
Syntax
FoldAll()
Description
Fold all foldable sections in the text.
FoldNode
Syntax
FoldNode()
Description
Fold the nearest foldable section in the text.
FoldRegion
Syntax
FoldRegion()
Description
Fold the nearest foldable region in the text.
GetMethodAtCursor
Syntax
GetMethodAtCursor(bSelect: Boolean): String
Description
Return the method in which the cursor is currently located in. Select it by setting bSelect to True. Returns False if no method is found.
GetSelection
Syntax
GetSelection(var startx,starty,endx,endy: Integer)
Description
Get the current positions of the selection.
GetTagAtCursor
Syntax
GetTagAtCursor(bSelect: Boolean): String;
Description
Return the tag in which the cursor is currently located in. The method returns False if a tag could not be found at the cursor.
Set bSelect to True in order to select the tag.
GotoNextEndTag
Syntax
GotoNextEndTag(bSelect: Boolean): Boolean
Description
Move the cursor to the next end tag. Select it by setting bSelect to True. Returns False if no tag is found.
GotoNextMethod
Syntax
GotoNextMethod(bSelect: Boolean): Boolean
Description
Move the cursor to the next method. Select it by setting bSelect to True. Returns False if no method is found.
GotoNextStartTag
Syntax
GotoNextStartTag(bSelect: Boolean): Boolean
Description
Move the cursor to the next start tag. Select it by setting bSelect to True. Returns False if no tag is found.
GotoPreviousEndTag
Syntax
GotoPreviousEndTag(bSelect: Boolean): Boolean
Description
Move the cursor to the previous end tag. Select it by setting bSelect to True. Returns False if no tag is found.
GotoPreviousMethod
Syntax
GotoPreviousMethod(bSelect: Boolean; bSkipCurrentMethod: Boolean): Boolean
Description
Move the cursor to the previous method. Select it by setting bSelect to True. Set bSkipCurrentMethod to True if you don't want to stop at the top of the current method. Returns False if no method is found.
GotoPreviousStartTag
Syntax
GotoPreviousStartTag(bSelect: Boolean): Boolean
Description
Move the cursor to the previous start tag. Select it by setting bSelect to True. Returns False if no tag is found.
HighlightText
Syntax
HighlightText(const wsText: String; const bWords: Boolean = True)
Description
Highlight all occurrences of the text given in the argument. E.g. if you enter HighlightText('Dummy'); all instances of "Dummy" in the text will be highlighted. If the word flag is true, only whole words are highlighted. Otherwise the selected text is highlighted.
Words are highlighted with a red background, selections with a green background.
NOTE! A text string is past as a single quote string in a Pascal script, but double quote string in a C++, VB or Java script.
E.g.
HighlightText('Lorem ipsum') in Pascal script
HighlightText("Lorem ipsum") in C++ script.
Indent
Syntax
Indent()
Description
Indents the current selection or insert a tab.
InsertTag
Syntax
InsertTag(sStartTag, sEndTag: String)
Description
Inserts the passed start and end tags at the current cursor position.
Example
// Pascal script
Document.CursorDocEnd(False);
Document.InsertTag('<a href="http://www.rj-texted.se">', '</a>');
// C++ script
Document.CursorDocEnd(False);
Document.InsertTag("<a href=\"http://www.rj-texted.se\">", "</a>");
InsertText
Syntax
InsertText(wStr: String)
Description
Inserts the passed text at the current cursor position.
NOTE! A text string is past as a single quote string in a Pascal script, but double quote string in a C++, VB or Java script.
E.g.
InsertText('Lorem ipsum') in Pascal script
InsertText("Lorem ipsum") in C++ script.
IsColumnModeActive
Syntax
IsColumnModeActive(): Boolean
Description
Check if column mode is active.
JoinLines
Syntax
JoinLines([bAddSpaces=true], [bSkipBlankLines=false])
Description
Join selected lines into one line. If no selection is made, the current and the next lines are joined.
Spaces are added between the lines when joined and blank lines are joined as well. You can use the function arguments to change this behavior.
Ex. JoinLines(true, true); // Join all selected lines but keep paragraphs by skipping blank lines.
LastSavedDate
Syntax
LastSavedDate(): TDateTime
Description
Return the datetime value for the last save of the current document.
MoveLinesDown
Syntax
MoveLinesDown()
Description
Move the current line, or selection, downwards in the text.
MoveLinesUp
Syntax
MoveLinesUp()
Description
Move the current line, or selection, upwards in the text.
MultiEditDelete
Syntax
MultiEditDelete()
Description
Delete all selections made using "AddSelectionAsMultiSelection()".
PasteFromClipboard
Syntax
PasteFromClipboard()
Description
Paste from the clipboard.
Print
Syntax
Print(bPrompt: Boolean)
Description
Prints the current document. If bPrompt is set to True, the user is prompted for print settings.
Redo
Syntax
Redo()
Description
Perform a redo operation.
Reload
Syntax
Reload(bPromptToSave: Boolean)
Description
Reloads the current document. Prompts the user to save if bPromptToSave is True.
ReplaceAll
Syntax
ReplaceAll(sFind, sReplace: String; bMatchCase, bWholeWords, bRegExp: Boolean; bSilent: Boolean = False): Integer
Description
Replace all found strings. Returns the number of replaced strings.
NOTE! A text string is past as a single quote string in a Pascal script, but double quote string in a C++, VB or Java script.
E.g.
Document.ReplaceAll('Lorem ipsum','Lor ips',false,false,false) in Pascal script
Document.ReplaceAll("Lorem ipsum","Lor ips",false,false,false) in C++ script.
Save
Syntax
Save(): Boolean
Description
Saves the current document. Returns true if successful.
SaveAs
Syntax
SaveAs(sFileName: String): Boolean
Description
Save the current document to the file specified by sFileName. Returns true if successful.
NOTE! A text string is past as a single quote string in a Pascal script, but double quote string in a C++, VB or Java script.
E.g.
Document.SaveAs('C:\MyFolder\Text.txt') in Pascal script
Document.SaveAs("C:\\MyFolder\\Text.txt") in C++ script.
SaveAsNoMRU
Syntax
SaveAsNoMRU(sFileName: String): Boolean
Description
Save the current document to the file specified by sFileName. The file will not show up in the list of recently opened files. Returns true if successful.
NOTE! A text string is past as a single quote string in a Pascal script, but double quote string in a C++, VB or Java script.
SelectAll
Syntax
SelectAll()
Description
Selects all text in the current document.
SelectCurrentLine
Syntax
SelectCurrentLine()
Description
Select the current line.
SelectLine
Syntax
SelectLine(Index: Integer)
Description
Select the passed line.
SetColumnMode
Syntax
SetColumnMode(const bActivate: Boolean)
Description
Activate or deactivate column mode editing.
SetSelection
Syntax
SetSelection(startx,starty,endx,endy: Integer; bRedraw: Boolean = True)
Description
Select a block of text.
SplitLines
Syntax
SplitLines()
Description
Split the current line, or lines in a selection, at the word wrap margin.
Undo
Syntax
Undo()
Description
Perform an undo operation.
UnfoldAll
Syntax
UnfoldAll()
Description
Unfold all fold able sections in the text.
UnfoldNode
Syntax
UnfoldNode()
Description
Unfold the nearest fold able section in the text.
UnfoldRegion
Syntax
UnfoldRegion()
Description
Unfold the nearest fold able region in the text.
UnhighlightText
Syntax
UnhighlightText(const wsText: String; const bWords: Boolean = True)
Description
Unhighlight the given text. If the wsText argument is empty all highlighted text is unhighlighted. You can either cancel highlighting of words or selected text.
NOTE! A text string is past as a single quote string in a Pascal script, but double quote string in a C++, VB or Java script.
E.g.
UnHighlightText('Lorem ipsum') in Pascal script
UnHighlightText("Lorem ipsum") in C++ script.
Unindent
Syntax
Unindent()
Description
Remove the indent in the current selection.
|