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.
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 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 |
# File 'lib/watobo/gui/chatviewer_frame.rb', line 60 def initialize(owner, opts) super(owner, opts) @text_matches = [] @style = 2 # default style @text = '' @max_len = -1 #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.
9 10 11 |
# File 'lib/watobo/gui/chatviewer_frame.rb', line 9 def max_len @max_len end |
Instance Method Details
#applyFilter ⇒ Object
131 132 133 134 135 136 137 138 139 140 141 142 143 144 |
# File 'lib/watobo/gui/chatviewer_frame.rb', line 131 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
15 16 17 |
# File 'lib/watobo/gui/chatviewer_frame.rb', line 15 def editable=(value) @simple_text_view.editable = value end |
#getText ⇒ Object
56 57 58 |
# File 'lib/watobo/gui/chatviewer_frame.rb', line 56 def getText @simple_text_view.textbox.to_s end |
#highlight(pattern) ⇒ Object
48 49 50 |
# File 'lib/watobo/gui/chatviewer_frame.rb', line 48 def highlight(pattern) highlightPattern(pattern) end |
#setFont(font_type = nil, size = nil) ⇒ Object
52 53 54 |
# File 'lib/watobo/gui/chatviewer_frame.rb', line 52 def setFont(font_type=nil, size=nil) @simple_text_view.setFont(font_type, size) end |
#setText(text, prefs = {}) ⇒ Object
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 |
# File 'lib/watobo/gui/chatviewer_frame.rb', line 19 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
11 12 13 |
# File 'lib/watobo/gui/chatviewer_frame.rb', line 11 def style=(new_style) @simple_text_view.style = new_style end |