29
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
|
# File 'lib/alexandria/ui/dndable.rb', line 29
def setup_view_source_dnd(view)
log.info { format('setup_view_source_dnd for %s', view) }
view.signal_connect_after('drag-begin') do |_widget, drag_context|
n_books = @parent.selected_books.length
if n_books > 1
pixmap, mask = Icons::BOOK_ICON.render_pixmap_and_mask(255)
context = Gdk::Pango.context
layout = Pango::Layout.new(context)
layout.markup = BADGE_MARKUP % n_books
width, height = layout.pixel_size
x = Icons::BOOK_ICON.width - width - 11
y = Icons::BOOK_ICON.height - height - 11
red_gc = Gdk::GC.new(pixmap)
red_gc.rgb_fg_color = Gdk::Color.parse('red')
red_gc.rgb_bg_color = Gdk::Color.parse('red')
pixmap.draw_arc(red_gc,
true,
x - 5, y - 2,
width + 9, height + 4,
0, 360 * 64)
pixmap.draw_layout(Gdk::GC.new(pixmap), x, y, layout)
Gtk::Drag.set_icon(drag_context,
pixmap.colormap,
pixmap,
mask,
10,
10)
end
end
view.signal_connect('drag-data-get') do |_widget, _drag_context, selection_data, _info, _time|
idents = @parent.selected_books.map(&:ident)
unless idents.empty?
selection_data.set(Gdk::Selection::TYPE_STRING,
idents.join(','))
end
end
view.enable_model_drag_source(:button1_mask,
Alexandria::UI::BOOKS_TARGET_TABLE,
:move)
end
|