Sha256: 3b50a6d34c9e1a80b9a2ec2a8ee24b2d3d5a811f9f71b1f6d2a4a852ff4938a2

Contents?: true

Size: 1.6 KB

Versions: 5

Compression:

Stored size: 1.6 KB

Contents

# frozen_string_literal: true

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

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

      def initialize(parent, smart_library)
        super(parent)

        @smart_library = smart_library

        dialog.add_buttons([Gtk::Stock::CANCEL, :cancel],
                           [Gtk::Stock::SAVE, :ok])

        dialog.title = _("Properties for '%s'") % @smart_library.name
        # FIXME: Should accept just :cancel
        dialog.default_response = Gtk::ResponseType::CANCEL
        @smart_library.rules.each { |x| insert_new_rule(x) }
        update_rules_header_box(@smart_library.predicate_operator_rule)
      end

      def acquire
        dialog.show_all

        while (response = dialog.run) != Gtk::ResponseType::CANCEL
          case response
          when Gtk::ResponseType::HELP
            handle_help_response
          when Gtk::ResponseType::OK
            break if handle_ok_response
          end
        end

        dialog.destroy
      end

      private

      def handle_ok_response
        user_confirms_possible_weirdnesses_before_saving? or return

        @smart_library.rules = smart_library_rules
        @smart_library.predicate_operator_rule =
          predicate_operator_rule
        @smart_library.save
        true
      end

      def handle_help_response
        Alexandria::UI.display_help(self, "edit-smart-library")
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
alexandria-book-collection-manager-0.7.10 lib/alexandria/ui/smart_library_properties_dialog.rb
alexandria-book-collection-manager-0.7.9 lib/alexandria/ui/smart_library_properties_dialog.rb
alexandria-book-collection-manager-0.7.8 lib/alexandria/ui/smart_library_properties_dialog.rb
alexandria-book-collection-manager-0.7.7 lib/alexandria/ui/smart_library_properties_dialog.rb
alexandria-book-collection-manager-0.7.6 lib/alexandria/ui/smart_library_properties_dialog.rb