

and the property with the method callback. Create a new menu item Instance from the MyMenuItem class, setting the name, tag Add the name and the nativepath of the selected file, separated with the Tab characterĪpp.RecentItemsCollection.AddRow(f.DisplayName + Chr(9) + f.NativePath) Var f As FolderItem = FolderItem.ShowOpenFileDialog("")
Textinputstream xojo code#
Then, add the Action event to the just added button and write the following code in the associated Code Editor: // Display a dialog so the user can choose a file So, select the Window1 window in the project to access the Layout Editor and add a new Button to it from the Library using the following data in the Inspector Panel: In addition, we will keep track of the added files in an Array of Strings.

In order to keep things simple, we will include a button in the user interface of the app that when clicked will let the user select any file, creating a new MyMenuItem instance that will reference that file and that will be added to the File submenu on the main menu bar. With our subclass completed, the second step is to provide a way to create new MyMenuItem instances and add them to the desired menu item. In our example, the Text will be the file name, while the Tag property of the MenuItem will store the NativePath pointing to the real file on the original drive. Once added, simply write this line of code in the resulting Code Editor: if pMenuItemCallback nil then pMenuItemCallback.Invoke(me.Text, me.Tag)Īs you can see, it limits itself to invoke the method pointed by the pMenuItemCallback property passing along both the Text and Tag properties of the instance. The last thing to do in our subclass definition is adding the Action Event Handler. The purpose of this property is to store the address of the method that will be invoked when the user selects a given menu item based on this class (i.e.: a recent item from the “Recent Items” submenu). Next, add a new property to the class using this data in the Inspector Panel: Parameteres: Caption As String, Value As String.Then, add a new Delegate to the subclass using the following data in the Inspector Panel: So, add a new class to the project using the following data in the Inspector Panel: This event is the one that will be fired every time the user selects an entry among those listed in the “Recent Items” submenu from the main File menu. This will be a subclass of the MenuItem class, so we can implement the Action Event Handler. Once you create a new Xojo Desktop project the first thing we need to do is to add a new class to it because this will be a dynamically created submenu. This blog post will teach you one of the multiple approaches to do this in Xojo.

It’s helpful and common these days to add a “Recent Items” menu that tracks the last opened files or other recent searches among other things.
