Class: BarMenu

Inherits:
Gtk::MenuBar
  • Object
show all
Includes:
Conf, ManqodCommon
Defined in:
lib/BarMenu.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(mainrouter, pack_dir = "horizontal") ⇒ BarMenu

Returns a new instance of BarMenu.



10
11
12
13
14
15
16
# File 'lib/BarMenu.rb', line 10

def initialize(mainrouter,pack_dir="horizontal")
	super()
	set_pack_direction(if pack_dir=="vertical" then Gtk::MenuBar::PACK_DIRECTION_TTB; else Gtk::MenuBar::PACK_DIRECTION_LTR;end)
	@mainrouter=mainrouter
	@last=nil
	reinitialize
end

Instance Attribute Details

#lastObject

Returns the value of attribute last.



17
18
19
# File 'lib/BarMenu.rb', line 17

def last
  @last
end

#mainrouterObject (readonly)

Returns the value of attribute mainrouter.



18
19
20
# File 'lib/BarMenu.rb', line 18

def mainrouter
  @mainrouter
end

Instance Method Details

#inspectObject



73
74
75
# File 'lib/BarMenu.rb', line 73

def inspect
	to_s
end

#recmenuitem(parentid, pmenu) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/BarMenu.rb', line 26

def recmenuitem(parentid,pmenu)
	admin_rows("select gtkmenu.*,
		ifnull(childcnt.cnt,'0') as childs 
		from gtkmenu 
		left join (select count(id) as cnt,parent from gtkmenu group by parent) as childcnt on childcnt.parent=gtkmenu.id
		left join (select count(id) as cnt,userid,groupid from usergroups group by groupid,userid) as ugrp on ugrp.groupid = gtkmenu.groupid
		where gtkmenu.parent='#{parentid}' and userid='#{nick_id}' and ugrp.cnt>0
		order by oid"){|row|
		menuitem=BarMenuItem.new(self,row['id'])
		@last=menuitem if row['id']==get_conf(0,0,"lastmenu")
		if row['childs'].to_i > 0 
			menuitem.submenu=Gtk::Menu.new()
			recmenuitem(row['id'],if row['parent'].to_i==-1 then pmenu else menuitem.submenu end)
		end
		pmenu.append(menuitem) unless row['parent'].to_i == -1
	}
end

#reinitializeObject



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
# File 'lib/BarMenu.rb', line 20

def reinitialize
	def remove_main_menu_items(pmenu)
		pmenu.each{|menu_item|
			pmenu.remove(menu_item)
		}
	end
	def recmenuitem(parentid,pmenu)
		admin_rows("select gtkmenu.*,
			ifnull(childcnt.cnt,'0') as childs 
			from gtkmenu 
			left join (select count(id) as cnt,parent from gtkmenu group by parent) as childcnt on childcnt.parent=gtkmenu.id
			left join (select count(id) as cnt,userid,groupid from usergroups group by groupid,userid) as ugrp on ugrp.groupid = gtkmenu.groupid
			where gtkmenu.parent='#{parentid}' and userid='#{nick_id}' and ugrp.cnt>0
			order by oid"){|row|
			menuitem=BarMenuItem.new(self,row['id'])
			@last=menuitem if row['id']==get_conf(0,0,"lastmenu")
			if row['childs'].to_i > 0 
				menuitem.submenu=Gtk::Menu.new()
				recmenuitem(row['id'],if row['parent'].to_i==-1 then pmenu else menuitem.submenu end)
			end
			pmenu.append(menuitem) unless row['parent'].to_i == -1
		}
	end
	remove_main_menu_items(self)
	recmenuitem(-1,self)
	show_all
end

#remove_main_menu_items(pmenu) ⇒ Object



21
22
23
24
25
# File 'lib/BarMenu.rb', line 21

def remove_main_menu_items(pmenu)
	pmenu.each{|menu_item|
		pmenu.remove(menu_item)
	}
end

#to_sObject



70
71
72
# File 'lib/BarMenu.rb', line 70

def to_s
	"Main Menu"
end

#update(notifier) ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/BarMenu.rb', line 48

def update(notifier)
	case notifier.class.name
		when 'MyWindow'
			reinitialize
			@mainrouter.update(last) if last
		when 'BarMenuItem'
			if notifier.target
				last=notifier
				set_conf(0,0,"lastmenu",notifier.id) if notifier.modname != "quit"
				edebug("#{last.target} emiting signal","menu","debug")
				#setting the window insensitive so user can't interact while destroying and reiniting stuff
#					get_ancestor(Gtk::Window).set_sensitive(false)
				set_sensitive(false)
				@mainrouter.update(last)
				set_sensitive(true) unless destroyed?
#					get_ancestor(Gtk::Window).set_sensitive(true) if !self.destroyed?
			end
		else
			edebug("unknown routing: #{notifier.class.name}","menu","warning")
	end
end