I have this list of properties in a text file that I’d like to import into a module. Unfortunately it seems I can not paste the block of text into Xojo (despite properties copied out of Xojo being in this format) and have to go through and make them all manually with the mouse + keyboard in the IDE, unless I’m missing something? Is there a way to paste these lines into the IDE and have them accepted as properties?
Public Property setting_Username As String
Public Property setting_Password As String
Public Property setting_PortNumber As Integer
Public Property setting_HostName As String
Public Property setting_MaxConnections As Integer
Public Property setting_Timeout As Integer
Public Property setting_LogFilePath As String
Public Property setting_DebugMode As Boolean
Public Property setting_EncryptionKey As String
Public Property setting_APIKey As String
Public Property setting_ThemeColor As String
Public Property setting_DefaultLanguage As String
Public Property setting_LoggingEnabled As Boolean
Public Property setting_ShowNotifications As Boolean
Public Property setting_BackupInterval As Integer
Public Property setting_LoggingLevel As Integer
Public Property setting_FontSize As Integer
Public Property setting_MaxAttempts As Integer
Public Property setting_DefaultView As String
Public Property setting_AutoSaveEnabled As Boolean
Public Property setting_AdminEmail As String
Public Property setting_RequireAuthentication As Boolean
Public Property setting_CacheEnabled As Boolean
Public Property setting_CacheExpiration As Integer
Public Property setting_DefaultTimeZone As String
Public Property setting_MaxFileSize As Long
Public Property setting_DefaultCurrency As String
Public Property setting_LogoImagePath As String
Public Property setting_AutoUpdateEnabled As Boolean
Public Property setting_MaxResultsPerPage As Integer
Public Property setting_DefaultCountry As String
Public Property setting_SecurityQuestion As String
Public Property setting_BackgroundImagePath As String
Public Property setting_DefaultPrinter As String
Public Property setting_ShowSplashScreen As Boolean
Public Property setting_RemoteServerURL As String
Public Property setting_LicenseKey As String
Public Property setting_MaxRetries As Integer
Public Property setting_DefaultDateFormat As String
Public Property setting_DisplayName As Str
Public Property setting_DefaultTimeFormat As String
Public Property setting_EnableNotifications As Boolean
Public Property setting_MaxItemsPerPage As Integer
Public Property setting_DefaultSortingOrder As String
Public Property setting_EnableLogging As Boolean
Public Property setting_WebServiceURL As String
Public Property setting_DefaultPageSize As Integer
Public Property setting_EnableCaching As Boolean
Make an integer, a string and a boolean property in a module. Make the module external as xml. Now take a peak at the xml and then create your properties in the xml format. Excel is a wonderful tool to make simple calculations.
Long story short, the plain text is only a portion of what is being copied to the clipboard. It also copies, in the case of properties, RSCI formatted data.
What you’re looking for can be done, but it unfortunately isn’t as simple as it seems.
You can get an idea of what it’s putting on the clipboard using a clipboard viewer:
what is strange is that this “copy-paste” text only works with xojo methods, but not it seems with properties.
I often copy paste methods from-to the forum and xojo it’s working fine
and Ijust tried with properties it simply don’t work.
it should.
I still fail to see why the plain-text data alone isn’t enough to be pasted as a property. They lack the default value and note section in Christian’s example, but those aren’t mandatory. The current limitation of Xojo to not paste these because obscure unneeded data isn’t in the clipboard makes no sense, IMO.
My point goes beyond: I can’t see why this feature would have to “be implemented” since it’s rather a feature that works when there’s more data (in other words, there’s something (probably code) which prevents pasting from working when only the minimum necessary data is present in the clipboard; it looks deliberate).
I can import but there’s too much I don’t know. For example, I don’t know what file extension it needs to be for xojo to import it as code and not as linked external file used by the project. I need to be able to experiment with creating various properties and see how the various changes to the properties alter the XML. Does the “visible” attribute refer to literal visibility in the IDE? Or might it be regarding the scope of the variable (ie public vs private)? In order to test all these things to make a working file, I need to be able to write one.
@Arnaud_N Wholeheartedly agree, the IDE should be able to see the text lines and convert them to the required internal property format. It’s able to do so with Methods (thank goodness!) so you’d think other project attributes would work as well. It might be something Xojo just never considered before so it would make a good feature request.
I LOVE Xojo as a language, but being forced to create all objects with a mouse is probably the most frustrating thing about working in it.
Private Sub ClipboardPropertiesToIDEScript()
dim cBoard as new Clipboard
if not cBoard.TextAvailable then return
dim contents as string = cBoard.Text
dim scopes() as string = Array("Public","Protected","Private")
dim commands() as string = Array("dim loc as string = Location")
dim rx as new RegEx
rx.SearchPattern = "(?mi-Us)^(\w+)\s(\w+)\s(.+)\sas\s(\w+)(?:\s=\s(.+))?"
dim rxOptions as RegExOptions = rx.Options
rxOptions.LineEndType = 4
dim match as RegExMatch = rx.Search(contents)
while match isa RegExMatch
if match.SubExpressionCount < 5 then
match = rx.Search
continue
end
dim scope as string = scopes.IndexOf(match.SubExpressionString(1)).ToString
dim item as string = match.SubExpressionString(2)
dim name as string = match.SubExpressionString(3)
dim type as string = match.SubExpressionString(4)
dim default as string = if(match.SubExpressionCount = 6,match.SubExpressionString(5),"")
commands.Append "DoCommand(""New" + item + """)"
commands.Append "ChangeDeclaration(""" + name + """, """ + default + """, """ + type + """, " + scope + ", """")"
commands.Append "Location = loc"
match = rx.Search
wend
cBoard.Text = Join(commands,EndOfLine)
cBoard.Close
End Sub
It looks the ChangeDeclaration trick doesn’t work with constants though, so this will only work with properties so you might as well hard code the item value.
You could “wrap” a module around your properties and save this as a text file with “.xojo_code” extension.
Then you can drag this text file into the IDE and once you have it in the IDE you can copy / past multiple properties as you want.
Your solution looks elegant. I haven’t tried it yet (and, since I know nothing about RegEx, I can’t read much of your code), but I think you made a remarkable piece here