| 1 |
|
| 2 |
require 'mui/gtk_extension' |
| 3 |
require 'mui/gtk_inneruserlist' |
| 4 |
|
| 5 |
require 'gtk3' |
| 6 |
require 'set' |
| 7 |
|
| 8 |
class Gtk::UserList < Gtk::EventBox |
| 9 |
include Enumerable |
| 10 |
|
| 11 |
attr_reader :listview |
| 12 |
|
| 13 |
ックとかされた時に呼ばれるProcを返す |
| 14 |
|
| 15 |
|
| 16 |
def self.row_activated |
| 17 |
->(this, path, column) do |
| 18 |
iter = this.model.get_iter(path) |
| 19 |
if iter |
| 20 |
Plugin.call(:open, iter[Gtk::InnerUserList::COL_USER]) |
| 21 |
end |
| 22 |
end |
| 23 |
end |
| 24 |
|
| 25 |
def initialize |
| 26 |
super |
| 27 |
@listview = Gtk::InnerUserList.new(self) |
| 28 |
add Gtk::ScrolledWindow.new.add(@listview) |
| 29 |
@listview.ssc(:row_activated, &self.class.row_activated) |
| 30 |
@listview.ssc(:draw){ |
| 31 |
emit_expose_user |
| 32 |
false |
| 33 |
} |
| 34 |
end |
| 35 |
|
| 36 |
def each |
| 37 |
@listview.each{ |m, p, i| i[Gtk::InnerUserList::COL_USER] } end |
| 38 |
|
| 39 |
を追加する |
| 40 |
|
| 41 |
返すEnumerable |
| 42 |
|
| 43 |
|
| 44 |
def add_user(users) |
| 45 |
@to_a = nil |
| 46 |
@listview.add_user(users) |
| 47 |
end |
| 48 |
|
| 49 |
まれるユーザを削除する |
| 50 |
|
| 51 |
ザの配列 |
| 52 |
|
| 53 |
|
| 54 |
def remove_user(users) |
| 55 |
@to_a = nil |
| 56 |
@listview.remove_user(users) |
| 57 |
end |
| 58 |
|
| 59 |
def gen_order(user) |
| 60 |
(@order_generator ||= gen_counter).call end |
| 61 |
|
| 62 |
順番を再計算する |
| 63 |
|
| 64 |
ーザ |
| 65 |
|
| 66 |
|
| 67 |
def reorder(user) |
| 68 |
type_strict user => User |
| 69 |
@listview.reorder(user) |
| 70 |
self end |
| 71 |
|
| 72 |
private |
| 73 |
|
| 74 |
def emit_expose_user |
| 75 |
val, current, last = @listview.visible_range |
| 76 |
if val |
| 77 |
Enumerator.new{|y| |
| 78 |
while (current <=> last) < 1 |
| 79 |
y << @listview.model.get_iter(current) |
| 80 |
break if not current.next! |
| 81 |
end |
| 82 |
}.reject{|iter| |
| 83 |
iter[Gtk::InnerUserList::COL_ICON] |
| 84 |
}.each do |iter| |
| 85 |
iter[Gtk::InnerUserList::COL_ICON] = iter[Gtk::InnerUserList::COL_USER].icon.load_pixbuf(width: 24, height: 24){|pixbuf| |
| 86 |
iter[Gtk::InnerUserList::COL_ICON] = pixbuf unless @listview.destroyed? |
| 87 |
} |
| 88 |
end |
| 89 |
end |
| 90 |
end |
| 91 |
|
| 92 |
end |
| 93 |
|