The mainapp object let you get access to some properties and methods used in the main application. All you have to do is to type "MainApp." and all the properties and methods available are listed in a listbox. They are also listed below.
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.
Properties
AppPath
Syntax
AppPath: String (read-only)
Description
Path to the folder where the main program and tools are located.
AppDataPath
Syntax
AppDataPath: String (read-only)
Description
Path to the application data folder.
Example
var
sz: String;
begin
sz := MainApp.AppDataPath + '\Syntax\PHP.syx';
MainApp.OpenFile(sz);
...
end.
CurrentFolder
Syntax
CurrentFolder: String
Description
Path displayed in the sidebar explorer.
Example
MainApp.CurrentFolder := 'C:\\MyFolder';
CurrentView
Syntax
CurrentView: Integer
Description
Set or get the current view.
You can use the following values:
1 - Home
2 - Editor
3 - IE Preview
4 - Chrome Preview
5 - File Commander
DocumentCount
Syntax
DocumentCount: Integer (read-only)
Description
Get the number of open documents.
DocumentIndex
Syntax
DocumentIndex: Integer
Description
Get the tab index of the current document or change the tab index to set another document to be the current.
ExeName
Syntax
ExeName: String (read-only)
Description
Get the file name of the main program, including path..
Height
Syntax
Height: Integer
Description
Height of the main window in pixels.
HInstance
Syntax
HInstance: Integer (read-only)
Description
Instance handle of the application.
hWnd
Syntax
hWnd: Integer (read-only)
Description
Handle to the main window.
Left
Syntax
Left: Integer
Description
Left coordinate of the main window.
ProjectDefaultDir
Syntax
ProjectDefaultDir: string (read-only)
Description
Returns the default source folder used by the current project. This folder is set in project options.
ProjectName
Syntax
ProjectName: string (read-only)
Description
Returns the name of the current project. The name does not include the project file extension.
Top
Syntax
Top: Integer
Description
Top coordinate of the main window.
Width
Syntax
Width: Integer
Description
Width of the main window in pixels.
WindowState
Syntax
WindowState: Integer
Description
Get or set the main window state.
You can use the following values:
0 - Normal
1 - Minimized
2 - Maximized
Methods
BringToFront
Syntax
BringToFront()
Description
Bring the main window to the front.
ClearMessageText
Syntax
ClearMessageText()
Description
Clear the text in the message field in the bottom bar.
CloseAll
Syntax
CloseAll(): Boolean
Description
Close all open documents. Return true if successful.
GetClipboard
Syntax
GetClipboard(): Integer
Description
Get the current clipboard as an integer value 0 - 5. 0 is the standard Windows clipboard, the others are user clipboards.
GetCurrentLanguageFileName
Syntax
GetCurrentlanguageFileName(): String
Description
Get the name of the currently used language file e.g. "eng.ini".
GetMainMenu
Syntax
GetMainMenu: TElMainMenu
Description
Return the main menu control.
Example
TElMainMenu aMenu = MainApp.GetMainMenu;
mNew = TElMenuItem.Create(aMenu);
mNew.Caption = "My Menu";
mNew.Name = "NewMenu";
aMenu.Items.Add(mNew);
HTML_TidyHTML
Syntax
HTML_TidyHTML()
Description
Run the HTML menu command to beautify HTML.
HTML_TidyXHTML
Syntax
HTML_TidyXHTML()
Description
Run the HTML menu command to beautify xHTML.
HTML_TidyXML
Syntax
HTML_TidyXML()
Description
Run the HTML menu command to beautify XML.
InputBox
Syntax
InputBox(const wsCaptions, wsPrompt: String): String
Description
Display a dialog box to obtain user input.
Example
var
s: string;
begin
s := MainApp.InputBox('Name', 'Enter a user name:');
...
end.
JSON_Minify
Syntax
JSON_Minify()
Description
Run the Format menu command to minify JSON code.
JSON_PrettyPrint
Syntax
JSON_PrettyPrint()
Description
Run the Format menu command to pretty print JSON code.
NewDocument
Syntax
NewDocument(sFileExt: String)
Description
Create a new document.
Valid sFileExt could be:
.asp
.aspx
.php
.html
.css
.txt
...
An empty string will open a normal text file with no syntax highlighting.
NewDocumentEx
Syntax
NewDocumentEx(String sFileExt; int nCodepage; bool bBOM; String sNewlineFormat)
Description
Create a new document and set the encoding, newline format and if a BOM should be used when saving to a file.
Ex.
MainApp.NewDocumentEx(".php", 65001, true, "Windows");
".php" file extension to create a PHP document, 65001 is the code page for UTF-8, true because we want to save a BOM with the file and "Windows" linefeeds (CRLF).
Valid sNewlineFormats are: "Windows", "Unix" and "Mac".
NextDoc
Syntax
NextDoc()
Description
Move to the next document tab. Moves to the first tab if the last tab is showing.
OpenFile
Syntax
OpenFile(const wsFile: String; [const bReadOnly: Boolean]): Boolean
Description
Open the passed file. If the passed string is empty a file dialog is opened. Returns true if the file opens or is already opened. The bReadOnly parameter is optional and will always be False, if not set. Set bReadOnly to open the file in read-only mode.
PreviousDoc
Syntax
PreviousDoc()
Description
Move to the previous document tab. Moves to the last tab if the first tab is showing.
Quit
Syntax
Quit()
Description
Quit the program. The user will be prompted to save any unsaved documents.
ReadOptionBoolean
Syntax
ReadOptionBoolean(section, key: String; default: Boolean): Boolean
Description
Read a boolean value from options.
Example
if MainApp.ReadOptionBoolean("Printing", "EnableHeader", false) {
}
ReadOptionInteger
Syntax
ReadOptionInteger(section, key: String; default: Integer): Integer
Description
Read an integer value from options.
Example
int nTop = MainApp.ReadOptionInteger("Printing", "MarginTop", 10);
ReadOptionString
Syntax
ReadOptionString(section, key, default: String): String
Description
Read a string value from options.
Example
string sHeader = MainApp.ReadOptionString("Printing", "HeaderLeft", "$(FileName)");
RunApp
Syntax
RunApp(const wsFile, wsParam: String; bOutput, bMinimized: Boolean; const OutputMode: Integer = 0): Boolean
Description
Execute an external application. You can include a file name (with path) and a parameter. Set bOutput to true in order to get the output from the program in the message view and
bMinimized if you want the application to start minimized.
OutputMode tell the editor if the output window in the bottom-bar should be opened. The parameter can have the value 0 - 4.
0 = Always open
1 = Only open if output data is available
2 = Only open if output data is available or the exit code > 0
3 = Only open if the exit code > 0
4 = Never open the output window
Example
// Open the current document in notepad. The fifth output parameter is optional.
MainApp.RunApp("c:\\Windows\\notepad.exe", Document.FileName, false, false);
RunAppAndWait
Syntax
RunAppAndWait(const wsFile, wsParam: String; bOutput, bMinimized: Boolean; const OutputMode: Integer = 0)
Description
Execute an external application and wait for it to finish. You can include a file name (with path) and a parameter. Set bOutput to true in order to get the output from the program in the message view and bMinimized if you want the application to start minimized.
OutputMode tell the editor if the output window in the bottom-bar should be opened. The parameter can have the value 0 - 4.
0 = Always open
1 = Only open if output data is available
2 = Only open if output data is available or the exit code > 0
3 = Only open if the exit code > 0
4 = Never open the output window
Example
// Open the current document in notepad and wait. The fifth output parameter is optional.
MainApp.RunAppAndWait("c:\\Windows\\notepad.exe", Document.FileName, false, false);
Document.Reload(False);
RunAppAndWaitF
Syntax
RunAppAndWaitF(const wsFile, wsParam, wsOutputFile: String; bMinimized: Boolean)
Description
Execute an external application and wait for it to finish. You can include a file name (with path) and a parameter. Set wsOutputFile to direct the output from the program to a file and bMinimized if you want the application to start minimized.
SaveAll
Syntax
SaveAll(): Boolean
Description
Save all documents. Returns true if successful.
SendToBack
Syntax
SendToBack()
Description
Send the main window to the back.
SetClipboard
Syntax
SetClipboard(const index: Integer)
Description
Set the current clipboard to be used. 0 is the standard Windows clipboard, 1 - 5 are the user clipboards.
SetHighlighter
Syntax
SetHighlighter(const Value: String)
Description
Change the current highlighter used. E.g. MainApp.SetHighlighter('C++');
SetMessageText
Syntax
SetMessageText(const wsText: String; [const bAppend: Boolean = False])
Description
Display text in the message field in the bottom bar. The bAppend argument is optional and defaults to False. If you set bAppend to True, the text will be appended to the already displayed text in the message field.
SetStatusText
Syntax
SetStatusText(sMessage: String)
Description
Set the text to be displayed in the status area.
Sort_Ascending
Syntax
Sort_Ascending()
Description
Run the Format menu command to sort text in ascending order.
Sort_Descending
Syntax
Sort_Descending()
Description
Run the Format menu command to sort text in descending order.
Sort_AscendingNumeric
Syntax
Sort_AscendingNumeric()
Description
Run the Format menu command to sort numbers and text in ascending order.
Sort_DescendingNumeric
Syntax
Sort_DescendingNumeric()
Description
Run the Format menu command to sort numbers and text in descending order.
Wait
Syntax
Wait(nMilliseconds: Integer)
Description
Pause for given number of milliseconds. Use wait to enable scripts to execute loops and still allow access to the UI. Without the call to Wait in the loop, the application appears locked and the user cannot change views.
Example
begin
...
while MainApp.CurrentView = 2 do
MainApp.Wait(100);
// Do something when the view has changed
...
end.
WriteOptionBoolean
Syntax
WriteOptionBoolean(section, key: String; value: Boolean)
Description
Write a boolean value to options.
Example
// Save a boolean value used by my extension script.
MainApp.WriteOptionBoolean("MyExtension", "Enabled", true);
WriteOptionInteger
Syntax
WriteOptionInteger(section, key: String; value: Integer)
Description
Write an integer value to options.
Example
// Store an integer value used by my extension script.
MainApp.WriteOptionInteger("MyExtension", "TopMargin", 10);
WriteOptionString
Syntax
WriteOptionString(section, key, value: String)
Description
Write a string value to options.
Example
// Store a string in options used by my extension script.
MainApp.WriteOptionString("MyExtension", "Path", "C:\Windows");
|