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_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 |
# 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 } @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
86 87 88 |
# File 'lib/gui.rb', line 86 def connectRadio(r) r.connect SEL_COMMAND, method(:onRadioUpdate) end |
#onListClick(sender, sel, ptr) ⇒ Object
115 116 117 118 |
# File 'lib/gui.rb', line 115 def onListClick(sender, sel, ptr) start :list @dirList.setFocus end |
#onPreviewClick(sender, sel, ptr) ⇒ Object
107 108 109 |
# File 'lib/gui.rb', line 107 def onPreviewClick(sender, sel, ptr) start :preview end |
#onRadioUpdate(sender, sel, ptr) ⇒ Object
90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/gui.rb', line 90 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
111 112 113 |
# File 'lib/gui.rb', line 111 def onReplaceClick(sender, sel, ptr) start :commit end |
#rename(name, args = {}) ⇒ Object
169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 |
# File 'lib/gui.rb', line 169 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
191 192 193 |
# File 'lib/gui.rb', line 191 def rename_add action rename :rename_add, :add => @add.value, :action => action end |
#rename_files_txt(action) ⇒ Object
210 211 212 213 214 215 |
# File 'lib/gui.rb', line 210 def rename_files_txt action rename(:rename_name_source, :source => NameFileSource.new('files.txt'), :filter => Filter.new(/^files.txt$/), :action => action) end |
#rename_fill(action) ⇒ Object
195 196 197 |
# File 'lib/gui.rb', line 195 def rename_fill action rename :rename_fill, :fill => PrepareRegexp.new(@fill.text), :action => action end |
#rename_from_full_name(action) ⇒ Object
199 200 201 |
# File 'lib/gui.rb', line 199 def rename_from_full_name action rename :rename_from_full_name, :pattern => PrepareRegexp.new(@fullNamePattern.text), :action => action end |
#rename_mark_change(action) ⇒ Object
203 204 205 206 207 208 |
# File 'lib/gui.rb', line 203 def rename_mark_change action rename(:rename_mark_change, :replace_pattern => PrepareRegexp.new('()$/'), # I could add boxes for these options :replace_text => '--changed--', :action => action) end |
#rename_replace(action) ⇒ Object
special functions
187 188 189 |
# File 'lib/gui.rb', line 187 def rename_replace action rename :rename_replace, :replace => @replace.text, :action => action end |
#selected_function ⇒ Object
120 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 |
# File 'lib/gui.rb', line 120 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
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 |
# File 'lib/gui.rb', line 148 def start(action) s = StringIO.new @r = CollectResults.new s @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 |