Class: Packet_Item

Inherits:
Object
  • Object
show all
Defined in:
lib/Packet_Item.rb

Overview

An item for Packet_List. This is a convenient wrapper for the FXIconItem.

Defined Under Namespace

Classes: Fox_Item

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(newParent, icon, *content) ⇒ Packet_Item

Creates a Packet_Item with newParent as the parent list, which is allowed to be nil. You can also use Packet_List#add_item instead.



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/Packet_Item.rb', line 68

def initialize(newParent, icon, *content)
	@content = content
	@sortable = Array.new(@content.size)
	@icon = icon
	@data = nil
	@parent = nil
	@sort_key = nil
	@searchable = nil
	# call parent=, don't forget the self!!
	self.parent = newParent
	show if newParent
	# update sortable
	@content.each_index do |pos|
		update_sortable(pos, @content[pos]) if parent
	end
end

Instance Attribute Details

#searchableObject

Returns the value of attribute searchable.



16
17
18
# File 'lib/Packet_Item.rb', line 16

def searchable
  @searchable
end

Instance Method Details

#[](column_nr) ⇒ Object

Get the content of the given column number.



86
87
88
# File 'lib/Packet_Item.rb', line 86

def [](column_nr)
	@content[column_nr]
end

#[]=(column_nr, newVal) ⇒ Object

Set new text for the given column number.



91
92
93
94
95
96
97
# File 'lib/Packet_Item.rb', line 91

def []=(column_nr, newVal) 
	@content[column_nr] = newVal
	return unless @parent
	@item.text = @content.join("\t")
	update_sortable(column_nr, newVal)
	@parent.recalc
end

#clearObject

Removes the item from its parent.



149
150
151
# File 'lib/Packet_Item.rb', line 149

def clear
	@parent = nil
end

#dataObject

Get user data.



144
145
146
# File 'lib/Packet_Item.rb', line 144

def data
	@data
end

#data=(data) ⇒ Object

Allows to set user data.



139
140
141
# File 'lib/Packet_Item.rb', line 139

def data=(data)
	@data = data
end

#fox_itemObject

Get the wrapper item.



134
135
136
# File 'lib/Packet_Item.rb', line 134

def fox_item
	@item
end

#iconObject

The icon of this item.



154
155
156
# File 'lib/Packet_Item.rb', line 154

def icon
	@icon
end

#parentObject

Get the parent list for this item.



111
112
113
# File 'lib/Packet_Item.rb', line 111

def parent
	@parent
end

#parent=(newParent) ⇒ Object

Set a new parent. This removes this item from the current list and adds itself to the new one.



117
118
119
120
121
122
123
124
# File 'lib/Packet_Item.rb', line 117

def parent=(newParent)
	return if newParent == @parent
	remove_item if @parent
	@parent = newParent
	@content.each_index do |pos|
		update_sortable(pos, @content[pos]) if @parent
	end
end

#showObject

Shows item on parent without updating the search index. This can be used if an item is removed and added to the same list.



128
129
130
131
# File 'lib/Packet_Item.rb', line 128

def show
	create_item
	@parent.add_item(self)
end

#sortable(pos) ⇒ Object

Get the sortable representation of this column’s content.



100
101
102
# File 'lib/Packet_Item.rb', line 100

def sortable(pos)
	@sortable[pos]
end

#update_sort_keyObject

update FXIconItem’s sort key and reversed status



105
106
107
108
# File 'lib/Packet_Item.rb', line 105

def update_sort_key
	@item.sort_key = @sortable[@parent.sort_index]
	@item.reversed = @parent.reversed? ? -1 : 1
end