alexandria-book-collection-manager 0.6.9 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.rubocop.yml +34 -30
- data/.rubocop_todo.yml +139 -54
- data/CHANGELOG.md +10 -0
- data/Gemfile +1 -0
- data/Rakefile +10 -11
- data/alexandria-book-collection-manager.gemspec +3 -2
- data/bin/alexandria +1 -1
- data/lib/alexandria.rb +3 -6
- data/lib/alexandria/about.rb +9 -9
- data/lib/alexandria/book_providers.rb +12 -12
- data/lib/alexandria/book_providers/adlibris.rb +14 -18
- data/lib/alexandria/book_providers/amazon_aws.rb +17 -31
- data/lib/alexandria/book_providers/amazon_ecs_util.rb +5 -6
- data/lib/alexandria/book_providers/barnes_and_noble.rb +51 -76
- data/lib/alexandria/book_providers/bol_it.rb +12 -12
- data/lib/alexandria/book_providers/deastore.rb +27 -31
- data/lib/alexandria/book_providers/douban.rb +9 -13
- data/lib/alexandria/book_providers/ibs_it.rb +10 -10
- data/lib/alexandria/book_providers/mcu.rb +12 -18
- data/lib/alexandria/book_providers/proxis.rb +14 -22
- data/lib/alexandria/book_providers/pseudomarc.rb +8 -18
- data/lib/alexandria/book_providers/renaud.rb +16 -16
- data/lib/alexandria/book_providers/siciliano.rb +25 -38
- data/lib/alexandria/book_providers/thalia.rb +13 -16
- data/lib/alexandria/book_providers/webster_it.rb +14 -18
- data/lib/alexandria/book_providers/worldcat.rb +21 -25
- data/lib/alexandria/book_providers/z3950.rb +19 -23
- data/lib/alexandria/config.rb +2 -2
- data/lib/alexandria/execution_queue.rb +3 -1
- data/lib/alexandria/export_library.rb +19 -22
- data/lib/alexandria/import_library.rb +14 -18
- data/lib/alexandria/import_library_csv.rb +12 -30
- data/lib/alexandria/models/book.rb +7 -9
- data/lib/alexandria/models/library.rb +44 -44
- data/lib/alexandria/net.rb +1 -1
- data/lib/alexandria/preferences.rb +12 -57
- data/lib/alexandria/scanners.rb +10 -6
- data/lib/alexandria/scanners/cuecat.rb +2 -2
- data/lib/alexandria/smart_library.rb +12 -12
- data/lib/alexandria/ui.rb +5 -2
- data/lib/alexandria/ui/callbacks.rb +106 -65
- data/lib/alexandria/ui/completion_models.rb +55 -51
- data/lib/alexandria/ui/dialogs/about_dialog.rb +1 -1
- data/lib/alexandria/ui/dialogs/acquire_dialog.rb +25 -51
- data/lib/alexandria/ui/dialogs/alert_dialog.rb +13 -11
- data/lib/alexandria/ui/dialogs/bad_isbns_dialog.rb +2 -2
- data/lib/alexandria/ui/dialogs/barcode_animation.rb +39 -23
- data/lib/alexandria/ui/dialogs/book_properties_dialog.rb +16 -21
- data/lib/alexandria/ui/dialogs/book_properties_dialog_base.rb +23 -24
- data/lib/alexandria/ui/dialogs/export_dialog.rb +46 -45
- data/lib/alexandria/ui/dialogs/import_dialog.rb +26 -35
- data/lib/alexandria/ui/dialogs/misc_dialogs.rb +11 -11
- data/lib/alexandria/ui/dialogs/new_book_dialog.rb +47 -59
- data/lib/alexandria/ui/dialogs/new_book_dialog_manual.rb +14 -13
- data/lib/alexandria/ui/dialogs/new_smart_library_dialog.rb +12 -11
- data/lib/alexandria/ui/dialogs/preferences_dialog.rb +37 -43
- data/lib/alexandria/ui/dialogs/smart_library_properties_dialog.rb +9 -8
- data/lib/alexandria/ui/dialogs/smart_library_properties_dialog_base.rb +47 -53
- data/lib/alexandria/ui/dndable.rb +5 -4
- data/lib/alexandria/ui/icons.rb +19 -19
- data/lib/alexandria/ui/iconview.rb +7 -12
- data/lib/alexandria/ui/iconview_tooltips.rb +22 -109
- data/lib/alexandria/ui/init.rb +7 -15
- data/lib/alexandria/ui/libraries_combo.rb +54 -48
- data/lib/alexandria/ui/listview.rb +30 -85
- data/lib/alexandria/ui/multi_drag_treeview.rb +110 -107
- data/lib/alexandria/ui/sidepane.rb +23 -25
- data/lib/alexandria/ui/sound.rb +18 -27
- data/lib/alexandria/ui/ui_manager.rb +126 -204
- data/lib/alexandria/undo_manager.rb +2 -2
- data/lib/alexandria/version.rb +4 -4
- data/spec/alexandria/book_providers_spec.rb +7 -4
- data/spec/alexandria/library_spec.rb +13 -16
- data/spec/alexandria/scanners/cuecat_spec.rb +1 -2
- data/spec/alexandria/ui/dialogs_spec.rb +5 -1
- data/spec/alexandria/ui/main_app_spec.rb +3 -3
- data/{lib/alexandria/utils.rb → spec/alexandria/ui/sound_spec.rb} +6 -11
- data/spec/alexandria/ui/ui_utilities_spec.rb +3 -3
- data/spec/spec_helper.rb +2 -2
- data/util/rake/fileinstall.rb +17 -33
- data/util/rake/gettextgenerate.rb +2 -4
- data/util/rake/omfgenerate.rb +1 -3
- metadata +23 -11
- data/lib/alexandria/ui/gtk_thread_help.rb +0 -89
@@ -1,5 +1,6 @@
|
|
1
1
|
# Copyright (C) 2004-2006 Laurent Sansonetti
|
2
2
|
# Copyright (C) 2008 Joseph Method
|
3
|
+
# Copyright (C) 2016 Matijs van Zuijlen
|
3
4
|
#
|
4
5
|
# Alexandria is free software; you can redistribute it and/or
|
5
6
|
# modify it under the terms of the GNU General Public License as
|
@@ -18,10 +19,10 @@
|
|
18
19
|
|
19
20
|
module Alexandria
|
20
21
|
module UI
|
21
|
-
BOOKS_TARGET_TABLE = [
|
22
|
+
BOOKS_TARGET_TABLE = [Gtk::TargetEntry.new('ALEXANDRIA_BOOKS', :same_app, 0)].freeze
|
22
23
|
|
23
24
|
module DragAndDropable
|
24
|
-
BADGE_MARKUP =
|
25
|
+
BADGE_MARKUP = '<span weight="heavy" foreground="white">%d</span>'.freeze
|
25
26
|
|
26
27
|
def setup_view_source_dnd(view)
|
27
28
|
# better be Loggable!
|
@@ -71,9 +72,9 @@ module Alexandria
|
|
71
72
|
end
|
72
73
|
end
|
73
74
|
|
74
|
-
view.enable_model_drag_source(
|
75
|
+
view.enable_model_drag_source(:button1_mask,
|
75
76
|
Alexandria::UI::BOOKS_TARGET_TABLE,
|
76
|
-
|
77
|
+
:move)
|
77
78
|
end
|
78
79
|
end
|
79
80
|
end
|
data/lib/alexandria/ui/icons.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
# Copyright (C) 2004-2006 Laurent Sansonetti
|
2
|
-
# Copyright (C) 2014 Matijs van Zuijlen
|
2
|
+
# Copyright (C) 2014-2016 Matijs van Zuijlen
|
3
3
|
#
|
4
4
|
# Alexandria is free software; you can redistribute it and/or
|
5
5
|
# modify it under the terms of the GNU General Public License as
|
@@ -16,18 +16,18 @@
|
|
16
16
|
# write to the Free Software Foundation, Inc., 51 Franklin Street,
|
17
17
|
# Fifth Floor, Boston, MA 02110-1301 USA.
|
18
18
|
|
19
|
-
class
|
19
|
+
class GdkPixbuf::Pixbuf
|
20
20
|
def tag(tag_pixbuf)
|
21
21
|
# Computes some tweaks.
|
22
22
|
tweak_x = tag_pixbuf.width / 3
|
23
23
|
tweak_y = tag_pixbuf.height / 3
|
24
24
|
|
25
25
|
# Creates the destination pixbuf.
|
26
|
-
new_pixbuf =
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
26
|
+
new_pixbuf = GdkPixbuf::Pixbuf.new(colorspace: :rgb,
|
27
|
+
has_alpha: true,
|
28
|
+
bits_per_sample: 8,
|
29
|
+
width: width + tweak_x,
|
30
|
+
height: height + tweak_y)
|
31
31
|
|
32
32
|
# Fills with blank.
|
33
33
|
new_pixbuf.fill!(0)
|
@@ -41,12 +41,12 @@ class Gdk::Pixbuf
|
|
41
41
|
# Copies the tag pixbuf there (north-est).
|
42
42
|
tag_pixbuf_x = width - (tweak_x * 2)
|
43
43
|
new_pixbuf.composite!(tag_pixbuf,
|
44
|
-
0, 0,
|
45
|
-
tag_pixbuf.width + tag_pixbuf_x,
|
46
|
-
tag_pixbuf.height,
|
47
|
-
tag_pixbuf_x, 0,
|
48
|
-
1, 1,
|
49
|
-
|
44
|
+
dest_x: 0, dest_y: 0,
|
45
|
+
dest_width: tag_pixbuf.width + tag_pixbuf_x,
|
46
|
+
dest_height: tag_pixbuf.height,
|
47
|
+
offset_x: tag_pixbuf_x, offset_y: 0,
|
48
|
+
scale_x: 1, scale_y: 1,
|
49
|
+
interpolation_type: :hyper, overall_alpha: 255)
|
50
50
|
new_pixbuf
|
51
51
|
end
|
52
52
|
end
|
@@ -63,11 +63,11 @@ module Alexandria
|
|
63
63
|
# Alexandria::UI::Icons namespace, e.g., Icons::STAR_SET
|
64
64
|
def self.load_icon_images
|
65
65
|
Dir.entries(ICONS_DIR).each do |file|
|
66
|
-
next unless file =~ /\.png$/
|
66
|
+
next unless file =~ /\.png$/ # skip non '.png' files
|
67
67
|
# Don't use upcase and use tr instead
|
68
68
|
# For example in Turkish the upper case of 'i' is still 'i'.
|
69
69
|
name = File.basename(file, '.png').tr('a-z', 'A-Z')
|
70
|
-
const_set(name,
|
70
|
+
const_set(name, GdkPixbuf::Pixbuf.new(file: File.join(ICONS_DIR, file)))
|
71
71
|
end
|
72
72
|
end
|
73
73
|
|
@@ -76,20 +76,20 @@ module Alexandria
|
|
76
76
|
return BOOK_ICON if library.nil?
|
77
77
|
filename = library.cover(book)
|
78
78
|
if File.exist?(filename)
|
79
|
-
return
|
79
|
+
return GdkPixbuf::Pixbuf.new(file: filename)
|
80
80
|
end
|
81
81
|
rescue => err
|
82
82
|
# report load error; FIX should go to a Logger...
|
83
83
|
puts err.message
|
84
84
|
puts err.backtrace.join("\n> ")
|
85
|
-
puts "Failed to load
|
85
|
+
puts "Failed to load GdkPixbuf::Pixbuf, please ensure that from #{filename} is a valid image file"
|
86
86
|
end
|
87
87
|
BOOK_ICON
|
88
88
|
end
|
89
89
|
|
90
90
|
def self.blank?(filename)
|
91
|
-
pixbuf =
|
92
|
-
pixbuf.width == 1
|
91
|
+
pixbuf = GdkPixbuf::Pixbuf.new(file: filename)
|
92
|
+
(pixbuf.width == 1) && (pixbuf.height == 1)
|
93
93
|
rescue => err
|
94
94
|
puts err.message
|
95
95
|
puts err.backtrace.join("\n> ")
|
@@ -1,5 +1,6 @@
|
|
1
1
|
# Copyright (C) 2004-2006 Laurent Sansonetti
|
2
2
|
# Copyright (C) 2008 Joseph Method
|
3
|
+
# Copyright (C) 2016 Matijs van Zuijlen
|
3
4
|
#
|
4
5
|
# Alexandria is free software; you can redistribute it and/or
|
5
6
|
# modify it under the terms of the GNU General Public License as
|
@@ -45,29 +46,23 @@ module Alexandria
|
|
45
46
|
log.info { "setup_books_iconview #{@iconview_model.inspect}" }
|
46
47
|
@iconview.model = @iconview_model
|
47
48
|
log.info { "now @iconview.model = #{@iconview.model.inspect}" }
|
48
|
-
@iconview.selection_mode =
|
49
|
+
@iconview.selection_mode = :multiple
|
49
50
|
@iconview.text_column = Columns::TITLE_REDUCED
|
50
51
|
@iconview.pixbuf_column = Columns::COVER_ICON
|
51
|
-
@iconview.
|
52
|
+
@iconview.item_orientation = :vertical
|
52
53
|
@iconview.row_spacing = 4
|
53
54
|
@iconview.column_spacing = 16
|
54
55
|
@iconview.item_width = ICON_WIDTH + 16
|
55
56
|
|
56
57
|
@iconview.signal_connect('selection-changed') do
|
57
58
|
log.debug { 'selection-changed' }
|
58
|
-
@tooltips.hide_tooltip
|
59
59
|
@parent.on_books_selection_changed
|
60
60
|
end
|
61
61
|
|
62
62
|
@iconview.signal_connect('item-activated') do
|
63
63
|
log.debug { 'item-activated' }
|
64
|
-
|
65
|
-
|
66
|
-
@tooltips.hide_tooltip
|
67
|
-
Gtk.timeout_add(100) do
|
68
|
-
@actiongroup['Properties'].activate
|
69
|
-
false
|
70
|
-
end
|
64
|
+
@actiongroup['Properties'].activate
|
65
|
+
false
|
71
66
|
end
|
72
67
|
|
73
68
|
# DND support for Gtk::IconView is shipped since GTK+ 2.8.0.
|
@@ -79,12 +74,12 @@ module Alexandria
|
|
79
74
|
ICONS_SORTS = [
|
80
75
|
Columns::TITLE, Columns::AUTHORS, Columns::ISBN,
|
81
76
|
Columns::PUBLISHER, Columns::EDITION, Columns::RATING, Columns::REDD, Columns::OWN, Columns::WANT
|
82
|
-
]
|
77
|
+
].freeze
|
83
78
|
def setup_books_iconview_sorting
|
84
79
|
mode = ICONS_SORTS[@prefs.arrange_icons_mode]
|
85
80
|
@iconview_model.set_sort_column_id(mode,
|
86
81
|
@prefs.reverse_icons ? Gtk::SORT_DESCENDING : Gtk::SORT_ASCENDING)
|
87
|
-
@filtered_model.refilter
|
82
|
+
@filtered_model.refilter # force redraw
|
88
83
|
end
|
89
84
|
end
|
90
85
|
end
|
@@ -2,7 +2,7 @@
|
|
2
2
|
#
|
3
3
|
# Copyright (C) 2007 kksou
|
4
4
|
# Copyright (C) 2008,2009 Cathal Mc Ginley
|
5
|
-
# Copyright (C) 2011, 2014 Matijs van Zuijlen
|
5
|
+
# Copyright (C) 2011, 2014, 2016 Matijs van Zuijlen
|
6
6
|
#
|
7
7
|
# Alexandria is free software; you can redistribute it and/or
|
8
8
|
# modify it under the terms of the GNU General Public License as
|
@@ -33,134 +33,47 @@ class IconViewTooltips
|
|
33
33
|
include Alexandria::Logging
|
34
34
|
|
35
35
|
def initialize(view)
|
36
|
-
@tooltip_window = Gtk::Window.new(Gtk::Window::POPUP)
|
37
|
-
@tooltip_window.name = 'gtk-tooltips'
|
38
|
-
@tooltip_window.resizable = false
|
39
|
-
@tooltip_window.border_width = 4
|
40
|
-
@tooltip_window.app_paintable = true
|
41
|
-
|
42
|
-
@tooltip_window.signal_connect('expose_event') { |window, event|
|
43
|
-
on_expose(window, event)
|
44
|
-
}
|
45
|
-
|
46
|
-
@tooltip_window.signal_connect('leave_notify_event') { |vw, event|
|
47
|
-
on_leave(vw, event)
|
48
|
-
}
|
49
|
-
|
50
|
-
@label = Gtk::Label.new('')
|
51
|
-
@label.wrap = true
|
52
|
-
@label.set_alignment(0.5, 0.5)
|
53
|
-
@label.use_markup = true
|
54
|
-
@label.show
|
55
|
-
|
56
|
-
@tooltip_window.add(@label)
|
57
36
|
set_view(view)
|
58
37
|
end
|
59
38
|
|
60
39
|
def set_view(view)
|
61
|
-
view.
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
Gtk::SHADOW_OUT,
|
75
|
-
nil,
|
76
|
-
@tooltip_window,
|
77
|
-
'tooltip',
|
78
|
-
0, 0, size[0], size[1])
|
79
|
-
# must return nil so the label contents get drawn correctly
|
80
|
-
nil
|
40
|
+
view.has_tooltip = true
|
41
|
+
view.signal_connect('query-tooltip') do |_widget, x, y, _keyboard_mode, tooltip|
|
42
|
+
tree_path = view.get_path_at_pos(x, y)
|
43
|
+
if tree_path
|
44
|
+
iter = view.model.get_iter(tree_path)
|
45
|
+
|
46
|
+
title = iter[2] # HACK: hardcoded, should use column names...
|
47
|
+
authors = iter[4]
|
48
|
+
publisher = iter[6]
|
49
|
+
year = iter[7]
|
50
|
+
tooltip.set_markup label_for_book(title, authors, publisher, year)
|
51
|
+
end
|
52
|
+
end
|
81
53
|
end
|
82
54
|
|
83
55
|
def label_for_book(title, authors, publisher, year)
|
84
56
|
# This is much too complex... but it works for now!
|
85
57
|
html = ''
|
86
|
-
|
58
|
+
unless title.empty?
|
87
59
|
html += "<b>#{CGI.escapeHTML(title)}</b>"
|
88
|
-
|
89
|
-
html += "\n"
|
90
|
-
end
|
60
|
+
html += "\n" unless authors.empty?
|
91
61
|
end
|
92
|
-
|
62
|
+
unless authors.empty?
|
93
63
|
html += "<i>#{CGI.escapeHTML(authors)}</i>"
|
94
64
|
end
|
95
|
-
if
|
96
|
-
html += "\n"
|
97
|
-
end
|
65
|
+
html += "\n" if !title.empty? || !authors.empty?
|
98
66
|
|
99
67
|
html += '<small>'
|
100
|
-
if publisher
|
101
|
-
html +=
|
68
|
+
if publisher && !publisher.empty?
|
69
|
+
html += CGI.escapeHTML(publisher).to_s
|
102
70
|
end
|
103
71
|
|
104
|
-
if year
|
105
|
-
if publisher
|
106
|
-
html += ' '
|
107
|
-
end
|
72
|
+
if year && !year.empty?
|
73
|
+
html += ' ' if publisher && !publisher.empty?
|
108
74
|
html += "(#{year})"
|
109
75
|
end
|
110
76
|
|
111
77
|
html + '</small>'
|
112
78
|
end
|
113
|
-
|
114
|
-
def on_motion(view, event)
|
115
|
-
tree_path = view.get_path(event.x, event.y)
|
116
|
-
# TODO translate path a few times, for sorting & filtering...
|
117
|
-
# hmmm, actually seems to work. Report a bug if you can spot a failure
|
118
|
-
if tree_path
|
119
|
-
iter = view.model.get_iter(tree_path)
|
120
|
-
if @latest_iter.nil?
|
121
|
-
@latest_iter = iter
|
122
|
-
|
123
|
-
@tooltip_timeout_id = Gtk.timeout_add(250) do
|
124
|
-
if @latest_iter == iter
|
125
|
-
|
126
|
-
title = iter[2] # HACK hardcoded, should use column names...
|
127
|
-
authors = iter[4]
|
128
|
-
publisher = iter[6]
|
129
|
-
year = iter[7]
|
130
|
-
@label.markup = label_for_book(title, authors, publisher, year)
|
131
|
-
## "<b>#{title}</b>\n<i>#{authors}</i>\n<small>#{publisher} <i>(#{year})</i></small>"
|
132
|
-
size = @tooltip_window.size_request
|
133
|
-
@tooltip_window.move(event.x_root - size[0],
|
134
|
-
event.y_root + 12)
|
135
|
-
@tooltip_window.show
|
136
|
-
# don't run again
|
137
|
-
false
|
138
|
-
else
|
139
|
-
@tooltip_timeout_id = nil
|
140
|
-
end
|
141
|
-
end
|
142
|
-
|
143
|
-
elsif @latest_iter != iter
|
144
|
-
hide_tooltip
|
145
|
-
end
|
146
|
-
|
147
|
-
else
|
148
|
-
hide_tooltip
|
149
|
-
end
|
150
|
-
end
|
151
|
-
|
152
|
-
def hide_tooltip
|
153
|
-
unless @tooltip_window.nil?
|
154
|
-
@tooltip_window.hide
|
155
|
-
if @tooltip_timeout_id
|
156
|
-
Gtk.timeout_remove(@tooltip_timeout_id)
|
157
|
-
@tooltip_timeout_id = nil
|
158
|
-
end
|
159
|
-
@latest_iter = nil
|
160
|
-
end
|
161
|
-
end
|
162
|
-
|
163
|
-
def on_leave(_view, _event)
|
164
|
-
@tooltip_window.hide
|
165
|
-
end
|
166
79
|
end
|
data/lib/alexandria/ui/init.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Copyright (C) 2004-2006 Laurent Sansonetti
|
2
2
|
# Copyright (C) 2008 Joseph Method
|
3
|
-
# Copyright (C) 2011 Matijs van Zuijlen
|
3
|
+
# Copyright (C) 2011, 2016 Matijs van Zuijlen
|
4
4
|
#
|
5
5
|
# Alexandria is free software; you can redistribute it and/or
|
6
6
|
# modify it under the terms of the GNU General Public License as
|
@@ -21,11 +21,11 @@ class CellRendererToggle < Gtk::CellRendererToggle
|
|
21
21
|
attr_accessor :text
|
22
22
|
type_register
|
23
23
|
install_property(GLib::Param::String.new(
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
24
|
+
'text',
|
25
|
+
'text',
|
26
|
+
'Some damn value',
|
27
|
+
'',
|
28
|
+
GLib::Param::READABLE | GLib::Param::WRITABLE))
|
29
29
|
end
|
30
30
|
|
31
31
|
class Gtk::ActionGroup
|
@@ -68,19 +68,11 @@ class Alexandria::BookProviders::AbstractProvider
|
|
68
68
|
end
|
69
69
|
end
|
70
70
|
|
71
|
-
module Pango
|
72
|
-
def self.ellipsizable?
|
73
|
-
@ellipsizable ||= Pango.constants.include?('ELLIPSIZE_END')
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
71
|
module Alexandria
|
78
72
|
module UI
|
79
73
|
def self.display_help(parent = nil, section = nil)
|
80
74
|
section_index = ''
|
81
|
-
if section
|
82
|
-
section_index = "##{section}"
|
83
|
-
end
|
75
|
+
section_index = "##{section}" if section
|
84
76
|
exec("gnome-help ghelp:alexandria#{section_index}") if fork.nil?
|
85
77
|
rescue
|
86
78
|
log.error(self) { 'Unable to load help browser' }
|
@@ -1,4 +1,5 @@
|
|
1
1
|
# Copyright (C) 2004-2006 Laurent Sansonetti
|
2
|
+
# Copyright (C) 2016 Matijs van Zuijlen
|
2
3
|
#
|
3
4
|
# Alexandria is free software; you can redistribute it and/or
|
4
5
|
# modify it under the terms of the GNU General Public License as
|
@@ -16,60 +17,65 @@
|
|
16
17
|
# Fifth Floor, Boston, MA 02110-1301 USA.
|
17
18
|
|
18
19
|
# Ideally this would be a subclass of GtkComboBox, but...
|
19
|
-
class Gtk::ComboBox
|
20
|
-
include GetText
|
21
|
-
extend GetText
|
22
|
-
GetText.bindtextdomain(Alexandria::TEXTDOMAIN, charset: 'UTF-8')
|
23
20
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
21
|
+
module Alexandria
|
22
|
+
module ComboBoxOverrides
|
23
|
+
include GetText
|
24
|
+
extend GetText
|
25
|
+
GetText.bindtextdomain(Alexandria::TEXTDOMAIN, charset: 'UTF-8')
|
26
|
+
|
27
|
+
def populate_with_libraries(libraries, selected_library)
|
28
|
+
libraries_names = libraries.map(&:name)
|
29
|
+
if selected_library
|
30
|
+
libraries_names.delete selected_library.name
|
31
|
+
libraries_names.unshift selected_library.name
|
32
|
+
end
|
33
|
+
clear
|
34
|
+
set_row_separator_func do |model, iter|
|
35
|
+
model.get_value(iter, 1) == '-'
|
36
|
+
end
|
37
|
+
self.model = Gtk::ListStore.new(GdkPixbuf::Pixbuf, String, TrueClass)
|
38
|
+
libraries_names.each do |library_name|
|
39
|
+
iter = model.append
|
40
|
+
iter[0] = Alexandria::UI::Icons::LIBRARY_SMALL
|
41
|
+
iter[1] = library_name
|
42
|
+
iter[2] = false
|
43
|
+
end
|
44
|
+
model.append[1] = '-'
|
36
45
|
iter = model.append
|
37
46
|
iter[0] = Alexandria::UI::Icons::LIBRARY_SMALL
|
38
|
-
iter[1] =
|
39
|
-
iter[2] =
|
47
|
+
iter[1] = _('New Library')
|
48
|
+
iter[2] = true
|
49
|
+
renderer = Gtk::CellRendererPixbuf.new
|
50
|
+
pack_start(renderer, false)
|
51
|
+
set_attributes(renderer, pixbuf: 0)
|
52
|
+
renderer = Gtk::CellRendererText.new
|
53
|
+
pack_start(renderer, true)
|
54
|
+
set_attributes(renderer, text: 1)
|
55
|
+
self.active = 0
|
56
|
+
# self.sensitive = libraries.length > 1
|
57
|
+
# This prohibits us from adding a "New Library" from this combo
|
58
|
+
# when we only have a single library
|
40
59
|
end
|
41
|
-
model.append[1] = '-'
|
42
|
-
iter = model.append
|
43
|
-
iter[0] = Alexandria::UI::Icons::LIBRARY_SMALL
|
44
|
-
iter[1] = _('New Library')
|
45
|
-
iter[2] = true
|
46
|
-
renderer = Gtk::CellRendererPixbuf.new
|
47
|
-
pack_start(renderer, false)
|
48
|
-
set_attributes(renderer, pixbuf: 0)
|
49
|
-
renderer = Gtk::CellRendererText.new
|
50
|
-
pack_start(renderer, true)
|
51
|
-
set_attributes(renderer, text: 1)
|
52
|
-
self.active = 0
|
53
|
-
# self.sensitive = libraries.length > 1
|
54
|
-
# This prohibits us from adding a "New Library" from this combo
|
55
|
-
# when we only have a single library
|
56
|
-
end
|
57
60
|
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
61
|
+
def selection_from_libraries(libraries)
|
62
|
+
iter = active_iter
|
63
|
+
is_new = false
|
64
|
+
library = nil
|
65
|
+
if iter[2]
|
66
|
+
name = Alexandria::Library.generate_new_name(libraries)
|
67
|
+
library = Alexandria::Library.load(name)
|
68
|
+
libraries << library
|
69
|
+
is_new = true
|
70
|
+
else
|
71
|
+
library = libraries.find do |x|
|
72
|
+
x.name == active_iter[1]
|
73
|
+
end
|
70
74
|
end
|
75
|
+
raise unless library
|
76
|
+
[library, is_new]
|
71
77
|
end
|
72
|
-
raise unless library
|
73
|
-
[library, is_new]
|
74
78
|
end
|
75
79
|
end
|
80
|
+
|
81
|
+
Gtk::ComboBox.prepend Alexandria::ComboBoxOverrides
|