Class: Watobo::Gui::TextViewer
- Inherits:
-
FXVerticalFrame
- Object
- FXVerticalFrame
- Watobo::Gui::TextViewer
- Defined in:
- lib/watobo/gui/chatviewer_frame.rb
Instance Attribute Summary collapse
-
#max_len ⇒ Object
Returns the value of attribute max_len.
Instance Method Summary collapse
- #applyFilter ⇒ Object
- #editable=(value) ⇒ Object
- #getText ⇒ Object
- #highlight(pattern) ⇒ Object
-
#initialize(owner, opts) ⇒ TextViewer
constructor
A new instance of TextViewer.
- #setFont(font_type = nil, size = nil) ⇒ Object
- #setText(text, prefs = {}) ⇒ Object
- #style=(new_style) ⇒ Object
Constructor Details
#initialize(owner, opts) ⇒ TextViewer
Returns a new instance of TextViewer.
80 81 82 83 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 118 119 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 147 148 149 |
# File 'lib/watobo/gui/chatviewer_frame.rb', line 80 def initialize(owner, opts) super(owner, opts) @text_matches = [] @style = 2 # default style @text = '' @max_len = 5000 @filter_mode = SEL_TYPE_HIGHLIGHT @cur_match_pos = 0 @text_dt = FXDataTarget.new('') @filter_dt = FXDataTarget.new('') 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, @filter_dt, 0, FRAME_SUNKEN|FRAME_THICK|LAYOUT_SIDE_TOP|LAYOUT_FILL_X) @filter_text.connect(SEL_COMMAND){ applyFilter() addFilterHistory() } @filter_text.connect(SEL_CHANGED) { applyFilter() } = FXMenuPane.new(self) FXMenuCommand.new(, "&Highlight").connect(SEL_COMMAND){ @filter_mode = SEL_TYPE_HIGHLIGHT applyFilter() @mode_btn.text = "Highlight" }#, method(:switchMethod)) FXMenuCommand.new(, "&Grep").connect(SEL_COMMAND){ @filter_mode = SEL_TYPE_GREP applyFilter() @mode_btn.text = "Grep" }#, method(:switchMethod)) @auto_apply_cbtn = FXCheckButton.new(text_view_header, "auto-apply", nil, 0, ICON_BEFORE_TEXT|LAYOUT_SIDE_TOP|LAYOUT_RIGHT|LAYOUT_FILL_Y) @mode_btn = FXMenuButton.new(text_view_header, "Highlight", nil, , :opts=> MENUBUTTON_DOWN|FRAME_RAISED|FRAME_THICK|ICON_AFTER_TEXT|LAYOUT_RIGHT|LAYOUT_FILL_Y) = FXButton.new(text_view_header, "&Reset", nil, nil, 0, FRAME_RAISED|FRAME_THICK|LAYOUT_FILL_Y) .connect(SEL_COMMAND){ resetFilter() } text_box_frame = FXVerticalFrame.new(self, LAYOUT_FILL_X|LAYOUT_FILL_Y|FRAME_SUNKEN|FRAME_THICK, :padding => 0) @simple_text_view = SimpleTextView.new(text_box_frame, :opts => LAYOUT_FILL_X|LAYOUT_FILL_Y,:padding => 0) @simple_text_view.style = 1 @simple_text_view.editable = false @simple_text_view.textStyle -= TEXT_WORDWRAP addHotkeyHandler(@simple_text_view.textbox) addHotkeyHandler(@filter_text) @filter_dt.connect(SEL_COMMAND) { applyFilter() } end |
Instance Attribute Details
#max_len ⇒ Object
Returns the value of attribute max_len.
30 31 32 |
# File 'lib/watobo/gui/chatviewer_frame.rb', line 30 def max_len @max_len end |
Instance Method Details
#applyFilter ⇒ Object
151 152 153 154 155 156 157 158 159 160 161 162 163 164 |
# File 'lib/watobo/gui/chatviewer_frame.rb', line 151 def applyFilter pattern = @filter_text.text @match_pos_label.text = "0/0" @simple_text_view.resetMatches() @simple_text_view.setText(@text) @match_pos_label.textColor = 'grey' return true if pattern == '' case @filter_mode when SEL_TYPE_GREP grepPattern(pattern) when SEL_TYPE_HIGHLIGHT highlightPattern(pattern) end end |
#editable=(value) ⇒ Object
35 36 37 |
# File 'lib/watobo/gui/chatviewer_frame.rb', line 35 def editable=(value) @simple_text_view.editable = value end |
#getText ⇒ Object
76 77 78 |
# File 'lib/watobo/gui/chatviewer_frame.rb', line 76 def getText @simple_text_view.textbox.to_s end |
#highlight(pattern) ⇒ Object
68 69 70 |
# File 'lib/watobo/gui/chatviewer_frame.rb', line 68 def highlight(pattern) highlightPattern(pattern) end |
#setFont(font_type = nil, size = nil) ⇒ Object
72 73 74 |
# File 'lib/watobo/gui/chatviewer_frame.rb', line 72 def setFont(font_type=nil, size=nil) @simple_text_view.setFont(font_type, size) end |
#setText(text, prefs = {}) ⇒ Object
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 |
# File 'lib/watobo/gui/chatviewer_frame.rb', line 39 def setText(text, prefs={}) normalized_text = text if text.is_a? String normalized_text = text.gsub(/[^[:print:]]/,".") elsif text.respond_to? :has_body? if text.content_type =~ /(xml)/ doc = Nokogiri::XML(text.body, &:noblanks) fbody = doc.to_xhtml( indent:3, indent_text:" ") normalized_text = text.headers.map{|h| h.strip }.join("\n") normalized_text << "\n\n" unless fbody.to_s.empty? normalized_text << fbody.to_s else normalized_text = text end end end @text = normalized_text #@text = text @simple_text_view.max_len = @max_len @simple_text_view.setText(text, prefs) @match_pos_label.text = "0/0" @match_pos_label.textColor = 'grey' applyFilter() if @auto_apply_cbtn.checked? end |
#style=(new_style) ⇒ Object
31 32 33 |
# File 'lib/watobo/gui/chatviewer_frame.rb', line 31 def style=(new_style) @simple_text_view.style = new_style end |