Class: Gtk::ActionGroup

Inherits:
Object
  • Object
show all
Defined in:
lib/gtk3/action-group.rb

Instance Method Summary collapse

Instance Method Details

#add_action(action, options = {}) ⇒ Object



20
21
22
23
24
25
26
27
28
# File 'lib/gtk3/action-group.rb', line 20

def add_action(action, options={})
  accelerator = options[:accelerator]

  if accelerator
    add_action_with_accel(action, accelerator)
  else
    add_action_raw(action)
  end
end

#add_action_rawObject



19
# File 'lib/gtk3/action-group.rb', line 19

alias_method :add_action_raw, :add_action

#add_actions(actions) ⇒ Object



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
# File 'lib/gtk3/action-group.rb', line 30

def add_actions(actions)
  actions.each do |config|
    if config.is_a?(Array)
      name        = config[0]
      stock_id    = config[1]
      label       = config[2]
      accelerator = config[3]
      tooltip     = config[4]
      callback    = config[5]
    else
      name        = config[:name]
      stock_id    = config[:stock_id]
      label       = config[:label]
      accelerator = config[:accelerator]
      tooltip     = config[:tooltip]
      callback    = config[:callback]
    end

    action = Action.new(name,
                        :label    => translate_string(label),
                        :tooltip  => translate_string(tooltip),
                        :stock_id => stock_id)
    action.signal_connect("activate") do
      callback.call(self, action)
    end
    add_action(action, :accelerator => accelerator)
  end
end

#add_radio_actions(actions, default_value = nil) ⇒ Object



91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'lib/gtk3/action-group.rb', line 91

def add_radio_actions(actions, default_value=nil)
  actions.each_with_index do |config, i|
    if config.is_a?(Array)
      name        = config[0]
      stock_id    = config[1]
      label       = config[2]
      accelerator = config[3]
      tooltip     = config[4]
      value       = config[5]
    else
      name        = config[:name]
      stock_id    = config[:stock_id]
      label       = config[:label]
      accelerator = config[:accelerator]
      tooltip     = config[:tooltip]
      value       = config[:value]
    end

    action = RadioAction.new(name,
                             value,
                             :label    => translate_string(label),
                             :tooltip  => translate_string(tooltip),
                             :stock_id => stock_id)
    action.active = true if value == default_value
    if i.zero?
      action.signal_connect("changed") do |connected_action, current_action|
        yield(connected_action, current_action)
      end
    end
    add_action(action, :accelerator => accelerator)
  end
end

#add_toggle_actions(actions) ⇒ Object



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
# File 'lib/gtk3/action-group.rb', line 59

def add_toggle_actions(actions)
  actions.each do |config|
    if config.is_a?(Array)
      name        = config[0]
      stock_id    = config[1]
      label       = config[2]
      accelerator = config[3]
      tooltip     = config[4]
      callback    = config[5]
      is_active   = config[6]
    else
      name        = config[:name]
      stock_id    = config[:stock_id]
      label       = config[:label]
      accelerator = config[:accelerator]
      tooltip     = config[:tooltip]
      callback    = config[:callback]
      is_active   = config[:is_active]
    end

    action = ToggleAction.new(name,
                              :label    => translate_string(label),
                              :tooltip  => translate_string(tooltip),
                              :stock_id => stock_id)
    action.active = true if is_active
    action.signal_connect("activate") do
      callback.call(self, action)
    end
    add_action(action, :accelerator => accelerator)
  end
end

#translate_string(string) ⇒ Object



125
126
127
128
129
# File 'lib/gtk3/action-group.rb', line 125

def translate_string(string)
  return nil if string.nil?

  translate_string_raw(string)
end

#translate_string_rawObject



124
# File 'lib/gtk3/action-group.rb', line 124

alias_method :translate_string_raw, :translate_string