Convert to Method


I used “Convert to Method” a minute ago and all I get is:

Cut of the selected code
Create a new Method,
Paste the code here
Untitled in the Method name highlighted and waiting for a new name.

It remove me a bit of work, but is absolute of no help: I could cut, cmd-M, and paste by myself.

Am I right ?
Or do I miss something ?

Oh, and I forgot to say:

no trace of code removal where my code was before applying the"Convert to Method" command.

However, the Cancel command works fine.

You are correct. This is a refactoring tool, just meant to save a few steps.

No Greg, I was wrong: I had greater hopes for this command ;-:slight_smile:
I was hoping to get the call with parameters (yes, this saves a lot of work from my part and add a lot of work from your part) and eventually return value.

It is the type of things which I prefer to make handly.

Have a great week…

@Norman Palardy,

Could ‘Convert to Method’ be updated to ask for a Method Name, place the Method Name where the code was, create the new method with the code, and finally name the Method with the Method Name?

it would be magic to also propose the parameters in that dialog ?

That would be magic… How might Xojo be able to determine that from a chunk of code?

the ide knows the variables inside a method (and outside also) as it knows how to autocomplete the sentences.
it also knows the types of the variables because in the autocompletion, it proposes to you only the things that are valid where you are typing. i.e. if you type "if " it proposes you only methods, variables that returns a boolean

so if you select some text in a method, it knows what variables are inside and outside what you’ve selected
so it can detect the parameters like that (sort of … sure it’s not that simple …)
for guessing the returning value, it seems even more complicated.

Neat idea. So if the IDE sees vars that are not dimmed, it might assume those are params?

I would like to have Norman’s opinion on all this before going further !

to remember the best ide I’ve seens so far, it was Prograph long ago (Kem also loved it !)
there was a way to group the methods into one, and it was able to detect the parameters, and the return values.
so yes this is definitely possible, depends on the Xojo team and the complexity to change the ide behavior.