We continue to improve our Personal Expenses application. This time we transform the PopupMenu categories into a ComboBox (https://docs.xojo.com/ComboBox), so that the user can add new categories that will also be saved and retrieved from the disk.
The ComboBox is in fact one of the elements of the graphical user interface that is available in the Xojo IDE Library, and whose operation is equivalent in the supported desktop platforms (macOS, Windows and Linux, including Raspberry Pi).
It could be said that the ComboBox brings together under a single control the functionalities provided by the PopupMenu on the one hand and the TextField (text input control) on the other. Therefore, the main virtue of this UI element is that the user can always choose any option from those available in the control's associated menu, or enter a new value that is not available as a chosen option.
In addition, the ComboBox provides another good virtue in the associated text field: the ability to auto-complete text. In this way, when we start writing, the ComboBox itself will provide us with a suggestion if the inserted text part is already part of one of the items that are included in the menu.
In short, replacing the PopupMenu that we have used so far to choose the category of an expense, with that of a ComboBox, will provide the user of our Personal Expenses application with all these advantages. Furthermore, this will allow us to add new expense categories that were not initially contemplated: the user will only have to type them in the text field of the ComboBox and it will be added as an additional option among those available in the relative control menu.
Link to the Xojo project accompanying the chapter: https://drive.google.com/file/d/1FnhfMREH-6XExfiFUV-hKrJwFPMlflrS/view
Of course, we also modify our code not only so that it is possible to save and recover these new categories on disk and from disk on the ComboBox, but also so that the items appear in alphabetical order in the control menu ... and also including the necessary checks. so that duplicate items are not added to the menu.
During this process we will see the implementation of new Event Handlers, such as the very useful "KeyDown" (available in the vast majority of user interface controls) and which allows us to intercept the key that has been pressed by the user while the control is focus. So, depending on the character of the key pressed (or the value of the key, for those cases where there is no visual representation, such as Return), our application can "intercept" it and act accordingly.
For example, this is what we do in the case of the ComboBox added to the Personal Expenses window design to intercept the Enter key or Tab key press.
Search ... and replace in the IDE During the development of our applications it is frequent the need to make changes to the names (or references) of the controls that we have already added in the design of our windows, methods, events, etc. To speed up these types of changes, among other operations, the Xojo IDE provides a find and replace functionality which we access by clicking on the magnifying glass icon available in the bottom bar of the IDE window.
Then, by entering the text of the searched item in the search field, we will get all the matches in the lower list. Furthermore, we can restrict the search for the inserted text so that it is carried out on all elements that belong to the project, only within the element that is selected in the Navigator or to the class (and subclasses) that is selected.
In the video accompanying this article, you can see this feature at work, being one of the code refactoring tools provided by the Xojo IDE.
Create your own projects and practice As usual, I encourage you to create your own projects in Xojo on which to put into practice everything we have seen so far ... and also what you have discovered for yourself by examining the User Guides and the available Language Reference. in the Xojo Documentation area (docs.xojo.com).
This way, you will not only reinforce what you have learned, but it will also be a good excuse to start building small applications and utilities that solve your needs.
-
Javier RodríguezXojo Ingegnere
Twitter: @xojoes
Facebook: http://facebook.com/xojoes/
Download the latest version from www.xojo.com
Xojo Resources in Spanish: https://docs.xojo.com/spanish