Pasting properties into the IDE?

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
1 Like

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.

This looks a bit more complicated:

<Property>
  <ItemName>integer_property</ItemName>
  <Compatibility></Compatibility>
  <Visible>1</Visible>
  <PartID>499075071</PartID>
  <ItemSource>
   <TextEncoding>134217984</TextEncoding>
   <SourceLine>integer_property As Integer</SourceLine>
   <SourceLine></SourceLine>
  </ItemSource>
  <TextEncoding>134217984</TextEncoding>
  <ItemDeclaration>integer_property As Integer</ItemDeclaration>
  <ItemFlags>0</ItemFlags>
  <IsShared>0</IsShared>
 </Property>
 <Property>
  <ItemName>string_property</ItemName>
  <Compatibility></Compatibility>
  <Visible>1</Visible>
  <PartID>1913921535</PartID>
  <ItemSource>
   <TextEncoding>134217984</TextEncoding>
   <SourceLine>string_property As String</SourceLine>
   <SourceLine></SourceLine>
  </ItemSource>
  <TextEncoding>134217984</TextEncoding>
  <ItemDeclaration>string_property As String</ItemDeclaration>
  <ItemFlags>0</ItemFlags>
  <IsShared>0</IsShared>
 </Property>
 <Property>
  <ItemName>boolean_property</ItemName>
  <Compatibility></Compatibility>
  <Visible>1</Visible>
  <PartID>611784703</PartID>
  <ItemSource>
   <TextEncoding>134217984</TextEncoding>
   <SourceLine>boolean_property As Boolean</SourceLine>
   <SourceLine></SourceLine>
  </ItemSource>
  <TextEncoding>134217984</TextEncoding>
  <ItemDeclaration>boolean_property As Boolean</ItemDeclaration>
  <ItemFlags>0</ItemFlags>
  <IsShared>0</IsShared>
 </Property>

Here is a topic from 2016 talking about this.

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:

That’s just a public integer property named myInteger

2 Likes

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.

1 Like

“feature” request
i agree this should work via paste from text file and it would be useful to add a bunch of new properties to the app.

1 Like

I could make this work. Unfortunately I only have the xojo lite licenses for Windows + Mac so my external files are not in human readable format.

{{«class RSCI», 392}, {«class utf8», 33}, {«class ut16», 68}, {string, 33}, {Unicode text, 66}, {«class RSCI», 392}}

That is what this AppleScript returns:
return clipboard info

And here’s the Property definition copied from the Navigation pane:


Public Property gRose As Integer

That makes 32 Bytes long.

NB: The multiple lines of comments does not appears (is not copied).

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.

3 Likes

You still should be able to import an xml file. The license can’t write but it can read.

Oh, I totally agree.

It would be very convenient if Xojo would implement this feature.

1 Like

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).

1 Like

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.

This still isn’t the ideal solution, but you could convert your list into an IDE Script

DoCommand("NewProperty")
ChangeDeclaration("UserName", "Bob Roberts", "String", 2, "")

That will create a private string property named “UserName” with a default value of “Bob Roberts” to whatever item you have selected in the IDE.

https://documentation.xojo.com/topics/build_automation/ide_scripting/project_commands.html

ETA: In order to add multiple items you need to reselect whatever you had selected originally

Var loc As String = Location

DoCommand("NewProperty")
ChangeDeclaration("UserName", "Bob Roberts", "String", 2, "")

Location = loc

DoCommand("NewProperty")
ChangeDeclaration("AnotherUserName", "John Smith", "String", 2, "")

It’s pretty clear that Xojo could give us a hand and just do exactly what this is doing with a paste of plain text.

Just for fun

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.

2 Likes

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.

#tag Module
Protected Module PropertyModule
	#tag Property, Flags = &h21
		Private Untitled As Integer
	#tag EndProperty

	#tag Property, Flags = &h21
		Private Untitled1 As Integer
	#tag EndProperty

	#tag Property, Flags = &h21
		Private Untitled2 As Integer
	#tag EndProperty

	#tag Property, Flags = &h21
		Private Untitled3 As Integer
	#tag EndProperty

	#tag Property, Flags = &h21
		Private Untitled4 As Integer
	#tag EndProperty


End Module
#tag EndModule

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