Class: Alexandria::UI::NewProviderDialog

Inherits:
ProviderPreferencesBaseDialog show all
Includes:
GetText
Defined in:
lib/alexandria/ui/new_provider_dialog.rb

Instance Attribute Summary

Attributes inherited from ProviderPreferencesBaseDialog

#dialog

Instance Method Summary collapse

Constructor Details

#initialize(parent) ⇒ NewProviderDialog

Returns a new instance of NewProviderDialog.



16
17
18
19
20
21
22
23
24
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
58
59
60
61
62
63
# File 'lib/alexandria/ui/new_provider_dialog.rb', line 16

def initialize(parent)
  super(title: _("New Provider"),
        parent: parent,
        flags: :modal,
        buttons: [[Gtk::Stock::CANCEL, Gtk::ResponseType::CANCEL]])
  @add_button = dialog.add_button(Gtk::Stock::ADD,
                                  Gtk::ResponseType::ACCEPT)

  instances = BookProviders.abstract_classes.map(&:new)
  @selected_instance = nil

  @table = Gtk::Table.new(2, 2)
  dialog.child.pack_start(@table)

  # Name.

  label_name = Gtk::Label.new(_("_Name:"))
  label_name.use_underline = true
  label_name.xalign = 0
  @table.attach_defaults(label_name, 0, 1, 0, 1)

  @entry_name = Gtk::Entry.new
  @entry_name.mandatory = true
  label_name.mnemonic_widget = @entry_name
  @table.attach_defaults(@entry_name, 1, 2, 0, 1)

  # Type.

  label_type = Gtk::Label.new(_("_Type:"))
  label_type.use_underline = true
  label_type.xalign = 0
  @table.attach_defaults(label_type, 0, 1, 1, 2)

  combo_type = Gtk::ComboBoxText.new
  instances.each do |instance|
    combo_type.append_text(instance.name)
  end
  combo_type.signal_connect("changed") do |cb|
    @selected_instance = instances[cb.active]
    fill_table(@table, @selected_instance)
    sensitize
    # FIXME: this should be re-written once we have multiple
    # abstract providers.
  end
  combo_type.active = 0
  label_type.mnemonic_widget = combo_type
  @table.attach_defaults(combo_type, 1, 2, 1, 2)
end

Instance Method Details

#acquireObject



65
66
67
68
69
70
71
72
73
74
75
# File 'lib/alexandria/ui/new_provider_dialog.rb', line 65

def acquire
  dialog.show_all
  if dialog.run == Gtk::ResponseType::ACCEPT
    @selected_instance.reinitialize(@entry_name.text)
    sync_variables
  else
    @selected_instance = nil
  end
  dialog.destroy
  instance
end

#instanceObject



77
78
79
# File 'lib/alexandria/ui/new_provider_dialog.rb', line 77

def instance
  @selected_instance
end