(wish) a = b change to b = a

I wish there was a keyboard key stroke that would take
a = b and convert it to b = a in the IDE.

Create a feature request.

Before creating, can you justify why the need of this feature?

For every occurrence? You could use a regular expression.

I wonder why you want to do this - just out of curiosity, I am guessing that you do it a lot to want it automated. There are some keyboard macro recorders that you could program to do this, if you are using Windows then AutoHotKey springs to mind

You could create a feature request or you could support <https://xojo.com/issue/11544> and then add your own editing hotkeys, functions and refactorings etc. if and when Xojo delivers an IDE Extension feature.

I had a method called FormToDictionary and another method called DictionaryToForm

for every entry in the dictionary I needed to assign the value to a variable.
There were about 20 keys to the dictionary that went to 20 text fields on a control…

MyLabelA.Text = myDictionary.value("A") MyLabelB.Text = myDictionary.value("B") MyLabelC.Text = myDictionary.value("C") MyLabelD.Text = myDictionary.value("D") MyLabelE.Text = myDictionary.value("E") MyLabelF.Text = myDictionary.value("F") MyLabelG.Text = myDictionary.value("G") MyLabelH.Text = myDictionary.value("H") MyLabelI.Text = myDictionary.value("I") MyLabelJ.Text = myDictionary.value("J") MyLabelK.Text = myDictionary.value("K") MyLabelL.Text = myDictionary.value("L") MyLabelM.Text = myDictionary.value("M") MyLabelN.Text = myDictionary.value("N")

I block copied this method and then began reversing the order

myDictionary.Value("A") = MyLabelA.Text

That’s why I asked…

With RegEx turned on, search this pattern:

(MyLabel.\\.Text) = (myDictionary\\.value\\("."\\))

Replace with:

\\2 = \\1

Regular expressions are your friends (and a tool like RegExRX will help you craft them). :slight_smile:

emacs ^T
nuf said. :slight_smile:

Also, there may have been an OOP-ier way to do this. What about subclassing the TextArea (or TextField) and adding a property “DictionaryKey”? Then you could put all of your fields into a control set, then use a loop to assign the key by index on open. When you need to assign to/from the Dictionary, you could loop through and grab the DictionaryKey from each one.

The advantage is that you can add or remove fields without having to change your other code.

You could also use and IDE Script.

If Xojo was to facilitate every recurring action thinkable, the windows and menu’s would fully cover the monitor.

In Windows You can automate just about any manual action in just about any program using AutoHotKey. In OSX the same can be done with AppleScript.

For things like this I tend to use SublimeText. It has a mode where you select several lines, hit a shortcut (cmd-shift-L on mac) and you edit all lines at the same time.

Or given that you only had 20 lines, I would have not asked the question on here, not spent time reading the replies and not implemented any of the suggested solutions above. It would have been done in no time manually…

(Please take in jest :slight_smile: )

IDE script doesn’t support regex. But you can use this function (I wrote it time ago for a similar problem):

function swapSelection(txt as String,swapOnChars as String) as String
dim v() as String=txt.split(endofline)
dim r() as String
for Each vv as String in v
dim rr() as String=vv.split(swapOnChars)
if rr.ubound>0 then
dim temp as String=rr(0)
rr(0)=rr(1)
rr(1)=temp
r.append join(rr,swapOnChars)
else
r.append vv
end if
next
return join(r,endofline)
end function
text= swapSelection(text," = ")

Last night i had an idea…
Every one is familiar with ^X / ^C for copy and paste…
but… I’m going to suggest ^B. ^B copies the selected text to a buffer, replaces the selected text with the contents of the clip board then replaces the contents of the clip board with the buffer.

This is essentially a swap selection / clipboard.

[quote=47917:@Brian O’Brien]Last night i had an idea…
Every one is familiar with ^X / ^C for copy and paste…
but… I’m going to suggest ^B. ^B copies the selected text to a buffer, replaces the selected text with the contents of the clip board then replaces the contents of the clip board with the buffer.

This is essentially a swap selection / clipboard.[/quote]
Love that idea. I would use that all the time

You can do exactly this easily with an AppleScript and some utility to tie it to a keystroke, like FastScripts.