IDE Scripting Project Commands
From Xojo Documentation
These commands are related to working with the IDE workspace windows, creating new projects and to directly modify or get information about project items or Xojo.
ChangeDeclaration(name As String, parameters As String, returnType As String, scope As Integer, implements As String)
Changes the declaration of the current property or method.
Notes
The value for scope may be one of the following:
- 0 = Public
- 1 = Protected
- 2 = Private
Generally this is used to rename a property or method after it has been added to a project item. In the case of a property, the parameters value is used for the default value of the property.
Sample Code
Add a new property to Window1 and set its values:
DoCommand("NewProperty")
ChangeDeclaration("UserName", "Bob Roberts", "String", 2, "")
End If
CloseProject(prompt As Boolean = True)
Close all Workspace windows associated with the project that is open in the front most Workspace window. If there are unsaved changes when you call this with prompt is True you will get a dialog asking if you want to save changes. Call it with prompt = False to close all projects without asking to save changes.
Sample Code
ConstantValue(name As String) As String
Gets or sets the value of a project item constant.
Sample Code
Change the value of an existing constant on App:
You can also refer to the full constant name like this:
ConstantValue("App.kBeta") = "True"
DecryptItem(password As String) As Boolean
Decrypts the selected project item using the specified password. Returns True if it succeeded.
Sample Code
Decrypt the project items in the array:
items = Array("Class1", "Class2")
Var name As String
For Each name In items
If SelectProjectItem(name) Then
If Not DecryptItem("pa55w0rd") Then
Print("Error encrypting " + name)
Exit For
End If
End If
Next
EncryptItem(password As String) As Boolean
Encrypts the selected project item using the specified password. Returns True if it succeeded.
Sample Code
Encrypt the project items in the array:
items = Array("Class1", "Class2")
Var name As String
For Each name In items
If SelectProjectItem(name) Then
If Not EncryptItem("pa55w0rd") Then
Print("Error encrypting " + name)
Exit For
End If
End If
Next
Location As String
Used to get or set a location in the project. This can be a project item or a property, method, event (etc.) or a project item. Separate each item with a period. When you set a location, the appropriate project item is selected in the Navigator.
Sample Code
Get the selected project item:
Select "Window1" in the Navigator:
To determine if a specific control is selected, add "Controls" to the object and follow it with the control name. For example, this checks if a button is selected on Window1:
NewConsoleProject
Creates a new console project and opens a new workspace window.
Sample Code
Create a new console project:
NewGUIProject
Creates a new desktop project and opens a new workspace window.
Sample Code
Create a new desktop project:
NewiOSProject
Creates a new iOS project and opens a new workspace window.
Sample Code
Create a new iOS project:
NewWebProject
Creates a new web project and opens a new workspace window.
Sample Code
Create a new web project:
ProjectItem As String
Returns the name of the project item that is selected in the Navigator (of the current tab, if more than one tab is open).
Sample Code
Display the name of the selected project item:
ProjectShellPath As String
Returns the shell path for the project currently being edited.
Notes
If the project has not yet been saved, this returns the empty string.
Sample Code
Displays the shell path for the current project:
PropertyValue(propName As String) As String
PropertyValue(propName As String, Assigns value As String)
Gets or sets the value of a project item property. This only works for properties of project items that are part of the Xojo framework (such as Window or App). You can only modify properties that are part of the framework (such as Window1.Title), not properties that you have added.
Notes
You can specify just the property name which will use the currently selected project item. Or you can specify a project item, followed by the property name using dot notation. When referring to the App object, always use the name “App” even if you have renamed it in your project.
The property value is always returned or set as a string, even if the property itself is not a string. For Boolean values use the string values "True" or "False".
Properties of App That Can Be Changed
Be sure to use the "App." prefix in front of any of these properties.
- DefaultWindow
- DefaultWebPage
- DefaultPhoneScreen
- DefaultTabletScreen
- MenuBar
- MajorVersion
- MinorVersion
- BugVersion
- StageCode
- NonReleaseVersion
- AutoIncrementVersionInformation
- Version
- Copyright
- Description
- WindowsAppName
- MDI
- MDICaption
- CompanyName
- ProductName
- InternalName
- FileDescription
- LinuxAppName
- MacOSXAppName
- iOSAppName
- AcceptFileTypes
- ApplicationIdentifier
- IncludeFunctionNames
- SupportsHiDPI
- SupportsDarkMode
- Port
- LaunchMessage
- HTMLHeader
- DisconnectMessage
- Identifier
- CopyRedistNextToWindowsEXE
- MacCreator
- OptimizationLevel
- WindowsRunAs (0= User, 1 = Highest Available, 2 = Administrator)
- CopyRedistNextToWindowsEXE
- SupportsWindows10
- SupportsWindows8
- SupportsWindows8.1
- SupportsWindows7
Sample Code
Set the App.Version property to match the version numbers:
version = PropertyValue("App.MajorVersion") + "." + _
PropertyValue("App.MinorVersion") + "." + _
PropertyValue("App.BugVersion") + " (" + _
PropertyValue("App.NonReleaseVersion") + ")"
PropertyValue("App.Version") = version
To set a Boolean value:
QuitIDE(saveChanges As Boolean)
Quits the IDE, either ignoring any unsaved changes or saving changes without prompting.
Sample Code
Quit and save changes:
SelectWindow(windowTitle As String)
SelectWindow(index As Integer)
Selects the IDE workspace window with the specified title or index (0-based), bringing it to the front.
Notes
The title is the project filename without the extension.
Sample Code
Bring the first workspace window to the front:
Bring the workspace named "Test" to the front:
SelectProjectItem(itemPath As String) As Boolean
Selects the project item specified by the path.
Notes
Returns True if the item was selected, False if not (usually because it does not exist). Specify the path using dot notation, with each level separated by a period.
To select a method, property or other item within a project item, use the Location method.
Sample Code
Select Method1 on Window1:
Select Class1 that is within Module1:
SubLocations(baseLocation As String) As String
Returns all the locations within the given base location (a module or folder) as a tab-delimited String (ChrB(9)). If baseLocation is an empty string, then all top-level project items are returned.
Sample Code
Display the name of each item in a folder:
itemList = Sublocations("Folder1")
Var items() As String
items = itemList.ToArray(ChrB(9))
Var name As String
For Each name In items
Print("Item: " + name)
Next
Text As String
Gets or sets the entire text of what is currently displayed in the current Code Editor.
Sample Code
Add a comment header to the top of the currently displayed method:
header = "// Copyright 2018 Acme, Inc."
Text = header + EndOfLine + EndOfLine + Text
TypeOfCurrentLocation As String
Returns a string that is the type of the item at the current location.
Sample Code
Show the type of the item at the current location:
WindowCount As Integer
Returns the number of open workspace windows in the IDE.
Sample Code
Get the number of workspace windows:
WindowTitle(index As Integer) As String
Returns the name of a workspace window using its index (0-based).
Sample Code
Loop through all open workspaces and saves their contents:
Var comma As String
Var i As Integer
For i = 0 To WindowCount - 1
SelectWindow(i)
saved = saved + comma + WindowTitle(i)
DoCommand("SaveFile")
comma = ", "
Next
Print("Saved: " + saved)
XojoVersion As Double
Returns the version of Xojo as a Double. For example, Xojo 2019 Release 2 would return 2019.02.
Notes
Note that “#if” requires a constant value and XojoVersion is a method on the Script context so cannot be used with #if. But in an IDE script or build script, using “if XojoVersion” to cause code to be skipped is the same as using “#if XojoVersion” to cause the code to be skipped.
Sample Code
Display the version: