class Sirens::TextView

Public Class Methods

view_accepted_styles() click to toggle source

Answer the styles accepted by this view.

Calls superclass method
# File lib/views/text_view.rb, line 9
def view_accepted_styles()
    super() + [:wrap_mode].freeze
end

Public Instance Methods

background_color=(value) click to toggle source
# File lib/views/text_view.rb, line 47
def background_color=(value)
    state_colors_from(value).each_pair do |state, value|
        next if value.nil?

        text_view.override_background_color( state, Gdk::RGBA.parse(value) )
    end
end
foreground_color=(value, state: :normal) click to toggle source
# File lib/views/text_view.rb, line 55
def foreground_color=(value, state: :normal)
    state_colors_from(value).each_pair do |state, value|
        next if value.nil?

        text_view.override_color( state, Gdk::RGBA.parse(value) )
    end
end
initialize_handles() click to toggle source

Initializing

# File lib/views/text_view.rb, line 16
def initialize_handles()
    @text_view = Gtk::TextView.new

    @main_handle = Gtk::ScrolledWindow.new
    @main_handle.set_policy(:automatic, :always)

    @main_handle.add(@text_view)
end
selected_text() click to toggle source

Returns the selected text of nil if no text is selected.

# File lib/views/text_view.rb, line 104
def selected_text()
    selection_bounds = text_view.buffer.selection_bounds

    return if selection_bounds.nil?

    text_view.buffer.get_text(selection_bounds[0], selection_bounds[1], false)
end
set_text(text) click to toggle source
# File lib/views/text_view.rb, line 93
def set_text(text)
    text = '' if text.nil?

    text_view.buffer.text = text
end
state_colors_from(value) click to toggle source
# File lib/views/text_view.rb, line 63
def state_colors_from(value)
    colors = Hash[
        normal: nil,
        active: nil,
        prelight: nil,
        selected: nil,
        insensitive: nil,
    ]

    if value.kind_of?(Hash)
        value.each_pair do |state, value|
            colors[state] = value
        end
    else
        colors[:normal] = value
    end

    colors
end
subscribe_to_ui_events() click to toggle source

Hooking GUI signals

# File lib/views/text_view.rb, line 27
def subscribe_to_ui_events()
    text_view.signal_connect('populate-popup') do |text_view, menu|
        menu_view = MenuView.new(menu_handle: menu)

        @populate_popup_menu_block.call(menu: menu_view)

        menu.show_all
    end
end
text() click to toggle source
# File lib/views/text_view.rb, line 89
def text()
    text_view.buffer.text
end
text_view() click to toggle source

Accessing

# File lib/views/text_view.rb, line 85
def text_view()
    @text_view
end
wrap_mode() click to toggle source
# File lib/views/text_view.rb, line 43
def wrap_mode()
    text_view.wrap_mode
end
wrap_mode=(value) click to toggle source

Styles

# File lib/views/text_view.rb, line 39
def wrap_mode=(value)
    text_view.wrap_mode = value
end