class FormatsEditor

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]

Public Class Methods

new(help) click to toggle source
Calls superclass method
# 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

Public Instance Methods

append_widget(text,widget) click to toggle source
# 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_tag() click to toggle source
# File lib/ManqodHelp/FormatsEditor.rb, line 97
def current_tag
        tag_table.lookup(@names.active_text)
end
populate() click to toggle source
# 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) click to toggle source
# 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
run() click to toggle source
# File lib/ManqodHelp/FormatsEditor.rb, line 133
def run
        populate_names
        populate
        show_all
end
tag_table() click to toggle source
# File lib/ManqodHelp/FormatsEditor.rb, line 94
def tag_table
        @help.browser.buffer.tag_table
end