class HelpBrowser
this file is part of manqod manqod is distributed under the CDDL licence the author of manqod is Dobai-Pataky Balint(dpblnt@gmail.com)
Attributes
help[R]
item[R]
items[R]
Public Class Methods
new(help)
click to toggle source
Calls superclass method
# File lib/ManqodHelp/HelpBrowser.rb, line 7 def initialize(help) @help=help super() @item=nil @link_cursor = Gdk::Cursor.new(Gdk::Cursor::HAND2) @hover=false @items=Hash.new @text_view=Gtk::TextView.new(Gtk::TextBuffer.new(FormatTagTable.new(self))).set_editable(false) add_with_viewport(@text_view) @text_view.modify_font(Pango::FontDescription.new('Sans 12')).set_wrap_mode(Gtk::TextTag::WRAP_WORD) set_size_request(500,200) set_policy(Gtk::POLICY_NEVER,Gtk::POLICY_AUTOMATIC) @text_view.signal_connect('motion-notify-event'){|me, ev| x,y = me.window_to_buffer_coords(Gtk::TextView::WINDOW_WIDGET,ev.x,ev.y) iter=me.get_iter_at_location(x,y) onlink = false iter.tags.each{|t| onlink=true if t.link} if onlink != @hover @hover=onlink me.get_window(Gtk::TextView::WINDOW_TEXT).set_cursor(@hover ? @link_cursor : nil) end false } @text_view.signal_connect('visibility-notify-event'){|me,ev| me.get_window(Gtk::TextView::WINDOW_TEXT).set_cursor(@hover ? @link_cursor : nil) false } end
Public Instance Methods
add_item(item,description="")
click to toggle source
# File lib/ManqodHelp/HelpBrowser.rb, line 83 def add_item(item,description="") unless @items.has_key?(item) @items[item]=description buffer.tag_table.add(item) end self end
add_text(ont)
click to toggle source
# File lib/ManqodHelp/HelpBrowser.rb, line 118 def add_text(ont) txt=ont.clone bounds=Hash.new cr=buffer.tag_table.markup_regexp while cr.source.length>0 && code=txt[cr] bounds[code]=Array.new unless bounds.has_key?(code) bounds[code].push(txt.indexU(code)) txt[code]="" end buffer.insert_at_cursor(txt) bounds.each_pair{|code,b| if tag=buffer.tag_table.lookup_by_code(code) b.each_index{|i| buffer.apply_tag(tag,buffer.get_iter_at_offset(b[i]),buffer.get_iter_at_offset(b[i+1])) if (i.divmod(2)[1] == 0) && b[i+1] } end } end
apply_links()
click to toggle source
# File lib/ManqodHelp/HelpBrowser.rb, line 67 def apply_links @items.each_key{|tag_name| if tag=buffer.tag_table.lookup(tag_name) txt=buffer.get_text i=-1 while i=txt.indexU(tag_name,i+1) buffer.apply_tag(tag,buffer.get_iter_at_offset(i),buffer.get_iter_at_offset(i+tag_name.lengthU)) end end } end
buffer()
click to toggle source
# File lib/ManqodHelp/HelpBrowser.rb, line 40 def buffer @text_view.buffer end
clear_items()
click to toggle source
# File lib/ManqodHelp/HelpBrowser.rb, line 91 def clear_items @items.clear end
empty()
click to toggle source
# File lib/ManqodHelp/HelpBrowser.rb, line 78 def empty buffer.remove_all_tags(buffer.bounds[0],buffer.bounds[1]) buffer.delete(buffer.bounds[0],buffer.bounds[1]) end
load_index()
click to toggle source
# File lib/ManqodHelp/HelpBrowser.rb, line 57 def load_index p "creating index" txt="[h1]Index[h1]\n\n" @items.each_key{|key| txt="#{txt}#{key}\n" } empty add_text(txt) apply_links end
load_item(item)
click to toggle source
# File lib/ManqodHelp/HelpBrowser.rb, line 43 def load_item(item) # p "loading item:#{item}" @item=nil if @items.has_key?(item) empty add_text(@items[item]) apply_links @item=item true else p "item not found:#{item}" false end end
remove_current_item()
click to toggle source
# File lib/ManqodHelp/HelpBrowser.rb, line 95 def remove_current_item if @item @items.delete(@item) ManqodDB.instance.manqod_db.remove_help_item(@item) empty if tag=buffer.tag_table.lookup(@item) buffer.tag_table.remove(tag) end @item=nil @help.index.populate end end
save_current_item()
click to toggle source
# File lib/ManqodHelp/HelpBrowser.rb, line 107 def save_current_item ManqodDB.instance.manqod_db.save_help_item(@item,@items[@item]) end
update_current_item(descr)
click to toggle source
# File lib/ManqodHelp/HelpBrowser.rb, line 110 def update_current_item(descr) if @item @items[@item]=descr empty add_text(@items[@item]) apply_links end end