Index: lib/alexandria/ui/callbacks.rb =================================================================== --- lib/alexandria/ui/callbacks.rb (revision 1067) +++ lib/alexandria/ui/callbacks.rb (revision 1072) @@ -19,6 +19,9 @@ module Alexandria module UI module Callbacks + + include Logging + def on_new widget, event name = Library.generate_new_name(@libraries.all_libraries) library = Library.load(name) @@ -208,6 +211,12 @@ def on_delete widget, event library = selected_library books = @library_listview.focus? ? nil : selected_books + is_smart = library.is_a?(SmartLibrary) + last_library = (@libraries.all_regular_libraries.length == 1) + if (!is_smart && last_library) + log.warn { "Attempted to delete last library, fix GUI" } + return + end if library.empty? or ReallyDeleteDialog.new(@main_app, library, books).ok? Index: lib/alexandria/ui/ui_manager.rb =================================================================== --- lib/alexandria/ui/ui_manager.rb (revision 1067) +++ lib/alexandria/ui/ui_manager.rb (revision 1072) @@ -306,6 +306,7 @@ 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) obj, path = widget.is_a?(Gtk::TreeView) \ ? [widget.selection, path.first] : [widget, path] @@ -313,6 +314,7 @@ unless obj.path_is_selected?(path) log.debug { "Select #{path}" } + library_already_selected = false widget.unselect_all obj.select_path(path) end @@ -321,10 +323,25 @@ end menu = determine_library_popup widget, event - Gtk.idle_add do - menu.popup(nil, nil, event.button, event.time) - false + + # 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. + + + if library_already_selected + sensitize_library selected_library + Gtk.idle_add do + menu.popup(nil, nil, event.button, event.time) + false + end end + end end @@ -972,7 +989,8 @@ @actiongroup["AddBook"].sensitive = !smart @actiongroup["AddBookManual"].sensitive = !smart @actiongroup["Properties"].sensitive = true - @actiongroup["Delete"].sensitive = true #(@libraries.all_regular_libraries.length > 1) + can_delete = smart || (@libraries.all_regular_libraries.length > 1) + @actiongroup["Delete"].sensitive = can_delete ## true #(@libraries.all_regular_libraries.length > 1) log.debug { "sensitize_library delete: #{@actiongroup["Delete"].sensitive?}" } end