Class: Ruber::FindInFiles::FindWidget
- Inherits:
-
Ruber::FilteredOutputWidget
- Object
- Qt::Widget
- OutputWidget
- Ruber::FilteredOutputWidget
- Ruber::FindInFiles::FindWidget
- Defined in:
- plugins/find_in_files/find_in_files_widgets.rb
Overview
Tool widget to display the output of a search.
It adds the “Filter on file names” toggle action to the RBM menu: when its on, any filter will be applied to the rows containing the file names; when it’s off (the default) the filter will only be applied to rows containing the found text.
Defined Under Namespace
Classes: Filter
Constant Summary
- FIND_ROLE =
The number of the role used to store the kind of find information stored in an index
IsTitleRole + 1
Constants inherited from OutputWidget
Instance Attribute Summary
Attributes inherited from Ruber::FilteredOutputWidget
Attributes inherited from OutputWidget
action_list, actions, auto_scroll, ignore_word_wrap_option, model, skip_first_file_in_title, view, working_dir
Instance Method Summary (collapse)
-
- (Object) clear_output
Remove the contents from the widget.
-
- (nil) display_output(lines)
Displays the output of rak in the widget.
-
- (Object) filter_on_filename_changed(b)
slot
private
Slot called when the user toggles the “Filter on file names” action.
-
- (String, Integer) find_filename_in_index(idx)
private
Override of OutputWidget#find_filename_in_index.
-
- (FindWidget) initialize(parent = nil)
constructor
Creates a new instance.
-
- (nil) setup_actions
private
Adds the custom actions to the RMB menu.
Methods inherited from Ruber::FilteredOutputWidget
#clear_filter, #copy, #copy_selected, #create_filter_from_editor, #create_standard_actions, #ignore_filter, keyReleaseEvent, #maybe_open_file, #scroll_to, #show_editor
Methods inherited from OutputWidget
#copy, #copy_selected, #create_standard_actions, #create_widgets, #do_auto_scroll, #fill_menu, #find_filename_in_string, #has_title?, #hints, #load_settings, #maybe_open_file, #pinned_down?, #rows_changed, #scroll_to, #selection_changed, #set_color_for, #set_output_type, #setup_model, #show_menu, #text_for_clipboard, #title=, #update_index_color, #with_auto_scrolling
Methods included from GuiStatesHandler
#change_state, included, #initialize_states_handler, #register_action_handler, #remove_action_handler_for, #state
Constructor Details
- (FindWidget) initialize(parent = nil)
Creates a new instance
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'plugins/find_in_files/find_in_files_widgets.rb', line 53 def initialize parent = nil super parent, :view => :tree, :filter => Filter.new, :use_default_font => true filter_model.filter_key_column = 1 filter_model.exclude = :toplevel model.append_column [] @current_file_item = Qt::StandardItem.new filter_model.connect(SIGNAL('rowsInserted(QModelIndex, int, int)')) do |par, st, en| if !par.valid? st.upto(en) do |i| view.set_first_column_spanned i, par, true view. filter_model.index(i, 0, par) end end end self.connect(SIGNAL(:about_to_fill_menu)) do actions.delete 'copy' actions.delete 'copy_selected' action_list.delete 'copy' action_list.delete 'copy_selected' end view.all_columns_show_focus = true view.header_hidden = true setup_actions end |
Instance Method Details
- (Object) clear_output
Remove the contents from the widget
109 110 111 112 113 |
# File 'plugins/find_in_files/find_in_files_widgets.rb', line 109 def clear_output @current_file_item = Qt::StandardItem.new super nil end |
- (nil) display_output(lines)
Displays the output of rak in the widget
Results in the same file are put under a single parent in the tree
have the format filename line|text
. Lines which don’t have this format are ignored
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'plugins/find_in_files/find_in_files_widgets.rb', line 87 def display_output lines lines.each do |l| match = l.match(/^(.+)\s+(\d+)\|(.*)$/) next unless match file, line, text = match.to_a[1..-1].map{|i| i.strip} if @current_file_item.text != file @current_file_item = model.insert(file, :message, nil)[0] @current_file_item.set_data Qt::Variant.new('file'), FIND_ROLE end it_line, it_text = model.insert [line.to_s, text], [:output1, :output], nil, :parent => @current_file_item it_line.set_data Qt::Variant.new('line'), FIND_ROLE it_text.set_data Qt::Variant.new('text'), FIND_ROLE end nil end |
- (Object) filter_on_filename_changed(b) (private)
Slot called when the user toggles the “Filter on file names” action
157 158 159 160 |
# File 'plugins/find_in_files/find_in_files_widgets.rb', line 157 def filter_on_filename_changed b filter_model.filter_key_column = b ? 0 : 1 filter_model.exclude = b ? :children : :toplevel end |
Slot Signature:
filter_on_filename_changed(bool)
- (String, Integer) find_filename_in_index(idx) (private)
Override of OutputWidget#find_filename_in_index
If the index corresponds to a file name, retrieves the line from the first child, while if it corresponds to a another entry, retrieves the file name from its parent and the line from the appropriate column on the same line
more information
140 141 142 143 144 145 146 147 148 149 150 |
# File 'plugins/find_in_files/find_in_files_widgets.rb', line 140 def find_filename_in_index idx it = model.item_from_index idx if it.data(FIND_ROLE).to_string == 'file' line = it.row_count > 0 ? it.child(0,0).text.to_i : 0 [it.text, line] else file = it.parent.text line = (it.data(FIND_ROLE).to_string == 'line' ? it : it.parent.child(it.row, 0)).text.to_i [file, line] end end |
- (nil) setup_actions (private)
Adds the custom actions to the RMB menu
122 123 124 125 126 127 128 |
# File 'plugins/find_in_files/find_in_files_widgets.rb', line 122 def setup_actions a = KDE::ToggleAction.new 'Filter on File Names', self actions['find_in_files-filter_on_files'] = a action_list.insert_after 'clear_filter', nil, 'find_in_files-filter_on_files' connect a, SIGNAL('toggled(bool)'), self, SLOT('filter_on_filename_changed(bool)') nil end |