Class: Alexandria::UI::ProviderPreferencesBaseDialog

Inherits:
Gtk::Dialog
  • Object
show all
Defined in:
lib/alexandria/ui/dialogs/preferences_dialog.rb

Direct Known Subclasses

NewProviderDialog, ProviderPreferencesDialog

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ ProviderPreferencesBaseDialog

Returns a new instance of ProviderPreferencesBaseDialog.



34
35
36
37
38
39
40
41
# File 'lib/alexandria/ui/dialogs/preferences_dialog.rb', line 34

def initialize(*args)
  super(*args)

  self.resizable = false
  child.border_width = 12

  @controls = []
end

Instance Method Details

#fill_table(table, provider) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/alexandria/ui/dialogs/preferences_dialog.rb', line 43

def fill_table(table, provider)
  i = table.n_rows
  table.resize(table.n_rows + provider.prefs.length,
               table.n_columns)
  table.border_width = 12
  table.row_spacings = 6
  table.column_spacings = 12

  @controls.clear

  provider.prefs.read.each do |variable|
    if variable.name == 'piggyback'
      next
      # ULTRA-HACK!! for bug #13302
      # not displaying the visual choice, as its usually unnecessary
      # Either way, this is confusing to the user: FIX
      #    -   Cathal Mc Ginley 2008-02-18
    end

    if variable.name == 'enabled'
      # also don't display Enabled/Disabled
      next
    end

    label = Gtk::Label.new('_' + variable.description + ':')
    label.use_underline = true
    label.xalign = 0
    table.attach_defaults(label, 0, 1, i, i + 1)

    if variable.possible_values.nil?
      entry = Gtk::Entry.new
      entry.text = variable.value.to_s
      entry.mandatory = variable.mandatory?
    else
      entry = Gtk::ComboBoxText.new
      variable.possible_values.each do |value|
        entry.append_text(value.to_s)
      end
      index = variable.possible_values.index(variable.value)
      entry.active = index
    end
    label.mnemonic_widget = entry

    @controls << [variable, entry]

    table.attach_defaults(entry, 1, 2, i, i + 1)
    i += 1
  end
  table
end

#sync_variablesObject



94
95
96
97
98
99
100
101
102
103
# File 'lib/alexandria/ui/dialogs/preferences_dialog.rb', line 94

def sync_variables
  @controls.each do |variable, entry|
    variable.new_value = case entry
                         when Gtk::ComboBox
                           variable.possible_values[entry.active]
                         when Gtk::Entry
                           entry.text
                         end
  end
end