Class: VimMate::ConfigWindow

Inherits:
Object
  • Object
show all
Defined in:
lib/config_window.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(main_window = nil) ⇒ ConfigWindow

Returns a new instance of ConfigWindow.



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/config_window.rb', line 4

def initialize(main_window=nil)
  @gtk_main_window = Gtk::Dialog.new("Configuration", main_window, Gtk::Dialog::MODAL,
                                     [ Gtk::Stock::CANCEL, Gtk::Dialog::RESPONSE_REJECT ],
                                     [ Gtk::Stock::OK, Gtk::Dialog::RESPONSE_ACCEPT ]
                                    )
  gtk_window.set_default_size(400,300)
  gtk_window.signal_connect('response') do |win,resp|
    case resp
    when Gtk::Dialog::RESPONSE_ACCEPT
      save_settings
      win.close
    when Gtk::Dialog::RESPONSE_REJECT
      win.close
    when Gtk::Dialog::RESPONSE_NONE
      puts "closing"
    end
  end
  @container = gtk_window.vbox
  fill_container
  gtk_window.show_all
end

Instance Attribute Details

#containerObject (readonly)

Returns the value of attribute container.



3
4
5
# File 'lib/config_window.rb', line 3

def container
  @container
end

Instance Method Details

#field_for(val) ⇒ Object



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/config_window.rb', line 69

def field_for(val)
  case val
  when String
    # TODO make "textarea" for more than 42 chars
    e = Gtk::Entry.new
    e.editable = true
    e.text = val
    e
  when Fixnum, Float
    Gtk::SpinButton.new(
      Gtk::Adjustment.new(val,0,10000,1,10,1),
      1,0)
  when FalseClass, TrueClass
    e = Gtk::ToggleButton.new
    e.active = val
    e
  else
   Gtk::Label.new(val.to_s)
  end
end

#fill_containerObject



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/config_window.rb', line 30

def fill_container
  @fields = {}
  Config::DEFAULT_CONFIG.keys.sort {|a,b| a.to_s <=> b.to_s}.each do |key|
    val = Config[key]
    box = Gtk::HBox.new(true,10)
      label = Gtk::Label.new(key.to_s.humanize)
      label.xalign = 1
      box.pack_start label, true, true 

      field = field_for val
      @fields[key] = field
      box.pack_start field, true, false
    container.pack_start box 
  end
end

#gtk_windowObject

The “window” for this object



26
27
28
# File 'lib/config_window.rb', line 26

def gtk_window
  @gtk_main_window
end

#save_settingsObject



46
47
48
49
50
51
52
53
# File 'lib/config_window.rb', line 46

def save_settings
  Config::DEFAULT_CONFIG.keys.each do |key|
    if new_val = val_of(key)
      Config.config[key] = new_val
    end
  end
  Config.write_config
end

#val_of(key) ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/config_window.rb', line 55

def val_of(key)
  field = @fields[key]
  case Config::DEFAULT_CONFIG[key]
  when String
    field.text
  when Fixnum
    field.value.to_i
  when Float
    field.value.to_f
  when FalseClass, TrueClass
    field.active?
  end
end