Class: VER::View
- Inherits:
-
Tk::Frame
- Object
- Tk::Frame
- VER::View
- Defined in:
- lib/ver/view.rb,
lib/ver/view/entry.rb,
lib/ver/view/console.rb
Defined Under Namespace
Classes: Console, Entry, List, Terminal
Instance Attribute Summary collapse
-
#layout ⇒ Object
readonly
Returns the value of attribute layout.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
-
#text ⇒ Object
readonly
Returns the value of attribute text.
Instance Method Summary collapse
- #close ⇒ Object
- #create(path = nil, line = nil) ⇒ Object
- #destroy ⇒ Object
- #filename ⇒ Object
- #find_or_create(path, line = nil, &block) ⇒ Object
- #focus ⇒ Object
- #focus_next ⇒ Object
- #focus_prev ⇒ Object
-
#initialize(layout, options = {}) ⇒ View
constructor
A new instance of View.
- #on_focus(event) ⇒ Object
- #on_modified(event) ⇒ Object
-
#on_movement(event) ⇒ Object
handling events.
- #open_empty ⇒ Object
- #open_path(path, line = 1) ⇒ Object
- #push_bottom ⇒ Object
- #push_down ⇒ Object
- #push_top ⇒ Object
- #push_up ⇒ Object
-
#setup ⇒ Object
-------
—+ | | @ | | | y | | @text | b | | | a | | | r |-------
—+ | @xbar | |-------
—+ | @status |-----------
. - #setup_events ⇒ Object
- #setup_grid ⇒ Object
- #setup_misc ⇒ Object
- #setup_scrollbars ⇒ Object
- #setup_status ⇒ Object
- #setup_text ⇒ Object
Constructor Details
#initialize(layout, options = {}) ⇒ View
Returns a new instance of View.
9 10 11 12 13 14 15 |
# File 'lib/ver/view.rb', line 9 def initialize(layout, = {}) super @layout = layout @text = @status = @ybar = @xbar = nil configure takefocus: false setup end |
Instance Attribute Details
#layout ⇒ Object (readonly)
Returns the value of attribute layout.
7 8 9 |
# File 'lib/ver/view.rb', line 7 def layout @layout end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
7 8 9 |
# File 'lib/ver/view.rb', line 7 def status @status end |
#text ⇒ Object (readonly)
Returns the value of attribute text.
7 8 9 |
# File 'lib/ver/view.rb', line 7 def text @text end |
Instance Method Details
#close ⇒ Object
147 148 149 150 151 |
# File 'lib/ver/view.rb', line 147 def close text.may_close do layout.close_view(self) end end |
#create(path = nil, line = nil) ⇒ Object
127 128 129 130 131 132 |
# File 'lib/ver/view.rb', line 127 def create(path = nil, line = nil) layout.create_view do |view| path ? view.open_path(path, line) : view.open_empty yield(view) if block_given? end end |
#destroy ⇒ Object
177 178 179 180 181 |
# File 'lib/ver/view.rb', line 177 def destroy [@text, @ybar, @xbar, @status].compact.each(&:destroy) super end |
#filename ⇒ Object
183 184 185 |
# File 'lib/ver/view.rb', line 183 def filename text.filename end |
#find_or_create(path, line = nil, &block) ⇒ Object
134 135 136 137 138 139 140 141 142 143 144 145 |
# File 'lib/ver/view.rb', line 134 def find_or_create(path, line = nil, &block) needle = Pathname(path.to_s). if found = layout.views.find{|view| view.filename == needle } found.push_top found.focus found.text.go_line(line) if line yield(found) if block_given? else create(needle, line, &block) end end |
#focus ⇒ Object
123 124 125 |
# File 'lib/ver/view.rb', line 123 def focus text.focus end |
#focus_next ⇒ Object
153 154 155 |
# File 'lib/ver/view.rb', line 153 def focus_next layout.focus_next(self) end |
#focus_prev ⇒ Object
157 158 159 |
# File 'lib/ver/view.rb', line 157 def focus_prev layout.focus_prev(self) end |
#on_focus(event) ⇒ Object
118 119 120 121 |
# File 'lib/ver/view.rb', line 118 def on_focus(event) @text.set_window_title @text.see(:insert) end |
#on_modified(event) ⇒ Object
112 113 114 115 116 |
# File 'lib/ver/view.rb', line 112 def on_modified(event) @text.see :insert # @text.refresh_highlight @text.status_projection(@status) end |
#on_movement(event) ⇒ Object
handling events
106 107 108 109 110 |
# File 'lib/ver/view.rb', line 106 def on_movement(event) @text.see :insert @text.refresh_selection @text.status_projection(@status) end |
#open_empty ⇒ Object
100 101 102 |
# File 'lib/ver/view.rb', line 100 def open_empty @text.open_empty end |
#open_path(path, line = 1) ⇒ Object
96 97 98 |
# File 'lib/ver/view.rb', line 96 def open_path(path, line = 1) @text.open_path(path, line) end |
#push_bottom ⇒ Object
173 174 175 |
# File 'lib/ver/view.rb', line 173 def push_bottom layout.push_bottom(self) end |
#push_down ⇒ Object
165 166 167 |
# File 'lib/ver/view.rb', line 165 def push_down layout.push_down(self) end |
#push_top ⇒ Object
169 170 171 |
# File 'lib/ver/view.rb', line 169 def push_top layout.push_top(self) end |
#push_up ⇒ Object
161 162 163 |
# File 'lib/ver/view.rb', line 161 def push_up layout.push_up(self) end |
#setup ⇒ Object
-------
—+ | | @ | | | y | | @text | b | | | a | | | r | -------
—+ | @xbar | | -------
—+ | @status | -----------
28 29 30 31 32 33 34 35 |
# File 'lib/ver/view.rb', line 28 def setup setup_text # setup_scrollbars # enable if you really want some. setup_status setup_grid setup_misc setup_events end |
#setup_events ⇒ Object
90 91 92 93 94 |
# File 'lib/ver/view.rb', line 90 def setup_events %w[Modified Focus Movement].each do |name| @text.bind("<<#{name}>>"){|event| __send__("on_#{name.downcase}", event) } end end |
#setup_grid ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/ver/view.rb', line 72 def setup_grid @text.grid_configure row: 0, column: 0, sticky: :nsew if @text @ybar.grid_configure row: 0, column: 1, sticky: :ns if @ybar @xbar.grid_configure row: 1, column: 0, sticky: :ew if @xbar @status.grid_configure row: 2, column: 0, sticky: :ew, columnspan: 2 if @status grid_columnconfigure 0, weight: 1 grid_columnconfigure 1, weight: 0 grid_rowconfigure 0, weight: 1 grid_rowconfigure 1, weight: 0 end |
#setup_misc ⇒ Object
84 85 86 87 88 |
# File 'lib/ver/view.rb', line 84 def setup_misc @text.status = @status @text.view = self @status.mode = :status_query end |
#setup_scrollbars ⇒ Object
58 59 60 61 62 63 64 65 66 |
# File 'lib/ver/view.rb', line 58 def # vertical scrollbar @ybar = Tk::Tile::YScrollbar.new(self) @text.(@ybar) # horizontal scrollbar @xbar = Tk::Tile::XScrollbar.new(self) @text.(@xbar) end |
#setup_status ⇒ Object
68 69 70 |
# File 'lib/ver/view.rb', line 68 def setup_status @status = Status.new(self, font: VER.[:font], takefocus: false) end |
#setup_text ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/ver/view.rb', line 37 def setup_text font, tabstop = VER..font, VER..tabstop tabs = font.measure('0') * tabstop @text = VER::Text.new( self, autoseparators: true, # insert separators into the undo flow borderwidth: 0, exportselection: true, # copy into X11 buffer automatically font: font, insertofftime: VER..insertofftime, insertontime: VER..insertontime, setgrid: true, # tell the wm that this is a griddy window takefocus: true, tabs: tabs, tabstyle: :wordprocessor, undo: true, # enable undo capabilities wrap: :word ) end |