Project

General

Profile

[Script] Editbox Auto Replace v0.1.1 » Editbox Auto Replace v0.1.ini

Mr. BS, 04/14/2015 08:15 AM

 
1
; http://dev.adiirc.com/boards/5/topics/275
2
; Editbox Auto Replace
3
; v0.1 by pereba
4

    
5
on *:START: {
6
  if ($exists(autoreplace.dat) && $exists(autoreplace_eval.dat)) {
7
    if (!$hget(autoreplace)) hmake autoreplace
8
    if (!$hget(autoreplace_eval)) hmake autoreplace_eval
9
    hload autoreplace autoreplace.dat | hload autoreplace_eval autoreplace_eval.dat
10
  }
11
}
12

    
13
alias autoreplace {
14
  if ($dialog(autoreplace)) dialog -x autoreplace
15
  dialog -ml autoreplace autoreplace
16
}
17

    
18
menu menubar {
19
  -
20
  Editbox Auto Replace:autoreplace
21
  -
22
}
23

    
24
; space key
25
on *:KEYDOWN:#,?:32:{
26
;on *:KEYUP:#,?:32:{
27
  ;$iif(!$window(@KeyDownDebug),window -nq1ke2 @KeyDownDebug) | echo -tm @KeyDownDebug User pressed key $keyval in $active char: $keychar mouse: $mouse.key $iif($mouse.key & 2,ctrl pressed?!)
28
  ;ignore ctrl+space (context menu)
29
  if ($mouse.key & 2) return
30

    
31
  var %c = $iif($numtok($left($editbox($active),$editbox($active).selstart),32) == 0 && %b,1,$v1)
32
  var %b = $editbox($active)
33
  var %a = $gettok(%b,%c,32)
34
  if ($hget(autoreplace,%a) && %a !isnum) {
35
    var %t = $iif($hget(autoreplace_eval,%a) == yes,$eval($hget(autoreplace,%a),2),$hget(autoreplace,%a))
36
    var %i = $calc($iif(%c == 1,1,2 + $len($gettok(%b,1- $calc(%c -1),32))) + $len(%t))
37
    editbox $+(-ab,%i,e,%i) $puttok(%b,%t,%c,32)
38
    .timer -m 1 1 sendkey
39
    halt
40
  }
41
}
42

    
43
alias -l sendkey {
44
  var %name sk $+ $ticks
45
  .comopen %name WScript.Shell
46
  .comclose %name $com(%name,SendKeys,3,bstr,$chr(32))
47
}
48

    
49
dialog autoreplace {
50
  title $aptitle(start)
51
  size -1 -1 248 150
52
  option dbu
53
  box "Text", 1, 4 4 65 114
54
  list 2, 9 13 55 100, size
55
  list 3, 79 13 117 100, size
56
  list 4, 211 13 28 100, size
57
  button "", 5, 4 122 240 24, disable
58
  button $chr(43) Add, 6, 12 128 37 12
59
  button $chr(10008) Delete, 7, 54 128 37 12
60
  button $chr(55357) $+ $chr(56396) Close, 8, 96 128 37 12, ok cancel
61
  box Replace with, 12, 74 4 127 114
62
  box Eval, 9, 206 4 38 114
63
  text Hint: double click to edit an item., 11, 161 131 81 8
64
  link $chr(9825), 10, 241 0 10 5
65
  button $chr(8635), 13, 138 128 15 12
66
}
67

    
68
alias -l aptitle {
69
  var %t = Editbox Auto Replace $chr(40) $+ $iif($hget(autoreplace,0),$v1,0) items $+ $chr(41)
70
  if ($1) return %t | dialog -t autoreplace %t
71
}
72

    
73
on *:dialog:autoreplace:init:*: list.words
74

    
75
; reload button
76
on *:dialog:autoreplace:sclick:13: list.words
77

    
78
; select full row
79
on *:dialog:autoreplace:sclick:2,3,4: select.line $dname $did($dname,$did).sel
80

    
81
alias -l select.line did -c $1 2 $2 | did -c $1 3 $2 | did -c $1 4 $2
82

    
83
; add button
84
on *:dialog:autoreplace:sclick:6: autoreplace_add
85

    
86
; delete button
87
on *:dialog:autoreplace:sclick:7: {
88
  if (($did($dname,2).seltext) && ($?!="Are sure you want to delete the item $v1 $+ ?")) {
89
    hdel $dname $did($dname,2).seltext | hdel $dname $+ _eval $did($dname,2).seltext | savetofile | list.words
90
  }
91
}
92

    
93
; edit replace content
94
on *:dialog:autoreplace:dclick:3: {
95
  var %input = $input(Replace $did($dname,2).seltext with...:,e,Auto Replace Edit,$did($dname,3).seltext)
96
  if ($len($replace(%input, $chr(32), $null))) {
97
    hadd -m $dname $did($dname,2).seltext %input | savetofile | list.words $dname $did($dname,$did).sel
98
  }
99
}
100

    
101
; edit word
102
on *:dialog:autoreplace:dclick:2: {
103
  var %input = $input(Edit the word $did($dname,2).seltext to....  (without space):,e,Replace Text Edit,$did($dname,2).seltext)
104
  if (!$regex(%input,/(\s)/Si) && %input != $did($dname,2).seltext) {
105
    hdel $dname $did($dname,2).seltext | hdel $dname $+ _eval $did($dname,2).seltext | hadd -m $dname %input $did($dname,3).seltext
106
    hadd -m $dname $+ _eval %input $did($dname,4).seltext | savetofile | list.words
107
  }
108
}
109

    
110
; toggle eval
111
on *:dialog:autoreplace:dclick:4: {
112
  if ($hget($dname $+ _eval,$did($dname,2).seltext)) {
113
    hadd autoreplace_eval $did($dname,2).seltext $iif($v1 == no, yes, no)
114
    hsave autoreplace_eval autoreplace_eval.dat | list.words $dname $did($dname,$did).sel
115
  }
116
}
117

    
118
alias -l list.words {
119
  did -r autoreplace 2,3,4
120
  var %i 1
121
  while (%i <= $hget(autoreplace,0).item) {
122
    did -a autoreplace 2 $hget(autoreplace,%i).item
123
    did -a autoreplace 3 $hget(autoreplace,%i).data
124
    did -a autoreplace 4 $hget(autoreplace_eval,%i).data
125
    inc %i
126
  }
127
  aptitle | if ($1) select.line $1 $2
128
}
129

    
130
alias -l savetofile hsave autoreplace autoreplace.dat | hsave autoreplace_eval autoreplace_eval.dat
131

    
132
alias -l autoreplace_add {
133
  var %word $$?="Add new word for the auto replace (without space):"
134
  var %replace $$?="Replace %word with...:"
135
  var %eval $$?!="Evaluate the replace content on usage?"
136
  if ($regex(%word,/([\$?\w]+)/Si)) {
137
    hadd -m autoreplace $regml(1) %replace | hadd -m autoreplace_eval $regml(1) $iif(%eval == $true,yes,no)
138
    savetofile | list.words | return
139
  }
140
  noop $input(Invalid word $+ $chr(44) try again.,o,Auto Replace Error)
141
  .timer -m 1 1 autoreplace_add
142
}
143

    
144
on *:dialog:autoreplace:sclick:10: run http://www.adiirc.com/
(1-1/3)