tkregreplace 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.txt +18 -8
- data/tkregreplace.rb +299 -232
- metadata +4 -4
data/README.txt
CHANGED
|
@@ -1,16 +1,17 @@
|
|
|
1
|
-
This program is currently in alpha status. It works pretty well at present
|
|
2
|
-
|
|
3
|
-
like the ability to save the text file back to disk. Also there may be somewhat
|
|
4
|
-
behavior from the UI, not so much becuase of bugs, but more as a
|
|
5
|
-
program attacks the problem. Before the final release of
|
|
6
|
-
implement the following
|
|
1
|
+
This program is currently in alpha status. It works pretty well at present as a
|
|
2
|
+
visualization tool, however crucial features are still missing from the program
|
|
3
|
+
like the ability to save the text file back to disk. Also there may be somewhat
|
|
4
|
+
unexpected behavior from the UI, not so much becuase of bugs, but more as a
|
|
5
|
+
reflection of how the program attacks the problem. Before the final release of
|
|
6
|
+
this program I would like to implement the following
|
|
7
7
|
|
|
8
8
|
saving files back to the disk
|
|
9
9
|
|
|
10
10
|
a proper about dialog
|
|
11
11
|
|
|
12
|
-
having all the search buttons obey symantics that the user would expect, like
|
|
13
|
-
|
|
12
|
+
having all the search buttons obey symantics that the user would expect, like
|
|
13
|
+
say perhaps searching starting from the current cursor position rather than from
|
|
14
|
+
the top and other minor refinements
|
|
14
15
|
|
|
15
16
|
cutting copying and pasting
|
|
16
17
|
|
|
@@ -18,3 +19,12 @@ an undo facility, preferably a multi level undo
|
|
|
18
19
|
|
|
19
20
|
|
|
20
21
|
I think If I can implement these features, this program could actually be useful to somebody.
|
|
22
|
+
|
|
23
|
+
changlog
|
|
24
|
+
|
|
25
|
+
version 0.1.1
|
|
26
|
+
Added rdoc documentation to the source and changed the gem so that it
|
|
27
|
+
will autogenerate this documentation.
|
|
28
|
+
|
|
29
|
+
version 0.1.0
|
|
30
|
+
Initial version, partial functionality, needs work
|
data/tkregreplace.rb
CHANGED
|
@@ -1,272 +1,339 @@
|
|
|
1
|
+
# This is a simple ruby script which uses the tk widget set for it's GUI
|
|
2
|
+
# environment. The program currently accepts no arguments.
|
|
3
|
+
#
|
|
4
|
+
# The purpose of this program are as follows:
|
|
5
|
+
# * to function as a tool for crafting regular expressions by showing a visual
|
|
6
|
+
# representation of the match.
|
|
7
|
+
# * to be able to perform replacement operations on the matched text using all
|
|
8
|
+
# the power that ruby regular expressions can provide, including the ability
|
|
9
|
+
# to use \1 \2 in the replacement string referring to groups captured by
|
|
10
|
+
# capturing parentheses.
|
|
11
|
+
# * to function as a light weight text editor. This last goal has sortof come
|
|
12
|
+
# about as a bi-product of the implementation.
|
|
13
|
+
|
|
1
14
|
require 'tk'
|
|
15
|
+
require 'optparse'
|
|
16
|
+
require 'rdoc/usage'
|
|
2
17
|
|
|
18
|
+
# This Class represents the TkRegReplace Program. Instantiating an object of
|
|
19
|
+
# this class will effectively start the GUI. You should not instantiate more
|
|
20
|
+
# than one instance of this class as once the TK environment is destroyed by
|
|
21
|
+
# the first instantiated object, it cannot be recreated again.
|
|
3
22
|
class TkRegReplace
|
|
23
|
+
private
|
|
24
|
+
# This method constructs a new instance of the TkRegReplace object
|
|
25
|
+
# in effect starting the GUI. It takes no parameters. The return value
|
|
26
|
+
# should not be used because by the time this function returns, the program
|
|
27
|
+
# should have ended and the object will be in an invalid state
|
|
28
|
+
def initialize
|
|
29
|
+
@root = TkRoot.new
|
|
4
30
|
|
|
5
|
-
|
|
6
|
-
|
|
31
|
+
@text = TkText.new(@root) do
|
|
32
|
+
font '-Adobe-Courier-Medium-R-Normal--*-120-*-*-*-*-*-*'
|
|
33
|
+
end
|
|
7
34
|
|
|
8
|
-
|
|
9
|
-
font '-Adobe-Courier-Medium-R-Normal--*-120-*-*-*-*-*-*'
|
|
10
|
-
end
|
|
35
|
+
@text.wrap = 'none'
|
|
11
36
|
|
|
12
|
-
|
|
37
|
+
menu_spec =
|
|
38
|
+
[
|
|
39
|
+
[
|
|
40
|
+
['File', 0],
|
|
41
|
+
['Open', proc {open_file}, 0, 'Ctrl+O'],
|
|
42
|
+
'---',
|
|
43
|
+
['Quit', proc{exit}, 0, 'Ctrl+Q']
|
|
44
|
+
],
|
|
45
|
+
[
|
|
46
|
+
['Edit', 0],
|
|
47
|
+
['Cut', proc{puts('Cut clicked')}, 2, 'Ctrl+X'],
|
|
48
|
+
['Copy', proc{puts('Copy clicked')}, 0, 'Ctrl+C'],
|
|
49
|
+
['Paste', proc{puts('Paste clicked')}, 0, 'Ctrl+V']
|
|
50
|
+
],
|
|
51
|
+
[
|
|
52
|
+
['Help', 0, {:menu_name=>'help'}],
|
|
53
|
+
['About This', proc{puts('xregexsearch&replace ruby script')}, 6]
|
|
54
|
+
]
|
|
55
|
+
]
|
|
13
56
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
],
|
|
22
|
-
[
|
|
23
|
-
['Edit', 0],
|
|
24
|
-
['Cut', proc{puts('Cut clicked')}, 2, 'Ctrl+X'],
|
|
25
|
-
['Copy', proc{puts('Copy clicked')}, 0, 'Ctrl+C'],
|
|
26
|
-
['Paste', proc{puts('Paste clicked')}, 0, 'Ctrl+V']
|
|
27
|
-
],
|
|
28
|
-
[
|
|
29
|
-
['Help', 0, {:menu_name=>'help'}],
|
|
30
|
-
['About This', proc{puts('xregexsearch&replace ruby script')}, 6]
|
|
31
|
-
]
|
|
32
|
-
]
|
|
57
|
+
@mbar = Tk.root.add_menubar(menu_spec)
|
|
58
|
+
@root.bind('Control-o', proc {open_file})
|
|
59
|
+
@root.bind('Control-q', proc {exit})
|
|
60
|
+
|
|
61
|
+
@frame1 = TkFrame.new(@root)
|
|
62
|
+
@frame2 = TkFrame.new(@root)
|
|
63
|
+
@frame3 = TkFrame.new(@root)
|
|
33
64
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
@frame1 = TkFrame.new(@root)
|
|
39
|
-
@frame2 = TkFrame.new(@root)
|
|
40
|
-
@frame3 = TkFrame.new(@root)
|
|
65
|
+
@entry1 = TkEntry.new(@frame2)
|
|
66
|
+
@entry1.bind('Return', proc {match})
|
|
67
|
+
@entry2 = TkEntry.new(@frame2)
|
|
41
68
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
69
|
+
@dmn = TkVariable.new(0)
|
|
70
|
+
@checkbox1 = TkCheckButton.new(@frame3,
|
|
71
|
+
'text' => "Dot matches newline mode",
|
|
72
|
+
'variable' => @dmn
|
|
73
|
+
)
|
|
45
74
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
75
|
+
@ic = TkVariable.new(1)
|
|
76
|
+
@checkbox2 = TkCheckButton.new(@frame3,
|
|
77
|
+
'text' => "Ignore Case",
|
|
78
|
+
'variable' => @ic
|
|
79
|
+
)
|
|
80
|
+
|
|
81
|
+
@tags = TkTextTag.new(@text, 'background' => 'red')
|
|
82
|
+
@tag = TkTextTag.new(@text, 'background' => 'blue')
|
|
51
83
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
)
|
|
57
|
-
|
|
58
|
-
@tags = TkTextTag.new(@text, 'background' => 'red')
|
|
59
|
-
@tag = TkTextTag.new(@text, 'background' => 'blue')
|
|
60
|
-
|
|
61
|
-
@button1 = TkButton.new(@frame1,
|
|
62
|
-
'text' => 'Match',
|
|
63
|
-
'command' => proc {@text.focus; match}
|
|
64
|
-
)
|
|
84
|
+
@button1 = TkButton.new(@frame1,
|
|
85
|
+
'text' => 'Match',
|
|
86
|
+
'command' => proc {@text.focus; match}
|
|
87
|
+
)
|
|
65
88
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
89
|
+
@button2 = TkButton.new(@frame1,
|
|
90
|
+
'text' => 'Match again',
|
|
91
|
+
'command' => proc {@text.focus; match_again}
|
|
92
|
+
)
|
|
93
|
+
|
|
94
|
+
@button3 = TkButton.new(@frame1,
|
|
95
|
+
'text' => "Match again reverse",
|
|
96
|
+
'command' => proc {@text.focus; match_again_backwards}
|
|
97
|
+
)
|
|
75
98
|
|
|
76
99
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
100
|
+
@button4 = TkButton.new(@frame1,
|
|
101
|
+
'text' => "Replace",
|
|
102
|
+
'command' => proc {replace}
|
|
103
|
+
)
|
|
81
104
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
105
|
+
@button5 = TkButton.new(@frame1,
|
|
106
|
+
'text' => "Replace All (from here downward)",
|
|
107
|
+
'command' => proc {replace_all}
|
|
108
|
+
)
|
|
86
109
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
110
|
+
@label1 = TkLabel.new(@frame2,
|
|
111
|
+
'text' => "Search String"
|
|
112
|
+
)
|
|
90
113
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
114
|
+
@label2 = TkLabel.new(@frame2,
|
|
115
|
+
'text' => "Replace String"
|
|
116
|
+
)
|
|
94
117
|
|
|
95
118
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
119
|
+
@scrollBar = TkScrollbar.new(@root,
|
|
120
|
+
'command' => proc {|*args| @text.yview(*args)}
|
|
121
|
+
)
|
|
99
122
|
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
123
|
+
@scrollBar2 = TkScrollbar.new(@root,
|
|
124
|
+
'orient' => "horizontal",
|
|
125
|
+
'command' => proc {|*args| @text.xview(*args)}
|
|
126
|
+
)
|
|
104
127
|
|
|
105
|
-
|
|
106
|
-
|
|
128
|
+
@text.yscrollcommand(proc { |first, last| @scrollBar.set(first, last)})
|
|
129
|
+
@text.xscrollcommand(proc { |first, last| @scrollBar2.set(first, last)})
|
|
107
130
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
131
|
+
@frame1.pack('side' => 'bottom', 'fill' => 'x')
|
|
132
|
+
@frame2.pack('side' => 'bottom', 'fill' => 'x', 'pady' => 10)
|
|
133
|
+
@frame3.pack('side' => 'bottom', 'fill' => 'x')
|
|
134
|
+
@checkbox1.pack('side' => 'left', 'fill' => 'x')
|
|
135
|
+
@checkbox2.pack('side' => 'left', 'fill' => 'x')
|
|
136
|
+
@label1.pack('side' => 'left', 'fill' => 'x')
|
|
137
|
+
@entry1.pack('side' => 'left', 'fill' => 'x', 'expand' => true)
|
|
138
|
+
@label2.pack('side' => 'left', 'fill' => 'x')
|
|
139
|
+
@entry2.pack('side' => 'left', 'fill' => 'x', 'expand' => true)
|
|
140
|
+
@button1.pack('side' => 'left', 'fill' => 'x', 'expand' => true)
|
|
141
|
+
@button2.pack('side' => 'left', 'fill' => 'x', 'expand' => true)
|
|
142
|
+
@button3.pack('side' => 'left', 'fill' => 'x', 'expand' => true)
|
|
143
|
+
@button4.pack('side' => 'left', 'fill' => 'x', 'expand' => true)
|
|
144
|
+
@button5.pack('side' => 'left', 'fill' => 'x', 'expand' => true)
|
|
145
|
+
@scrollBar.pack('side' => 'right', 'fill' => 'y')
|
|
146
|
+
@scrollBar2.pack('side' => 'bottom', 'fill' => 'x')
|
|
147
|
+
@text.pack('side' => 'right', 'fill' => 'both', 'expand' => true)
|
|
125
148
|
|
|
126
|
-
|
|
127
|
-
|
|
149
|
+
Tk.mainloop
|
|
150
|
+
end
|
|
128
151
|
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
152
|
+
# This is the callback that is associated with the file_open menu item
|
|
153
|
+
# Parameters: none
|
|
154
|
+
# Return Value: none
|
|
155
|
+
def open_file # :doc:
|
|
156
|
+
filetypes = [["All Files", "*"], ["Text Files", "*.txt"]]
|
|
157
|
+
filename = Tk.getOpenFile('filetypes' => filetypes, 'parent' => @root)
|
|
158
|
+
if filename != ""
|
|
159
|
+
@text.value=(File.read(filename))
|
|
160
|
+
end
|
|
134
161
|
end
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
x =
|
|
149
|
-
|
|
162
|
+
|
|
163
|
+
# This is the callback that performs the match operation, if dot matches
|
|
164
|
+
# newline mode is selected then this method will perform it's operation in a
|
|
165
|
+
# while loop which can be expensive. Even disregarding the while loop for
|
|
166
|
+
# normal matches, this method is pretty expensive. It has to do with how
|
|
167
|
+
# I'm calculating the mapping between the TK coordinates which are needed by
|
|
168
|
+
# the TkTags and the very large string that is returned from the
|
|
169
|
+
# TkText#value call. This could stand improvement, but since it's
|
|
170
|
+
# functioning I'm probably only going to come back to it after most of the
|
|
171
|
+
# rest of the functionality of the program is in place.
|
|
172
|
+
# Parameters: none
|
|
173
|
+
# Return Value: none
|
|
174
|
+
def match # :doc:
|
|
175
|
+
y = 1; x = 0
|
|
176
|
+
map = Array.new
|
|
177
|
+
string = @text.value
|
|
178
|
+
for i in 0..string.length
|
|
179
|
+
if (string[i] == "\n"[0])
|
|
180
|
+
map[i] = "#{y}.#{x}"
|
|
181
|
+
y = y+1
|
|
182
|
+
x = 0
|
|
183
|
+
else
|
|
184
|
+
map[i] = "#{y}.#{x}"
|
|
185
|
+
x = x+1
|
|
186
|
+
end
|
|
187
|
+
end
|
|
188
|
+
|
|
189
|
+
@tags.destroy
|
|
190
|
+
@tag.destroy
|
|
191
|
+
@tags = TkTextTag.new(@text, 'background' => 'red')
|
|
192
|
+
@tag = TkTextTag.new(@text, 'background' => 'blue')
|
|
193
|
+
|
|
194
|
+
if @entry1.value != ""
|
|
195
|
+
if @dmn == 1 and @ic == 1
|
|
196
|
+
@reg = Regexp.new("(?im:#{@entry1.value})")
|
|
197
|
+
elsif @ic == 1
|
|
198
|
+
@reg = Regexp.new("(?i:#{@entry1.value})")
|
|
199
|
+
elsif @dmn == 1
|
|
200
|
+
@reg = Regexp.new("(?m:#{@entry1.value})")
|
|
201
|
+
else
|
|
202
|
+
@reg = Regexp.new("#{@entry1.value}")
|
|
203
|
+
end
|
|
204
|
+
if (@reg =~ string)
|
|
205
|
+
c = 0
|
|
206
|
+
@tag_index = 0
|
|
207
|
+
@tags.add("#{map[$`.size]}", "#{map[($`.size + $&.size)]}")
|
|
208
|
+
@tag.add(@tags.ranges[0][0],@tags.ranges[0][1])
|
|
209
|
+
@tags.remove(@tag.ranges[0][0], @tag.ranges[0][1])
|
|
210
|
+
@text.set_insert("#{map[$`.size]}")
|
|
211
|
+
@text.see("#{map[$`.size]}")
|
|
212
|
+
c = c + $&.size + $`.size
|
|
213
|
+
while (@reg =~ $')
|
|
214
|
+
if $& == ""
|
|
215
|
+
$' =~ /\n/
|
|
216
|
+
c = c + 1
|
|
217
|
+
else
|
|
218
|
+
@tags.add("#{map[c + $`.size]}", "#{map[c + $`.size + $&.size]}")
|
|
219
|
+
c = c + $&.size + $`.size
|
|
220
|
+
end
|
|
221
|
+
end
|
|
222
|
+
end
|
|
223
|
+
end
|
|
150
224
|
end
|
|
151
225
|
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
if (@reg =~ string)
|
|
168
|
-
c = 0
|
|
169
|
-
@tag_index = 0
|
|
170
|
-
@tags.add("#{map[$`.size]}", "#{map[($`.size + $&.size)]}")
|
|
171
|
-
@tag.add(@tags.ranges[0][0],@tags.ranges[0][1])
|
|
172
|
-
@tags.remove(@tag.ranges[0][0], @tag.ranges[0][1])
|
|
173
|
-
@text.set_insert("#{map[$`.size]}")
|
|
174
|
-
@text.see("#{map[$`.size]}")
|
|
175
|
-
c = c + $&.size + $`.size
|
|
176
|
-
while (@reg =~ $')
|
|
177
|
-
if $& == ""
|
|
178
|
-
$' =~ /\n/
|
|
179
|
-
c = c + 1
|
|
180
|
-
else
|
|
181
|
-
@tags.add("#{map[c + $`.size]}", "#{map[c + $`.size + $&.size]}")
|
|
182
|
-
c = c + $&.size + $`.size
|
|
183
|
-
end
|
|
226
|
+
# This callback matches the next item in the original match, it does not
|
|
227
|
+
# check if the user re-entered a new search string, it simply moves to
|
|
228
|
+
# the next tag. It wraps if you are on the last tag
|
|
229
|
+
# Parameters: none
|
|
230
|
+
# Return Value: none
|
|
231
|
+
def match_again # :doc:
|
|
232
|
+
if @tags.ranges.length > 0
|
|
233
|
+
@tag_index = @tag_index + 1
|
|
234
|
+
@tag_index = 0 if @tag_index > @tags.ranges.length
|
|
235
|
+
@tags.add(@tag.ranges[0][0], @tag.ranges[0][1])
|
|
236
|
+
@tag.remove(@tag.ranges[0][0], @tag.ranges[0][1])
|
|
237
|
+
@tag.add(@tags.ranges[@tag_index][0], @tags.ranges[@tag_index][1])
|
|
238
|
+
@tags.remove(@tag.ranges[0][0], @tag.ranges[0][1])
|
|
239
|
+
@text.set_insert(@tag.ranges[0][0])
|
|
240
|
+
@text.see(@tag.ranges[0][0])
|
|
184
241
|
end
|
|
185
|
-
end
|
|
186
242
|
end
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
@tag_index = @tag_index - 1
|
|
205
|
-
@tag_index = @tags.ranges.length if @tag_index < 0
|
|
206
|
-
@tags.add(@tag.ranges[0][0], @tag.ranges[0][1])
|
|
207
|
-
@tag.remove(@tag.ranges[0][0], @tag.ranges[0][1])
|
|
208
|
-
@tag.add(@tags.ranges[@tag_index][0], @tags.ranges[@tag_index][1])
|
|
209
|
-
@tags.remove(@tag.ranges[0][0], @tag.ranges[0][1])
|
|
210
|
-
@text.set_insert(@tag.ranges[0][0])
|
|
211
|
-
@text.see(@tag.ranges[0][0])
|
|
243
|
+
|
|
244
|
+
# This callback matches the previous item in the original match, it does not
|
|
245
|
+
# check if the user re-entered a new search string, it simply moves to the
|
|
246
|
+
# previous tag. It wraps if you are on the first tag
|
|
247
|
+
# Parameters: none
|
|
248
|
+
# Return Value: none
|
|
249
|
+
def match_again_backwards # :doc:
|
|
250
|
+
if @tags.ranges.length > 0
|
|
251
|
+
@tag_index = @tag_index - 1
|
|
252
|
+
@tag_index = @tags.ranges.length if @tag_index < 0
|
|
253
|
+
@tags.add(@tag.ranges[0][0], @tag.ranges[0][1])
|
|
254
|
+
@tag.remove(@tag.ranges[0][0], @tag.ranges[0][1])
|
|
255
|
+
@tag.add(@tags.ranges[@tag_index][0], @tags.ranges[@tag_index][1])
|
|
256
|
+
@tags.remove(@tag.ranges[0][0], @tag.ranges[0][1])
|
|
257
|
+
@text.set_insert(@tag.ranges[0][0])
|
|
258
|
+
@text.see(@tag.ranges[0][0])
|
|
259
|
+
end
|
|
212
260
|
end
|
|
213
|
-
end
|
|
214
261
|
|
|
215
|
-
|
|
216
|
-
if
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
262
|
+
# This callback is responsible for performing replacements. It will only
|
|
263
|
+
# carry out replacements in already highlighted areas, ie if you have typed
|
|
264
|
+
# some text into the text box, and it has text that would have been matched
|
|
265
|
+
# by the match command, but you haven't re-executed the match callback
|
|
266
|
+
# function, that text will not be a part of the replacement.
|
|
267
|
+
# Parameters: none
|
|
268
|
+
# Return Value: none
|
|
269
|
+
def replace # :doc:
|
|
270
|
+
if @entry1.value != ""
|
|
271
|
+
if @dmn == 1 and @ic == 1
|
|
272
|
+
@reg = Regexp.new("(?im:#{@entry1.value})")
|
|
273
|
+
elsif @ic == 1
|
|
274
|
+
@reg = Regexp.new("(?i:#{@entry1.value})")
|
|
275
|
+
elsif @dmn == 1
|
|
276
|
+
@reg = Regexp.new("(?m:#{@entry1.value})")
|
|
277
|
+
else
|
|
278
|
+
@reg = Regexp.new("#{@entry1.value}")
|
|
279
|
+
end
|
|
280
|
+
end
|
|
281
|
+
|
|
282
|
+
if (@tag.ranges.length > 0)
|
|
283
|
+
string = @text.get(@tag.ranges[0][0], @tag.ranges[0][1])
|
|
284
|
+
string.sub!(@reg, @entry2.value)
|
|
285
|
+
@text.insert(@tag.ranges[0][0], string)
|
|
286
|
+
@text.delete(@tag.ranges[0][0], @tag.ranges[0][1])
|
|
287
|
+
unless @tag_index > @tags.ranges.length-1
|
|
288
|
+
@tag.add(@tags.ranges[@tag_index][0], @tags.ranges[@tag_index][1])
|
|
289
|
+
@tags.remove(@tag.ranges[0][0], @tag.ranges[0][1])
|
|
290
|
+
@text.set_insert(@tag.ranges[0][0])
|
|
291
|
+
@text.see(@tag.ranges[0][0])
|
|
292
|
+
end
|
|
293
|
+
end
|
|
239
294
|
end
|
|
240
|
-
end
|
|
241
295
|
|
|
242
|
-
|
|
243
|
-
if
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
296
|
+
# This callback is responsible for performing replacements. It will only
|
|
297
|
+
# carry out replacements in already highlighted areas, ie if you have typed
|
|
298
|
+
# some text into the text box, and it has text that would have been matched
|
|
299
|
+
# by the match command, but you haven't re-executed the match callback
|
|
300
|
+
# function, that text will not be a part of the replacement. This method
|
|
301
|
+
# replaces all occurances in one go.
|
|
302
|
+
# Parameters: none
|
|
303
|
+
# Return Value: none
|
|
304
|
+
def replace_all # :doc:
|
|
305
|
+
if @entry1.value != ""
|
|
306
|
+
if @dmn == 1 and @ic == 1
|
|
307
|
+
@reg = Regexp.new("(?im:#{@entry1.value})")
|
|
308
|
+
elsif @ic == 1
|
|
309
|
+
@reg = Regexp.new("(?i:#{@entry1.value})")
|
|
310
|
+
elsif @dmn == 1
|
|
311
|
+
@reg = Regexp.new("(?m:#{@entry1.value})")
|
|
312
|
+
else
|
|
313
|
+
@reg = Regexp.new("#{@entry1.value}")
|
|
314
|
+
end
|
|
315
|
+
end
|
|
254
316
|
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
317
|
+
while(@tag.ranges.length > 0)
|
|
318
|
+
string = @text.get(@tag.ranges[0][0], @tag.ranges[0][1])
|
|
319
|
+
string.sub!(@reg, @entry2.value)
|
|
320
|
+
@text.insert(@tag.ranges[0][0], string)
|
|
321
|
+
@text.delete(@tag.ranges[0][0], @tag.ranges[0][1])
|
|
322
|
+
unless @tag_index > @tags.ranges.length-1
|
|
323
|
+
@tag.add(@tags.ranges[@tag_index][0], @tags.ranges[@tag_index][1])
|
|
324
|
+
@tags.remove(@tag.ranges[0][0], @tag.ranges[0][1])
|
|
325
|
+
@text.set_insert(@tag.ranges[0][0])
|
|
326
|
+
@text.see(@tag.ranges[0][0])
|
|
327
|
+
end
|
|
328
|
+
end
|
|
266
329
|
end
|
|
267
|
-
end
|
|
268
330
|
end
|
|
269
331
|
|
|
332
|
+
opts = OptionParser.new
|
|
333
|
+
opts.on("-h", "--help") {RDoc::usage}
|
|
334
|
+
|
|
335
|
+
opts.parse(ARGV)
|
|
336
|
+
|
|
270
337
|
TkRegReplace.new
|
|
271
338
|
|
|
272
339
|
# mark = TkTextMarkInsert.new(@text)
|
metadata
CHANGED
|
@@ -3,11 +3,11 @@ rubygems_version: 0.8.10
|
|
|
3
3
|
specification_version: 1
|
|
4
4
|
name: tkregreplace
|
|
5
5
|
version: !ruby/object:Gem::Version
|
|
6
|
-
version: 0.1.
|
|
7
|
-
date: 2005-11-
|
|
6
|
+
version: 0.1.1
|
|
7
|
+
date: 2005-11-17
|
|
8
8
|
summary: TK program which visualizes and caries out regular expression matches and or replacements on text files
|
|
9
9
|
require_paths:
|
|
10
|
-
-
|
|
10
|
+
- "."
|
|
11
11
|
email: pfharlock@yahoo.com
|
|
12
12
|
homepage:
|
|
13
13
|
rubyforge_project:
|
|
@@ -15,7 +15,7 @@ description:
|
|
|
15
15
|
autorequire:
|
|
16
16
|
default_executable:
|
|
17
17
|
bindir: "."
|
|
18
|
-
has_rdoc:
|
|
18
|
+
has_rdoc: true
|
|
19
19
|
required_ruby_version: !ruby/object:Gem::Version::Requirement
|
|
20
20
|
requirements:
|
|
21
21
|
-
|