Sha256: 8db34958c27a4780d47722db9779cc7853b7a5004146f6f8d98cb4f69bf0ae48

Contents?: true

Size: 1.72 KB

Versions: 2

Compression:

Stored size: 1.72 KB

Contents

# frozen_string_literal: true

# This file is part of Alexandria.
#
# See the file README.md for authorship and licensing information.

require "alexandria/ui/alert_dialog"

module Alexandria
  module UI
    class ReallyDeleteDialog < AlertDialog
      include GetText
      GetText.bindtextdomain(Alexandria::TEXTDOMAIN, charset: "UTF-8")

      def initialize(parent, library, books = nil)
        # Deleting a library.
        if books.nil?
          message = _("Are you sure you want to delete '%s'?") % library.name
          description = if library.is_a?(SmartLibrary) || library.empty?
                          nil
                        else
                          n_("If you continue, %d book will be deleted.",
                             "If you continue, %d books will be deleted.",
                             library.size) % library.size
                        end
          # Deleting books.
        else
          message = if books.length == 1
                      format(_("Are you sure you want to delete '%s' " \
                        "from '%s'?"), books.first.title, library.name)
                    else
                      _("Are you sure you want to delete the " \
                        "selected books from '%s'?") % library.name
                    end
          description = nil
        end

        super(parent, message, Gtk::Stock::DIALOG_QUESTION,
              [[Gtk::Stock::CANCEL, Gtk::ResponseType::CANCEL],
               [Gtk::Stock::DELETE, Gtk::ResponseType::OK]],
              description)

        self.default_response = Gtk::ResponseType::CANCEL
      end

      def ok?
        show_all && (@response = run)
        destroy
        @response == Gtk::ResponseType::OK
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
alexandria-book-collection-manager-0.7.5 lib/alexandria/ui/really_delete_dialog.rb
alexandria-book-collection-manager-0.7.4 lib/alexandria/ui/really_delete_dialog.rb