Class: Watobo::Gui::CustomViewer
- Inherits:
-
FXVerticalFrame
- Object
- FXVerticalFrame
- Watobo::Gui::CustomViewer
- Defined in:
- lib/watobo/gui/custom_viewer.rb
Constant Summary collapse
- SEL_TYPE_GREP =
0- SEL_TYPE_HIGHLIGHT =
1
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) ⇒ CustomViewer
constructor
A new instance of CustomViewer.
- #setFont(font_type = nil, size = nil) ⇒ Object
- #setText(object = nil, prefs = {}) ⇒ Object
- #style=(new_style) ⇒ Object
Constructor Details
#initialize(owner, opts) ⇒ CustomViewer
Returns a new instance of CustomViewer.
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 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 |
# File 'lib/watobo/gui/custom_viewer.rb', line 142 def initialize(owner, opts) super(owner, opts) @text_matches = [] @style = 2 # default style @text = '' @object = nil @max_len = 5000 @filter_mode = SEL_TYPE_HIGHLIGHT @cur_match_pos = 0 @text_dt = FXDataTarget.new('') @filter_dt = FXDataTarget.new('') @handler = nil @handler_file = nil @handler_path = nil @handler_ctrl = ViewerHandlerCtrl.new(self) 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.
95 96 97 |
# File 'lib/watobo/gui/custom_viewer.rb', line 95 def max_len @max_len end |
Instance Method Details
#applyFilter ⇒ Object
220 221 222 223 224 225 226 227 228 229 230 231 232 233 |
# File 'lib/watobo/gui/custom_viewer.rb', line 220 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
101 102 103 |
# File 'lib/watobo/gui/custom_viewer.rb', line 101 def editable=(value) @simple_text_view.editable = value end |
#getText ⇒ Object
138 139 140 |
# File 'lib/watobo/gui/custom_viewer.rb', line 138 def getText @simple_text_view.textbox.to_s end |
#highlight(pattern) ⇒ Object
130 131 132 |
# File 'lib/watobo/gui/custom_viewer.rb', line 130 def highlight(pattern) highlightPattern(pattern) end |
#setFont(font_type = nil, size = nil) ⇒ Object
134 135 136 |
# File 'lib/watobo/gui/custom_viewer.rb', line 134 def setFont(font_type=nil, size=nil) @simple_text_view.setFont(font_type, size) end |
#setText(object = nil, prefs = {}) ⇒ Object
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
# File 'lib/watobo/gui/custom_viewer.rb', line 105 def setText(object=nil, prefs={}) o = object.nil? ? @object : object return false if o.nil? @object = o normalized_text = o.to_s if o.is_a? Watobo::Request or o.is_a? Watobo::Response if @handler_ctrl.has_handler? result = @handler_ctrl.call_handler(o) normalized_text = result end else return false end @text = normalized_text #@text = text @simple_text_view.max_len = -1 @simple_text_view.setText(normalized_text, prefs) @match_pos_label.text = "0/0" @match_pos_label.textColor = 'grey' applyFilter() if @auto_apply_cbtn.checked? end |
#style=(new_style) ⇒ Object
97 98 99 |
# File 'lib/watobo/gui/custom_viewer.rb', line 97 def style=(new_style) @simple_text_view.style = new_style end |