fxri 0.3.4 → 0.3.5
Sign up to get free protection for your applications and to get access to all the features.
- data/fxri +4 -344
- data/fxri.gemspec +24 -24
- data/fxri.rb +351 -0
- data/lib/Empty_Text_Field_Handler.rb +63 -63
- data/lib/FoxDisplayer.rb +148 -148
- data/lib/FoxTextFormatter.rb +274 -274
- data/lib/Icon_Loader.rb +35 -35
- data/lib/Packet_Item.rb +178 -178
- data/lib/Packet_List.rb +192 -192
- data/lib/Recursive_Open_Struct.rb +233 -238
- data/lib/Search_Engine.rb +165 -165
- data/lib/fxirb.rb +401 -400
- metadata +13 -22
- data/bugs/fxri bug `concat' can't convert nil into Array (TypeError).eml +0 -50
- data/bugs/fxri with Ruby v1.8.5 via OneClickInstaller v1.8.5-21.eml +0 -167
- data/fxri-0.3.4.gem +0 -0
- data/lib/fxirb-0.2.1/CHANGELOG +0 -31
- data/lib/fxirb-0.2.1/fxirb.rb +0 -395
data/lib/Icon_Loader.rb
CHANGED
@@ -1,35 +1,35 @@
|
|
1
|
-
# Copyright (c) 2004, 2005 Martin Ankerl
|
2
|
-
|
3
|
-
# Converts a Recursive_Open_Struct that contains filenames of PNG-icons into real icons.
|
4
|
-
class Icon_Loader
|
5
|
-
# Create a new Icon_Loader. You need to specify the Fox-application.
|
6
|
-
def initialize(app)
|
7
|
-
@app = app
|
8
|
-
end
|
9
|
-
|
10
|
-
# Takes each attribute of the given Recursive_Open_Struct,
|
11
|
-
# converts it into a real icon, and sets it.
|
12
|
-
def cfg_to_icons(cfg)
|
13
|
-
cfg.attrs.each do |attr|
|
14
|
-
value = cfg.send(attr.to_sym)
|
15
|
-
if (value.class == Recursive_Open_Struct)
|
16
|
-
cfg_to_icons(value)
|
17
|
-
else
|
18
|
-
# value is a filename
|
19
|
-
icon = make_icon(value)
|
20
|
-
cfg.send((attr + "=").to_sym, icon)
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
# Constructs an icon from the given filename (from the icons directory).
|
26
|
-
def make_icon(filename)
|
27
|
-
filename = File.join($cfg.icons_path, filename)
|
28
|
-
icon = nil
|
29
|
-
File.open(filename, "rb") do |f|
|
30
|
-
icon = FXPNGIcon.new(@app, f.read, 0)
|
31
|
-
end
|
32
|
-
icon.create
|
33
|
-
icon
|
34
|
-
end
|
35
|
-
end
|
1
|
+
# Copyright (c) 2004, 2005 Martin Ankerl
|
2
|
+
|
3
|
+
# Converts a Recursive_Open_Struct that contains filenames of PNG-icons into real icons.
|
4
|
+
class Icon_Loader
|
5
|
+
# Create a new Icon_Loader. You need to specify the Fox-application.
|
6
|
+
def initialize(app)
|
7
|
+
@app = app
|
8
|
+
end
|
9
|
+
|
10
|
+
# Takes each attribute of the given Recursive_Open_Struct,
|
11
|
+
# converts it into a real icon, and sets it.
|
12
|
+
def cfg_to_icons(cfg)
|
13
|
+
cfg.attrs.each do |attr|
|
14
|
+
value = cfg.send(attr.to_sym)
|
15
|
+
if (value.class == Recursive_Open_Struct)
|
16
|
+
cfg_to_icons(value)
|
17
|
+
else
|
18
|
+
# value is a filename
|
19
|
+
icon = make_icon(value)
|
20
|
+
cfg.send((attr + "=").to_sym, icon)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
# Constructs an icon from the given filename (from the icons directory).
|
26
|
+
def make_icon(filename)
|
27
|
+
filename = File.join($cfg.icons_path, filename)
|
28
|
+
icon = nil
|
29
|
+
File.open(filename, "rb") do |f|
|
30
|
+
icon = FXPNGIcon.new(@app, f.read, 0)
|
31
|
+
end
|
32
|
+
icon.create
|
33
|
+
icon
|
34
|
+
end
|
35
|
+
end
|
data/lib/Packet_Item.rb
CHANGED
@@ -1,179 +1,179 @@
|
|
1
|
-
# Copyright (c) 2004, 2005 Christoph Heindl and Martin Ankerl
|
2
|
-
class MutexDummy
|
3
|
-
def synchronize
|
4
|
-
yield
|
5
|
-
end
|
6
|
-
end
|
7
|
-
|
8
|
-
# Lock used to synchronize item removes.
|
9
|
-
# for now, a global lock is good enough.
|
10
|
-
$fx_icon_item_remove_mutex = Mutex.new
|
11
|
-
|
12
|
-
|
13
|
-
# An item for Packet_List. This is a convenient wrapper for the FXIconItem.
|
14
|
-
class Packet_Item
|
15
|
-
|
16
|
-
attr_accessor :searchable
|
17
|
-
|
18
|
-
# Fox_Item is a very thin wrapper that calles Packet_Item functionality.
|
19
|
-
class Fox_Item < FXIconItem
|
20
|
-
# optimization: directly sort by sort_key and reversed
|
21
|
-
attr_accessor :sort_key
|
22
|
-
attr_accessor :reversed
|
23
|
-
|
24
|
-
# Create a new item with packet_item as the parent. *args is passed to the FXIconItem.
|
25
|
-
def initialize(packet_item, *args)
|
26
|
-
@packet_item = packet_item
|
27
|
-
@sort_key = nil
|
28
|
-
@reversed = 1
|
29
|
-
@is_deleted = false
|
30
|
-
super(*args)
|
31
|
-
end
|
32
|
-
|
33
|
-
# Sometimes draw is called AFTER the item has been removed.
|
34
|
-
# In this case: return immediately. Otherwise a Runtime Error would occur!
|
35
|
-
def draw(*args)
|
36
|
-
$fx_icon_item_remove_mutex.synchronize do
|
37
|
-
#puts "draw"
|
38
|
-
return if @is_deleted
|
39
|
-
super
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
# Mark item as deleted, to prevent execution of draw afterwards
|
44
|
-
# this is called from Packet_List which uses the same mutex
|
45
|
-
# as draw.
|
46
|
-
def deleted
|
47
|
-
@is_deleted = true
|
48
|
-
end
|
49
|
-
|
50
|
-
# Called from sortItems, uses packet_item's comparison.
|
51
|
-
def <=>(other)
|
52
|
-
(@sort_key <=> other.sort_key) * @reversed
|
53
|
-
end
|
54
|
-
|
55
|
-
# Get the packet item
|
56
|
-
def packet_item
|
57
|
-
@packet_item
|
58
|
-
end
|
59
|
-
|
60
|
-
# Pass-through method
|
61
|
-
def data
|
62
|
-
@packet_item.data
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
# Creates a Packet_Item with newParent as the parent list, which is allowed to be nil.
|
67
|
-
# You can also use Packet_List#add_item instead.
|
68
|
-
def initialize(newParent, icon, *content)
|
69
|
-
@content = content
|
70
|
-
@sortable = Array.new(@content.size)
|
71
|
-
@icon = icon
|
72
|
-
@data = nil
|
73
|
-
@parent = nil
|
74
|
-
@sort_key = nil
|
75
|
-
@searchable = nil
|
76
|
-
# call parent=, don't forget the self!!
|
77
|
-
self.parent = newParent
|
78
|
-
show if newParent
|
79
|
-
# update sortable
|
80
|
-
@content.each_index do |pos|
|
81
|
-
update_sortable(pos, @content[pos]) if parent
|
82
|
-
end
|
83
|
-
end
|
84
|
-
|
85
|
-
# Get the content of the given column number.
|
86
|
-
def [](column_nr)
|
87
|
-
@content[column_nr]
|
88
|
-
end
|
89
|
-
|
90
|
-
# Set new text for the given column number.
|
91
|
-
def []=(column_nr, newVal)
|
92
|
-
@content[column_nr] = newVal
|
93
|
-
return unless @parent
|
94
|
-
@item.text = @content.join("\t")
|
95
|
-
update_sortable(column_nr, newVal)
|
96
|
-
@parent.recalc
|
97
|
-
end
|
98
|
-
|
99
|
-
# Get the sortable representation of this column's content.
|
100
|
-
def sortable(pos)
|
101
|
-
@sortable[pos]
|
102
|
-
end
|
103
|
-
|
104
|
-
# update FXIconItem's sort key and reversed status
|
105
|
-
def update_sort_key
|
106
|
-
@item.sort_key = @sortable[@parent.sort_index]
|
107
|
-
@item.reversed = @parent.reversed? ? -1 : 1
|
108
|
-
end
|
109
|
-
|
110
|
-
# Get the parent list for this item.
|
111
|
-
def parent
|
112
|
-
@parent
|
113
|
-
end
|
114
|
-
|
115
|
-
# Set a new parent. This removes this item from the current list and adds itself to
|
116
|
-
# the new one.
|
117
|
-
def parent=(newParent)
|
118
|
-
return if newParent == @parent
|
119
|
-
remove_item if @parent
|
120
|
-
@parent = newParent
|
121
|
-
@content.each_index do |pos|
|
122
|
-
update_sortable(pos, @content[pos]) if @parent
|
123
|
-
end
|
124
|
-
end
|
125
|
-
|
126
|
-
# Shows item on parent without updating the search index. This can be used
|
127
|
-
# if an item is removed and added to the same list.
|
128
|
-
def show
|
129
|
-
create_item
|
130
|
-
@parent.add_item(self)
|
131
|
-
end
|
132
|
-
|
133
|
-
# Get the wrapper item.
|
134
|
-
def fox_item
|
135
|
-
@item
|
136
|
-
end
|
137
|
-
|
138
|
-
# Allows to set user data.
|
139
|
-
def data=(data)
|
140
|
-
@data = data
|
141
|
-
end
|
142
|
-
|
143
|
-
# Get user data.
|
144
|
-
def data
|
145
|
-
@data
|
146
|
-
end
|
147
|
-
|
148
|
-
# Removes the item from its parent.
|
149
|
-
def clear
|
150
|
-
@parent = nil
|
151
|
-
end
|
152
|
-
|
153
|
-
# The icon of this item.
|
154
|
-
def icon
|
155
|
-
@icon
|
156
|
-
end
|
157
|
-
|
158
|
-
private
|
159
|
-
|
160
|
-
# Calles the sort function to update the sortable representation of column pos.
|
161
|
-
def update_sortable(pos, newVal)
|
162
|
-
sort_function = @parent.sort_function(pos)
|
163
|
-
if sort_function
|
164
|
-
@sortable[pos] = sort_function.call(newVal)
|
165
|
-
else
|
166
|
-
@sortable[pos] = newVal
|
167
|
-
end
|
168
|
-
end
|
169
|
-
|
170
|
-
# Remove item from parent
|
171
|
-
def remove_item
|
172
|
-
@parent.remove_item(self)
|
173
|
-
end
|
174
|
-
|
175
|
-
# Creates wrapper item, and sets it's data
|
176
|
-
def create_item
|
177
|
-
@item = Fox_Item.new(self, @content.join("\t"), @icon, @icon)
|
178
|
-
end
|
1
|
+
# Copyright (c) 2004, 2005 Christoph Heindl and Martin Ankerl
|
2
|
+
class MutexDummy
|
3
|
+
def synchronize
|
4
|
+
yield
|
5
|
+
end
|
6
|
+
end
|
7
|
+
|
8
|
+
# Lock used to synchronize item removes.
|
9
|
+
# for now, a global lock is good enough.
|
10
|
+
$fx_icon_item_remove_mutex = Mutex.new
|
11
|
+
|
12
|
+
|
13
|
+
# An item for Packet_List. This is a convenient wrapper for the FXIconItem.
|
14
|
+
class Packet_Item
|
15
|
+
|
16
|
+
attr_accessor :searchable
|
17
|
+
|
18
|
+
# Fox_Item is a very thin wrapper that calles Packet_Item functionality.
|
19
|
+
class Fox_Item < FXIconItem
|
20
|
+
# optimization: directly sort by sort_key and reversed
|
21
|
+
attr_accessor :sort_key
|
22
|
+
attr_accessor :reversed
|
23
|
+
|
24
|
+
# Create a new item with packet_item as the parent. *args is passed to the FXIconItem.
|
25
|
+
def initialize(packet_item, *args)
|
26
|
+
@packet_item = packet_item
|
27
|
+
@sort_key = nil
|
28
|
+
@reversed = 1
|
29
|
+
@is_deleted = false
|
30
|
+
super(*args)
|
31
|
+
end
|
32
|
+
|
33
|
+
# Sometimes draw is called AFTER the item has been removed.
|
34
|
+
# In this case: return immediately. Otherwise a Runtime Error would occur!
|
35
|
+
def draw(*args)
|
36
|
+
$fx_icon_item_remove_mutex.synchronize do
|
37
|
+
#puts "draw"
|
38
|
+
return if @is_deleted
|
39
|
+
super
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
# Mark item as deleted, to prevent execution of draw afterwards
|
44
|
+
# this is called from Packet_List which uses the same mutex
|
45
|
+
# as draw.
|
46
|
+
def deleted
|
47
|
+
@is_deleted = true
|
48
|
+
end
|
49
|
+
|
50
|
+
# Called from sortItems, uses packet_item's comparison.
|
51
|
+
def <=>(other)
|
52
|
+
(@sort_key <=> other.sort_key) * @reversed
|
53
|
+
end
|
54
|
+
|
55
|
+
# Get the packet item
|
56
|
+
def packet_item
|
57
|
+
@packet_item
|
58
|
+
end
|
59
|
+
|
60
|
+
# Pass-through method
|
61
|
+
def data
|
62
|
+
@packet_item.data
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
# Creates a Packet_Item with newParent as the parent list, which is allowed to be nil.
|
67
|
+
# You can also use Packet_List#add_item instead.
|
68
|
+
def initialize(newParent, icon, *content)
|
69
|
+
@content = content
|
70
|
+
@sortable = Array.new(@content.size)
|
71
|
+
@icon = icon
|
72
|
+
@data = nil
|
73
|
+
@parent = nil
|
74
|
+
@sort_key = nil
|
75
|
+
@searchable = nil
|
76
|
+
# call parent=, don't forget the self!!
|
77
|
+
self.parent = newParent
|
78
|
+
show if newParent
|
79
|
+
# update sortable
|
80
|
+
@content.each_index do |pos|
|
81
|
+
update_sortable(pos, @content[pos]) if parent
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
# Get the content of the given column number.
|
86
|
+
def [](column_nr)
|
87
|
+
@content[column_nr]
|
88
|
+
end
|
89
|
+
|
90
|
+
# Set new text for the given column number.
|
91
|
+
def []=(column_nr, newVal)
|
92
|
+
@content[column_nr] = newVal
|
93
|
+
return unless @parent
|
94
|
+
@item.text = @content.join("\t")
|
95
|
+
update_sortable(column_nr, newVal)
|
96
|
+
@parent.recalc
|
97
|
+
end
|
98
|
+
|
99
|
+
# Get the sortable representation of this column's content.
|
100
|
+
def sortable(pos)
|
101
|
+
@sortable[pos]
|
102
|
+
end
|
103
|
+
|
104
|
+
# update FXIconItem's sort key and reversed status
|
105
|
+
def update_sort_key
|
106
|
+
@item.sort_key = @sortable[@parent.sort_index]
|
107
|
+
@item.reversed = @parent.reversed? ? -1 : 1
|
108
|
+
end
|
109
|
+
|
110
|
+
# Get the parent list for this item.
|
111
|
+
def parent
|
112
|
+
@parent
|
113
|
+
end
|
114
|
+
|
115
|
+
# Set a new parent. This removes this item from the current list and adds itself to
|
116
|
+
# the new one.
|
117
|
+
def parent=(newParent)
|
118
|
+
return if newParent == @parent
|
119
|
+
remove_item if @parent
|
120
|
+
@parent = newParent
|
121
|
+
@content.each_index do |pos|
|
122
|
+
update_sortable(pos, @content[pos]) if @parent
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
# Shows item on parent without updating the search index. This can be used
|
127
|
+
# if an item is removed and added to the same list.
|
128
|
+
def show
|
129
|
+
create_item
|
130
|
+
@parent.add_item(self)
|
131
|
+
end
|
132
|
+
|
133
|
+
# Get the wrapper item.
|
134
|
+
def fox_item
|
135
|
+
@item
|
136
|
+
end
|
137
|
+
|
138
|
+
# Allows to set user data.
|
139
|
+
def data=(data)
|
140
|
+
@data = data
|
141
|
+
end
|
142
|
+
|
143
|
+
# Get user data.
|
144
|
+
def data
|
145
|
+
@data
|
146
|
+
end
|
147
|
+
|
148
|
+
# Removes the item from its parent.
|
149
|
+
def clear
|
150
|
+
@parent = nil
|
151
|
+
end
|
152
|
+
|
153
|
+
# The icon of this item.
|
154
|
+
def icon
|
155
|
+
@icon
|
156
|
+
end
|
157
|
+
|
158
|
+
private
|
159
|
+
|
160
|
+
# Calles the sort function to update the sortable representation of column pos.
|
161
|
+
def update_sortable(pos, newVal)
|
162
|
+
sort_function = @parent.sort_function(pos)
|
163
|
+
if sort_function
|
164
|
+
@sortable[pos] = sort_function.call(newVal)
|
165
|
+
else
|
166
|
+
@sortable[pos] = newVal
|
167
|
+
end
|
168
|
+
end
|
169
|
+
|
170
|
+
# Remove item from parent
|
171
|
+
def remove_item
|
172
|
+
@parent.remove_item(self)
|
173
|
+
end
|
174
|
+
|
175
|
+
# Creates wrapper item, and sets it's data
|
176
|
+
def create_item
|
177
|
+
@item = Fox_Item.new(self, @content.join("\t"), @icon, @icon)
|
178
|
+
end
|
179
179
|
end
|
data/lib/Packet_List.rb
CHANGED
@@ -1,192 +1,192 @@
|
|
1
|
-
# Copyright (c) 2004, 2005 Martin Ankerl
|
2
|
-
require 'set'
|
3
|
-
|
4
|
-
# Packet_List is a more convenient wrapper for FXIconList. This class has to be used
|
5
|
-
# in combination with Packet_Item.
|
6
|
-
class Packet_List < FXIconList
|
7
|
-
include Responder
|
8
|
-
|
9
|
-
# Create a new Packet_List. All parameters are passed to the parental constructor FXIconList.
|
10
|
-
def initialize(data, *args)
|
11
|
-
@data = data
|
12
|
-
@sort_mutex = Mutex.new
|
13
|
-
@sort_thread = nil
|
14
|
-
if FOXVERSION=="1.0"
|
15
|
-
def getItem(num)
|
16
|
-
retrieveItem(num)
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
@header_item_index = 0
|
21
|
-
@reversed = true
|
22
|
-
@conversions = Array.new
|
23
|
-
@items = Set.new
|
24
|
-
super(*args)
|
25
|
-
|
26
|
-
header.connect(SEL_COMMAND) do |sender, sel, item_number|
|
27
|
-
on_cmd_header(item_number)
|
28
|
-
end
|
29
|
-
|
30
|
-
|
31
|
-
# HACK: only works when one header is there.
|
32
|
-
self.connect(SEL_CONFIGURE) do |sender, sel, data|
|
33
|
-
update_header_width
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
def create
|
38
|
-
super
|
39
|
-
recalc
|
40
|
-
end
|
41
|
-
|
42
|
-
# HACK: only works when one header is there.
|
43
|
-
def update_header_width
|
44
|
-
header.setItemSize(0, width-verticalScrollBar.width)
|
45
|
-
recalc
|
46
|
-
end
|
47
|
-
|
48
|
-
|
49
|
-
# Called whenever a header is clicked
|
50
|
-
def on_cmd_header(header_item_index)
|
51
|
-
@data.gui_mutex.synchronize do
|
52
|
-
header.setArrowDir(@header_item_index, MAYBE)
|
53
|
-
if @header_item_index == header_item_index
|
54
|
-
@reversed = !@reversed
|
55
|
-
else
|
56
|
-
@reversed = true
|
57
|
-
end
|
58
|
-
@header_item_index = header_item_index
|
59
|
-
header.setArrowDir(@header_item_index, @reversed)
|
60
|
-
sortItems
|
61
|
-
end
|
62
|
-
# sort array
|
63
|
-
@data.items.sort! do |a, b|
|
64
|
-
cmp = a.sortable(header_item_index) <=> b.sortable(header_item_index)
|
65
|
-
if @reversed
|
66
|
-
-cmp
|
67
|
-
else
|
68
|
-
cmp
|
69
|
-
end
|
70
|
-
end
|
71
|
-
return 0
|
72
|
-
end
|
73
|
-
|
74
|
-
def sortItems
|
75
|
-
@items.each do |item|
|
76
|
-
item.update_sort_key
|
77
|
-
end
|
78
|
-
super
|
79
|
-
end
|
80
|
-
|
81
|
-
# Check if the search order is reversed (happens when clicking on the same header twice)
|
82
|
-
def reversed?
|
83
|
-
@reversed
|
84
|
-
end
|
85
|
-
|
86
|
-
# Get index of the header that should be used for sorting
|
87
|
-
def sort_index
|
88
|
-
@header_item_index
|
89
|
-
end
|
90
|
-
|
91
|
-
# Add a new header. The block that you need to specify is used to convert a string of this
|
92
|
-
# column into something that can be used for sorting. The yielded parameter item_colum_text
|
93
|
-
# is the text of one item of this column.
|
94
|
-
def add_header(text, width, &conversion) # :yields: item_column_text
|
95
|
-
appendHeader(text, nil, width)
|
96
|
-
header.setArrowDir(0, false) if @conversions.empty?
|
97
|
-
@conversions.push conversion
|
98
|
-
end
|
99
|
-
|
100
|
-
# Create a new Packet_Item. After the icon, you can specify the text for each of the columns.
|
101
|
-
# Here is an example:
|
102
|
-
# list.create_item(my_icon, "Martin", "Ankerl", "2005")
|
103
|
-
def create_item(icon, *args)
|
104
|
-
Packet_Item.new(self, icon, *args)
|
105
|
-
end
|
106
|
-
|
107
|
-
# Add a new Packet_Item to this list.Called from within Packet_Item during Packet_Item#parent=
|
108
|
-
def add_item(item)
|
109
|
-
@items.add item
|
110
|
-
appendItem(item.fox_item)
|
111
|
-
item
|
112
|
-
end
|
113
|
-
|
114
|
-
# Remove the given Packet_Item from the list. This is slow, because
|
115
|
-
# the item has to be searched with a linear search. To remove all items
|
116
|
-
# use #clear.
|
117
|
-
def remove_item(item)
|
118
|
-
i = 0
|
119
|
-
@items.delete item
|
120
|
-
fox_item = item.fox_item
|
121
|
-
i += 1 while i < numItems && fox_item != getItem(i)
|
122
|
-
removeItem(i) if i < numItems
|
123
|
-
item
|
124
|
-
end
|
125
|
-
|
126
|
-
def appendItem(*args)
|
127
|
-
$fx_icon_item_remove_mutex.synchronize do
|
128
|
-
#puts "appendItem"
|
129
|
-
super
|
130
|
-
end
|
131
|
-
end
|
132
|
-
|
133
|
-
# Before actually deleting, the item has to be marked as deleted to prevent
|
134
|
-
# drawing afterwards.
|
135
|
-
def removeItem(*args)
|
136
|
-
$fx_icon_item_remove_mutex.synchronize do
|
137
|
-
#puts "removeitem"
|
138
|
-
# at first, mark item as deleted to prevent drawing afterwards
|
139
|
-
getItem(args[0]).deleted
|
140
|
-
# do the evil delete
|
141
|
-
super
|
142
|
-
end
|
143
|
-
end
|
144
|
-
|
145
|
-
# Remove all items, but do this within the mutex to be sure everything goes ok.
|
146
|
-
def clearItems(*args)
|
147
|
-
$fx_icon_item_remove_mutex.synchronize do
|
148
|
-
#puts "clearitems"
|
149
|
-
super
|
150
|
-
end
|
151
|
-
end
|
152
|
-
|
153
|
-
# This may be called when the item is currently beeing deleted.
|
154
|
-
# this method works only before or after the delete, therefore
|
155
|
-
# the mutex is necessary.
|
156
|
-
def getContentWidth(*args)
|
157
|
-
$fx_icon_item_remove_mutex.synchronize do
|
158
|
-
#puts "contentwidth"
|
159
|
-
super
|
160
|
-
end
|
161
|
-
end
|
162
|
-
|
163
|
-
# This may be called when the item is currently beeing deleted.
|
164
|
-
# this method works only before or after the delete, therefore
|
165
|
-
# the mutex is necessary.
|
166
|
-
def getContentHeight(*args)
|
167
|
-
$fx_icon_item_remove_mutex.synchronize do
|
168
|
-
#puts "contentheight"
|
169
|
-
super
|
170
|
-
end
|
171
|
-
end
|
172
|
-
|
173
|
-
# Removes all items from the list.
|
174
|
-
def clear
|
175
|
-
@items.each { |item| item.clear }
|
176
|
-
@items.clear
|
177
|
-
# todo: mutex!?
|
178
|
-
clearItems
|
179
|
-
end
|
180
|
-
|
181
|
-
# use in combination with Packet_Item#show
|
182
|
-
def dirty_clear
|
183
|
-
clearItems
|
184
|
-
@items.clear
|
185
|
-
end
|
186
|
-
|
187
|
-
# Get the sort for a given header index. The sort function has been supplied
|
188
|
-
# when calling #new. This is used from Packet_Item.
|
189
|
-
def sort_function(header_item_index)
|
190
|
-
@conversions[header_item_index]
|
191
|
-
end
|
192
|
-
end
|
1
|
+
# Copyright (c) 2004, 2005 Martin Ankerl
|
2
|
+
require 'set'
|
3
|
+
|
4
|
+
# Packet_List is a more convenient wrapper for FXIconList. This class has to be used
|
5
|
+
# in combination with Packet_Item.
|
6
|
+
class Packet_List < FXIconList
|
7
|
+
include Responder
|
8
|
+
|
9
|
+
# Create a new Packet_List. All parameters are passed to the parental constructor FXIconList.
|
10
|
+
def initialize(data, *args)
|
11
|
+
@data = data
|
12
|
+
@sort_mutex = Mutex.new
|
13
|
+
@sort_thread = nil
|
14
|
+
if FOXVERSION=="1.0"
|
15
|
+
def getItem(num)
|
16
|
+
retrieveItem(num)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
@header_item_index = 0
|
21
|
+
@reversed = true
|
22
|
+
@conversions = Array.new
|
23
|
+
@items = Set.new
|
24
|
+
super(*args)
|
25
|
+
|
26
|
+
header.connect(SEL_COMMAND) do |sender, sel, item_number|
|
27
|
+
on_cmd_header(item_number)
|
28
|
+
end
|
29
|
+
|
30
|
+
|
31
|
+
# HACK: only works when one header is there.
|
32
|
+
self.connect(SEL_CONFIGURE) do |sender, sel, data|
|
33
|
+
update_header_width
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def create
|
38
|
+
super
|
39
|
+
recalc
|
40
|
+
end
|
41
|
+
|
42
|
+
# HACK: only works when one header is there.
|
43
|
+
def update_header_width
|
44
|
+
header.setItemSize(0, width-verticalScrollBar.width)
|
45
|
+
recalc
|
46
|
+
end
|
47
|
+
|
48
|
+
|
49
|
+
# Called whenever a header is clicked
|
50
|
+
def on_cmd_header(header_item_index)
|
51
|
+
@data.gui_mutex.synchronize do
|
52
|
+
header.setArrowDir(@header_item_index, MAYBE)
|
53
|
+
if @header_item_index == header_item_index
|
54
|
+
@reversed = !@reversed
|
55
|
+
else
|
56
|
+
@reversed = true
|
57
|
+
end
|
58
|
+
@header_item_index = header_item_index
|
59
|
+
header.setArrowDir(@header_item_index, @reversed)
|
60
|
+
sortItems
|
61
|
+
end
|
62
|
+
# sort array
|
63
|
+
@data.items.sort! do |a, b|
|
64
|
+
cmp = a.sortable(header_item_index) <=> b.sortable(header_item_index)
|
65
|
+
if @reversed
|
66
|
+
-cmp
|
67
|
+
else
|
68
|
+
cmp
|
69
|
+
end
|
70
|
+
end
|
71
|
+
return 0
|
72
|
+
end
|
73
|
+
|
74
|
+
def sortItems
|
75
|
+
@items.each do |item|
|
76
|
+
item.update_sort_key
|
77
|
+
end
|
78
|
+
super
|
79
|
+
end
|
80
|
+
|
81
|
+
# Check if the search order is reversed (happens when clicking on the same header twice)
|
82
|
+
def reversed?
|
83
|
+
@reversed
|
84
|
+
end
|
85
|
+
|
86
|
+
# Get index of the header that should be used for sorting
|
87
|
+
def sort_index
|
88
|
+
@header_item_index
|
89
|
+
end
|
90
|
+
|
91
|
+
# Add a new header. The block that you need to specify is used to convert a string of this
|
92
|
+
# column into something that can be used for sorting. The yielded parameter item_colum_text
|
93
|
+
# is the text of one item of this column.
|
94
|
+
def add_header(text, width, &conversion) # :yields: item_column_text
|
95
|
+
appendHeader(text, nil, width)
|
96
|
+
header.setArrowDir(0, false) if @conversions.empty?
|
97
|
+
@conversions.push conversion
|
98
|
+
end
|
99
|
+
|
100
|
+
# Create a new Packet_Item. After the icon, you can specify the text for each of the columns.
|
101
|
+
# Here is an example:
|
102
|
+
# list.create_item(my_icon, "Martin", "Ankerl", "2005")
|
103
|
+
def create_item(icon, *args)
|
104
|
+
Packet_Item.new(self, icon, *args)
|
105
|
+
end
|
106
|
+
|
107
|
+
# Add a new Packet_Item to this list.Called from within Packet_Item during Packet_Item#parent=
|
108
|
+
def add_item(item)
|
109
|
+
@items.add item
|
110
|
+
appendItem(item.fox_item)
|
111
|
+
item
|
112
|
+
end
|
113
|
+
|
114
|
+
# Remove the given Packet_Item from the list. This is slow, because
|
115
|
+
# the item has to be searched with a linear search. To remove all items
|
116
|
+
# use #clear.
|
117
|
+
def remove_item(item)
|
118
|
+
i = 0
|
119
|
+
@items.delete item
|
120
|
+
fox_item = item.fox_item
|
121
|
+
i += 1 while i < numItems && fox_item != getItem(i)
|
122
|
+
removeItem(i) if i < numItems
|
123
|
+
item
|
124
|
+
end
|
125
|
+
|
126
|
+
def appendItem(*args)
|
127
|
+
$fx_icon_item_remove_mutex.synchronize do
|
128
|
+
#puts "appendItem"
|
129
|
+
super
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
# Before actually deleting, the item has to be marked as deleted to prevent
|
134
|
+
# drawing afterwards.
|
135
|
+
def removeItem(*args)
|
136
|
+
$fx_icon_item_remove_mutex.synchronize do
|
137
|
+
#puts "removeitem"
|
138
|
+
# at first, mark item as deleted to prevent drawing afterwards
|
139
|
+
getItem(args[0]).deleted
|
140
|
+
# do the evil delete
|
141
|
+
super
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
# Remove all items, but do this within the mutex to be sure everything goes ok.
|
146
|
+
def clearItems(*args)
|
147
|
+
$fx_icon_item_remove_mutex.synchronize do
|
148
|
+
#puts "clearitems"
|
149
|
+
super
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
153
|
+
# This may be called when the item is currently beeing deleted.
|
154
|
+
# this method works only before or after the delete, therefore
|
155
|
+
# the mutex is necessary.
|
156
|
+
def getContentWidth(*args)
|
157
|
+
$fx_icon_item_remove_mutex.synchronize do
|
158
|
+
#puts "contentwidth"
|
159
|
+
super
|
160
|
+
end
|
161
|
+
end
|
162
|
+
|
163
|
+
# This may be called when the item is currently beeing deleted.
|
164
|
+
# this method works only before or after the delete, therefore
|
165
|
+
# the mutex is necessary.
|
166
|
+
def getContentHeight(*args)
|
167
|
+
$fx_icon_item_remove_mutex.synchronize do
|
168
|
+
#puts "contentheight"
|
169
|
+
super
|
170
|
+
end
|
171
|
+
end
|
172
|
+
|
173
|
+
# Removes all items from the list.
|
174
|
+
def clear
|
175
|
+
@items.each { |item| item.clear }
|
176
|
+
@items.clear
|
177
|
+
# todo: mutex!?
|
178
|
+
clearItems
|
179
|
+
end
|
180
|
+
|
181
|
+
# use in combination with Packet_Item#show
|
182
|
+
def dirty_clear
|
183
|
+
clearItems
|
184
|
+
@items.clear
|
185
|
+
end
|
186
|
+
|
187
|
+
# Get the sort for a given header index. The sort function has been supplied
|
188
|
+
# when calling #new. This is used from Packet_Item.
|
189
|
+
def sort_function(header_item_index)
|
190
|
+
@conversions[header_item_index]
|
191
|
+
end
|
192
|
+
end
|