Project commands

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.

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:

If SelectProjectItem("Window1") Then
  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

CloseProject(False)

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:

If SelectProjectItem("App") Then
  ' kBeta must already exist
  ConstantValue("kBeta") = "True"
End If

You can also refer to the full constant name like this:

' kBeta must already exist
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:

Var items() As String
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:

Var items() As String
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

ItemAttribute(name As String) As String

Returns the value of the attribute specified by the name parameter on the currently selected item. Returns an empty string if the attribute does not exist. String values will have their quotation marks stripped off.

ItemAttribute(name As String, Assigns value As String)

Sets the value of the attribute specified by the name parameter on the currently selected item. For string values, you must include the quotation marks.

ItemDescription As String

Used to get or set the description of a events, methods, properties, etc.

ItemHasAttribute(name As String) As Boolean

Returns True if the currently selected item has an attribute with the specified name.

ItemRemoveAttribute(name As String)

Removes all attributes with the specified name on the currently selected item.

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:

Var loc As String = Location

Select "Window1" in the Navigator:

Location = "Window1"

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:

If Location = "Window1.Controls.Button1" Then
  Print("Button1 is Selected!")
End If

NewAndroidProject

Creates a new Android project and opens a new workspace window.

NewConsoleProject

Creates a new console project and opens a new workspace window.

Sample code

Create a new console project:

NewConsoleProject

NewGUIProject

Creates a new desktop project and opens a new workspace window.

Sample code

Create a new desktop project:

NewGUIProject

NewiOSProject

Creates a new iOS project and opens a new workspace window.

Sample code

Create a new iOS project:

NewiOSProject

NewWebProject

Creates a new web project and opens a new workspace window.

Sample code

Create a new web project:

NewWebProject

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:

Print(ProjectItem)

ProjectShellPath As String

Returns the shell path for the project currently being edited.

If the project has not yet been saved, this returns the empty string.

Sample code

Displays the shell path for the current project:

Print(ProjectShellPath)

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.

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

  • Application Identifier (the space is necessary here)

  • IncludeFunctionNames

  • SupportsHiDPI

  • SupportsDarkMode

  • Port

  • LaunchMessage

  • HTMLHeader

  • DisconnectMessage

  • Identifier

  • CopyRedistNextToWindowsEXE

  • MacCreator

  • OptimizationLevel

    • ' 0 = Default

    • ' 4 = Aggressive

    • ' 6 = Moderate

PropertyValue("App.OptimizationLevel") = "4"
  • 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:

Var version As String
version = PropertyValue("App.MajorVersion") + "." + _
  PropertyValue("App.MinorVersion") + "." + _
  PropertyValue("App.BugVersion") + " (" + _
  PropertyValue("App.NonReleaseVersion") + ")"

PropertyValue("App.Version") = version

To set a Boolean value:

PropertyValue("App.SupportsDarkMode") = "True"

QuitIDE(saveChanges As Boolean)

Quits the IDE, either ignoring any unsaved changes or saving changes without prompting.

Sample code

Quit and save changes:

QuitIDE(True)

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.

The title is the project filename without the extension.

Sample code

Bring the first workspace window to the front:

SelectWndow(0)

Bring the workspace named "Test" to the front:

SelectWindow("Test")

SelectProjectItem(itemPath As String) As Boolean

Selects the project item specified by the path.

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:

Var selected As Boolean = SelectProjectItem("Window1.Method1")

Select Class1 that is within Module1:

Var selected As Boolean = SelectProjectItem("Module1.Class1")

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:

Var itemList As String
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:

Var header As String
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. This can either be a project item or a code item.

The following types may be returned:

Name

Attribute

Attribute List

Class

Computed Property

Constant

Cursor

Database

Debugger

Delegate

Enumeration

Event Declaration

Event Implementation

External Method

External Objective-C Method

FileType

Folder

Interface

Menu

Menu Handler

Method

Module

Movie

Note

Picture

Profiler

Property

Schema

Structure

Toolbar

Web Form

Window

Sample code

Show the type of the item at the current location:

If SelectProjectItem("Window1.Method1") Then
  Print(TypeOfCurrentLocation) ' displays Method
End If

Displays the type (Super) of Window1:

SelectWindow("Window1")
Print TypeOfCurrentLocation

WindowCount As Integer

Returns the number of open workspace windows in the IDE.

Sample code

Get the number of workspace windows:

Var count As Integer = WindowCount

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 saved As String
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.

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:

Print("XojoVersion: " + Format(XojoVersion, "0000.00#"))