MB[Script] Editbox Auto Replace v0.1.1
Added by Mr. BS over 10 years ago
The title above is all I need to say. Check video bellow to be amazed by this awesome feature. :D
<video controls>
<source src="/attachments/download/858/Editbox_Auto_Replace.mp4">
Your browser does not support the video tag. https://www.googledrive.com/host/0B36riaEyLqg_eWtrdkpjVnM4cm8
</video>
Changelog¶
- v0.1.1
- Added ignore to shit+space, to prevent auto replace.
- Small cosmetic changes for Windows 10. - v0.1
- Initial release.
Script¶
; http://dev.adiirc.com/boards/5/topics/275
; Editbox Auto Replace
; v0.1.1 by pereba
on *:START: {
if ($exists(autoreplace.dat) && $exists(autoreplace_eval.dat)) {
if (!$hget(autoreplace)) hmake autoreplace
if (!$hget(autoreplace_eval)) hmake autoreplace_eval
hload autoreplace autoreplace.dat | hload autoreplace_eval autoreplace_eval.dat
}
}
alias autoreplace {
if ($dialog(autoreplace)) dialog -x autoreplace
dialog -ml autoreplace autoreplace
}
menu menubar {
-
Editbox Auto Replace:autoreplace
-
}
; space key
on *:KEYDOWN:#,?:32:{
; ignore shit+space (to void auto replace) and ctrl+space (context menu)
if (($mouse.key & 4) || ($mouse.key & 2)) return
var %c = $iif($numtok($left($editbox($active),$editbox($active).selstart),32) == 0 && %b,1,$v1)
var %b = $editbox($active)
var %a = $gettok(%b,%c,32)
if ($hget(autoreplace,%a) && %a !isnum) {
var %t = $iif($hget(autoreplace_eval,%a) == yes,$eval($hget(autoreplace,%a),2),$hget(autoreplace,%a))
var %i = $calc($iif(%c == 1,1,2 + $len($gettok(%b,1- $calc(%c -1),32))) + $len(%t))
editbox $+(-ab,%i,e,%i) $puttok(%b,%t,%c,32)
.timer -m 1 1 sendkey
halt
}
}
alias -l sendkey {
var %name sk $+ $ticks
.comopen %name WScript.Shell
.comclose %name $com(%name,SendKeys,3,bstr,$chr(32))
}
dialog autoreplace {
title $aptitle(start)
size -1 -1 248 150
option dbu
box "Text", 1, 4 4 65 114
list 2, 9 13 55 100, size
list 3, 79 13 117 100, size
list 4, 211 13 28 100, size
box "", 5, 4 120 240 25
button $chr(43) Add, 6, 12 128 37 12
button $chr(10008) Delete, 7, 54 128 37 12
button $chr(55357) $+ $chr(56396) Close, 8, 96 128 37 12, ok cancel
box Replace with, 12, 74 4 127 114
box Eval, 9, 206 4 38 114
text Hint: double click to edit an item., 11, 161 131 81 8
link $chr(9825), 10, 241 0 10 5
button $chr(8635), 13, 138 128 15 12
}
alias -l aptitle {
var %t = Editbox Auto Replace $chr(40) $+ $iif($hget(autoreplace,0),$v1,0) items $+ $chr(41)
if ($1) return %t | dialog -t autoreplace %t
}
on *:dialog:autoreplace:init:*: list.words
; reload button
on *:dialog:autoreplace:sclick:13: list.words
; select full row
on *:dialog:autoreplace:sclick:2,3,4: select.line $dname $did($dname,$did).sel
alias -l select.line did -c $1 2 $2 | did -c $1 3 $2 | did -c $1 4 $2
; add button
on *:dialog:autoreplace:sclick:6: autoreplace_add
; delete button
on *:dialog:autoreplace:sclick:7: {
if (($did($dname,2).seltext) && ($?!="Are sure you want to delete the item $v1 $+ ?")) {
hdel $dname $did($dname,2).seltext | hdel $dname $+ _eval $did($dname,2).seltext | savetofile | list.words
}
}
; edit replace content
on *:dialog:autoreplace:dclick:3: {
var %input = $input(Replace $did($dname,2).seltext with...:,e,Auto Replace Edit,$did($dname,3).seltext)
if ($len($replace(%input, $chr(32), $null))) {
hadd -m $dname $did($dname,2).seltext %input | savetofile | list.words $dname $did($dname,$did).sel
}
}
; edit word
on *:dialog:autoreplace:dclick:2: {
var %input = $input(Edit the word $did($dname,2).seltext to.... (without space):,e,Replace Text Edit,$did($dname,2).seltext)
if (!$regex(%input,/(\s)/Si) && %input != $did($dname,2).seltext) {
hdel $dname $did($dname,2).seltext | hdel $dname $+ _eval $did($dname,2).seltext | hadd -m $dname %input $did($dname,3).seltext
hadd -m $dname $+ _eval %input $did($dname,4).seltext | savetofile | list.words
}
}
; toggle eval
on *:dialog:autoreplace:dclick:4: {
if ($hget($dname $+ _eval,$did($dname,2).seltext)) {
hadd autoreplace_eval $did($dname,2).seltext $iif($v1 == no, yes, no)
hsave autoreplace_eval autoreplace_eval.dat | list.words $dname $did($dname,$did).sel
}
}
alias -l list.words {
did -r autoreplace 2,3,4
var %i 1
while (%i <= $hget(autoreplace,0).item) {
did -a autoreplace 2 $hget(autoreplace,%i).item
did -a autoreplace 3 $hget(autoreplace,%i).data
did -a autoreplace 4 $hget(autoreplace_eval,%i).data
inc %i
}
aptitle | if ($1) select.line $1 $2
}
alias -l savetofile hsave autoreplace autoreplace.dat | hsave autoreplace_eval autoreplace_eval.dat
alias -l autoreplace_add {
var %word $$?="Add new word for the auto replace (without space):"
var %replace $$?="Replace %word with...:"
var %eval $$?!="Evaluate the replace content on usage?"
if ($regex(%word,/([\$?\w]+)/Si)) {
hadd -m autoreplace $regml(1) %replace | hadd -m autoreplace_eval $regml(1) $iif(%eval == $true,yes,no)
savetofile | list.words | return
}
noop $input(Invalid word $+ $chr(44) try again.,o,Auto Replace Error)
.timer -m 1 1 autoreplace_add
}
on *:dialog:autoreplace:sclick:10: run http://www.adiirc.com/
Replies (4)
RW RE: [Script] Editbox Auto Replace v0.1.1 - Added by r w almost 10 years ago
think this got broken in one of the recent adiirc updates, can't eval
MB RE: [Script] Editbox Auto Replace v0.1.1 - Added by Mr. BS almost 10 years ago
Thanks for the report.
Problem seems to be in event On Keydown/up. Probably a regression introduced by some of that recent changes: #2409 #2410 #2432.
Try to change line 25 to:
on *:KEYDOWN:*:32:{
Should fix the problem for now.
RW RE: [Script] Editbox Auto Replace v0.1.1 - Added by r w almost 10 years ago
yeah that did it. thanks :>
MW RE: [Script] Editbox Auto Replace v0.1.1 - Added by Megan Woulffe over 6 years ago
I set up an autoreplace for $date , but when it's called it shows up as DD/MM/YYYY, whereas the documentation on it says it should be MM/DD/YYYY. I don't know if this was a change in the identifier or not.