Class: VER::View

Inherits:
Tk::Frame
  • Object
show all
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

Instance Method Summary collapse

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, options = {})
  super
  @layout = layout
  @text = @status = @ybar = @xbar = nil
  configure takefocus: false
  setup
end

Instance Attribute Details

#layoutObject (readonly)

Returns the value of attribute layout.



7
8
9
# File 'lib/ver/view.rb', line 7

def layout
  @layout
end

#statusObject (readonly)

Returns the value of attribute status.



7
8
9
# File 'lib/ver/view.rb', line 7

def status
  @status
end

#textObject (readonly)

Returns the value of attribute text.



7
8
9
# File 'lib/ver/view.rb', line 7

def text
  @text
end

Instance Method Details

#closeObject



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

#destroyObject



177
178
179
180
181
# File 'lib/ver/view.rb', line 177

def destroy
  [@text, @ybar, @xbar, @status].compact.each(&:destroy)

  super
end

#filenameObject



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).expand_path

  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

#focusObject



123
124
125
# File 'lib/ver/view.rb', line 123

def focus
  text.focus
end

#focus_nextObject



153
154
155
# File 'lib/ver/view.rb', line 153

def focus_next
  layout.focus_next(self)
end

#focus_prevObject



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_emptyObject



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_bottomObject



173
174
175
# File 'lib/ver/view.rb', line 173

def push_bottom
  layout.push_bottom(self)
end

#push_downObject



165
166
167
# File 'lib/ver/view.rb', line 165

def push_down
  layout.push_down(self)
end

#push_topObject



169
170
171
# File 'lib/ver/view.rb', line 169

def push_top
  layout.push_top(self)
end

#push_upObject



161
162
163
# File 'lib/ver/view.rb', line 161

def push_up
  layout.push_up(self)
end

#setupObject

-------—+ | | @ | | | 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_eventsObject



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_gridObject



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_miscObject



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_scrollbarsObject



58
59
60
61
62
63
64
65
66
# File 'lib/ver/view.rb', line 58

def setup_scrollbars
  # vertical scrollbar
  @ybar = Tk::Tile::YScrollbar.new(self)
  @text.yscrollbar(@ybar)

  # horizontal scrollbar
  @xbar = Tk::Tile::XScrollbar.new(self)
  @text.xscrollbar(@xbar)
end

#setup_statusObject



68
69
70
# File 'lib/ver/view.rb', line 68

def setup_status
  @status = Status.new(self, font: VER.options[:font], takefocus: false)
end

#setup_textObject



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.options.font, VER.options.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.options.insertofftime,
    insertontime:     VER.options.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