Project

General

Profile

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

Mr. BS, 08/24/2015 05:14 PM

 
1
; http://dev.adiirc.com/boards/5/topics/275
2
; Editbox Auto Replace
3
; v0.1.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
  ; ignore shit+space (to void auto replace) and ctrl+space (context menu)
27
  if (($mouse.key & 4) || ($mouse.key & 2)) return
28

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

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

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

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

    
71
on *:dialog:autoreplace:init:*: list.words
72

    
73
; reload button
74
on *:dialog:autoreplace:sclick:13: list.words
75

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

    
79
alias -l select.line did -c $1 2 $2 | did -c $1 3 $2 | did -c $1 4 $2
80

    
81
; add button
82
on *:dialog:autoreplace:sclick:6: autoreplace_add
83

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

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

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

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

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

    
128
alias -l savetofile hsave autoreplace autoreplace.dat | hsave autoreplace_eval autoreplace_eval.dat
129

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

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