class MenuHolder

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

holder[RW]
last[RW]
pack_dir[RW]
parent_menu[RW]

Public Class Methods

new(parent_menu,pack_dir="horizontal") click to toggle source
Calls superclass method
# File lib/ButtonMenu.rb, line 10
  def initialize(parent_menu,pack_dir="horizontal")
        @parent_menu=parent_menu
        @pack_dir=pack_dir
        @last=nil
        if pack_dir=="vertical" then super(1,1,0,1);else super(1,1,1,0);end
        @holder=if pack_dir=="vertical" then Gtk::VBox.new; else Gtk::HBox.new;end
        holder.set_homogeneous(false)
        holder.set_border_width(0)
        add(holder)
#       add(Gtk::Frame.new.add(holder))
#       set_layout_style(Gtk::ButtonBox::SPREAD)
#       set_icon_size_set(true)
#       set_icon_size(Gtk::IconSize.from_name("gtk-small-toolbar"))
        reinitialize
  end

Public Instance Methods

hide_items(except_this=nil) click to toggle source
# File lib/ButtonMenu.rb, line 103
  def hide_items(except_this=nil)
        holder.each{|menuitem|
                if menuitem==except_this
                  menuitem.show
                  edebug(menuitem.inspect+" showing","menu","debug")
                  else
                  menuitem.hide
                  edebug(menuitem.inspect+" hiding","menu","debug")
                end #if menuitem.class.name == "MenuItem"
#         end
        }
  end
hide_tree() click to toggle source
# File lib/ButtonMenu.rb, line 96
def hide_tree
      holder.each{|menuitem|
        menuitem.submenu.hide_items if menuitem.class.name=="ButtonMenuItem" and menuitem.submenu
      }
      hide_items
end
inspect() click to toggle source
# File lib/ButtonMenu.rb, line 146
def inspect
              ret="ButtonMenuHolder"
              ret=ret+" of "+parent_menu.text if parent_menu.class.name == "ButtonMenuItem"
              ret
end
recmenuitem(parentid,pmenu) click to toggle source
# File lib/ButtonMenu.rb, line 34
                def recmenuitem(parentid,pmenu)
                        menuitem=nil
                        admin_rows("select gtkmenu.*,
ifnull(childs.cnt,0) as child_cnt
from gtkmenu 
left join (select count(id) as cnt,parent from gtkmenu group by gtkmenu.parent) as childs on childs.parent = gtkmenu.id
left join (select count(id) as cnt, groupid from usergroups where userid='#{nick_id}' group by groupid) as perm on perm.groupid = gtkmenu.groupid
where gtkmenu.parent='#{parentid}' and (perm.cnt>0) order by oid"){|row|
                                menuitem=ButtonMenuItem.new(row['id'],pmenu)
                                if pmenu.nil?
                                        menuitem.add_observer(self)
                                else
                                        menuitem.add_observer(pmenu) 
                                end
                                @last=menuitem if row['id'].to_i==get_conf(0,0,"lastmenu").to_i
                                if row['child_cnt'].to_i > 0 
                                        menuitem.submenu=MenuHolder.new(menuitem,pack_dir)
                                        @last=menuitem.submenu.last if menuitem.submenu.last
                                end
                                holder.pack_start(menuitem,false,true)
                                holder.pack_start(menuitem.submenu,false,true) if menuitem.submenu
                        }
                        edebug("#{menuitem.inspect}(parentid: #{parentid}) added","menu","debug")
                        menuitem# unless menuitem.nil?
                end
reinitialize() click to toggle source
# File lib/ButtonMenu.rb, line 30
        def reinitialize
                def remove_main_menu_items(pmenu)
                        pmenu.holder.each{|menu_item| pmenu.remove(menu_item)}
                end
                def recmenuitem(parentid,pmenu)
                        menuitem=nil
                        admin_rows("select gtkmenu.*,
ifnull(childs.cnt,0) as child_cnt
from gtkmenu 
left join (select count(id) as cnt,parent from gtkmenu group by gtkmenu.parent) as childs on childs.parent = gtkmenu.id
left join (select count(id) as cnt, groupid from usergroups where userid='#{nick_id}' group by groupid) as perm on perm.groupid = gtkmenu.groupid
where gtkmenu.parent='#{parentid}' and (perm.cnt>0) order by oid"){|row|
                                menuitem=ButtonMenuItem.new(row['id'],pmenu)
                                if pmenu.nil?
                                        menuitem.add_observer(self)
                                else
                                        menuitem.add_observer(pmenu) 
                                end
                                @last=menuitem if row['id'].to_i==get_conf(0,0,"lastmenu").to_i
                                if row['child_cnt'].to_i > 0 
                                        menuitem.submenu=MenuHolder.new(menuitem,pack_dir)
                                        @last=menuitem.submenu.last if menuitem.submenu.last
                                end
                                holder.pack_start(menuitem,false,true)
                                holder.pack_start(menuitem.submenu,false,true) if menuitem.submenu
                        }
                        edebug("#{menuitem.inspect}(parentid: #{parentid}) added","menu","debug")
                        menuitem# unless menuitem.nil?
                end
        
                remove_main_menu_items(self)
                case parent_menu.class.name
                        when 'MainRouter'
                                fomenu=recmenuitem(-1,nil)
                                add_observer(parent_menu)
                                if last.nil?
                                        begin
                                                fomenu.show_up(fomenu)
                                        rescue =>err
                                                tell_exception("no main menu!",backtrace_to_debug(err),"menu","error",false,false,"you might not have permission to view the main menu")
                                        end
                                else
                                        last.show_up(last)
                                end
                        when 'ButtonMenuItem'
                                holder.pack_start(StartSeparator.new(pack_dir),true,true) if !parent_menu.parent_menu.nil?
                                recmenuitem(parent_menu.menu_id,parent_menu)
                                holder.pack_end(EndSeparator.new(pack_dir),true,true) if !parent_menu.parent_menu.nil?
                        else
                                edebug("reinitialize: unknown routing(#{caller.class.name})","menu","warning")
                end
#       show_all
        end
remove_main_menu_items(pmenu) click to toggle source
# File lib/ButtonMenu.rb, line 31
def remove_main_menu_items(pmenu)
        pmenu.holder.each{|menu_item| pmenu.remove(menu_item)}
end
show_items(new_size,caller) click to toggle source
# File lib/ButtonMenu.rb, line 84
def show_items(new_size,caller)
        before_caller=true
        holder.each{|menuitem|
                menuitem.resize_image(new_size) if menuitem.class.name == "ButtonMenuItem"
#        set_child_packing(menuitem,false,true,1,Gtk::PackType::START) if before_caller
#        set_child_packing(menuitem,false,true,1,Gtk::PackType::END) if !before_caller
                menuitem.show
                before_caller=false if caller == menuitem
                edebug("#{menuitem} showing","menu")
        }
end
to_s() click to toggle source
# File lib/ButtonMenu.rb, line 151
def to_s
      inspect
end
update(notifier) click to toggle source
# File lib/ButtonMenu.rb, line 116
        def update(notifier)
                case notifier.class.name
                        when 'MyWindow'
                                edebug(inspect+" emiting signal","menu","debug")
#               reinitialize
                                if last
                                        last.show_up(last)
                                        changed
                                        notify_observers(last)
                                end
                        when 'ButtonMenuItem'
                                if notifier.target
                                        @last=notifier
                                        set_conf(0,0,"lastmenu",notifier.menu_id) if notifier.modname != "quit"
                                        edebug(inspect+" emiting signal","menu","debug")
                                        changed
                  #focused=get_ancestor(Gtk::Window).focus
                  #setting the window insensitive so user can't interact while destroying and reinitint stuff
#                       get_ancestor(Gtk::Window).
                                        set_sensitive(false)
                                        measure(last,"cyan"){notify_observers(last)}
#                 get_ancestor(Gtk::Window).
                                        set_sensitive(true) unless destroyed?
                        #.set_focus(focused)
                                end
                        else
                                edebug(".update: unknown routing(#{notifier.class.name})","menu","warning")
                end
        end