lib/alexandria/ui/listview.rb in alexandria-book-collection-manager-0.7.3 vs lib/alexandria/ui/listview.rb in alexandria-book-collection-manager-0.7.4
- old
+ new
@@ -2,22 +2,22 @@
# This file is part of Alexandria.
#
# See the file README.md for authorship and licensing information.
-require 'alexandria/ui/columns'
+require "alexandria/ui/columns"
module Alexandria
module UI
include Logging
include GetText
- GetText.bindtextdomain(Alexandria::TEXTDOMAIN, charset: 'UTF-8')
+ GetText.bindtextdomain(Alexandria::TEXTDOMAIN, charset: "UTF-8")
class ListViewManager
include Logging
include GetText
include DragAndDropable
- BOOKS_TARGET_TABLE = [['ALEXANDRIA_BOOKS', :same_app, 0]].freeze
+ BOOKS_TARGET_TABLE = [["ALEXANDRIA_BOOKS", :same_app, 0]].freeze
def initialize(_listview, parent)
@parent = parent
@prefs = @parent.prefs
@listview = @parent.listview
@@ -27,87 +27,87 @@
@actiongroup = @parent.actiongroup
setup_books_listview
end
def setup_title_column
- title = _('Title')
- log.debug { format('Create listview column for %s', title) }
+ title = _("Title")
+ log.debug { format("Create listview column for %s", title) }
column = Gtk::TreeViewColumn.new(title)
renderer = Gtk::CellRendererPixbuf.new
column.pack_start(renderer, false)
- column.add_attribute(renderer, 'pixbuf', Columns::COVER_LIST)
+ column.add_attribute(renderer, "pixbuf", Columns::COVER_LIST)
renderer = Gtk::CellRendererText.new
renderer.ellipsize = :end
column.pack_start(renderer, true)
- column.add_attribute(renderer, 'text', Columns::TITLE)
+ column.add_attribute(renderer, "text", Columns::TITLE)
column.sort_column_id = Columns::TITLE
column.resizable = true
@listview.append_column(column)
end
TEXT_COLUMNS = [
- [_('Authors'), Columns::AUTHORS],
- [_('ISBN'), Columns::ISBN],
- [_('Publisher'), Columns::PUBLISHER],
- [_('Publish Year'), Columns::PUBLISH_DATE],
- [_('Binding'), Columns::EDITION],
- [_('Loaned To'), Columns::LOANED_TO]
+ [_("Authors"), Columns::AUTHORS],
+ [_("ISBN"), Columns::ISBN],
+ [_("Publisher"), Columns::PUBLISHER],
+ [_("Publish Year"), Columns::PUBLISH_DATE],
+ [_("Binding"), Columns::EDITION],
+ [_("Loaned To"), Columns::LOANED_TO]
].freeze
CHECK_COLUMNS = [
- [_('Read'), Columns::REDD],
- [_('Own'), Columns::OWN],
- [_('Want'), Columns::WANT]
+ [_("Read"), Columns::REDD],
+ [_("Own"), Columns::OWN],
+ [_("Want"), Columns::WANT]
].freeze
def setup_books_listview
- log.debug { 'setup_books_listview' }
+ log.debug { "setup_books_listview" }
@listview.model = @listview_model
setup_title_column
TEXT_COLUMNS.each do |title, iterid|
setup_text_column title, iterid
end
CHECK_COLUMNS.each do |title, iterid|
setup_check_column title, iterid
end
setup_rating_column
@listview.selection.mode = :multiple
- @listview.selection.signal_connect('changed') do
- log.debug { 'changed' }
+ @listview.selection.signal_connect("changed") do
+ log.debug { "changed" }
@parent.on_books_selection_changed
end
setup_tags_column
setup_row_activation
setup_view_source_dnd(@listview)
end
def setup_tags_column
# adding tags column...
- title = _('Tags')
- log.debug { 'Create listview column for tags...' }
+ title = _("Tags")
+ log.debug { "Create listview column for tags..." }
renderer = Gtk::CellRendererText.new
renderer.ellipsize = :end
column = Gtk::TreeViewColumn.new(title, renderer,
text: Columns::TAGS)
column.sort_column_id = Columns::TAGS
column.resizable = true
@listview.append_column(column)
end
def setup_row_activation
- @listview.signal_connect('row-activated') do
- log.debug { 'row-activated' }
- @actiongroup['Properties'].activate
+ @listview.signal_connect("row-activated") do
+ log.debug { "row-activated" }
+ @actiongroup["Properties"].activate
false
end
end
def setup_rating_column
- title = _('Rating')
- log.debug { format('Create listview column for %s...', title) }
+ title = _("Rating")
+ log.debug { format("Create listview column for %s...", title) }
column = Gtk::TreeViewColumn.new(title)
column.sizing = :fixed
width = (Icons::STAR_SET.width + 1) * Book::MAX_RATING_STARS
column.fixed_width = column.min_width = column.max_width = width
Book::MAX_RATING_STARS.times do |i|
@@ -125,11 +125,11 @@
end
def setup_check_column(title, iterid)
renderer = CellRendererToggle.new
renderer.activatable = true
- renderer.signal_connect('toggled') do |_rndrr, path|
+ renderer.signal_connect("toggled") do |_rndrr, path|
begin
tree_path = Gtk::TreePath.new(path)
child_path = @listview_model.convert_path_to_child_path(tree_path)
if child_path
unfiltered_path = @filtered_model.convert_path_to_child_path(child_path)
@@ -157,39 +157,39 @@
end
end
end
end
- rescue StandardError => e
- log.error { "toggle failed for path #{path} #{e}\n" + e.backtrace.join("\n") }
+ rescue StandardError => ex
+ log.error { "toggle failed for path #{path} #{ex}\n" + e.backtrace.join("\n") }
end
end
column = Gtk::TreeViewColumn.new(title, renderer, text: iterid)
column.sort_column_id = iterid
column.resizable = true
- log.debug { format('Create listview column for %s...', title) }
+ log.debug { format("Create listview column for %s...", title) }
- column.add_attribute(renderer, 'active', iterid)
- column.add_attribute(renderer, 'inconsistent', Columns::OWN) if iterid == Columns::WANT
+ column.add_attribute(renderer, "active", iterid)
+ column.add_attribute(renderer, "inconsistent", Columns::OWN) if iterid == Columns::WANT
log.debug { "append_column #{column}" }
@listview.append_column(column)
end
def setup_text_column(title, iterid)
- log.debug { format('Create listview column for %s...', title) }
+ log.debug { format("Create listview column for %s...", title) }
renderer = Gtk::CellRendererText.new
renderer.ellipsize = :end
column = Gtk::TreeViewColumn.new(title, renderer,
text: iterid)
column.sort_column_id = iterid
column.resizable = true
@listview.append_column(column)
end
def setup_listview_columns_visibility
- log.debug { 'setup_listview_columns_visibility' }
+ log.debug { "setup_listview_columns_visibility" }
# Show or hide list view columns according to the preferences.
cols_visibility = [
@prefs.col_authors_visible,
@prefs.col_isbn_visible,
@prefs.col_publisher_visible,
@@ -202,13 +202,13 @@
@prefs.col_rating_visible,
@prefs.col_tags_visible
]
cols = @listview.columns[1..-1] # skip "Title"
cols.each_index do |i|
- cols[i].visible = cols_visibility[i]
+ cols[i].visible = !!cols_visibility[i]
end
- log.debug { 'Columns visibility: ' + cols.map { |col| "#{col.title} #{col.visible?}" }.join(', ') }
+ log.debug { "Columns visibility: " + cols.map { |col| "#{col.title} #{col.visible?}" }.join(", ") }
end
# Sets the width of each column based on any respective
# preference value stored.
def setup_listview_columns_width
@@ -225,13 +225,13 @@
c.sizing = :fixed
c.fixed_width = width
end
end
end
- log.debug {
- 'Columns width: ' +
- @listview.columns.map { |col| "#{col.title} #{col.width}" }.join(', ')
- }
+ log.debug do
+ "Columns width: " +
+ @listview.columns.map { |col| "#{col.title} #{col.width}" }.join(", ")
+ end
end
end
end
end