Class: ManqodHelp

Inherits:
Gtk::Window
  • Object
show all
Defined in:
lib/ManqodHelp.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

Instance Method Summary collapse

Constructor Details

#initializeManqodHelp

Returns a new instance of ManqodHelp.



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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
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
# File 'lib/ManqodHelp.rb', line 7

def initialize
	@admin=false
	super()
	set_title("Manqod Help")
	add(vb=Gtk::VBox.new)
	vb.pack_start(@toolbar=HelpToolbar.new(self),false,false).
		pack_start(hp=Gtk::HPaned.new)

	toolbar.append(@back_button=Gtk::ToolButton.new(Gtk::Stock::GO_BACK))
	toolbar.append
	toolbar.append(Gtk::Label.new("Search:"))
	toolbar.append(@filter=Gtk::Entry.new)
	toolbar.append(filter_button=Gtk::ToolButton.new(Gtk::Stock::FIND))
	toolbar.append(clear=Gtk::ToolButton.new(Gtk::Stock::CLEAR))
	toolbar.append
	toolbar.append(@formats_button=Gtk::ToolButton.new(Gtk::Stock::BOLD).set_no_show_all(true))
	toolbar.append(@new_item_button=Gtk::ToolButton.new(Gtk::Stock::NEW).set_no_show_all(true))
	toolbar.append(@edit_item_button=Gtk::ToolButton.new(Gtk::Stock::EDIT).set_no_show_all(true))
	toolbar.append(@delete_item_button=Gtk::ToolButton.new(Gtk::Stock::DELETE).set_no_show_all(true))
	toolbar.append(hidden=Gtk::EventBox.new.add(Gtk::Label.new)).set_expand(true)
	toolbar.append
	toolbar.append(@close=Gtk::ToolButton.new(Gtk::Stock::CLOSE))

	hp.add1(@index=HelpIndex.new(self)).
		add2(@browser=HelpBrowser.new(self)).
		set_position(150).
		set_position_set(true)

	filter.signal_connect('activate',filter_button){|me,filter_button|
		filter_button.clicked
	}
	filter_button.signal_connect('clicked'){|me|
		@index.refilter
	}
	clear.signal_connect('clicked'){|me|
		filter.text=""
		@index.refilter
	}
	@back_button.signal_connect('clicked'){|me|
		@index.go_back
	}
	@close.signal_connect('clicked'){|me|
		destroy
	}
	hidden.signal_connect('event'){|me,ev|
		if ev.event_type == Gdk::Event::BUTTON3_PRESS
			@admin=!@admin
			@formats_button.set_visible(@admin)
			@new_item_button.set_visible(@admin)
			@edit_item_button.set_visible(@admin)
			@delete_item_button.set_visible(@admin)
		end
	}
	@formats_button.signal_connect('clicked'){|me|
		FormatsEditor.new(self).run
	}
	@new_item_button.signal_connect('clicked'){|me|
		w=Gtk::Dialog.new("New item index",self,Gtk::Dialog::MODAL|Gtk::Dialog::DESTROY_WITH_PARENT,[Gtk::Stock::NEW,Gtk::Dialog::RESPONSE_ACCEPT],[Gtk::Stock::CANCEL,Gtk::Dialog::RESPONSE_REJECT]).set_default_response(Gtk::Dialog::RESPONSE_ACCEPT)
		w.vbox.pack_start(Gtk::Label.new("Item Index(only use indexes that you want to be links):"),false,false).pack_start(e=Gtk::Entry.new,false,false)
		w.show_all.run{|response|
			if response == Gtk::Dialog::RESPONSE_ACCEPT
				browser.add_item(e.text)
				index.populate.set_cursor(e.text)
				browser.save_current_item
			end
			w.destroy
		}

	}
	@edit_item_button.signal_connect('clicked'){|me|
		if browser.item
			w=Gtk::Dialog.new("Editing item",self,Gtk::Dialog::MODAL|Gtk::Dialog::DESTROY_WITH_PARENT,[Gtk::Stock::CLOSE,Gtk::Dialog::RESPONSE_ACCEPT]).set_default_response(Gtk::Dialog::RESPONSE_ACCEPT)
			w.vbox.pack_start(Gtk::ScrolledWindow.new.add(e=Gtk::TextView.new).set_size_request(400,200).set_policy(Gtk::POLICY_AUTOMATIC,Gtk::POLICY_AUTOMATIC),false,false)
			e.buffer.set_text(browser.items[browser.item])
			e.buffer.signal_connect('changed'){|me| browser.update_current_item(me.get_text)}
			w.show_all.run{|response|
				browser.save_current_item
				w.destroy
			}
		end
	}
	@delete_item_button.signal_connect('clicked'){|me|
		if browser.item
			w=Gtk::Dialog.new("Removing item",self,Gtk::Dialog::MODAL|Gtk::Dialog::DESTROY_WITH_PARENT,[Gtk::Stock::DELETE,Gtk::Dialog::RESPONSE_ACCEPT],[Gtk::Stock::CANCEL,Gtk::Dialog::RESPONSE_REJECT]).set_default_response(Gtk::Dialog::RESPONSE_REJECT)
			w.vbox.pack_start(Gtk::Label.new("Are you sure about removing the selected item?"),false,false)
			w.show_all.run{|response| 
				browser.remove_current_item if response == Gtk::Dialog::RESPONSE_ACCEPT
				w.destroy
			}
		end
	}
	update_back_button
end

Instance Attribute Details

#adminObject (readonly)

Returns the value of attribute admin.



101
102
103
# File 'lib/ManqodHelp.rb', line 101

def admin
  @admin
end

#browserObject (readonly)

Returns the value of attribute browser.



100
101
102
# File 'lib/ManqodHelp.rb', line 100

def browser
  @browser
end

#filterObject (readonly)

Returns the value of attribute filter.



101
102
103
# File 'lib/ManqodHelp.rb', line 101

def filter
  @filter
end

#indexObject (readonly)

Returns the value of attribute index.



100
101
102
# File 'lib/ManqodHelp.rb', line 100

def index
  @index
end

#toolbarObject (readonly)

Returns the value of attribute toolbar.



100
101
102
# File 'lib/ManqodHelp.rb', line 100

def toolbar
  @toolbar
end

Instance Method Details

#populateObject



103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/ManqodHelp.rb', line 103

def populate
	browser.clear_items
	browser.buffer.tag_table.clear
	i=ManqodDB.instance.cache.get("help_items")
	i.each_pair{|key,descr| browser.add_item(key,descr)}
	index.populate

	i=ManqodDB.instance.cache.get("help_formats")
	i.each_pair{|key,format| browser.buffer.tag_table.add(format)}
#		buffer.tag_table.add({"name"=>"_header","code"=>Regexp.escape("[h1]"),"font"=>"Sans Bold 20"})
	
	self
end

#update_back_buttonObject



116
117
118
# File 'lib/ManqodHelp.rb', line 116

def update_back_button
	@back_button.set_sensitive(@index.can_go_back?)
end