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.
Files changed (86) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.rubocop.yml +34 -30
  4. data/.rubocop_todo.yml +139 -54
  5. data/CHANGELOG.md +10 -0
  6. data/Gemfile +1 -0
  7. data/Rakefile +10 -11
  8. data/alexandria-book-collection-manager.gemspec +3 -2
  9. data/bin/alexandria +1 -1
  10. data/lib/alexandria.rb +3 -6
  11. data/lib/alexandria/about.rb +9 -9
  12. data/lib/alexandria/book_providers.rb +12 -12
  13. data/lib/alexandria/book_providers/adlibris.rb +14 -18
  14. data/lib/alexandria/book_providers/amazon_aws.rb +17 -31
  15. data/lib/alexandria/book_providers/amazon_ecs_util.rb +5 -6
  16. data/lib/alexandria/book_providers/barnes_and_noble.rb +51 -76
  17. data/lib/alexandria/book_providers/bol_it.rb +12 -12
  18. data/lib/alexandria/book_providers/deastore.rb +27 -31
  19. data/lib/alexandria/book_providers/douban.rb +9 -13
  20. data/lib/alexandria/book_providers/ibs_it.rb +10 -10
  21. data/lib/alexandria/book_providers/mcu.rb +12 -18
  22. data/lib/alexandria/book_providers/proxis.rb +14 -22
  23. data/lib/alexandria/book_providers/pseudomarc.rb +8 -18
  24. data/lib/alexandria/book_providers/renaud.rb +16 -16
  25. data/lib/alexandria/book_providers/siciliano.rb +25 -38
  26. data/lib/alexandria/book_providers/thalia.rb +13 -16
  27. data/lib/alexandria/book_providers/webster_it.rb +14 -18
  28. data/lib/alexandria/book_providers/worldcat.rb +21 -25
  29. data/lib/alexandria/book_providers/z3950.rb +19 -23
  30. data/lib/alexandria/config.rb +2 -2
  31. data/lib/alexandria/execution_queue.rb +3 -1
  32. data/lib/alexandria/export_library.rb +19 -22
  33. data/lib/alexandria/import_library.rb +14 -18
  34. data/lib/alexandria/import_library_csv.rb +12 -30
  35. data/lib/alexandria/models/book.rb +7 -9
  36. data/lib/alexandria/models/library.rb +44 -44
  37. data/lib/alexandria/net.rb +1 -1
  38. data/lib/alexandria/preferences.rb +12 -57
  39. data/lib/alexandria/scanners.rb +10 -6
  40. data/lib/alexandria/scanners/cuecat.rb +2 -2
  41. data/lib/alexandria/smart_library.rb +12 -12
  42. data/lib/alexandria/ui.rb +5 -2
  43. data/lib/alexandria/ui/callbacks.rb +106 -65
  44. data/lib/alexandria/ui/completion_models.rb +55 -51
  45. data/lib/alexandria/ui/dialogs/about_dialog.rb +1 -1
  46. data/lib/alexandria/ui/dialogs/acquire_dialog.rb +25 -51
  47. data/lib/alexandria/ui/dialogs/alert_dialog.rb +13 -11
  48. data/lib/alexandria/ui/dialogs/bad_isbns_dialog.rb +2 -2
  49. data/lib/alexandria/ui/dialogs/barcode_animation.rb +39 -23
  50. data/lib/alexandria/ui/dialogs/book_properties_dialog.rb +16 -21
  51. data/lib/alexandria/ui/dialogs/book_properties_dialog_base.rb +23 -24
  52. data/lib/alexandria/ui/dialogs/export_dialog.rb +46 -45
  53. data/lib/alexandria/ui/dialogs/import_dialog.rb +26 -35
  54. data/lib/alexandria/ui/dialogs/misc_dialogs.rb +11 -11
  55. data/lib/alexandria/ui/dialogs/new_book_dialog.rb +47 -59
  56. data/lib/alexandria/ui/dialogs/new_book_dialog_manual.rb +14 -13
  57. data/lib/alexandria/ui/dialogs/new_smart_library_dialog.rb +12 -11
  58. data/lib/alexandria/ui/dialogs/preferences_dialog.rb +37 -43
  59. data/lib/alexandria/ui/dialogs/smart_library_properties_dialog.rb +9 -8
  60. data/lib/alexandria/ui/dialogs/smart_library_properties_dialog_base.rb +47 -53
  61. data/lib/alexandria/ui/dndable.rb +5 -4
  62. data/lib/alexandria/ui/icons.rb +19 -19
  63. data/lib/alexandria/ui/iconview.rb +7 -12
  64. data/lib/alexandria/ui/iconview_tooltips.rb +22 -109
  65. data/lib/alexandria/ui/init.rb +7 -15
  66. data/lib/alexandria/ui/libraries_combo.rb +54 -48
  67. data/lib/alexandria/ui/listview.rb +30 -85
  68. data/lib/alexandria/ui/multi_drag_treeview.rb +110 -107
  69. data/lib/alexandria/ui/sidepane.rb +23 -25
  70. data/lib/alexandria/ui/sound.rb +18 -27
  71. data/lib/alexandria/ui/ui_manager.rb +126 -204
  72. data/lib/alexandria/undo_manager.rb +2 -2
  73. data/lib/alexandria/version.rb +4 -4
  74. data/spec/alexandria/book_providers_spec.rb +7 -4
  75. data/spec/alexandria/library_spec.rb +13 -16
  76. data/spec/alexandria/scanners/cuecat_spec.rb +1 -2
  77. data/spec/alexandria/ui/dialogs_spec.rb +5 -1
  78. data/spec/alexandria/ui/main_app_spec.rb +3 -3
  79. data/{lib/alexandria/utils.rb → spec/alexandria/ui/sound_spec.rb} +6 -11
  80. data/spec/alexandria/ui/ui_utilities_spec.rb +3 -3
  81. data/spec/spec_helper.rb +2 -2
  82. data/util/rake/fileinstall.rb +17 -33
  83. data/util/rake/gettextgenerate.rb +2 -4
  84. data/util/rake/omfgenerate.rb +1 -3
  85. metadata +23 -11
  86. 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 = [['ALEXANDRIA_BOOKS', Gtk::Drag::TARGET_SAME_APP, 0]]
22
+ BOOKS_TARGET_TABLE = [Gtk::TargetEntry.new('ALEXANDRIA_BOOKS', :same_app, 0)].freeze
22
23
 
23
24
  module DragAndDropable
24
- BADGE_MARKUP = "<span weight=\"heavy\" foreground=\"white\">%d</span>"
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(Gdk::Window::BUTTON1_MASK,
75
+ view.enable_model_drag_source(:button1_mask,
75
76
  Alexandria::UI::BOOKS_TARGET_TABLE,
76
- Gdk::DragContext::ACTION_MOVE)
77
+ :move)
77
78
  end
78
79
  end
79
80
  end
@@ -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 Gdk::Pixbuf
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 = Gdk::Pixbuf.new(Gdk::Pixbuf::COLORSPACE_RGB,
27
- true,
28
- 8,
29
- width + tweak_x,
30
- height + tweak_y)
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
- Gdk::Pixbuf::INTERP_HYPER, 255)
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$/ # skip non '.png' files
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, Gdk::Pixbuf.new(File.join(ICONS_DIR, file)))
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 Gdk::Pixbuf.new(filename)
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 Gdk::Pixbuf, please ensure that from #{filename} is a valid image file"
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 = Gdk::Pixbuf.new(filename)
92
- pixbuf.width == 1 and pixbuf.height == 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 = Gtk::SELECTION_MULTIPLE
49
+ @iconview.selection_mode = :multiple
49
50
  @iconview.text_column = Columns::TITLE_REDUCED
50
51
  @iconview.pixbuf_column = Columns::COVER_ICON
51
- @iconview.orientation = Gtk::ORIENTATION_VERTICAL
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
- # Dirty hack to avoid the beginning of a drag within this
65
- # handler.
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 # force redraw
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.signal_connect('motion_notify_event') { |vw, event|
62
- on_motion(vw, event)
63
- }
64
- view.signal_connect('leave_notify_event') { |vw, event|
65
- on_leave(vw, event)
66
- }
67
- end
68
-
69
- def on_expose(window, _event)
70
- # this paints a nice outline around the label
71
- size = window.size_request
72
- window.style.paint_flat_box(window.window,
73
- Gtk::STATE_NORMAL,
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
- if title.size > 0
58
+ unless title.empty?
87
59
  html += "<b>#{CGI.escapeHTML(title)}</b>"
88
- if authors.size > 0
89
- html += "\n"
90
- end
60
+ html += "\n" unless authors.empty?
91
61
  end
92
- if authors.size > 0
62
+ unless authors.empty?
93
63
  html += "<i>#{CGI.escapeHTML(authors)}</i>"
94
64
  end
95
- if (title.size > 0) or (authors.size > 0)
96
- html += "\n"
97
- end
65
+ html += "\n" if !title.empty? || !authors.empty?
98
66
 
99
67
  html += '<small>'
100
- if publisher and publisher.size > 0
101
- html += "#{CGI.escapeHTML(publisher)}"
68
+ if publisher && !publisher.empty?
69
+ html += CGI.escapeHTML(publisher).to_s
102
70
  end
103
71
 
104
- if year and year.size > 0
105
- if publisher and publisher.size > 0
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
@@ -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
- 'text',
25
- 'text',
26
- 'Some damn value',
27
- '',
28
- GLib::Param::READABLE | GLib::Param::WRITABLE))
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
- def populate_with_libraries(libraries, selected_library)
25
- libraries_names = libraries.map(&:name)
26
- if selected_library
27
- libraries_names.delete selected_library.name
28
- libraries_names.unshift selected_library.name
29
- end
30
- clear
31
- set_row_separator_func do |_model, iter|
32
- iter[1] == '-'
33
- end
34
- self.model = Gtk::ListStore.new(Gdk::Pixbuf, String, TrueClass)
35
- libraries_names.each do |library_name|
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] = library_name
39
- iter[2] = false
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
- def selection_from_libraries(libraries)
59
- iter = active_iter
60
- is_new = false
61
- library = nil
62
- if iter[2]
63
- name = Alexandria::Library.generate_new_name(libraries)
64
- library = Alexandria::Library.load(name)
65
- libraries << library
66
- is_new = true
67
- else
68
- library = libraries.find do |x|
69
- x.name == active_iter[1]
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