Class: RenameWindow
Overview
connections to main renaming worker
Instance Attribute Summary collapse
-
#renamer ⇒ Object
Returns the value of attribute renamer.
Instance Method Summary collapse
- #connectRadio(r) ⇒ Object
-
#initialize(app) ⇒ RenameWindow
constructor
A new instance of RenameWindow.
- #onListClick(sender, sel, ptr) ⇒ Object
- #onPreviewClick(sender, sel, ptr) ⇒ Object
- #onRadioUpdate(sender, sel, ptr) ⇒ Object
- #onReplaceClick(sender, sel, ptr) ⇒ Object
- #rename(name, args = {}) ⇒ Object
- #rename_add(action) ⇒ Object
- #rename_count(action) ⇒ Object
- #rename_files_txt(action) ⇒ Object
- #rename_fill(action) ⇒ Object
- #rename_from_full_name(action) ⇒ Object
- #rename_mark_change(action) ⇒ Object
-
#rename_replace(action) ⇒ Object
– special functions.
- #selected_function ⇒ Object
- #start(action) ⇒ Object
Constructor Details
#initialize(app) ⇒ RenameWindow
Returns a new instance of RenameWindow.
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/gui.rb', line 17 def initialize(app) super(app, 'Rename File Set', nil, nil, DECOR_ALL, 20, 100, 1000, 600) FXHorizontalFrame.new(self, LAYOUT_FILL | PACK_UNIFORM_WIDTH) { |mainFrame| # navigation on left @dirList = FXDirList.new mainFrame, nil, 0, LAYOUT_FILL | FRAME_NORMAL # controls in centre FXVerticalFrame.new(mainFrame, LAYOUT_FILL | PACK_UNIFORM_WIDTH) { |controls| FXLabel.new controls, 'Search (replace first capture):', nil, LAYOUT_FILL_X | JUSTIFY_LEFT @search = FXTextField.new controls, 0, nil, LAYOUT_FILL FXGroupBox.new(controls, 'Replacement Method', LAYOUT_FILL | FRAME_GROOVE | JUSTIFY_LEFT ) { |group| @selReplace = FXRadioButton.new(group, 'Replace with:') { |r| connectRadio r } @replace = FXTextField.new group, 30, nil, PACK_UNIFORM_WIDTH @selAdd = FXRadioButton.new(group, 'Add to captured digits: ', nil, LAYOUT_FILL_Y) { |r| connectRadio r } @add = FXSpinner.new(group, 10, nil, FRAME_NORMAL) { |s| s.range = (-500..500)} @selRoman = FXRadioButton.new(group, 'Convert to Roman Numerals', nil, LAYOUT_FILL_X ) { |r| connectRadio r } @selTapeNumbers = FXRadioButton.new(group, 'Convert Tape Numbers', nil, LAYOUT_FILL_X) { |r| connectRadio r } @selFill = FXRadioButton.new(group, 'Replace capture with last match capture:', nil, LAYOUT_FILL_X) { |r| connectRadio r } @fill = FXTextField.new group, 30, nil, PACK_UNIFORM_WIDTH @selFile = FXRadioButton.new(group, 'Replace from files.txt', nil, LAYOUT_FILL_X) { |r| connectRadio r } @selCount = FXRadioButton.new(group, 'Count', nil, LAYOUT_FILL_X) { |r| connectRadio r } @selMarkChange = FXRadioButton.new(group, 'Mark Changes', nil, LAYOUT_FILL_X) { |r| connectRadio r } @selFromFullName = FXRadioButton.new(group, 'Replace with capture in full name:', nil, LAYOUT_FILL_X) { |r| connectRadio r } @fullNamePattern = FXTextField.new group, 30, nil, PACK_UNIFORM_WIDTH @selMoveUp = FXRadioButton.new(group, 'Move to Parent Directory', nil, LAYOUT_FILL_X) { |r| connectRadio r } @selCapitalize = FXRadioButton.new(group, 'Capitalize', nil, LAYOUT_FILL_X) { |r| connectRadio r } } FXButton.new(controls, '&List Files', nil, nil, 0, LAYOUT_FILL_X | BUTTON_NORMAL) { |b| b.connect SEL_COMMAND, method(:onListClick) } FXButton.new(controls, '&Preview', nil, nil, 0, LAYOUT_FILL_X | FRAME_RAISED | FRAME_THICK) { |b| b.connect SEL_COMMAND, method(:onPreviewClick) } FXButton.new(controls, '&Apply', nil, nil, 0, LAYOUT_FILL_X | FRAME_RAISED | FRAME_THICK) { |b| b.connect SEL_COMMAND, method(:onReplaceClick) } } # results on right @results = FXText.new mainFrame, nil, 0, LAYOUT_FILL | FRAME_NORMAL | TEXT_READONLY @results.setFont(FXFont.new(getApp(), "courier new", 7)) } @selReplace.checkState = TRUE onRadioUpdate @selReplace, nil, nil end |
Instance Attribute Details
#renamer ⇒ Object
Returns the value of attribute renamer.
15 16 17 |
# File 'lib/gui.rb', line 15 def renamer @renamer end |
Instance Method Details
#connectRadio(r) ⇒ Object
87 88 89 |
# File 'lib/gui.rb', line 87 def connectRadio(r) r.connect SEL_COMMAND, method(:onRadioUpdate) end |
#onListClick(sender, sel, ptr) ⇒ Object
116 117 118 119 |
# File 'lib/gui.rb', line 116 def onListClick(sender, sel, ptr) start :list @dirList.setFocus end |
#onPreviewClick(sender, sel, ptr) ⇒ Object
108 109 110 |
# File 'lib/gui.rb', line 108 def onPreviewClick(sender, sel, ptr) start :preview end |
#onRadioUpdate(sender, sel, ptr) ⇒ Object
91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/gui.rb', line 91 def onRadioUpdate(sender, sel, ptr) sender.parent.each_child do |c| if FXRadioButton === c and c != sender c.checkState = FALSE end end @selReplace.checked? ? @replace.enable : @replace.disable @selAdd.checked? ? @add.enable : @add.disable @selFill.checked? ? @fill.enable : @fill.disable @selFromFullName.checked? ? @fullNamePattern.enable : @fullNamePattern.disable end |
#onReplaceClick(sender, sel, ptr) ⇒ Object
112 113 114 |
# File 'lib/gui.rb', line 112 def onReplaceClick(sender, sel, ptr) start :commit end |
#rename(name, args = {}) ⇒ Object
173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 |
# File 'lib/gui.rb', line 173 def rename(name, args = {}) args[:search] ||= PrepareRegexp.new @search.text args[:filter] = Filter.add(args[:filter], Filter.new(/^\.+$/)) args[:file_provider] = Provider::File::NonRecursive.new(Provider::Folder::Tree.new(@dirList)) PrepareRegexp.each(args) do |k, v| args[k] = t = v.create(false, false, true) do |mode, output| @r.output(mode, output) end end @renamer.run name, args do |*a| @r.output(*a) end end |
#rename_add(action) ⇒ Object
200 201 202 |
# File 'lib/gui.rb', line 200 def rename_add action rename :rename_add, :add => @add.value, :action => action end |
#rename_count(action) ⇒ Object
227 228 229 230 |
# File 'lib/gui.rb', line 227 def rename_count action rename(:rename_count, :count_start => 1, # could add a box for this option. :action => action) end |
#rename_files_txt(action) ⇒ Object
219 220 221 222 223 224 225 |
# File 'lib/gui.rb', line 219 def rename_files_txt action # note the name change rename(:rename_name_source, :source => NameFileSource.new('files.txt'), :filter => Filter.new(/^files.txt$/), :action => action) end |
#rename_fill(action) ⇒ Object
204 205 206 |
# File 'lib/gui.rb', line 204 def rename_fill action rename :rename_fill, :fill => PrepareRegexp.new(@fill.text), :action => action end |
#rename_from_full_name(action) ⇒ Object
208 209 210 |
# File 'lib/gui.rb', line 208 def rename_from_full_name action rename :rename_from_full_name, :pattern => PrepareRegexp.new(@fullNamePattern.text), :action => action end |
#rename_mark_change(action) ⇒ Object
212 213 214 215 216 217 |
# File 'lib/gui.rb', line 212 def rename_mark_change action rename(:rename_mark_change, :replace_pattern => PrepareRegexp.new('()$/'), # could add boxes for these options :replace_text => '--changed--', :action => action) end |
#rename_replace(action) ⇒ Object
– special functions
these should be changed to just return a hash of special options for the function. The rest is all wet. ++
196 197 198 |
# File 'lib/gui.rb', line 196 def rename_replace action rename :rename_replace, :replace => @replace.text, :action => action end |
#selected_function ⇒ Object
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 |
# File 'lib/gui.rb', line 121 def selected_function if @selReplace.checked? :rename_replace elsif @selFile.checked? :rename_files_txt elsif @selAdd.checked? :rename_add elsif @selCount.checked? :rename_count elsif @selFromFullName.checked? :rename_from_full_name elsif @selMoveUp.checked? :rename_move_up elsif @selRoman.checked? :rename_roman elsif @selMarkChange.checked? :rename_mark_change elsif @selTapeNumbers.checked? :rename_tape_numbers elsif @selCapitalize.checked? :rename_capitalize elsif @selFill.checked? :rename_fill else throw "No operation selected, or selection unknown." end end |
#start(action) ⇒ Object
149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 |
# File 'lib/gui.rb', line 149 def start(action) # require 'innate/reload' # reload 'providers' s = StringIO.new @r = CollectResults.new s, 60 # @r.lineways = true @r.list = action == :list begin fn = selected_function if methods.include? fn.to_s method(fn).call action else rename fn, :action => action end rescue => e @r.output(:error, e) end @r.display s.rewind @results.text = s.read.lstrip end |