rrename 0.2.0 → 0.3.0
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/CHANGES +13 -0
- data/Makefile +4 -4
- data/README +1 -2
- data/TODO +2 -6
- data/replaceschemas.yaml +90 -0
- data/rrename.gemspec +3 -3
- data/rrename.glade +27 -3
- data/rrename.rb +148 -56
- metadata +4 -2
data/CHANGES
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
== Version Current
|
2
|
+
|
3
|
+
== Version 0.3.0
|
4
|
+
|
5
|
+
* work only on the selection
|
6
|
+
* make add and remove files redo / undoable
|
7
|
+
* apply command from menu automatically
|
8
|
+
* added default replace schemas
|
9
|
+
* changed quoting of replace string \\1 -> \1
|
10
|
+
|
11
|
+
== Version 0.2.0
|
12
|
+
|
13
|
+
== Version 0.1
|
data/Makefile
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
|
2
|
-
VERSION=0.
|
2
|
+
VERSION=0.3.0
|
3
3
|
DIST=../dist
|
4
4
|
NAME=rrename
|
5
5
|
DIR=${NAME}
|
6
6
|
TARGZ=${DIR}-${VERSION}.tar.gz
|
7
7
|
DEST=${DIST}/${DIR}
|
8
|
-
FILES=${NAME}.glade ${NAME}.rb ${NAME}.gemspec Makefile TODO README
|
8
|
+
FILES=${NAME}.glade ${NAME}.rb ${NAME}.gemspec replaceschemas.yaml Makefile CHANGES TODO README
|
9
9
|
GEM=${NAME}-${VERSION}.gem
|
10
10
|
GEMSPEC=${NAME}.gemspec
|
11
11
|
|
@@ -17,13 +17,13 @@ release: ${DIST}/${TARGZ}
|
|
17
17
|
gem: ${DIST}/${GEM}
|
18
18
|
|
19
19
|
|
20
|
-
${DIST}/${TARGZ}:
|
20
|
+
${DIST}/${TARGZ}: $(FILES)
|
21
21
|
rm -rfv ${DEST}
|
22
22
|
mkdir ${DEST}
|
23
23
|
cp ${FILES} ${DEST}
|
24
24
|
tar -C ${DIST} -cvzf ${DIST}/${TARGZ} ${DIR}
|
25
25
|
|
26
|
-
${DIST}/${GEM}:
|
26
|
+
${DIST}/${GEM}: $(FILES)
|
27
27
|
gem build ${GEMSPEC}
|
28
28
|
mv ${GEM} ${DIST}
|
29
29
|
|
data/README
CHANGED
data/TODO
CHANGED
data/replaceschemas.yaml
ADDED
@@ -0,0 +1,90 @@
|
|
1
|
+
---
|
2
|
+
replace dots: !ruby/object:ReplaceSchema
|
3
|
+
initializeCode: n=1
|
4
|
+
iterationCode: n=n+1
|
5
|
+
name: replace dots
|
6
|
+
pattern: "\\.(?!...$)"
|
7
|
+
substitute: "_"
|
8
|
+
titlecase: !ruby/object:ReplaceSchema
|
9
|
+
initializeCode: n=0
|
10
|
+
iterationCode: "ausnahmen=[\"of\"]\n\ns=match[0].gsub(/[^ _]*/) { |m| \n\tif ausnahmen.include?
|
11
|
+
m then\n\t\tm\n\telse\n\t\tm.capitalize\n\tend}"
|
12
|
+
name: titlecase
|
13
|
+
pattern: "^.*"
|
14
|
+
substitute: "#{s}"
|
15
|
+
default: !ruby/object:ReplaceSchema
|
16
|
+
initializeCode: n=0
|
17
|
+
iterationCode: n=n+1
|
18
|
+
name: default
|
19
|
+
pattern: ''
|
20
|
+
substitute: ''
|
21
|
+
capitalize: !ruby/object:ReplaceSchema
|
22
|
+
initializeCode: n=0
|
23
|
+
iterationCode: n=n+1
|
24
|
+
name: capitalize
|
25
|
+
pattern: "^.*"
|
26
|
+
substitute: "#{match[0].capitalize}"
|
27
|
+
flatten dirs: !ruby/object:ReplaceSchema
|
28
|
+
initializeCode: n=0
|
29
|
+
iterationCode: n=n+1
|
30
|
+
name: flatten dirs
|
31
|
+
pattern: "^(.*)$"
|
32
|
+
substitute: "../#{file.parent.name}_-_\\1"
|
33
|
+
replace underscores: !ruby/object:ReplaceSchema
|
34
|
+
initializeCode: n=1
|
35
|
+
iterationCode: n=n+1
|
36
|
+
name: replace underscores
|
37
|
+
pattern: "_"
|
38
|
+
substitute: " "
|
39
|
+
"foo - 01 bar.bla -> foo - bar - 01 of 22.bla": !ruby/object:ReplaceSchema
|
40
|
+
initializeCode: >-
|
41
|
+
n=1
|
42
|
+
|
43
|
+
max=22
|
44
|
+
|
45
|
+
iterationCode: n=n+1
|
46
|
+
name: "foo - 01 bar.bla -> foo - bar - 01 of 22.bla"
|
47
|
+
pattern: "(.*)_-_([0-9]+)_(.*)(\\....)"
|
48
|
+
substitute: "\\1_-_\\3_-_\\2_of_#{max}\\4"
|
49
|
+
replace date to iso: !ruby/object:ReplaceSchema
|
50
|
+
initializeCode: n=0
|
51
|
+
iterationCode: n=n+1
|
52
|
+
name: replace date to iso
|
53
|
+
pattern: "(\\d\\d)\\.(\\d\\d)\\.(\\d\\d+)"
|
54
|
+
substitute: "\\3-\\2-\\1"
|
55
|
+
downcase: !ruby/object:ReplaceSchema
|
56
|
+
initializeCode: n=0
|
57
|
+
iterationCode: n=n+1
|
58
|
+
name: downcase
|
59
|
+
pattern: "^.*"
|
60
|
+
substitute: "#{match[0].downcase}"
|
61
|
+
something -> 01 of XX: !ruby/object:ReplaceSchema
|
62
|
+
initializeCode: n=0
|
63
|
+
iterationCode: n=n+1
|
64
|
+
name: something -> 01 of XX
|
65
|
+
pattern: "_Track.*(?=\\.)"
|
66
|
+
substitute: "_#{\"%0.2i\" % n}_of_XX"
|
67
|
+
insert parent name: !ruby/object:ReplaceSchema
|
68
|
+
initializeCode: "n=0
|
69
|
+
|
70
|
+
"
|
71
|
+
iterationCode: >-
|
72
|
+
n=n+1
|
73
|
+
|
74
|
+
p=file.parent.name
|
75
|
+
|
76
|
+
name: insert parent name
|
77
|
+
pattern: Titel
|
78
|
+
substitute: "#{p}"
|
79
|
+
replace whitespace: !ruby/object:ReplaceSchema
|
80
|
+
initializeCode: n=1
|
81
|
+
iterationCode: n=n+1
|
82
|
+
name: replace whitespace
|
83
|
+
pattern: " "
|
84
|
+
substitute: "_"
|
85
|
+
shrink whitespace: !ruby/object:ReplaceSchema
|
86
|
+
initializeCode: n=1
|
87
|
+
iterationCode: n=n+1
|
88
|
+
name: shrink whitespace
|
89
|
+
pattern: "([_ ])*"
|
90
|
+
substitute: "\\1"
|
data/rrename.gemspec
CHANGED
@@ -6,7 +6,7 @@ spec = Gem::Specification.new do |s|
|
|
6
6
|
#### Basic information.
|
7
7
|
|
8
8
|
s.name = 'rrename'
|
9
|
-
s.version = "0.
|
9
|
+
s.version = "0.3.0"
|
10
10
|
s.summary = <<-EOF
|
11
11
|
A GNOME2 based tool for interactively renameing files
|
12
12
|
with regular expressions.
|
@@ -27,8 +27,8 @@ EOF
|
|
27
27
|
|
28
28
|
#### Which files are to be included in this gem? Everything! (Except CVS directories.)
|
29
29
|
|
30
|
-
s.files = ["rrename.glade", "rrename.rb", "
|
31
|
-
|
30
|
+
s.files = ["rrename.glade", "rrename.rb", "replaceschemas.yaml",
|
31
|
+
"rrename.gemspec", "Makefile", "TODO", "CHANGES", "README"]
|
32
32
|
|
33
33
|
|
34
34
|
#### Load-time details: library and application (you will need one or both).
|
data/rrename.glade
CHANGED
@@ -54,7 +54,7 @@
|
|
54
54
|
<signal name="activate" handler="on_addfiles" last_modification_time="Tue, 26 Apr 2005 20:53:14 GMT"/>
|
55
55
|
|
56
56
|
<child internal-child="image">
|
57
|
-
<widget class="GtkImage" id="
|
57
|
+
<widget class="GtkImage" id="image5">
|
58
58
|
<property name="visible">True</property>
|
59
59
|
<property name="stock">gtk-directory</property>
|
60
60
|
<property name="icon_size">1</property>
|
@@ -169,6 +169,19 @@
|
|
169
169
|
</widget>
|
170
170
|
</child>
|
171
171
|
|
172
|
+
<child>
|
173
|
+
<widget class="GtkMenuItem" id="replace_schema">
|
174
|
+
<property name="visible">True</property>
|
175
|
+
<property name="label" translatable="yes">_Replace</property>
|
176
|
+
<property name="use_underline">True</property>
|
177
|
+
|
178
|
+
<child>
|
179
|
+
<widget class="GtkMenu" id="replace_schema_menu">
|
180
|
+
</widget>
|
181
|
+
</child>
|
182
|
+
</widget>
|
183
|
+
</child>
|
184
|
+
|
172
185
|
<child>
|
173
186
|
<widget class="GtkMenuItem" id="settings1">
|
174
187
|
<property name="visible">True</property>
|
@@ -178,8 +191,13 @@
|
|
178
191
|
<widget class="GtkMenu" id="settings1_menu">
|
179
192
|
|
180
193
|
<child>
|
181
|
-
<widget class="
|
194
|
+
<widget class="GtkCheckMenuItem" id="replace_selection">
|
182
195
|
<property name="visible">True</property>
|
196
|
+
<property name="tooltip" translatable="yes">work only on selected items</property>
|
197
|
+
<property name="label" translatable="yes">only replace selection</property>
|
198
|
+
<property name="use_underline">True</property>
|
199
|
+
<property name="active">False</property>
|
200
|
+
<signal name="activate" handler="on_replace_selection_activate" last_modification_time="Sun, 03 Jul 2005 19:07:22 GMT"/>
|
183
201
|
</widget>
|
184
202
|
</child>
|
185
203
|
</widget>
|
@@ -187,6 +205,12 @@
|
|
187
205
|
</widget>
|
188
206
|
</child>
|
189
207
|
|
208
|
+
<child>
|
209
|
+
<widget class="GtkSeparatorMenuItem" id="separator3">
|
210
|
+
<property name="visible">True</property>
|
211
|
+
</widget>
|
212
|
+
</child>
|
213
|
+
|
190
214
|
<child>
|
191
215
|
<widget class="GtkMenuItem" id="help1">
|
192
216
|
<property name="visible">True</property>
|
@@ -350,7 +374,7 @@
|
|
350
374
|
<widget class="GtkEntry" id="replace_entry">
|
351
375
|
<property name="visible">True</property>
|
352
376
|
<property name="tooltip" translatable="yes">insert string here
|
353
|
-
|
377
|
+
\1 \2 => matched region
|
354
378
|
#{ruby expression}
|
355
379
|
#{n} => 1,2,3..n
|
356
380
|
#{"%.2i" % n} => 01, 02, 03 ...
|
data/rrename.rb
CHANGED
@@ -4,7 +4,7 @@
|
|
4
4
|
#
|
5
5
|
# Copyright (c) 2005 Jens Lincke
|
6
6
|
#
|
7
|
-
# Last edited: 2005-
|
7
|
+
# Last edited: 2005-09-05 19:33:56 by jens on wh11-618.st.uni-magdeburg.de
|
8
8
|
#
|
9
9
|
# This program is free software.
|
10
10
|
# You can distribute/modify this program under the terms of
|
@@ -65,6 +65,10 @@ class Standoff
|
|
65
65
|
|
66
66
|
end
|
67
67
|
|
68
|
+
#
|
69
|
+
# Command / CommandProcessor Design Pattern
|
70
|
+
#
|
71
|
+
|
68
72
|
class CommandProcessor
|
69
73
|
attr_accessor :history
|
70
74
|
|
@@ -201,22 +205,27 @@ class AddFilesCommand
|
|
201
205
|
|
202
206
|
def initialize(renameFiles, files)
|
203
207
|
@renameFiles= renameFiles
|
204
|
-
@
|
205
|
-
@
|
208
|
+
@fileset= renameFiles.fileset
|
209
|
+
@log= renameFiles.log
|
210
|
+
@files= files
|
206
211
|
end
|
212
|
+
|
207
213
|
def exec
|
208
|
-
@files.
|
214
|
+
@fileEntries = @files.collect {|filename|
|
209
215
|
file= GLib.filename_to_utf8(filename)
|
210
|
-
@
|
216
|
+
@fileset.add(file)
|
211
217
|
}
|
212
218
|
end
|
213
219
|
|
214
220
|
def redo
|
221
|
+
@fileset.add_entries @fileEntries
|
215
222
|
end
|
216
223
|
|
217
224
|
def undo
|
225
|
+
p "remove" + @fileEntries.to_s
|
226
|
+
@fileset.remove_entries @fileEntries
|
218
227
|
end
|
219
|
-
|
228
|
+
|
220
229
|
def to_s
|
221
230
|
return "add files to list"
|
222
231
|
end
|
@@ -237,10 +246,11 @@ class RemoveSelectedCommand
|
|
237
246
|
|
238
247
|
def undo
|
239
248
|
@log.p "undo remove files from list: "
|
240
|
-
@fileset.
|
249
|
+
@fileset.add_entries(@removed)
|
241
250
|
end
|
242
251
|
|
243
252
|
def redo
|
253
|
+
@fileset.remove_entries(@removed)
|
244
254
|
end
|
245
255
|
|
246
256
|
def to_s
|
@@ -276,9 +286,10 @@ class FileSet
|
|
276
286
|
attr_accessor :log
|
277
287
|
|
278
288
|
def initialize(renameFiles)
|
279
|
-
@renameFiles= renameFiles
|
280
|
-
@log= renameFiles.log
|
281
|
-
@entries= Hash.new
|
289
|
+
@renameFiles = renameFiles
|
290
|
+
@log = renameFiles.log
|
291
|
+
@entries = Hash.new
|
292
|
+
@options = renameFiles.options
|
282
293
|
end
|
283
294
|
|
284
295
|
def markup(regex_str)
|
@@ -291,28 +302,28 @@ class FileSet
|
|
291
302
|
end
|
292
303
|
|
293
304
|
def add(file)
|
294
|
-
|
305
|
+
return add_to_node(file, nil)
|
295
306
|
end
|
296
307
|
|
297
|
-
def
|
308
|
+
def add_to_node(file, node)
|
298
309
|
filename= GLib.filename_from_utf8(file)
|
299
310
|
fileStat= File.stat(filename)
|
300
311
|
filename= GLib.filename_from_utf8(file)
|
301
312
|
if File.exist?(filename) then
|
302
313
|
@log.p "added #{file}"
|
303
|
-
|
304
314
|
if node then
|
305
|
-
|
315
|
+
return add_entry(FileEntry.new(file, self), node)
|
306
316
|
else
|
307
|
-
|
317
|
+
return add_entry(FileEntry.new(file, self))
|
308
318
|
end
|
309
319
|
|
310
320
|
else
|
311
321
|
@log.p file + " don't exist"
|
322
|
+
return nil
|
312
323
|
end
|
313
324
|
end
|
314
325
|
|
315
|
-
def
|
326
|
+
def add_entry_to_node(entry, parent)
|
316
327
|
if(parent) then
|
317
328
|
entry.parent= parent
|
318
329
|
end
|
@@ -320,15 +331,15 @@ class FileSet
|
|
320
331
|
entry.iter[0]= entry
|
321
332
|
end
|
322
333
|
|
323
|
-
def
|
334
|
+
def include?(entry)
|
324
335
|
return @entries[entry.expand_path]
|
325
336
|
end
|
326
337
|
|
327
|
-
def
|
328
|
-
if not
|
338
|
+
def add_entry(entry)
|
339
|
+
if not include?(entry) then
|
329
340
|
@entries[entry.expand_path]=entry
|
330
341
|
parent= @entries[File.expand_path(entry.path)]
|
331
|
-
|
342
|
+
add_entry_to_node(entry, parent)
|
332
343
|
end
|
333
344
|
end
|
334
345
|
|
@@ -341,23 +352,43 @@ class FileSet
|
|
341
352
|
end
|
342
353
|
end
|
343
354
|
|
355
|
+
def sub_backslashes(string)
|
356
|
+
string.gsub(/\\([0-9])/,"\\\\\\\\\\1")
|
357
|
+
end
|
358
|
+
|
359
|
+
def selection_each &aBlock
|
360
|
+
if @options.only_replace_selection then
|
361
|
+
@renameFiles.treeview.selection.selected_each { |*args|
|
362
|
+
aBlock.call *args}
|
363
|
+
else
|
364
|
+
@renameFiles.treestore.each { |*args| aBlock.call *args}
|
365
|
+
end
|
366
|
+
end
|
367
|
+
|
344
368
|
def replace(replaceSchema)
|
345
369
|
file=nil
|
370
|
+
match=nil
|
346
371
|
aBinding= binding
|
347
372
|
save_eval(replaceSchema.initializeCode, aBinding)
|
348
373
|
@regex= Regexp.new(replaceSchema.pattern)
|
349
|
-
|
374
|
+
substitute= '"'+sub_backslashes(replaceSchema.substitute)+'"'
|
375
|
+
|
376
|
+
|
377
|
+
selection_each { |model,path,iter|
|
350
378
|
file= iter[0]
|
351
|
-
if file.match(@regex) then
|
379
|
+
if match= file.match(@regex) then
|
352
380
|
save_eval(replaceSchema.iterationCode, aBinding)
|
353
|
-
|
354
|
-
file.replace(@regex,
|
381
|
+
evaled_substitute= save_eval(substitute, aBinding)
|
382
|
+
file.replace(@regex,evaled_substitute) if evaled_substitute
|
355
383
|
model.signal_emit("row-changed", path, iter)
|
356
384
|
end
|
357
|
-
|
385
|
+
}
|
386
|
+
rescue RegexpError
|
387
|
+
@log.p "RegexpError: " + replaceSchema.pattern
|
358
388
|
end
|
359
389
|
|
360
390
|
def file_history_pop
|
391
|
+
|
361
392
|
@renameFiles.treestore.each do |model,path,iter|
|
362
393
|
file= iter[0]
|
363
394
|
oldname= file.name
|
@@ -373,33 +404,38 @@ class FileSet
|
|
373
404
|
end
|
374
405
|
end
|
375
406
|
|
376
|
-
def
|
377
|
-
|
378
|
-
|
379
|
-
removed= []
|
380
|
-
@renameFiles.treeview.selection.selected_each {|model, path, iter|
|
381
|
-
remove_list << iter
|
382
|
-
removed << iter[0]
|
383
|
-
}
|
384
|
-
remove_list.each { |iter|
|
407
|
+
def remove_iters(iters)
|
408
|
+
entries= iters.collect {|each| each[0]}
|
409
|
+
iters.each { |iter|
|
385
410
|
remove_iter(iter)
|
386
411
|
}
|
387
|
-
|
412
|
+
entries.each { |each| @entries.delete each.expand_path}
|
413
|
+
return entries
|
414
|
+
end
|
415
|
+
|
416
|
+
def remove_selected()
|
417
|
+
remove_entries @renameFiles.selected_entries
|
388
418
|
end
|
389
419
|
|
390
420
|
def remove_iter(iter)
|
391
421
|
if @renameFiles.treestore.iter_is_valid? iter then
|
392
422
|
@log.p "remove #{iter[0].name} from list"
|
393
423
|
@entries.delete iter[0].expand_path
|
394
|
-
|
395
424
|
@renameFiles.treestore.remove(iter)
|
396
425
|
end
|
397
426
|
end
|
398
427
|
|
399
|
-
def
|
400
|
-
entries.each { |entry|
|
428
|
+
def add_entries(entries)
|
429
|
+
entries.each { |entry| add_entry(entry) }
|
401
430
|
end
|
402
431
|
|
432
|
+
def remove_entries(entries)
|
433
|
+
iters= @renameFiles.sub_iters_of_entries(entries)
|
434
|
+
remove_iters(iters)
|
435
|
+
end
|
436
|
+
|
437
|
+
|
438
|
+
|
403
439
|
def undo_rename
|
404
440
|
@renameFiles.treestore.each { |model,path,iter|
|
405
441
|
file= iter[0]
|
@@ -431,7 +467,8 @@ class FileEntry
|
|
431
467
|
@path= File.dirname(filename)
|
432
468
|
@name= File.basename(filename)
|
433
469
|
@old_name= @name.clone
|
434
|
-
@colors= ["red", "
|
470
|
+
@colors= ["red", "blue", "orange","darkred","darkblue","yellow",
|
471
|
+
"darkgreen"]
|
435
472
|
@fileset= fileset
|
436
473
|
@name_history= []
|
437
474
|
@rename_history= []
|
@@ -491,9 +528,9 @@ class FileEntry
|
|
491
528
|
if old_name_name then
|
492
529
|
old_name_name
|
493
530
|
@old_name= old_name_name[0]
|
494
|
-
@name=
|
531
|
+
@name= old_name_name[1]
|
495
532
|
from= GLib.filename_from_utf8(@path + "/" + @old_name)
|
496
|
-
to=
|
533
|
+
to= GLib.filename_from_utf8(@path + "/" + @name)
|
497
534
|
|
498
535
|
if not File.exists?(from) or not File.exists?(to) then
|
499
536
|
@log.p "rename #{to} to #{from} back"
|
@@ -603,6 +640,7 @@ class RenameFiles
|
|
603
640
|
glade_file= find_in_load_path("/RenameFiles/rrename.glade")
|
604
641
|
glade_file= find_in_load_path("/rrename.glade") if not glade_file
|
605
642
|
glade_file= File.dirname($0) + "/rrename.glade" if not glade_file
|
643
|
+
@base_dir= File.dirname(glade_file)
|
606
644
|
@glade= GladeXML.new(glade_file, nil, "rrename"){|handler| method(handler)}
|
607
645
|
|
608
646
|
# get widgets from glade
|
@@ -615,13 +653,16 @@ class RenameFiles
|
|
615
653
|
@log_view= @glade.get_widget("log_textview")
|
616
654
|
@textview_eval_initialize= @glade.get_widget("textview_eval_initialize")
|
617
655
|
@textview_eval_iteration= @glade.get_widget("textview_eval_eachmatch")
|
618
|
-
@settings_menu= @glade.get_widget("settings1_menu")
|
656
|
+
# @settings_menu= @glade.get_widget("settings1_menu")
|
657
|
+
@replace_schema_menu= @glade.get_widget("replace_schema_menu")
|
619
658
|
@replace_schema_name= @glade.get_widget("replace_schema_name")
|
659
|
+
|
620
660
|
|
621
661
|
# initialize
|
622
662
|
@replace_schemas= Hash.new
|
623
663
|
add_replace_schema(replaceschema)
|
624
664
|
|
665
|
+
@options= OpenStruct.new
|
625
666
|
@logbuffer= @log_view.buffer
|
626
667
|
@log= Log.new(@logbuffer, @appbar)
|
627
668
|
@comandProcessor= CommandProcessor.new(self)
|
@@ -681,8 +722,42 @@ class RenameFiles
|
|
681
722
|
end
|
682
723
|
|
683
724
|
def add_replace_schema(replaceSchema)
|
684
|
-
@replace_schemas[replaceSchema.name]
|
685
|
-
|
725
|
+
if @replace_schemas[replaceSchema.name] then
|
726
|
+
@replace_schemas[replaceSchema.name]= replaceSchema
|
727
|
+
else
|
728
|
+
@replace_schemas[replaceSchema.name]= replaceSchema
|
729
|
+
update_replace_schema_menu
|
730
|
+
end
|
731
|
+
end
|
732
|
+
|
733
|
+
def file_entry_iters
|
734
|
+
result= []
|
735
|
+
@treestore.each{ |model,path,iter| result << iter}
|
736
|
+
return result
|
737
|
+
end
|
738
|
+
|
739
|
+
def selected_iters()
|
740
|
+
result= []
|
741
|
+
@treeview.selection.selected_each {|model, path, iter|
|
742
|
+
result << iter}
|
743
|
+
return result
|
744
|
+
end
|
745
|
+
|
746
|
+
def selected_entries()
|
747
|
+
return selected_iters.collect { |each| each[0]}
|
748
|
+
end
|
749
|
+
|
750
|
+
def sub_iters_of_entries(entries)
|
751
|
+
subEntries= entries.clone
|
752
|
+
iters=[]
|
753
|
+
file_entry_iters.each { |iter|
|
754
|
+
if subEntries.include? iter[0] or
|
755
|
+
subEntries.include? iter[0].parent then
|
756
|
+
iters << iter
|
757
|
+
subEntries << iter[0]
|
758
|
+
end
|
759
|
+
}
|
760
|
+
return iters
|
686
761
|
end
|
687
762
|
|
688
763
|
def replaceschema
|
@@ -702,6 +777,11 @@ class RenameFiles
|
|
702
777
|
@textview_eval_iteration.buffer.text = replaceschema.iterationCode
|
703
778
|
end
|
704
779
|
|
780
|
+
def set_replaceschema_named(name)
|
781
|
+
set_replaceschema(@replace_schemas[name])
|
782
|
+
end
|
783
|
+
|
784
|
+
|
705
785
|
def confpath
|
706
786
|
GLib.home_dir+"/"+CONFDIR+"/"
|
707
787
|
end
|
@@ -723,28 +803,36 @@ class RenameFiles
|
|
723
803
|
|
724
804
|
def load_replace_schemas
|
725
805
|
file= confpath+REPLACESCHEMAS
|
806
|
+
if not File.exists?(file)
|
807
|
+
@log.p "loading default replace schemas"
|
808
|
+
file=@base_dir+"/"+REPLACESCHEMAS
|
809
|
+
end
|
810
|
+
load_replace_schemas_from_file( file)
|
811
|
+
end
|
812
|
+
|
813
|
+
def load_replace_schemas_from_file( file)
|
726
814
|
begin
|
727
815
|
@replace_schemas= YAML::load(File.open(file))
|
728
816
|
set_replaceschema= @replace_schemas[0]
|
729
817
|
rescue
|
730
818
|
@log.p "can not open "+file
|
731
819
|
end
|
732
|
-
|
820
|
+
update_replace_schema_menu
|
733
821
|
end
|
734
|
-
|
735
|
-
def
|
736
|
-
@
|
737
|
-
@
|
822
|
+
|
823
|
+
def update_replace_schema_menu
|
824
|
+
@replace_schema_menu.each { |each|
|
825
|
+
@replace_schema_menu.remove each
|
738
826
|
}
|
739
827
|
@replace_schemas.sort.each { |name, replaceSchema|
|
740
828
|
item= Gtk::MenuItem.new(replaceSchema.name)
|
741
|
-
@
|
829
|
+
@replace_schema_menu.append(item)
|
742
830
|
item.signal_connect( "activate" ) {
|
743
|
-
|
831
|
+
set_replaceschema_named(replaceSchema.name)
|
744
832
|
@comandProcessor.exec(@replaceCommand)
|
745
833
|
}
|
746
834
|
}
|
747
|
-
@
|
835
|
+
@replace_schema_menu.show_all
|
748
836
|
|
749
837
|
@replace_schemas.sort.each { |name, replaceSchema|
|
750
838
|
@replace_schema_name.append_history(0,name)
|
@@ -806,13 +894,17 @@ class RenameFiles
|
|
806
894
|
|
807
895
|
def on_replace_schema_delete
|
808
896
|
@replace_schemas.delete(replaceschema.name)
|
809
|
-
|
897
|
+
update_replace_schema_menu
|
810
898
|
end
|
811
899
|
|
812
900
|
def on_replace_schema_name_changed
|
813
901
|
set_replaceschema @replace_schemas[@replace_schema_name.gtk_entry.text]
|
814
902
|
end
|
815
903
|
|
904
|
+
def on_replace_selection_activate(*widget)
|
905
|
+
@options.only_replace_selection= widget[0].active?
|
906
|
+
end
|
907
|
+
|
816
908
|
def on_quit(*widget)
|
817
909
|
save_replace_schemas
|
818
910
|
Gtk.main_quit
|
@@ -838,7 +930,7 @@ class RenameFiles
|
|
838
930
|
return result
|
839
931
|
end
|
840
932
|
|
841
|
-
def
|
933
|
+
def after_start
|
842
934
|
load_replace_schemas
|
843
935
|
set_replaceschema @replace_schemas["default"]
|
844
936
|
if @options.recursive then
|
@@ -849,10 +941,10 @@ class RenameFiles
|
|
849
941
|
end
|
850
942
|
|
851
943
|
def parse_options(args)
|
852
|
-
@options= OpenStruct.new
|
853
944
|
@options.verbose= false
|
854
945
|
@options.print= true
|
855
946
|
@options.recursive= false
|
947
|
+
@options.only_replace_selection= false
|
856
948
|
@file_list= []
|
857
949
|
|
858
950
|
|
@@ -889,7 +981,7 @@ end
|
|
889
981
|
|
890
982
|
@app= RenameFiles.new
|
891
983
|
Thread.new {
|
892
|
-
@app.
|
984
|
+
@app.after_start
|
893
985
|
}
|
894
986
|
Gtk.main
|
895
987
|
|
metadata
CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.8.10
|
|
3
3
|
specification_version: 1
|
4
4
|
name: rrename
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.
|
7
|
-
date: 2005-
|
6
|
+
version: 0.3.0
|
7
|
+
date: 2005-09-05
|
8
8
|
summary: A GNOME2 based tool for interactively renameing files with regular expressions.
|
9
9
|
require_paths:
|
10
10
|
- lib
|
@@ -29,9 +29,11 @@ authors:
|
|
29
29
|
files:
|
30
30
|
- rrename.glade
|
31
31
|
- rrename.rb
|
32
|
+
- replaceschemas.yaml
|
32
33
|
- rrename.gemspec
|
33
34
|
- Makefile
|
34
35
|
- TODO
|
36
|
+
- CHANGES
|
35
37
|
- README
|
36
38
|
test_files: []
|
37
39
|
rdoc_options: []
|