Class: HelpBrowser
- Inherits:
-
Gtk::ScrolledWindow
- Object
- Gtk::ScrolledWindow
- HelpBrowser
- Defined in:
- lib/ManqodHelp/HelpBrowser.rb
Overview
this file is part of manqod manqod is distributed under the CDDL licence the author of manqod is Dobai-Pataky Balint([email protected])
Instance Attribute Summary collapse
-
#help ⇒ Object
readonly
Returns the value of attribute help.
-
#item ⇒ Object
readonly
Returns the value of attribute item.
-
#items ⇒ Object
readonly
Returns the value of attribute items.
Instance Method Summary collapse
- #add_item(item, description = "") ⇒ Object
- #add_text(ont) ⇒ Object
- #apply_links ⇒ Object
- #buffer ⇒ Object
- #clear_items ⇒ Object
- #empty ⇒ Object
-
#initialize(help) ⇒ HelpBrowser
constructor
A new instance of HelpBrowser.
- #load_index ⇒ Object
- #load_item(item) ⇒ Object
- #remove_current_item ⇒ Object
- #save_current_item ⇒ Object
- #update_current_item(descr) ⇒ Object
Constructor Details
#initialize(help) ⇒ HelpBrowser
Returns a new instance of HelpBrowser.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# 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) (@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..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 |
Instance Attribute Details
#help ⇒ Object (readonly)
Returns the value of attribute help.
38 39 40 |
# File 'lib/ManqodHelp/HelpBrowser.rb', line 38 def help @help end |
#item ⇒ Object (readonly)
Returns the value of attribute item.
38 39 40 |
# File 'lib/ManqodHelp/HelpBrowser.rb', line 38 def item @item end |
#items ⇒ Object (readonly)
Returns the value of attribute items.
38 39 40 |
# File 'lib/ManqodHelp/HelpBrowser.rb', line 38 def items @items end |
Instance Method Details
#add_item(item, description = "") ⇒ Object
83 84 85 86 87 88 89 |
# 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) ⇒ Object
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
# 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 ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 |
# 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 ⇒ Object
40 41 42 |
# File 'lib/ManqodHelp/HelpBrowser.rb', line 40 def buffer @text_view.buffer end |
#clear_items ⇒ Object
91 92 93 |
# File 'lib/ManqodHelp/HelpBrowser.rb', line 91 def clear_items @items.clear end |
#empty ⇒ Object
78 79 80 81 |
# File 'lib/ManqodHelp/HelpBrowser.rb', line 78 def empty buffer.(buffer.bounds[0],buffer.bounds[1]) buffer.delete(buffer.bounds[0],buffer.bounds[1]) end |
#load_index ⇒ Object
57 58 59 60 61 62 63 64 65 66 |
# 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) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# 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 ⇒ Object
95 96 97 98 99 100 101 102 103 104 105 106 |
# 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 ⇒ Object
107 108 109 |
# 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) ⇒ Object
110 111 112 113 114 115 116 117 |
# 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 |