class Rabbit::Menu
Public Class Methods
new(actions)
click to toggle source
# File lib/rabbit/menu.rb, line 35 def initialize(actions) @merge = Gtk::UIManager.new @merge.insert_action_group(actions, 0) @jump_to_actions = nil @jump_to_merge_id = nil @theme_actions = nil @theme_merge_id = nil update_ui end
Public Instance Methods
attach(window)
click to toggle source
# File lib/rabbit/menu.rb, line 45 def attach(window) window.add_accel_group(accel_group) end
detach(window)
click to toggle source
# File lib/rabbit/menu.rb, line 49 def detach(window) window.remove_accel_group(accel_group) end
popup(button, time)
click to toggle source
# File lib/rabbit/menu.rb, line 64 def popup(button, time) @menu.popup(nil, nil, button, time) end
Private Instance Methods
_format_xml(axml, output, indent)
click to toggle source
# File lib/rabbit/menu.rb, line 189 def _format_xml(axml, output, indent) case axml when Array tag, *others = axml output.print("#{@indent * indent}<#{tag}") if others.first.is_a?(Hash) attrs, *others = others attrs.each do |key, value| output.print(" #{h(key)}=\"#{h(value)}\"") if value end end if others.empty? output.print("/>\n") else output.print(">\n") others.each do |other| _format_xml(other, output, indent + 1) end output.print("#{@indent * indent}</#{tag}>\n") end when String output.print(h(axml)) else raise "!?!?!?: #{axml.inspect}" end end
accel_group()
click to toggle source
# File lib/rabbit/menu.rb, line 69 def accel_group # @merge.accel_group @accel_group = @merge.accel_group # <- workaround for Ruby/GLib <= 0.18.1 end
escape_label(label)
click to toggle source
# File lib/rabbit/menu.rb, line 85 def escape_label(label) label.gsub(/_/, '__') end
format_xml(axml)
click to toggle source
# File lib/rabbit/menu.rb, line 181 def format_xml(axml) output = StringIO.new @indent = " " _format_xml(axml, output, 0) output.rewind output.read end
items()
click to toggle source
# File lib/rabbit/menu.rb, line 238 def items [ [:item, "ToggleIndexMode"], [:separator], [:item, "ToggleGraffitiMode"], [:menu, "Graffiti", [:item, "ClearGraffiti"], [:item, "UndoGraffiti"], [:item, "ChangeGraffitiColor"], ], [:separator], [:item, "ToggleFullScreen"], [:separator], [:item, "ToggleInfoWindow"], [:separator], [:item, "RadioBlankWhiteout"], [:item, "RadioBlankBlackout"], [:item, "RadioBlankShow"], # [:separator], # [:item, "ToggleCommentFrame"], # [:item, "ToggleCommentView"], [:separator], [:item, "ToggleSpotlight"], [:item, "ToggleMagnifier"], [:separator], [:item, "ToggleTerminal"], [:separator], [:menu, "JumpTo"], [:separator], [:item, "Previous"], [:item, "Next"], [:item, "PreviousSlide"], [:item, "NextSlide"], [:item, "FirstSlide"], [:item, "LastSlide"], [:separator], [:item, "Iconify"], [:separator], [:item, "Redraw"], [:item, "ClearSlide"], [:item, "ReloadTheme"], [:menu, "ChangeTheme"], [:menu, "MergeTheme"], [:separator], [:item, "CacheAllSlides"], [:separator], [:item, "SaveAsImage"], [:item, "Print"], [:separator], [:item, "ResetTimer"], [:item, "ResetAdjustment"], [:separator], [:menu, "LogLevel", [:item, "RadioLogLevelDebug"], [:item, "RadioLogLevelInfo"], [:item, "RadioLogLevelWarning"], [:item, "RadioLogLevelError"], [:item, "RadioLogLevelFatal"], [:item, "RadioLogLevelUnknown"], ], [:separator], [:item, "Quit"], ] end
items_to_axml(items)
click to toggle source
# File lib/rabbit/menu.rb, line 224 def items_to_axml(items) items.collect do |key, name, *others| params = {:name => name, :action => name} case key when :separator [:separator] when :item [:menuitem, params] when :menu [:menu, params, *items_to_axml(others)] end end end
make_jump_to_action(jump_to_action, title, i)
click to toggle source
# File lib/rabbit/menu.rb, line 74 def make_jump_to_action(jump_to_action, title, i) name = "JumpTo#{i}" label = "#{i}: #{escape_label(Utils.unescape_title(title))}" tooltip = _("Jump to the %dth slide") % i action = Gtk::Action.new(name, :label => label, :tooltip => tooltip) action.signal_connect("activate") do jump_to_action.activate {i} end action end
show_tearoff(sub_menus=@menu.children)
click to toggle source
# File lib/rabbit/menu.rb, line 167 def show_tearoff(sub_menus=@menu.children) sub_menus.each do |child| if child.respond_to?(:submenu) and child.submenu tearoff, *child_sub_menus = child.submenu.children tearoff.show show_tearoff(child_sub_menus) end end end
ui_axml()
click to toggle source
# File lib/rabbit/menu.rb, line 216 def ui_axml [:ui, [:popup, *items_to_axml(items) ] ] end
ui_xml()
click to toggle source
# File lib/rabbit/menu.rb, line 177 def ui_xml format_xml(ui_axml) end
update_ui()
click to toggle source
# File lib/rabbit/menu.rb, line 109 def update_ui @merge_ui = @merge.add_ui(ui_xml) @menu = @merge.get_widget("/popup") tearoff = Gtk::TearoffMenuItem.new tearoff.show @menu.prepend(tearoff) end