Class: Alexandria::UI::UIManager

Inherits:
BuilderBase show all
Includes:
Logging, GetText
Defined in:
lib/alexandria/ui/ui_manager.rb

Overview

rubocop:disable Metrics/ClassLength

Constant Summary collapse

LIST_STORE_COLUMNS =
[
  GdkPixbuf::Pixbuf,    # COVER_LIST
  GdkPixbuf::Pixbuf,    # COVER_ICON
  String,         # TITLE
  String,         # TITLE_REDUCED
  String,         # AUTHORS
  String,         # ISBN
  String,         # PUBLISHER
  String,         # PUBLISH_DATE
  String,         # EDITION
  Integer,        # RATING
  String,         # IDENT
  String,         # NOTES
  TrueClass,      # REDD
  TrueClass,      # OWN
  TrueClass,      # WANT
  String,         # TAGS
  String          # LOANED TO
].freeze
ICON_TITLE_MAXLEN =

characters

20
ICON_HEIGHT =

pixels

90
REDUCE_TITLE_REGEX =
Regexp.new("^(.{#{ICON_TITLE_MAXLEN}}).*$")
ICONS_SORTS =
[
  Columns::TITLE, Columns::AUTHORS, Columns::ISBN,
  Columns::PUBLISHER, Columns::EDITION, Columns::RATING,
  Columns::REDD, Columns::OWN, Columns::WANT
].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Logging

included, #log

Constructor Details

#initialize(parent) ⇒ UIManager

Returns a new instance of UIManager.



25
26
27
28
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
# File 'lib/alexandria/ui/ui_manager.rb', line 25

def initialize(parent)
  super("main_app__builder.glade", widget_names)
  @parent = parent

  @library_separator_iter = nil
  @libraries = nil
  @move_mid = nil
  @clicking_on_sidepane = true

  get_preferences
  load_libraries
  setup_window_icons
  setup_callbacks
  create_uimanager
  add_menus_and_popups_from_xml
  setup_menus
  setup_toolbar
  setup_move_actions
  setup_active_model
  setup_dependents
  setup_accel_group
  setup_popups
  setup_window_events
  setup_books_iconview_sorting
  on_books_selection_changed
  restore_preferences
  log.debug { "UI Manager initialized: #{@iconview.model.inspect}" }
  @clicking_on_sidepane = true

  @library_listview.signal_connect("cursor-changed") do
    @clicking_on_sidepane = true
  end
end

Instance Attribute Details

#actiongroupObject

Returns the value of attribute actiongroup.



16
17
18
# File 'lib/alexandria/ui/ui_manager.rb', line 16

def actiongroup
  @actiongroup
end

#appbarObject

Returns the value of attribute appbar.



16
17
18
# File 'lib/alexandria/ui/ui_manager.rb', line 16

def appbar
  @appbar
end

#filtered_modelObject

Returns the value of attribute filtered_model.



16
17
18
# File 'lib/alexandria/ui/ui_manager.rb', line 16

def filtered_model
  @filtered_model
end

#iconviewObject

Returns the value of attribute iconview.



16
17
18
# File 'lib/alexandria/ui/ui_manager.rb', line 16

def iconview
  @iconview
end

#iconview_modelObject

Returns the value of attribute iconview_model.



16
17
18
# File 'lib/alexandria/ui/ui_manager.rb', line 16

def iconview_model
  @iconview_model
end

#listviewObject

Returns the value of attribute listview.



16
17
18
# File 'lib/alexandria/ui/ui_manager.rb', line 16

def listview
  @listview
end

#listview_modelObject

Returns the value of attribute listview_model.



16
17
18
# File 'lib/alexandria/ui/ui_manager.rb', line 16

def listview_model
  @listview_model
end

#main_appObject

Returns the value of attribute main_app.



16
17
18
# File 'lib/alexandria/ui/ui_manager.rb', line 16

def main_app
  @main_app
end

#modelObject (readonly)

Returns the value of attribute model.



18
19
20
# File 'lib/alexandria/ui/ui_manager.rb', line 18

def model
  @model
end

#prefsObject

Returns the value of attribute prefs.



16
17
18
# File 'lib/alexandria/ui/ui_manager.rb', line 16

def prefs
  @prefs
end

Instance Method Details

#add_main_toolbar_itemsObject



112
113
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/alexandria/ui/ui_manager.rb', line 112

def add_main_toolbar_items
  mid = @uimanager.new_merge_id
  @uimanager.add_ui(mid, "ui/", "MainToolbar", "MainToolbar",
                    :toolbar, false)
  @uimanager.add_ui(mid, "ui/MainToolbar/", "New", "New",
                    :toolitem, false)
  @uimanager.add_ui(mid, "ui/MainToolbar/", "AddBook", "AddBook",
                    :toolitem, false)
  # @uimanager.add_ui(mid, "ui/MainToolbar/", "sep", "sep",
  #                  :separator, false)
  # @uimanager.add_ui(mid, "ui/MainToolbar/", "Refresh", "Refresh",
  #                  :toolitem, false)
end

#add_menus_and_popups_from_xmlObject



205
206
207
208
209
210
211
# File 'lib/alexandria/ui/ui_manager.rb', line 205

def add_menus_and_popups_from_xml
  log.debug { "add_menus_and_popups_from_xml" }
  ["menus.xml", "popups.xml"].each do |ui_file|
    @uimanager.add_ui(File.join(Alexandria::Config::DATA_DIR,
                                "ui", ui_file))
  end
end

#append_book(book, _tail = nil) ⇒ Object



792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
# File 'lib/alexandria/ui/ui_manager.rb', line 792

def append_book(book, _tail = nil)
  log.debug { @model.inspect }
  iter = @model.append
  log.debug { "iter == #{iter}" }
  if iter
    fill_iter_with_book(iter, book)
  else
    log.debug { "@model.append" }
    iter = @model.append
    fill_iter_with_book(iter, book)
    log.debug { "no iter for book #{book}" }
  end
  library = selected_library
  if library.deleted_books.include?(book)
    log.debug { "Stop! Don't delete this book! We re-added it!" }
    library.undelete(book)
    UndoManager.instance.push { undoable_delete(library, [book]) }
  end
  iter
end

#append_library(library, autoselect = false) ⇒ Object



813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
# File 'lib/alexandria/ui/ui_manager.rb', line 813

def append_library(library, autoselect = false)
  log.debug { "append_library #{library.name}" }
  model = @library_listview.model
  is_smart = library.is_a?(SmartLibrary)
  if is_smart
    @library_separator_iter = append_library_separator if @library_separator_iter.nil?
    iter = model.append
  else
    iter = if @library_separator_iter.nil?
             model.append
           else
             model.insert_before(@library_separator_iter)
           end
  end

  iter[0] = is_smart ? Icons::SMART_LIBRARY_SMALL : Icons::LIBRARY_SMALL
  iter[1] = library.name
  iter[2] = true      # editable?
  iter[3] = false     # separator?
  if autoselect
    @library_listview.set_cursor(iter.path,
                                 @library_listview.get_column(0),
                                 true)
    @actiongroup["Sidepane"].active = true
  end
  iter
end

#append_library_separatorObject



841
842
843
844
845
846
847
848
849
# File 'lib/alexandria/ui/ui_manager.rb', line 841

def append_library_separator
  log.debug { "append_library_separator" }
  iter = @library_listview.model.append
  iter[0] = nil
  iter[1] = nil
  iter[2] = false     # editable?
  iter[3] = true      # separator?
  iter
end

#book_from_iter(library, iter) ⇒ Object



923
924
925
926
# File 'lib/alexandria/ui/ui_manager.rb', line 923

def book_from_iter(library, iter)
  log.debug { "Book from iter: #{library} #{iter}" }
  library.find { |x| x.ident == iter[Columns::IDENT] }
end

#cache_scaled_icon(icon, width, height) ⇒ Object



738
739
740
741
742
# File 'lib/alexandria/ui/ui_manager.rb', line 738

def cache_scaled_icon(icon, width, height)
  log.debug { "cache_scaled_icon #{icon}, #{width}, #{height}" }
  @cache ||= {}
  @cache[[icon, width, height]] ||= icon.scale(width, height)
end

#collate_selected_books(page) ⇒ Object



943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
# File 'lib/alexandria/ui/ui_manager.rb', line 943

def collate_selected_books(page)
  result = []
  library = selected_library

  if page.zero?
    result = @iconview.selected_items.map do |path|
      path = view_path_to_model_path(@iconview, path)
      book_from_iter(library, @model.get_iter(path))
    end
  else
    selection = @listview.selection
    rows, _model = selection.selected_rows
    result = rows.map do |path|
      path = view_path_to_model_path(@listview, path)
      book_from_iter(library, @model.get_iter(path))
    end
  end

  result
end

#cover_icon(icon, rating) ⇒ Object



782
783
784
785
786
787
788
789
790
# File 'lib/alexandria/ui/ui_manager.rb', line 782

def cover_icon(icon, rating)
  if icon.height > ICON_HEIGHT
    new_width = icon.width / (icon.height / ICON_HEIGHT.to_f)
    new_height = [ICON_HEIGHT, icon.height].min
    icon = cache_scaled_icon(icon, new_width, new_height)
  end
  icon = Icons.tag_icon(icon, Icons::FAVORITE_TAG) if rating == Book::MAX_RATING_STARS
  icon
end

#cover_list_icon(icon) ⇒ Object



778
779
780
# File 'lib/alexandria/ui/ui_manager.rb', line 778

def cover_list_icon(icon)
  cache_scaled_icon(icon, 20, 25)
end

#create_uimanagerObject



69
70
71
72
73
# File 'lib/alexandria/ui/ui_manager.rb', line 69

def create_uimanager
  log.debug { "Adding actiongroup to uimanager" }
  @uimanager = Gtk::UIManager.new
  @uimanager.insert_action_group(@actiongroup, 0)
end

#current_viewObject



1108
1109
1110
1111
1112
1113
1114
1115
# File 'lib/alexandria/ui/ui_manager.rb', line 1108

def current_view
  case @notebook.page
  when 0
    @iconview
  when 1
    @listview
  end
end

#detach_old_librariesObject



588
589
590
591
592
593
594
595
596
# File 'lib/alexandria/ui/ui_manager.rb', line 588

def detach_old_libraries
  log.debug { "Un-observing old libraries" }
  @libraries.all_regular_libraries.each do |library|
    if library.is_a?(Library)
      library.delete_observer(self)
      @completion_models.remove_source(library)
    end
  end
end

#determine_delete_optionObject



530
531
532
# File 'lib/alexandria/ui/ui_manager.rb', line 530

def determine_delete_option
  @libraries.all_regular_libraries.length > 1 || selected_library.is_a?(SmartLibrary)
end

#determine_library_popup(widget, event) ⇒ Object



371
372
373
374
375
376
377
378
379
# File 'lib/alexandria/ui/ui_manager.rb', line 371

def determine_library_popup(widget, event)
  if widget.get_path_at_pos(event.x, event.y).nil?
    @nolibrary_popup
  elsif selected_library.is_a?(SmartLibrary)
    @smart_library_popup
  else
    @library_popup
  end
end

#event_is_right_click(event) ⇒ Object



381
382
383
# File 'lib/alexandria/ui/ui_manager.rb', line 381

def event_is_right_click(event)
  (event.event_type == :button_press) && (event.button == 3)
end

#fill_iter_with_book(iter, book) ⇒ Object



748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
# File 'lib/alexandria/ui/ui_manager.rb', line 748

def fill_iter_with_book(iter, book)
  iter[Columns::IDENT] = book.ident.to_s
  iter[Columns::TITLE] = book.title
  iter[Columns::TITLE_REDUCED] = reduced_title(book.title)
  iter[Columns::AUTHORS] = book.authors.join(", ")
  iter[Columns::ISBN] = book.isbn.to_s
  iter[Columns::PUBLISHER] = book.publisher
  iter[Columns::PUBLISH_DATE] = book.publishing_year.to_s
  iter[Columns::EDITION] = book.edition
  iter[Columns::NOTES] = (book.notes || "")
  iter[Columns::LOANED_TO] = (book.loaned_to || "")

  rating = book.rating || Book::DEFAULT_RATING
  # ascending order is the default
  iter[Columns::RATING] = Book::MAX_RATING_STARS - rating

  iter[Columns::OWN] = book.own?
  iter[Columns::REDD] = book.redd?
  iter[Columns::WANT] = book.want?
  iter[Columns::TAGS] = book.tags&.join(",") || ""

  icon = Icons.cover(selected_library, book)
  iter[Columns::COVER_LIST] = cover_list_icon(icon)
  iter[Columns::COVER_ICON] = cover_icon(icon, rating)
end

#filter_iter(iter, filter) ⇒ Object



279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
# File 'lib/alexandria/ui/ui_manager.rb', line 279

def filter_iter(iter, filter)
  if filter.empty?
    true
  else
    @filter_books_mode ||= 0
    data = case @filter_books_mode
           when 0
             (iter[Columns::TITLE] || "") +
               (iter[Columns::AUTHORS] || "") +
               (iter[Columns::ISBN] || "") +
               (iter[Columns::PUBLISHER] || "") +
               (iter[Columns::NOTES] || "") +
               (iter[Columns::TAGS] || "")
           when 2 then iter[Columns::TITLE]
           when 3 then iter[Columns::AUTHORS]
           when 4 then iter[Columns::ISBN]
           when 5 then iter[Columns::PUBLISHER]
           when 6 then iter[Columns::NOTES]
           when 7 then iter[Columns::TAGS]
           end
    !data.nil? && data.downcase.include?(filter.downcase)
  end
end

#get_appbar_status(library, books) ⇒ Object



433
434
435
436
437
438
439
440
441
442
443
# File 'lib/alexandria/ui/ui_manager.rb', line 433

def get_appbar_status(library, books)
  case books.length
  when 0
    get_library_selection_text library
  when 1
    _("'%s' selected") % books.first.title
  else
    n_("%d book selected", "%d books selected",
       books.length) % books.length
  end
end

#get_library_selection_text(library) ⇒ Object



408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
# File 'lib/alexandria/ui/ui_manager.rb', line 408

def get_library_selection_text(library)
  case library.length
  when 0
    _("Library '%s' selected") % library.name

  else
    n_unrated = library.n_unrated
    if n_unrated == library.length
      format(n_("Library '%s' selected, %d unrated book",
                "Library '%s' selected, %d unrated books",
                library.length), library.name, library.length)
    elsif n_unrated.zero?
      format(n_("Library '%s' selected, %d book",
                "Library '%s' selected, %d books",
                library.length), library.name, library.length)
    else
      format(n_("Library '%s' selected, %d book, " \
                "%d unrated",
                "Library '%s' selected, %d books, " \
                "%d unrated",
                library.length), library.name, library.length, n_unrated)
    end
  end
end

#get_preferencesObject



91
92
93
# File 'lib/alexandria/ui/ui_manager.rb', line 91

def get_preferences
  @prefs = Preferences.instance
end

#get_previous_selected_library(library) ⇒ Object



1145
1146
1147
1148
1149
1150
1151
1152
1153
# File 'lib/alexandria/ui/ui_manager.rb', line 1145

def get_previous_selected_library(library)
  log.debug { "get_previous_selected_library: #{library}" }
  @previous_selected_library = selected_library
  if @previous_selected_library == library
    @previous_selected_library = nil
  else
    select_library(library)
  end
end

#get_view_actiongroupObject



999
1000
1001
1002
1003
1004
1005
1006
# File 'lib/alexandria/ui/ui_manager.rb', line 999

def get_view_actiongroup
  case @prefs.view_as
  when 0
    @actiongroup["AsIcons"]
  when 1
    @actiongroup["AsList"]
  end
end

#handle_ruined_booksObject



615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
# File 'lib/alexandria/ui/ui_manager.rb', line 615

def handle_ruined_books
  new_message = _(
    "The data files for the following books are malformed or empty. Do you wish to " \
    "attempt to download new information for them from the online book providers?\n")

  @libraries.ruined_books.each do |bi|
    new_message += "\n#{bi[1] || bi[1].inspect}"
  end
  recovery_dialog = Gtk::MessageDialog.new(@main_app, Gtk::Dialog::MODAL,
                                           Gtk::MessageDialog::WARNING,
                                           Gtk::MessageDialog::BUTTONS_OK_CANCEL,
                                           new_message).show
  recovery_dialog.signal_connect("response") do |_dialog, response_type|
    recovery_dialog.destroy
    if response_type == Gtk::ResponseType::OK
      # progress indicator...
      @progressbar.fraction = 0
      show_progress_bar

      total_book_count = @libraries.ruined_books.size
      fraction_per_book = 1.0 / total_book_count
      prog_percentage = 0

      @libraries.ruined_books.reverse!
      GLib::Idle.add do
        ruined_book = @libraries.ruined_books.pop
        if ruined_book
          _book, isbn, library = ruined_book
          repair_ruined_book(isbn, library)

          prog_percentage += fraction_per_book
          @progressbar.fraction = prog_percentage

          true
        else
          ## Totally copied and pasted from refresh_books...
          ## call this the second strike... (CathalMagus)

          # @iconview.unfreeze
          # @filtered_model.refilter
          # @listview.columns_autosize

          @progressbar.fraction = 1
          hide_progress_bar
          ## Refresh the status bar.
          set_status_label("")
          # on_books_selection_changed
          false
        end
      end
    end
  end
end

#handle_update_caller_library(ary) ⇒ Object



558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
# File 'lib/alexandria/ui/ui_manager.rb', line 558

def handle_update_caller_library(ary)
  library, kind, book = ary
  if library == selected_library
    @iconview.freeze # This makes @iconview.model == nil
    @listview.freeze # NEW
    case kind
    when Library::BOOK_ADDED
      append_book(book)
    when Library::BOOK_UPDATED
      iter = iter_from_ident(book.saved_ident)
      fill_iter_with_book(iter, book) if iter
    when Library::BOOK_REMOVED
      @model.remove(iter_from_book(book))
    end
    @iconview.unfreeze
    @listview.unfreeze # NEW
    select_a_book(book) if [Library::BOOK_ADDED, Library::BOOK_UPDATED].include? kind
  elsif selected_library.is_a?(SmartLibrary)
    refresh_books
  end
end

#hide_progress_barObject



709
710
711
# File 'lib/alexandria/ui/ui_manager.rb', line 709

def hide_progress_bar
  progress_bar.visible = false
end

#iter_from_book(book) ⇒ Object



939
940
941
# File 'lib/alexandria/ui/ui_manager.rb', line 939

def iter_from_book(book)
  iter_from_ident(book.ident)
end

#iter_from_ident(ident) ⇒ Object



928
929
930
931
932
933
934
935
936
937
# File 'lib/alexandria/ui/ui_manager.rb', line 928

def iter_from_ident(ident)
  iter = @model.iter_first
  ok = true if iter
  while ok
    return iter if iter[Columns::IDENT] == ident

    ok = iter.next!
  end
  nil
end

#library_sort_orderObject

Gets the sort order of the current library, for use by export



1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
# File 'lib/alexandria/ui/ui_manager.rb', line 1118

def library_sort_order
  # added by Cathal Mc Ginley, 23 Oct 2007
  log.debug do
    "library_sort_order #{@notebook.page}: " \
      "#{@iconview.model.inspect} #{@listview.model.inspect}"
  end
  result, sort_column, sort_order = current_view.model.sort_column_id
  if result
    column_ids_to_attributes = { 2  => :title,
                                 4  => :authors,
                                 5  => :isbn,
                                 6  => :publisher,
                                 7  => :publishing_year,
                                 8  => :edition, # binding
                                 12 => :redd,
                                 13 => :own,
                                 14 => :want,
                                 9  => :rating }

    sort_attribute = column_ids_to_attributes.fetch sort_column
    ascending = (sort_order == :ascending)
    LibrarySortOrder.new(sort_attribute, ascending)
  else
    LibrarySortOrder::Unsorted.new
  end
end

#load_librariesObject



598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
# File 'lib/alexandria/ui/ui_manager.rb', line 598

def load_libraries
  log.info { _("Loading libraries...") }
  @completion_models = CompletionModels.instance
  if @libraries
    detach_old_libraries
    @libraries.reload
  else
    @libraries = LibraryCollection.instance
    @libraries.reload
    handle_ruined_books unless @libraries.ruined_books.empty?
  end
  @libraries.all_regular_libraries.each do |library|
    library.add_observer(self)
    @completion_models.add_source(library)
  end
end

#move_selected_books_to_library(library) ⇒ Object



1071
1072
1073
1074
1075
1076
1077
1078
1079
# File 'lib/alexandria/ui/ui_manager.rb', line 1071

def move_selected_books_to_library(library)
  books = selected_books.select do |book|
    !library.include?(book) ||
      ConflictWhileCopyingDialog.new(@main_app,
                                     library,
                                     book).replace?
  end
  undoable_move(selected_library, library, books)
end

#on_books_button_press_event(widget, event) ⇒ Object



385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
# File 'lib/alexandria/ui/ui_manager.rb', line 385

def on_books_button_press_event(widget, event)
  log.debug { "books_button_press_event" }
  event_is_right_click event or return

  widget.grab_focus

  if (path = widget.get_path_at_pos(event.x.to_i, event.y.to_i))
    obj, path =
      widget.is_a?(Gtk::TreeView) ? [widget.selection, path.first] : [widget, path]

    unless obj.path_is_selected?(path)
      log.debug { "Select #{path}" }
      widget.unselect_all
      obj.select_path(path)
    end
  else
    widget.unselect_all
  end

  menu = selected_books.empty? ? @nobook_popup : @book_popup
  menu.popup_at_pointer(event)
end

#on_books_selection_changedObject



449
450
451
452
453
454
455
456
457
458
459
460
# File 'lib/alexandria/ui/ui_manager.rb', line 449

def on_books_selection_changed
  library = selected_library
  books = selected_books
  set_status_label(get_appbar_status(library, books))

  # Focus is the wrong idiom here.
  unless @clicking_on_sidepane || (@main_app.focus == @library_listview)
    sensizite_action_group_items(books, library)
    sensitize_provider_actions(books)
  end
  @clicking_on_sidepane = false
end

#on_close_sidepaneObject



534
535
536
537
# File 'lib/alexandria/ui/ui_manager.rb', line 534

def on_close_sidepane
  log.debug { "on_close_sidepane" }
  @actiongroup["Sidepane"].active = false
end

#on_focus(widget, _event_focus) ⇒ Object



514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
# File 'lib/alexandria/ui/ui_manager.rb', line 514

def on_focus(widget, _event_focus)
  if @clicking_on_sidepane || (widget == @library_listview)
    log.debug { "on_focus: @library_listview" }
    GLib::Idle.add do
      %w(OnlineInformation SelectAll DeselectAll).each do |action|
        @actiongroup[action].sensitive = false
      end
      @actiongroup["Properties"].sensitive = selected_library.is_a?(SmartLibrary)
      @actiongroup["Delete"].sensitive = determine_delete_option
      false
    end
  else
    on_books_selection_changed
  end
end

#on_library_button_press_event(widget, event) ⇒ Object



303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
# File 'lib/alexandria/ui/ui_manager.rb', line 303

def on_library_button_press_event(widget, event)
  log.debug { "library_button_press_event" }

  # right click
  if event_is_right_click event
    log.debug { "library right click!" }
    library_already_selected = true
    if (path = widget.get_path_at_pos(event.x, event.y))
      @clicking_on_sidepane = true
      obj, path =
        widget.is_a?(Gtk::TreeView) ? [widget.selection, path.first] : [widget, path]
      widget.has_focus = true

      unless obj.path_is_selected?(path)

        log.debug { "Select #{path}" }
        library_already_selected = false
        widget.unselect_all
        obj.select_path(path)
        sensitize_library selected_library

        if widget.is_a?(Gtk::TreeView)
          GLib::Idle.add do
            # cur_path, focus_col = widget.cursor

            widget.focus = true

            widget.set_cursor(path, nil, false)
            widget.grab_focus
            widget.has_focus = true
            false
          end
          # widget.has_focus = true
        end

        # library_already_selected = true
      end
    else
      widget.unselect_all
    end

    menu = determine_library_popup widget, event

    # Fixes part of bug #25021.
    #
    # If the library was not selected when it was right-clicked
    # we should select the library first (we call on_focus
    # manually, since the above call to obj.select_path(path) doesn't
    # seem to suffice).
    #
    # Then we wait a while and only *then* pop up the menu.
    sensitize_library selected_library if library_already_selected

    GLib::Idle.add do
      menu.popup_at_pointer(event)
      false
    end

    # not a right click
  elsif (path = widget.get_path_at_pos(event.x, event.y))
    @clicking_on_sidepane = true
    obj, path =
      widget.is_a?(Gtk::TreeView) ? [widget.selection, path.first] : [widget, path]
    obj.select_path(path)
    sensitize_library selected_library
  end
end

#on_switch_page(_notebook, _page, page_num) ⇒ Object



508
509
510
511
512
# File 'lib/alexandria/ui/ui_manager.rb', line 508

def on_switch_page(_notebook, _page, page_num)
  log.debug { "on_switch_page" }
  @actiongroup["ArrangeIcons"].sensitive = page_num.zero?
  on_books_selection_changed
end

#open_web_browser(url) ⇒ Object



580
581
582
583
584
585
586
# File 'lib/alexandria/ui/ui_manager.rb', line 580

def open_web_browser(url)
  if url.nil?
    log.warn("Attempt to open browser with nil url")
    return
  end
  Gtk.show_uri url
end

#progress_barObject



701
702
703
# File 'lib/alexandria/ui/ui_manager.rb', line 701

def progress_bar
  @progress_bar ||= @appbar.children.first
end

#reduced_title(title) ⇒ Object



774
775
776
# File 'lib/alexandria/ui/ui_manager.rb', line 774

def reduced_title(title)
  title.sub(REDUCE_TITLE_REGEX, '\1...')
end

#refresh_booksObject



851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
# File 'lib/alexandria/ui/ui_manager.rb', line 851

def refresh_books
  log.debug { "refresh_books" }
  @library_listview.set_sensitive(false)
  library = selected_library
  @iconview.freeze
  @listview.freeze
  @model.clear

  @progressbar.fraction = 0
  show_progress_bar

  set_status_label(_("Loading '%s'...") % library.name)
  total = library.length
  log.debug { "library #{library.name} length #{library.length}" }
  n = 0

  GLib::Idle.add do
    block_return = true
    book = library[n]
    if book
      begin
        append_book(book)
      rescue StandardError => ex
        trace = ex.backtrace.join("\n > ")
        log.error { "append_books failed #{ex.message} #{trace}" }
      end
      fraction = n * 1.0 / total
      log.debug { "#index #{n} fraction #{fraction}" }
      @progressbar.fraction = fraction
      n += 1
    else
      @iconview.unfreeze
      @listview.unfreeze # NEW / bdewey
      @filtered_model.refilter
      @listview.columns_autosize

      @progressbar.fraction = 1
      hide_progress_bar

      # Refresh the status bar.
      on_books_selection_changed
      @library_listview.set_sensitive(true)
      block_return = false
    end

    block_return
  end
end

#refresh_librariesObject



970
971
972
973
974
975
976
977
978
979
980
981
982
983
# File 'lib/alexandria/ui/ui_manager.rb', line 970

def refresh_libraries
  log.debug { "refresh_libraries" }
  library = selected_library

  # Change the application's title.
  @main_app.title = library.name + " - " + TITLE

  # Disable the selected library in the move libraries actions.
  @libraries.all_regular_libraries.each do |i_library|
    action = @actiongroup[i_library.action_name]
    action.sensitive = i_library != library if action
  end
  sensitize_library library
end

#remove_library_iterObject



1155
1156
1157
1158
1159
1160
1161
1162
1163
# File 'lib/alexandria/ui/ui_manager.rb', line 1155

def remove_library_iter
  old_iter = @library_listview.selection.selected
  # commenting out this code seems to fix #20681
  # "crashes when switching to smart library mid-load"
  # next_iter = @library_listview.selection.selected
  # next_iter.next!
  @library_listview.model.remove(old_iter)
  # @library_listview.selection.select_iter(next_iter)
end

#remove_library_separatorObject



1184
1185
1186
1187
1188
1189
# File 'lib/alexandria/ui/ui_manager.rb', line 1184

def remove_library_separator
  return if @library_separator_iter.nil? || @libraries.all_smart_libraries.any?

  @library_listview.model.remove(@library_separator_iter)
  @library_separator_iter = nil
end

#repair_ruined_book(isbn, library) ⇒ Object



669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
# File 'lib/alexandria/ui/ui_manager.rb', line 669

def repair_ruined_book(isbn, library)
  book_rslt = Alexandria::BookProviders.isbn_search(isbn.to_s)
  book = book_rslt[0]
  cover_uri = book_rslt[1]

  # TODO: if the book was saved okay, make sure the old
  # empty yaml file doesn't stick around esp if doing
  # isbn-10 --> isbn-13 conversion...
  if isbn.size == 10
    filename = library.yaml(isbn)
    log.debug { "removing old file #{filename}" }
    begin
      File.delete(filename)
    rescue StandardError => ex
      log.error { "Could not delete empty file #{filename}" }
    end
  end

  log.debug do
    "Trying to add #{book.title}, #{cover_uri} " \
      "in library ''#{library.name}'"
  end
  library.save_cover(book, cover_uri) unless cover_uri.nil?
  library << book
  library.save(book)
  set_status_label(format(_("Added '%s' to library '%s'"),
                          book.title, library.name))
rescue StandardError => ex
  log.error { "Couldn't add book #{isbn}: #{ex}" }
  log.error { ex.backtrace.join("\n") }
end

#restore_preferencesObject



1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
# File 'lib/alexandria/ui/ui_manager.rb', line 1008

def restore_preferences
  log.debug { "Restoring preferences" }
  if @prefs.maximized
    @main_app.maximize
  else
    @main_app.move(*@prefs.position) unless @prefs.position == [0, 0]
    @main_app.resize(*@prefs.size)
    @maximized = false
  end
  @paned.position = @prefs.sidepane_position
  @actiongroup["Sidepane"].active = @prefs.sidepane_visible
  @actiongroup["Toolbar"].active = @prefs.toolbar_visible
  @actiongroup["Statusbar"].active = @prefs.statusbar_visible
  @appbar.visible = @prefs.statusbar_visible
  action = get_view_actiongroup
  action.activate
  library = nil
  unless @prefs.selected_library.nil?
    library = @libraries.all_libraries.find do |x|
      x.name == @prefs.selected_library
    end
  end
  select_a_library library
end

#save_preferencesObject



1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
# File 'lib/alexandria/ui/ui_manager.rb', line 1043

def save_preferences
  log.debug { "save_preferences" }
  @prefs.position = @main_app.position
  @prefs.size = @main_app.allocation.to_a[2..3]
  @prefs.maximized = @maximized
  @prefs.sidepane_position = @paned.position
  @prefs.sidepane_visible = @actiongroup["Sidepane"].active?
  @prefs.toolbar_visible = @actiongroup["Toolbar"].active?
  @prefs.statusbar_visible = @actiongroup["Statusbar"].active?
  @prefs.view_as = @notebook.page
  @prefs.selected_library = selected_library.name
  cols_width = {}
  @listview.columns.each do |c|
    cols_width[c.title] = c.width
  end
  @prefs.cols_width = "{" + cols_width.to_a.map do |t, v|
    '"' + t + '": ' + v.to_s
  end.join(", ") + "}"
  log.debug { "cols_width: #{@prefs.cols_width} " }
  @prefs.save!
end

#select_a_book(book) ⇒ Object



539
540
541
542
# File 'lib/alexandria/ui/ui_manager.rb', line 539

def select_a_book(book)
  select_book_in_view(book, @listview)
  select_book_in_view(book, @iconview)
end

#select_a_library(library) ⇒ Object



1033
1034
1035
1036
1037
1038
1039
1040
1041
# File 'lib/alexandria/ui/ui_manager.rb', line 1033

def select_a_library(library)
  if library
    select_library(library)
  else
    # Select the first item by default.
    iter = @library_listview.model.iter_first
    @library_listview.selection.select_iter(iter)
  end
end

#select_library(library) ⇒ Object



910
911
912
913
914
915
916
917
918
919
920
921
# File 'lib/alexandria/ui/ui_manager.rb', line 910

def select_library(library)
  log.debug { "select library #{library}" }
  iter = @library_listview.model.iter_first
  ok = true
  while ok
    if iter[1] == library.name
      @library_listview.selection.select_iter(iter)
      break
    end
    ok = iter.next!
  end
end

#selected_booksObject



964
965
966
967
968
# File 'lib/alexandria/ui/ui_manager.rb', line 964

def selected_books
  selected = collate_selected_books(@notebook.page).compact
  log.debug { "Selected books = #{selected.inspect}" }
  selected
end

#selected_libraryObject



900
901
902
903
904
905
906
907
908
# File 'lib/alexandria/ui/ui_manager.rb', line 900

def selected_library
  log.debug { "selected_library" }
  if (iter = @library_listview.selection.selected)
    target_name = iter[1]
    @libraries.all_libraries.find { _1.name == target_name }
  else
    @libraries.all_libraries.first
  end
end

#sensitize_library(library) ⇒ Object



985
986
987
988
989
990
991
992
993
994
995
996
997
# File 'lib/alexandria/ui/ui_manager.rb', line 985

def sensitize_library(library)
  smart = library.is_a?(SmartLibrary)
  log.debug { "sensitize_library: smartlibrary = #{smart}" }
  GLib::Idle.add do
    @actiongroup["AddBook"].sensitive = !smart
    @actiongroup["AddBookManual"].sensitive = !smart
    @actiongroup["Properties"].sensitive = smart
    can_delete = smart || (@libraries.all_regular_libraries.length > 1)
    @actiongroup["Delete"].sensitive = can_delete
    log.debug { "sensitize_library delete: #{@actiongroup['Delete'].sensitive?}" }
    false
  end
end

#sensitize_provider_actions(books) ⇒ Object

Sensitize providers URL



489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
# File 'lib/alexandria/ui/ui_manager.rb', line 489

def sensitize_provider_actions(books)
  return if books.length != 1

  b = books.first
  # FIXME: Clean up endless negation in this logic
  no_urls = true
  BookProviders.list.each do |provider|
    has_no_url = true
    begin
      has_no_url = b.isbn.nil? || b.isbn.strip.empty? || provider.url(b).nil?
    rescue StandardError => ex
      log.warn { "Error determining URL from #{provider.name}; #{ex.message}" }
    end
    @actiongroup[provider.action_name].sensitive = !has_no_url
    no_urls = false unless has_no_url
  end
  @actiongroup["OnlineInformation"].sensitive = false if no_urls
end

#sensizite_action_group_items(books, library) ⇒ Object



462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
# File 'lib/alexandria/ui/ui_manager.rb', line 462

def sensizite_action_group_items(books, library)
  log.debug { "Currently focused widget: #{@main_app.focus.inspect}" }
  log.debug { "#{@library_listview} : #{@library_popup} : #{@listview}" }
  log.debug do
    "@library_listview: #{@library_listview.has_focus?} " \
      "or @library_popup:#{@library_popup.has_focus?}"
  end
  log.debug { "@library_listview does *NOT* have focus" }
  log.debug { "Books are empty: #{books.empty?}" }

  @actiongroup["Properties"].sensitive = @actiongroup["OnlineInformation"].sensitive =
    books.length == 1
  @actiongroup["SelectAll"].sensitive = books.length < library.length
  @actiongroup["DeselectAll"].sensitive = @actiongroup["SetRating"].sensitive =
    !books.empty?

  can_delete_or_move =
    if library.is_a?(SmartLibrary)
      false
    else
      !books.empty?
    end
  @actiongroup["Delete"].sensitive = @actiongroup["Move"].sensitive =
    can_delete_or_move
end

#set_status_label(txt) ⇒ Object



445
446
447
# File 'lib/alexandria/ui/ui_manager.rb', line 445

def set_status_label(txt)
  @status_label.text = txt
end

#setup_accel_groupObject



213
214
215
216
# File 'lib/alexandria/ui/ui_manager.rb', line 213

def setup_accel_group
  log.debug { "setup_accel_group" }
  @main_app.add_accel_group(@uimanager.accel_group)
end

#setup_active_modelObject



262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
# File 'lib/alexandria/ui/ui_manager.rb', line 262

def setup_active_model
  log.debug { "setting up active model" }
  # The active model.

  @model = Gtk::ListStore.new(*LIST_STORE_COLUMNS)

  # Filter books according to the search toolbar widgets.
  @filtered_model = Gtk::TreeModelFilter.new(@model)
  @filtered_model.set_visible_func do |_model, iter|
    filter_iter(iter, @filter_entry.text)
  end

  # Give filter entry the initial keyboard focus.
  @filter_entry.grab_focus
  log.debug { "done setting up active model" }
end

#setup_book_providersObject



189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
# File 'lib/alexandria/ui/ui_manager.rb', line 189

def setup_book_providers
  log.debug { "setup_book_providers" }
  mid = @uimanager.new_merge_id
  ui_paths = ["ui/MainMenubar/ViewMenu/OnlineInformation/",
              "ui/BookPopup/OnlineInformation/",
              "ui/NoBookPopup/OnlineInformation/"]
  BookProviders.list.each do |provider|
    name = provider.action_name
    ui_paths.each do |path|
      log.debug { "Adding #{name} to #{path}" }
      @uimanager.add_ui(mid, path, name, name,
                        :menuitem, false)
    end
  end
end

#setup_books_iconview_sortingObject



1219
1220
1221
1222
1223
1224
# File 'lib/alexandria/ui/ui_manager.rb', line 1219

def setup_books_iconview_sorting
  sort_order = @prefs.reverse_icons ? :descending : :ascending
  mode = ICONS_SORTS[@prefs.arrange_icons_mode]
  @iconview_model.set_sort_column_id(mode, sort_order)
  @filtered_model.refilter # force redraw
end

#setup_callbacksObject



86
87
88
89
# File 'lib/alexandria/ui/ui_manager.rb', line 86

def setup_callbacks
  self.class.send(:include, Callbacks)
  connect_signals
end

#setup_dependentsObject



75
76
77
78
79
80
81
82
83
84
# File 'lib/alexandria/ui/ui_manager.rb', line 75

def setup_dependents
  @listview_model = Gtk::TreeModelSort.new(@filtered_model)
  @iconview_model = Gtk::TreeModelSort.new(@filtered_model)
  @listview_manager = ListViewManager.new @listview, self
  @iconview_manager = IconViewManager.new @iconview, self
  @sidepane_manager = SidepaneManager.new @library_listview, self
  @library_listview = @sidepane_manager.library_listview
  @listview_manager.setup_listview_columns_visibility
  @listview_manager.setup_listview_columns_width
end

#setup_menusObject



218
219
220
221
# File 'lib/alexandria/ui/ui_manager.rb', line 218

def setup_menus
  @menubar = @uimanager.get_widget("/MainMenubar")
  @vbox1.add(@menubar, position: 0, expand: false, fill: false)
end

#setup_move_actionsObject



1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
# File 'lib/alexandria/ui/ui_manager.rb', line 1081

def setup_move_actions
  @actiongroup.actions.each do |action|
    next unless action.name.start_with?("MoveIn")

    @actiongroup.remove_action(action)
  end
  actions = @libraries.all_regular_libraries.map do |library|
    [
      library.action_name, nil,
      _("In '_%s'") % library.name,
      nil, nil, proc { move_selected_books_to_library(library) }
    ]
  end
  @actiongroup.add_actions(actions)
  @uimanager.remove_ui(@move_mid) if @move_mid
  @move_mid = @uimanager.new_merge_id
  ui_paths = ["ui/MainMenubar/EditMenu/Move/",
              "ui/BookPopup/Move/"]
  @libraries.all_regular_libraries.each do |library|
    name = library.action_name
    ui_paths.each do |path|
      @uimanager.add_ui(@move_mid, path, name, name,
                        :menuitem, false)
    end
  end
end

#setup_popupsObject



223
224
225
226
227
228
229
230
# File 'lib/alexandria/ui/ui_manager.rb', line 223

def setup_popups
  log.debug { "setup_popups" }
  @library_popup = @uimanager.get_widget("/LibraryPopup")
  @smart_library_popup = @uimanager.get_widget("/SmartLibraryPopup")
  @nolibrary_popup = @uimanager.get_widget("/NoLibraryPopup")
  @book_popup = @uimanager.get_widget("/BookPopup")
  @nobook_popup = @uimanager.get_widget("/NoBookPopup")
end

#setup_toolbarObject



95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/alexandria/ui/ui_manager.rb', line 95

def setup_toolbar
  log.debug { "setup_toolbar" }
  setup_book_providers
  add_main_toolbar_items
  @toolbar = @uimanager.get_widget("/MainToolbar")
  @toolbar.show_arrow = true
  @toolbar.insert(Gtk::SeparatorToolItem.new, -1)
  setup_toolbar_combobox
  setup_toolbar_filter_entry
  @toolbar.insert(Gtk::SeparatorToolItem.new, -1)
  setup_toolbar_viewas
  @toolbar.show_all
  @actiongroup["Undo"].sensitive = @actiongroup["Redo"].sensitive = false
  UndoManager.instance.add_observer(self)
  @vbox1.add(@toolbar, position: 1, expand: false, fill: false)
end

#setup_toolbar_comboboxObject



139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
# File 'lib/alexandria/ui/ui_manager.rb', line 139

def setup_toolbar_combobox
  cb = Gtk::ComboBoxText.new
  cb.set_row_separator_func do |model, iter|
    # TODO: Replace with iter[0] if possible
    model.get_value(iter, 0) == "-"
  end
  [_("Match everything"),
   "-",
   _("Title contains"),
   _("Authors contain"),
   _("ISBN contains"),
   _("Publisher contains"),
   _("Notes contain"),
   _("Tags contain")].each do |item|
    cb.append_text(item)
  end
  cb.active = 0
  cb.signal_connect("changed") { |combo| on_criterion_combobox_changed(combo) }

  # Put the combo box in a event box because it is not currently
  # possible assign a tooltip to a combo box.
  eb = Gtk::EventBox.new
  eb << cb
  @toolitem = Gtk::ToolItem.new
  @toolitem.border_width = 5
  @toolitem << eb
  @toolbar.insert(@toolitem, -1)
  eb.set_tooltip_text _("Change the search type")
end

#setup_toolbar_filter_entryObject



126
127
128
129
130
131
132
133
134
135
136
137
# File 'lib/alexandria/ui/ui_manager.rb', line 126

def setup_toolbar_filter_entry
  @filter_entry = Gtk::Entry.new
  @filter_entry.signal_connect("changed") do |entry|
    on_toolbar_filter_entry_changed(entry)
  end
  @toolitem = Gtk::ToolItem.new
  @toolitem.expand = true
  @toolitem.border_width = 5
  @filter_entry.set_tooltip_text _("Type here the search criterion")
  @toolitem << @filter_entry
  @toolbar.insert(@toolitem, -1)
end

#setup_toolbar_viewasObject



169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
# File 'lib/alexandria/ui/ui_manager.rb', line 169

def setup_toolbar_viewas
  @toolbar_view_as = Gtk::ComboBoxText.new
  @toolbar_view_as.append_text(_("View as Icons"))
  @toolbar_view_as.append_text(_("View as List"))
  @toolbar_view_as.active = 0
  @toolbar_view_as_signal_hid = @toolbar_view_as.signal_connect("changed") do |combo|
    on_toolbar_view_as_changed(combo)
  end

  # Put the combo box in a event box because it is not currently
  # possible assign a tooltip to a combo box.
  eb = Gtk::EventBox.new
  eb << @toolbar_view_as
  @toolitem = Gtk::ToolItem.new
  @toolitem.border_width = 5
  @toolitem << eb
  @toolbar.insert(@toolitem, -1)
  eb.set_tooltip_text _("Choose how to show books")
end

#setup_window_eventsObject



232
233
234
235
236
237
238
239
240
# File 'lib/alexandria/ui/ui_manager.rb', line 232

def setup_window_events
  log.debug { "setup_window_events" }
  @main_app.signal_connect("window-state-event") do |window, event|
    on_window_state_event(window, event)
  end
  @main_app.signal_connect("destroy") do |window|
    on_window_destroy(window)
  end
end

#setup_window_iconsObject



1207
1208
1209
1210
1211
# File 'lib/alexandria/ui/ui_manager.rb', line 1207

def setup_window_icons
  @main_app.icon = Icons::ALEXANDRIA_SMALL
  Gtk::Window.set_default_icon_name("alexandria")
  @main_app.icon_name = "alexandria"
end

#showObject



59
60
61
# File 'lib/alexandria/ui/ui_manager.rb', line 59

def show
  @main_app.show
end

#show_progress_barObject



705
706
707
# File 'lib/alexandria/ui/ui_manager.rb', line 705

def show_progress_bar
  progress_bar.visible = true
end

#start_progress_bar_pulsing(dialog) ⇒ Object



713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
# File 'lib/alexandria/ui/ui_manager.rb', line 713

def start_progress_bar_pulsing(dialog)
  GLib::Idle.add do
    show_progress_bar
    @progress_pulsing = GLib::Timeout.add(100) do
      if dialog.destroyed?
        @progress_pulsing = nil
        hide_progress_bar
        false
      else
        progress_bar.pulse
        true
      end
    end
    false
  end
end

#stop_progress_bar_pulsingObject



730
731
732
733
734
735
736
# File 'lib/alexandria/ui/ui_manager.rb', line 730

def stop_progress_bar_pulsing
  GLib::Idle.add do
    hide_progress_bar
    GLib::Source.remove(@progress_pulsing) if @progress_pulsing
    false
  end
end

#undoable_delete(library, books = nil) ⇒ Object



1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
# File 'lib/alexandria/ui/ui_manager.rb', line 1165

def undoable_delete(library, books = nil)
  # Deleting a library.
  if books.nil?
    library.delete_observer(self) if library.is_a?(Library)
    library.delete
    @libraries.remove_library(library)
    remove_library_separator
    remove_library_iter
    get_previous_selected_library library
    setup_move_actions
    select_library(@previous_selected_library) unless @previous_selected_library.nil?
    @previous_selected_library = nil
  else
    # Deleting books.
    books.each { |book| library.delete(book) }
  end
  UndoManager.instance.push { undoable_undelete(library, books) }
end

#undoable_move(source, dest, books) ⇒ Object



1065
1066
1067
1068
1069
# File 'lib/alexandria/ui/ui_manager.rb', line 1065

def undoable_move(source, dest, books)
  log.debug { "undoable_move" }
  Library.move(source, dest, *books)
  UndoManager.instance.push { undoable_move(dest, source, books) }
end

#undoable_undelete(library, books = nil) ⇒ Object



1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
# File 'lib/alexandria/ui/ui_manager.rb', line 1191

def undoable_undelete(library, books = nil)
  # Undeleting a library.
  if books.nil?
    library.undelete
    @libraries.add_library(library)
    append_library(library)
    setup_move_actions
    library.add_observer(self) if library.is_a?(Library)
    # Undeleting books.
  else
    books.each { |book| library.undelete(book) }
  end
  select_library(library)
  UndoManager.instance.push { undoable_delete(library, books) }
end

#update(*ary) ⇒ Object



544
545
546
547
548
549
550
551
552
553
554
555
556
# File 'lib/alexandria/ui/ui_manager.rb', line 544

def update(*ary)
  log.debug { "on_update #{ary}" }
  caller = ary.first
  case caller
  when UndoManager
    @actiongroup["Undo"].sensitive = caller.can_undo?
    @actiongroup["Redo"].sensitive = caller.can_redo?
  when Library
    handle_update_caller_library ary unless caller.updating?
  else
    raise _("unrecognized update event")
  end
end

#widget_namesObject



63
64
65
66
67
# File 'lib/alexandria/ui/ui_manager.rb', line 63

def widget_names
  [:main_app, :paned, :vbox1, :library_listview,
   :notebook, :iconview, :listview, :status_label, :appbar,
   :progressbar]
end