summaryrefslogtreecommitdiffhomepage
path: root/samples/99_genre_dev_tools/add_buttons_to_console/app/main.rb
blob: b580477ed10ef3d68a688fd188257718790c9d94 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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
# You can customize the buttons that show up in the Console.
class GTK::Console::Menu
  # STEP 1: Override the custom_buttons function.
  def custom_buttons
    [
      (button id: :yay,
              # row for button
              row: 3,
              # column for button
              col: 10,
              # text
              text: "I AM CUSTOM",
              # when clicked call the custom_button_clicked function
              method: :custom_button_clicked),

      (button id: :yay,
              # row for button
              row: 3,
              # column for button
              col: 9,
              # text
              text: "CUSTOM ALSO",
              # when clicked call the custom_button_also_clicked function
              method: :custom_button_also_clicked)
    ]
  end

  # STEP 2: Define the function that should be called.
  def custom_button_clicked
    log "* INFO: I AM CUSTOM was clicked!"
  end

  def custom_button_also_clicked
    log "* INFO: Custom Button Clicked at #{Kernel.global_tick_count}!"

    all_buttons_as_string = $gtk.console.menu.buttons.map do |b|
      <<-S.strip
** id: #{b[:id]}
:PROPERTIES:
:id:     :#{b[:id]}
:method: :#{b[:method]}
:text:   #{b[:text]}
:END:
S
    end.join("\n")

    log <<-S
* INFO: Here are all the buttons:
#{all_buttons_as_string}
S
  end
end

def tick args
  args.outputs.labels << [args.grid.center.x, args.grid.center.y,
                          "Open the DragonRuby Console to see the custom menu items.",
                          0, 1]
end