Class: Sirens::TextView

Inherits:
WidgetView show all
Defined in:
lib/views/text_view.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from WidgetView

#add_view, #apply_prop, #apply_props, #initialize, #main_handle

Methods inherited from AbstractView

accepted_styles, #accepted_styles, #add_view, #attribute_at, #height, #height=, #initialize, #main_handle, #populate_popup_menu_block=, #remove_view, #set_attribute, #show, #show_popup_menu, #width, #width=

Constructor Details

This class inherits a constructor from Sirens::WidgetView

Class Method Details

.view_accepted_stylesObject

Answer the styles accepted by this view.



9
10
11
# File 'lib/views/text_view.rb', line 9

def view_accepted_styles()
    super() + [:wrap_mode].freeze
end

Instance Method Details

#background_color=(value) ⇒ Object



47
48
49
50
51
52
53
# 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) ⇒ Object



55
56
57
58
59
60
61
# 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_handlesObject

Initializing



16
17
18
19
20
21
22
23
# 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_textObject

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



104
105
106
107
108
109
110
# 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) ⇒ Object



93
94
95
96
97
# 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) ⇒ Object



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# 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_eventsObject

Hooking GUI signals



27
28
29
30
31
32
33
34
35
# 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

#textObject



89
90
91
# File 'lib/views/text_view.rb', line 89

def text()
    text_view.buffer.text
end

#text_viewObject

Accessing



85
86
87
# File 'lib/views/text_view.rb', line 85

def text_view()
    @text_view
end

#wrap_modeObject



43
44
45
# File 'lib/views/text_view.rb', line 43

def wrap_mode()
    text_view.wrap_mode
end

#wrap_mode=(value) ⇒ Object

Styles



39
40
41
# File 'lib/views/text_view.rb', line 39

def wrap_mode=(value)
    text_view.wrap_mode = value
end