Lock Control in Window Script

Is it possible to create and run a script that would update all control to Lock in an Xojo Script?

If so does anyone have one to shear?

No. You can hand over one instance of a class to a XojoScript. So you would need to run a script per control.

But what do you mean with exactly by “Lock”?

In the IDE when editing a Window or Container there is a lock in the Tool Bar that can be used to lock a control in place so that is can not be moved.

Oh, I of course thought of something you wanted to achieve at runtime of your application.

In the case of the IDE, just select all controls before you click the “Lock” button. On OS X the keyboard shortcut is Cmd-A, on Windows (probably) Ctrl-A.

Understand that. Have an application I want all the controls in all the windows and containers to be set with the Lock on. None of them are currently. That application has 17+ major windows and each window has 5+ containers. It would save lots of time to have a scrip to accomplish the task.

AFAIK that’s not possible because you can’t loop over the controls in a window in an IDE script.

Have you tried recording a script & see what it does ?
You should then be able to modify it to do all windows etc

It is not a problem to loop over all project items and to filter out al the windows (and container controls). But Docommand"Select All" is not implemented as per the IDE script docs.
There is a Docommand “LockPositions”, but to be able to use it one has to select the control by name. And I don’t know of any way to loop over the controls of a window and get all their names.

[quote=242893:@Norman Palardy]

Have you tried recording a script & see what it does ?
You should then be able to modify it to do all windows etc[/quote]

Recording a script to select all and lock all control work. However I don’t see a way to “do all windows” automatically.

If you have to select the window or container manually then run the script, that would require as much effort and doing it without a script.

To bad we (users) do not have format of the source files so we can modify them.

Well, a quick look at an XML format project shows where the lock resides. Here is the structure, which appears immediately after all the properties of each control :

<ControlIndex>0</ControlIndex> <Locked>0</Locked>

The above is for a non locked control. The Locked field becomes 1 when a control is locked.

I would venture as supposing that a global replace of <Locked>0</Locked> into <Locked>1</Locked> would lock every single control in the project.

At least, it is probably worth an experiment on a copy.

[quote=242925:@Eli Ott]It is not a problem to loop over all project items and to filter out al the windows (and container controls). But Docommand"Select All" is not implemented as per the IDE script docs.
There is a Docommand “LockPositions”, but to be able to use it one has to select the control by name. And I don’t know of any way to loop over the controls of a window and get all their names.[/quote]

Just FYI that every command that you can invoke in the IDE should be recordable and DoCommand with the name of the command is all you need
Whats exposed in the IDE Script API is things that you cannot do via DoCommand - like “select this specific window” etc

[quote=242959:@Jim Smith]
To bad we (users) do not have format of the source files so we can modify them.[/quote]
Well … having had to fix a few projects that users HAVE edited and had no backup for …
IF you do this make darned sure you have a back up copy - or two
Its very easy for you editing the project manually to break the project
As you might guess I tend to recommend against this

You might have a peek at some of the scripts that Jeremy Cowgar has published as they tend to be quite extensive & do some interesting things

  Dim itemList As String
  itemList = Sublocations("")
  Dim items() As String
  items = itemList.Split(ChrB(9))
  Dim name As String
  For Each name In items
    If SelectProjectItem(name) Then
      if TypeOfCurrentLocation() = "Window" then
        DoCommand("SelectAll")
        DoCommand("LockPositions")
      end if
    end if
  Next

As I wrote – citing the docs – DoCommand(“SelectAll”) has not been implemented.

The doc is obsolete. It works in 2015R4.

However, I tried replacing all <Locked>0</Locked> by <Locked>1</Locked> and it works like a charm.

I believe it will be a whole lot easier to lock all controls in the 17 windows Jim mentioned in one pass and without need for a complicated script.

Works to unlock all controls in a project as well, if needed.

The script I wrote is not that complicated & locks all controls on all windows

[quote=242995:@Eli Ott] DoCommand(“SelectAll”)
DoCommand(“LockPositions”)[/quote]
The docs are wrong
The SelectAll command is how the IDE does “select all” and its worked for many many years

Thats why I suggested recording the script & see what you get

If recording the script & see what you get is the only way to go, it should say so on each of the IDE Script pages (including a remark that the docs are inaccurate).

At this moment the docs are still wrong.

As of this moment, I’ve updated the doc page.

[quote=242966:@Michel Bujardet]Well, a quick look at an XML format project shows where the lock resides. Here is the structure, which appears immediately after all the properties of each control :

0
0

The above is for a non locked control. The Locked field becomes 1 when a control is locked.

I would venture as supposing that a global replace of 0 into 1 would lock every single control in the project.

At least, it is probably worth an experiment on a copy.[/quote]

Saved project as XML, verified that I still had original project file. Then using BBEdit and did a find and replace changing all the "0 with 1. Then save the file and check several of the windows and several on the containers; controls were locked; then I did a debug run and all is well.

Thanks Michel.

BTW the project has 347271 lines in the XML project file. There were 1930 changes. All this took about 15 minutes.

You are welcome, Jim.