Sha256: 1bbea40abf2660341eaa36b447aa499fb92efc54441c39865cce5750fc131627

Contents?: true

Size: 1.77 KB

Versions: 1

Compression:

Stored size: 1.77 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 NewSmartLibraryDialog < SmartLibraryPropertiesDialogBase
      include GetText
      GetText.bindtextdomain(Alexandria::TEXTDOMAIN, charset: 'UTF-8')

      def initialize(parent)
        super(parent)

        add_buttons([Gtk::Stock::CANCEL, :cancel],
                    [Gtk::Stock::NEW, :ok])

        self.title = _('New Smart Library')
        # FIXME: Should accept just :cancel
        self.default_response = Gtk::ResponseType::CANCEL
      end

      def acquire
        show_all
        insert_new_rule

        while ((response = run) != Gtk::ResponseType::CANCEL) &&
            (response != Gtk::ResponseType::DELETE_EVENT)

          if response == Gtk::ResponseType::HELP
            Alexandria::UI.display_help(self, 'new-smart-library')
          elsif response == Gtk::ResponseType::OK
            if user_confirms_possible_weirdnesses_before_saving?
              rules = smart_library_rules
              basename = smart_library_base_name(rules) || _('Smart Library')
              name = Library.generate_new_name(
                LibraryCollection.instance.all_libraries,
                basename)
              library = SmartLibrary.new(name,
                                         rules,
                                         predicate_operator_rule)
              yield(library)
              break
            end
          end
        end

        destroy
      end

      private

      def smart_library_base_name(rules)
        if rules.length == 1
          value = rules.first.value
          return value if value.is_a?(String) && !value.strip.empty?
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
alexandria-book-collection-manager-0.7.3 lib/alexandria/ui/dialogs/new_smart_library_dialog.rb