Class: FormatsEditor

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

#initialize(help) ⇒ FormatsEditor

Returns a new instance of FormatsEditor.



6
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
# File 'lib/ManqodHelp/FormatsEditor.rb', line 6

def initialize(help)
	@help=help
	super()
	set_transient_for(help)
	set_modal(true)
	add(Gtk::VBox.new.
		pack_start(Gtk::HBox.new.pack_start(@names=Gtk::ComboBox.new).
			pack_start(@new_format=Gtk::Button.new(Gtk::Stock::NEW),false,false).
			pack_start(@remove_format=Gtk::Button.new(Gtk::Stock::REMOVE),false,false)
		).
		pack_start(@props=Gtk::Table.new(2,1))
	)
	append_widget("Name(unique):",@name=Gtk::Entry.new)
	append_widget("Code(regexp escaped):",@code=Gtk::Entry.new)
	append_widget("Font:",@font=Gtk::FontButton.new)
	append_widget("Foreground:",Gtk::HBox.new.pack_start(@foreground=Gtk::ColorButton.new).pack_start(@foreground_set=Gtk::ToggleButton.new("set"),false,false))
	append_widget("Background:",Gtk::HBox.new.pack_start(@background=Gtk::ColorButton.new).pack_start(@background_set=Gtk::ToggleButton.new("set"),false,false))
	append_widget("Justification:",@justification=FormatJustificationWidget.new(self))
	append_widget(nil,Gtk::HBox.new.pack_start(@underline=Gtk::ToggleButton.new(Gtk::Stock::UNDERLINE)).pack_start(@strikethrough=Gtk::ToggleButton.new(Gtk::Stock::STRIKETHROUGH)))

	@code.signal_connect('changed'){|me|
		if tag=tag_table.lookup(@names.active_text)
			tag.set_code(me.text).save
		end
	}
	@font.signal_connect("font-set"){|me|
		if tag=tag_table.lookup(@names.active_text)
			tag.set_font(me.font_name).save
		end
	}
	@foreground.signal_connect("color-set"){|me|
		if tag=tag_table.lookup(@names.active_text)
			tag.set_foreground_gdk(me.color).save
		end
	}
	@foreground_set.signal_connect('toggled'){|me|
		if tag=tag_table.lookup(@names.active_text)
			tag.set_foreground_set(me.active?).save
		end			
	}
	@background.signal_connect("color-set"){|me|
		if tag=tag_table.lookup(@names.active_text)
			tag.set_background_gdk(me.color).set_background_set(true).save
		end
	}
	@background_set.signal_connect('toggled'){|me|
		if tag=tag_table.lookup(@names.active_text)
			tag.set_background_set(me.active?).save
		end			
	}
	@underline.signal_connect("toggled"){|me|
		if tag=tag_table.lookup(@names.active_text)
			tag.set_underline(me.active? ? Pango::AttrUnderline::SINGLE : Pango::AttrUnderline::NONE).set_underline_set(me.active?).save
		end			
	}
	@strikethrough.signal_connect("toggled"){|me|
		if tag=tag_table.lookup(@names.active_text)
			tag.set_strikethrough(me.active?).set_strikethrough_set(me.active?).save
		end			
	}
	
	set_width_request(500)
	@names.signal_connect("changed"){|me|
		populate
	}
	@new_format.signal_connect('clicked',self){|me,fe|
		w=Gtk::Dialog.new("New format name",fe,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("Format Name(only use names that can't be links):"),false,false).pack_start(e=Gtk::Entry.new,false,false)
		w.show_all.run{|response|
			if response == Gtk::Dialog::RESPONSE_ACCEPT
				tag_table.add({"name"=>e.text})
				populate_names(e.text)
				tag=tag_table.lookup(e.text)
				ManqodDB.instance.manqod_db.save_help_format(e.text,tag.export)
			end
			w.destroy
		}
	}
	@remove_format.signal_connect('clicked'){|me|
		if tag=tag_table.lookup(@names.active_text)
			tag_table.remove(tag)
			populate_names
			ManqodDB.instance.manqod_db.remove_help_format(@names.active_text)
		end
	}
end

Instance Attribute Details

#helpObject (readonly)

Returns the value of attribute help.



92
93
94
# File 'lib/ManqodHelp/FormatsEditor.rb', line 92

def help
  @help
end

Instance Method Details

#append_widget(text, widget) ⇒ Object



127
128
129
130
131
132
# File 'lib/ManqodHelp/FormatsEditor.rb', line 127

def append_widget(text,widget)
	r=@props.n_rows
	@props.n_rows=@props.n_rows+1
	@props.attach_defaults(Gtk::Label.new(text),0,1,r,r+1)
	@props.attach_defaults(widget,1,2,r,r+1)
end

#current_tagObject



97
98
99
# File 'lib/ManqodHelp/FormatsEditor.rb', line 97

def current_tag
	tag_table.lookup(@names.active_text)
end

#populateObject



112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# File 'lib/ManqodHelp/FormatsEditor.rb', line 112

def populate
#		{"name"=>"_header","code"=>Regexp.escape("[h1]"),"font"=>"Sans Bold 20"}
	if @names.active_text && tag=tag_table.lookup(@names.active_text)
		@name.set_text(tag.name)
		@code.set_text(tag.code.to_s)
		@font.set_font_name(tag.font)
		@foreground.set_color(tag.foreground_gdk)
		@background.set_color(tag.background_gdk)
		@foreground_set.set_active(tag.foreground_set?)
		@background_set.set_active(tag.background_set?)
		@justification.set_value(tag.justification)
		@underline.set_active(tag.underline == Pango::AttrUnderline::SINGLE)
		@strikethrough.set_active(tag.strikethrough?)
	end
end

#populate_names(active = nil) ⇒ Object



101
102
103
104
105
106
107
108
109
110
# File 'lib/ManqodHelp/FormatsEditor.rb', line 101

def populate_names(active=nil)
	@names.model.clear
	tag_table.each{|tag|
		@names.append_text(tag.name) unless tag.link
	}
	i=nil
	while (i ? i.next! : i=@names.model.iter_first)
		@names.set_active_iter(i) if i[0] == active
	end
end

#runObject



133
134
135
136
137
# File 'lib/ManqodHelp/FormatsEditor.rb', line 133

def run
	populate_names
	populate
	show_all
end

#tag_tableObject



94
95
96
# File 'lib/ManqodHelp/FormatsEditor.rb', line 94

def tag_table
	@help.browser.buffer.tag_table
end