Class: Watobo::Gui::HTMLViewerFrame

Inherits:
FXVerticalFrame
  • Object
show all
Defined in:
lib/watobo/gui/html_viewer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(owner, opts) ⇒ HTMLViewerFrame

Returns a new instance of HTMLViewerFrame.



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
150
151
152
153
154
155
156
157
# File 'lib/watobo/gui/html_viewer.rb', line 106

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_lenObject

Returns the value of attribute max_len.



61
62
63
# File 'lib/watobo/gui/html_viewer.rb', line 61

def max_len
  @max_len
end

Instance Method Details

#applyFilterObject



159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
# File 'lib/watobo/gui/html_viewer.rb', line 159

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

#getTextObject



102
103
104
# File 'lib/watobo/gui/html_viewer.rb', line 102

def getText
  @html_viewer.to_s
end

#highlight(pattern) ⇒ Object



98
99
100
# File 'lib/watobo/gui/html_viewer.rb', line 98

def highlight(pattern)
  highlightPattern(pattern)
end

#setText(text, prefs = {}) ⇒ Object



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
# File 'lib/watobo/gui/html_viewer.rb', line 63

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