Class: Watobo::Gui::HTMLViewerFrame
- Inherits:
-
FXVerticalFrame
- Object
- FXVerticalFrame
- Watobo::Gui::HTMLViewerFrame
- Defined in:
- lib/watobo/gui/html_viewer.rb
Instance Attribute Summary collapse
-
#max_len ⇒ Object
Returns the value of attribute max_len.
Instance Method Summary collapse
- #applyFilter ⇒ Object
- #getText ⇒ Object
- #highlight(pattern) ⇒ Object
-
#initialize(owner, opts) ⇒ HTMLViewerFrame
constructor
A new instance of HTMLViewerFrame.
- #setText(text, prefs = {}) ⇒ Object
Constructor Details
#initialize(owner, opts) ⇒ HTMLViewerFrame
Returns a new instance of HTMLViewerFrame.
127 128 129 130 131 132 133 134 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 |
# File 'lib/watobo/gui/html_viewer.rb', line 127 def initialize(owner, opts) super(owner, opts) @text_matches = [] @style = 2 # default style @text = '' @max_len = 5000 @filter_mode = SEL_TYPE_HIGHLIGHT @match_pos = 0 text_view_header = FXHorizontalFrame.new(self, :opts => LAYOUT_FILL_X|LAYOUT_SIDE_BOTTOM|LAYOUT_FIX_HEIGHT,:height => 24, :padding => 0) #@auto_apply_cbtn.connect(SEL_COMMAND, method(:onInterceptChanged)) pmatch_btn = FXButton.new(text_view_header, "<", nil, nil, 0, FRAME_RAISED|LAYOUT_FILL_Y) @match_pos_label = FXLabel.new(text_view_header, "0/0", :opts => LAYOUT_FILL_Y) @match_pos_label.textColor = 'grey' pmatch_btn.connect(SEL_COMMAND) { gotoPrevMatch() } nmatch_btn = FXButton.new(text_view_header, ">", nil, nil, 0, FRAME_RAISED|LAYOUT_FILL_Y) nmatch_btn.connect(SEL_COMMAND) { gotoNextMatch() } # @filter_text = FXTextField.new(text_view_header, 10, # :target => @filter_dt, :selector => FXDataTarget::ID_VALUE, # :opts => FRAME_SUNKEN|FRAME_THICK|LAYOUT_FILL_X|LAYOUT_FILL_Y) @filter_text = FXComboBox.new(text_view_header, 20, nil, 0, FRAME_SUNKEN|FRAME_THICK|LAYOUT_SIDE_TOP|LAYOUT_FILL_X) @filter_text.connect(SEL_COMMAND){ applyFilter() addFilterHistory() } @filter_text.connect(SEL_CHANGED) { applyFilter() } @auto_apply_cbtn = FXCheckButton.new(text_view_header, "auto-apply", nil, 0, ICON_BEFORE_TEXT|LAYOUT_SIDE_TOP|LAYOUT_RIGHT|LAYOUT_FILL_Y) text_box_frame = FXVerticalFrame.new(self, LAYOUT_FILL_X|LAYOUT_FILL_Y|FRAME_SUNKEN|FRAME_THICK, :padding => 0) @html_viewer = HTMLViewer.new(text_box_frame, :opts => LAYOUT_FILL_X|LAYOUT_FILL_Y) #searchflags = FXScintilla::SCFIND_WHOLEWORD|FXScintilla::SCFIND_MATCHCASE|FXScintilla::SCFIND_REGEXP|FXScintilla::SCFIND_WORDSTART @searchflags = FXScintilla::SCFIND_REGEXP @html_viewer.setSearchFlags @searchflags addHotkeyHandler(@html_viewer) addHotkeyHandler(@filter_text) # @filter_dt.connect(SEL_COMMAND) { applyFilter() } end |
Instance Attribute Details
#max_len ⇒ Object
Returns the value of attribute max_len.
82 83 84 |
# File 'lib/watobo/gui/html_viewer.rb', line 82 def max_len @max_len end |
Instance Method Details
#applyFilter ⇒ Object
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 |
# File 'lib/watobo/gui/html_viewer.rb', line 180 def applyFilter pattern = @filter_text.text return if pattern.empty? @match_pos_label.text = "0/0" @match_pos_label.textColor = 'grey' @text_matches = @html_viewer.search_text(pattern) if @text_matches.length > 0 @match_pos_label.textColor = 'black' @match_pos_label.text = "1/#{@text_matches.length}" show_match_pos(0) end end |
#getText ⇒ Object
123 124 125 |
# File 'lib/watobo/gui/html_viewer.rb', line 123 def getText @html_viewer.to_s end |
#highlight(pattern) ⇒ Object
119 120 121 |
# File 'lib/watobo/gui/html_viewer.rb', line 119 def highlight(pattern) highlightPattern(pattern) end |
#setText(text, prefs = {}) ⇒ Object
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/watobo/gui/html_viewer.rb', line 84 def setText(text, prefs={}) normalized_text = "- empty -" if text.is_a? String normalized_text = text.gsub(/[^[:print:]]/,".") elsif text.respond_to? :has_body? unless text.body.nil? or text.body.empty? body = text.body.strip if text.content_type =~ /(html|xml)/ doc = Nokogiri::XML(body, &:noblanks) fbody = doc.to_xhtml( indent:3, indent_text:" ") normalized_text = fbody.to_s else normalized_text = body end end elsif text.is_a? Array normalized_text = text.join end @text = normalized_text # puts normalized_text @html_viewer.setText(@text) #@html_viewer.encodedFromUTF8(normalized_text) @match_pos_label.text = "0/0" @match_pos_label.textColor = 'grey' @html_viewer.setTargetStart 0 @html_viewer.setTargetEnd @html_viewer.getLength applyFilter() if @auto_apply_cbtn.checked? end |