Standardize Format Question

I’m hoping someone has an IDE script or something for this…

I really like the Standardize Format option in the IDE. Thing is, I have some large projects that were written without the option turned on. They are under version control, so anytime I’m working I end up with a handful of lines that have only had uppercase added to a character or two, making a mess in my commit.

It would be nice to be able to just standardize the whole project in one shot and have a single commit that is just “standardize format”.

Any ideas other than cursoring through every line manually to update the formatting? (that would take hours…)

I’d love that, too… And for that I’ve added this Feature Request in 2017: <>

A workaround would be an IDE Script, which iterates over the project, selects every “project item”, traverses through it’s “code items”, select all, applies “Standardize Format”. But it seems that’s also not possible - according to this forum thread.

So I guess our best chance is to let Xojo know that implementing this Feature Request is of interest to many developers :slight_smile:

@Thomas Tempelmann : Maybe Arbed can do that?

I think IDE Communicator could be used… I’d just need to manually read the project and get all the items, then look at each item to get the dot notation for each method/event etc. (my doc generator has some code I could possibly recycle)

Or… is there any way to get a list of the methods etc from a project item? I can select a method as long as I know it’s name, but there’s no way I can see to get the names? Getting the project items can be done, but not methods etc?

there isnt
had a long discussion with another user about this
IDE script was not intended for this kind of usage amd grew up out of an early need to be able to do some automation of builds (way back in around 2005-2010) as builds were largely done by hand
And it has remained mostly that way with a few bits & pieces added on over the years

In order to facilitate the kind of usage you want to make of it IDE scripting would need to expose some kind of “project model” where you could have a ProjectItem (class, folder, module, etc) and then iterate over all of them in a project
For each of these you would need a way to ask how many code items it contained of a certain type (method, constants properties, etc) and iterate over those
And you would need to be able to ask each project item how many items it contained since folders and modules can contain other items
Once you had these building blocks you could probably recursively iterate across an entire project and run a reformat script

But you’d also want things like being able to add new items (apparently a fair number of people use ID scripting to generate code (?) )
So you would need methods to add new properties, methods, events event handlers, properties, etc
And constants - you would want to be able to create them with a specific name, type and default
And then a mechanism to add specific localized values (regardless of whether its a localized string or not since localized values also work for integers etc but they are resolved at build time not runtime)

It’s a non-trivial amount of work to do
And I know there is a FR for this
Gee look at that :stuck_out_tongue:

Yeah I’ve thought about this before :slight_smile:

It looks like (for my purpose) the only thing missing is that subLocations doesn’t return anything for a regular project item (class/window/etc). If it just dumped out a list of all the events/methods/properties etc. I could work with that. Or if, item.methods etc returned a list…
It can select a method/property etc if I know the name, and I can iterate all the nested project items… just can’t get any info about an item.

Sublocations is what contained project items are there

Right, but a method is a location in a class… so wouldn’t it make sense for subLocations(“someclass”) to return the subLocations of the class? typeOfCurrentLocation works on a method, therefore a method is a location. So either it should be called subItems, or return the locations like it says…
That one addition would open a ton of possibilities…

see my previous post

might it ? I suppose - have no idea about the implications of it
it just never did and now I suspect there is other script code that might depend on its current behaviour so adding this might break things
lord knows

Yeah, I could see where people might check for an empty return string to know they’ve reached a class/window/menubar… that would break if it was changed. They should be relying on TypeOfCurrentLocation, but that doesn’t mean they are. shrug


That doesn’t rely on subLocations returning “”… it rely’s on SelectProjectItem returning False to determine if an item is a folder, but that’s not really related.

that might work
again I have no idea what would break if anything
but it still leaves a lot of things that cannot be done very well with the current implementation
and thats what that FR was about - addressing those things that cant be done well

Right… now that I’m messing with it, if you set location to a control… it reports Window for TypeOfCurrentLocation and “” for subLocations. Same results as if you select a window. It does let you select window.control.event though. I just wish there was a way to know about those locations.

I think your FR goes a lot deeper than what I’m looking for.

@Jürg Otter For now, I hacked together a little app that you can drag a .xojo_project to. It just parses through the files and finds all the events and methods. Then it sends a script to the ide to select each one and then do “text=text” to fire the Standardize Format stuff.

No handling for computed properties yet. I’m going to run it on one of my larger projects overnight and see how it does. Seems like it’s probably going to take quite a while…
If it looks like it mostly worked, I’d be happy to share.