Class: MenuHolder

Inherits:
Gtk::Alignment
  • Object
show all
Includes:
Conf, ManqodCommon, Observable
Defined in:
lib/ButtonMenu.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])

Constant Summary

Constants included from ManqodCommon

ManqodCommon::CRITICAL, ManqodCommon::DEBUG, ManqodCommon::ERROR, ManqodCommon::INFO, ManqodCommon::NORMAL, ManqodCommon::WARNING

Constants included from Eprint

Eprint::DOMAIN, Eprint::LEVEL

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Conf

#get_conf, #load_conf, #save_conf, #set_conf

Methods included from ManqodCommon

#add_where, #admin, #admin_cache, #admin_qrow, #admin_rows, #backtrace_to_debug, #cache, #changed_ids_of_base, #client, #client_fields, #client_image_of_id, #client_qrow, #client_query, #client_rows, #eeval, #escape_string, #getBinding, #guess_base, #guess_table, #image_of_id, #lzero, #manqod_db, #measure, #myexec, #nick, #nick_id, #number_format, #qrow, #query, #reconnect_manqod_db, #rows, #run_events, #send_message, #sendmail, #set_manqod_db_uri, #set_nick

Methods included from Eprint

#ecode, #edebug, #eerror, #einfo, #enormal, #eprint, #ewarn, #gtk_set_edebug, #set_edebug, #tell_exception

Constructor Details

#initialize(parent_menu, pack_dir = "horizontal") ⇒ MenuHolder

Returns a new instance of MenuHolder.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# 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

Instance Attribute Details

#holderObject

Returns the value of attribute holder.



27
28
29
# File 'lib/ButtonMenu.rb', line 27

def holder
  @holder
end

#lastObject

Returns the value of attribute last.



25
26
27
# File 'lib/ButtonMenu.rb', line 25

def last
  @last
end

#pack_dirObject

Returns the value of attribute pack_dir.



28
29
30
# File 'lib/ButtonMenu.rb', line 28

def pack_dir
  @pack_dir
end

#parent_menuObject

Returns the value of attribute parent_menu.



26
27
28
# File 'lib/ButtonMenu.rb', line 26

def parent_menu
  @parent_menu
end

Instance Method Details

#hide_items(except_this = nil) ⇒ Object



103
104
105
106
107
108
109
110
111
112
113
114
# 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_treeObject



96
97
98
99
100
101
# 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

#inspectObject



146
147
148
149
150
# 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) ⇒ Object



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
# 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

#reinitializeObject



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
# 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) ⇒ Object



31
32
33
# 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) ⇒ Object



84
85
86
87
88
89
90
91
92
93
94
# 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_sObject



151
152
153
# File 'lib/ButtonMenu.rb', line 151

def to_s
	inspect
end

#update(notifier) ⇒ Object



116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
# 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