Class: Ruber::FindInFiles::FindReplaceInFilesDlg
- Inherits:
-
KDE::Dialog
- Object
- KDE::Dialog
- Ruber::FindInFiles::FindReplaceInFilesDlg
- Defined in:
- plugins/find_in_files/find_in_files_dlg.rb
Overview
Dialog to set options for search/replace in files.
A single dialog is used for both search and replace. The action performed depends on whether the user clicks the Find or the Replace button. This dialog can be used either as a modal or modeless dialog: if it is modal, use the value returned by #action to see whether the user chose find or replace; in modeless mode rely on the #find and #replace signals.
Defined Under Namespace
Constant Summary
- MODES =
A list of possible matching modes
[:regexp, :plain]
- PLACES =
A list of possible files where to search files
[:project_files, :project_dir, :open_files, :custom_dir]
- FILE_TYPES =
A map between the text shown in the file type widget and rak options
{ 'C++ files' => :cpp, 'C files' => :c, 'C# files' => :csharp, 'CSS files' => :css, 'Elisp files' => :elisp, 'Erlang files' => :erlang, 'Fortran files' => :fortran, 'Haskell files' => :haskell, 'hh files' => :hh, 'HTML files' => :html, 'Java files' => :java, 'Javascript file' => :js, 'jsp files' => :jsp, 'Lisp files' => :lisp, 'Makefiles' => :make, 'Mason files' => :mason, 'OCaml files' => :ocaml, 'Parrot files' => :parrot, 'Perl files' => :perl, 'PHP files' => :php, 'Prolog files' => :prolog, 'Python files' => :python, 'Ruby files' => :ruby, 'Scheme files' => :scheme, 'Shell files' => :shell, 'SQL files' => :sql, 'TCL files' => :tcl, 'TeX files' => :tex, 'Text files' => :text, 'tt files' => :tt, 'Visual Basic files' => :vb, 'Vim files' => :vim, 'XML files' => :xml, 'YAML files' => :yaml }
Instance Attribute Summary (collapse)
-
- (Symbol?) action
readonly
The action chosen by the user when closing the dialog he chose the Replace button and nil if he pressed the Cancel button or if the dialog hasn???t been closed as yet.
Instance Method Summary (collapse)
-
- (nil) add_completions
private
Adds the values in the various line edit widgets to the respective completers.
-
- (Boolean) all_files?
Whether the search should be made on all files or only on some file types.
-
- (Boolean) allow_project(val)
Whether the “Project files” and “Project directory” entries should be shown in the Search in widget or not.
-
- (Boolean) case_sensitive?
Whether the search should be case sensitive or not.
-
- (Object) clear
Sets the contents of the dialog???s widgets to their default values.
-
- (nil) create_filter_text
private
Fills the text of the File type widget with a string according to the selected entries.
-
- (String?) custom_filter
The regexp to pass to rak -g option.
-
- (String?) directory
The contents of the Directory widget is disabled (because the user chose something else than Custom directory in the Search in widget).
-
- (Boolean) eventFilter(obj, e)
Event filter to make the Predefined filters combo box be checkable.
-
- (<Symbol>?) filters
The file types the search should be restricted to types combo box (converted so they match the name of the options rak accepts) or nil if the user checked the All files radio button.
-
- (String) find_text
The text in the Find widget.
-
- (FindReplaceInFilesDlg) initialize(parent = Ruber[:main_window])
constructor
A new instance of FindReplaceInFilesDlg.
-
- (Symbol) mode
The mode chosen by the user.
-
- (Symbol) places
Where to find the files to search:.
-
- (String) replacement_text
The text in the Replace widget.
-
- (Boolean) whole_words?
Whether the search should be performed only in whole words or not.
Signal Summary
-
- find
Signal emitted when the user presses the Find button.
-
- replace
Signal emitted when the user presses the Replace button.
Constructor Details
- (FindReplaceInFilesDlg) initialize(parent = Ruber[:main_window])
A new instance of FindReplaceInFilesDlg
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 |
# File 'plugins/find_in_files/find_in_files_dlg.rb', line 135 def initialize parent = Ruber[:main_window] @operation = nil super User1|User2|Cancel User1, KDE.i18n('Replace') User2, KDE.i18n('Find') User2 User1, false User2, false @ui = ::Ui::FindReplaceInFilesWidget.new @ui.setupUi @ui.find_text.completer = Completer.new @ui.find_text @ui.replace_text.completer = Completer.new @ui.replace_text @ui.custom_filter.completer = Completer.new @ui.custom_filter @ui.directory.mode = KDE::File::Directory @ui.find_text.connect SIGNAL('textChanged(QString)') do enable = !@ui.find_text.text.empty? User1, enable User2, enable end @ui.replace_text.connect(SIGNAL('textChanged(QString)')) do self. = @ui.replace_text.text.empty? ? User2 : User1 end @ui.places.connect(SIGNAL('currentIndexChanged(int)')) do |i| @ui.directory.enabled = (i == @ui.places.count - 1) end (User1).connect SIGNAL(:clicked) do @action = :replace add_completions accept emit replace end (User2).connect SIGNAL(:clicked) do @action = :find add_completions accept emit find end @ui.use_predefined_filters.connect SIGNAL('toggled(bool)') do |b| @ui.types.enabled = b end @ui.all_files.connect SIGNAL('toggled(bool)') do |b| @ui.types.enabled = !b end @ui.types.line_edit.read_only = true @ui.types.view.install_event_filter Filter.new(self) @ui.types.view..install_event_filter Filter.new(self) @ui.types.add_items FILE_TYPES.keys.sort @ui.types.model.each do |i| i.checkable = true i.checked = (i.text == 'Ruby files' || i.text == 'YAML files') end create_filter_text end |
Instance Attribute Details
- (Symbol?) action (readonly)
The action chosen by the user when closing the dialog he chose the Replace button and nil if he pressed the Cancel button or if the dialog hasn???t been closed as yet
130 131 132 |
# File 'plugins/find_in_files/find_in_files_dlg.rb', line 130 def action @action end |
Instance Method Details
- (nil) add_completions (private)
Adds the values in the various line edit widgets to the respective completers
373 374 375 376 377 |
# File 'plugins/find_in_files/find_in_files_dlg.rb', line 373 def add_completions @ui.find_text.completer.add_entry @ui.find_text.text @ui.replace_text.completer.add_entry @ui.replace_text.text unless @ui.replace_text.text.empty? @ui.custom_filter.completer.add_entry @ui.custom_filter.text unless @ui.custom_filter.text.empty? end |
- (Boolean) all_files?
Whether the search should be made on all files or only on some file types
those with file type matching the entries selected in the File type combo box
290 291 292 |
# File 'plugins/find_in_files/find_in_files_dlg.rb', line 290 def all_files? @ui.all_files.checked? end |
- (Boolean) allow_project=(val)
Whether the “Project files” and “Project directory” entries should be shown in the Search in widget or not.
209 210 211 212 213 214 215 |
# File 'plugins/find_in_files/find_in_files_dlg.rb', line 209 def allow_project= val if @ui.places.count == 4 and !val 2.times{@ui.places.remove_item 0} elsif @ui.places.count == 2 and val @ui.places.insert_items 0, ['Project files', 'Project directory'] end end |
- (Boolean) case_sensitive?
Whether the search should be case sensitive or not
256 257 258 |
# File 'plugins/find_in_files/find_in_files_dlg.rb', line 256 def case_sensitive? @ui.case_sensitive.checked? end |
- (Object) clear
Sets the contents of the dialog???s widgets to their default values
This method doesn’t erase the completers and is usually called before showing the dialog. Note: this also sets allow_project to true
326 327 328 329 330 331 332 333 334 335 336 337 338 339 |
# File 'plugins/find_in_files/find_in_files_dlg.rb', line 326 def clear self.allow_project = true @action = nil @ui.find_text.text='' @ui.replace_text.clear @ui.mode.current_index = 0 @ui.whole_words.checked = false @ui.case_sensitive.checked = true @ui.use_predefined_filters.checked = true @ui.custom_filter.clear @ui.places.current_index = 0 @ui.find_text.set_focus @ui.directory.enabled = false end |
- (nil) create_filter_text (private)
Fills the text of the File type widget with a string according to the selected entries
384 385 386 387 388 |
# File 'plugins/find_in_files/find_in_files_dlg.rb', line 384 def create_filter_text text = @ui.types.model.select{|i| i.checked?}.map{|i| i.text}.join '; ' text = 'All files' if text.empty? @ui.types.edit_text = text end |
- (String?) custom_filter
The regexp to pass to rak -g option
the Custom filter widget
279 280 281 282 |
# File 'plugins/find_in_files/find_in_files_dlg.rb', line 279 def custom_filter text = @ui.custom_filter.text text.empty? ? nil : text end |
- (String?) directory
The contents of the Directory widget is disabled (because the user chose something else than Custom directory in the Search in widget)
316 317 318 |
# File 'plugins/find_in_files/find_in_files_dlg.rb', line 316 def directory @ui.directory.enabled? ? @ui.directory.text : nil end |
- (Boolean) eventFilter(obj, e)
Event filter to make the Predefined filters combo box be checkable.
346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 |
# File 'plugins/find_in_files/find_in_files_dlg.rb', line 346 def eventFilter obj, e if e.type == Qt::Event::MouseButtonRelease obj=obj.parent unless obj.is_a?(Qt::ListView) idx = obj.index_at e.pos if idx.valid? op = Qt::StyleOption.new op.initFrom obj op.rect = obj.visual_rect(idx) r = obj.style.sub_element_rect(Qt::Style::SE_ViewItemCheckIndicator, op) if r.contains(e.pos) it = @ui.types.model.item_from_index idx it.checked = !it.checked? create_filter_text return true end end end false end |
- (<Symbol>?) filters
The file types the search should be restricted to types combo box (converted so they match the name of the options rak accepts) or nil if the user checked the All files radio button
266 267 268 269 270 271 |
# File 'plugins/find_in_files/find_in_files_dlg.rb', line 266 def filters if @ui.use_predefined_filters.checked? @ui.types.model.map{|i| i.checked? ? FILE_TYPES[i.text] : nil}.compact else nil end end |
- (String) find_text
The text in the Find widget
221 222 223 |
# File 'plugins/find_in_files/find_in_files_dlg.rb', line 221 def find_text @ui.find_text.text end |
- (Symbol) mode
The mode chosen by the user.
237 238 239 |
# File 'plugins/find_in_files/find_in_files_dlg.rb', line 237 def mode MODES[@ui.mode.current_index] end |
- (Symbol) places
Where to find the files to search:
in the Search in combo box:
:project_files
perform the search only among the files belonging to the current project:project_directory
perform the search among all the files in the current proejct???s directory:open_files
perform the search only in files corresponding to open documents (note that the search will be performed in the files, not in the text in the documents):custom_dir
perform the search among all the files in the directory selected by the user in the Directory widget
304 305 306 307 308 |
# File 'plugins/find_in_files/find_in_files_dlg.rb', line 304 def places idx = @ui.places.current_index idx +=2 if @ui.places.count == 2 PLACES[idx] end |
- (String) replacement_text
The text in the Replace widget
229 230 231 |
# File 'plugins/find_in_files/find_in_files_dlg.rb', line 229 def replacement_text @ui.replace_text.text end |
- (Boolean) whole_words?
Whether the search should be performed only in whole words or not
or also in the middle of a word
247 248 249 |
# File 'plugins/find_in_files/find_in_files_dlg.rb', line 247 def whole_words? @ui.whole_words.checked? end |
Signal Details
- find
Signal emitted when the user presses the Find button.
- replace
Signal emitted when the user presses the Replace button.