Class: Yatte::TabManager
- Inherits:
-
Object
- Object
- Yatte::TabManager
- Defined in:
- lib/yatte/tab_manager.rb
Defined Under Namespace
Classes: Tab
Instance Attribute Summary collapse
-
#active_index ⇒ Object
readonly
Returns the value of attribute active_index.
-
#tabs ⇒ Object
readonly
Returns the value of attribute tabs.
Instance Method Summary collapse
- #activate(index) ⇒ Object
- #active ⇒ Object
- #close(index) ⇒ Object
- #count ⇒ Object
-
#initialize ⇒ TabManager
constructor
A new instance of TabManager.
- #next_tab ⇒ Object
- #open(filename) ⇒ Object
- #open_empty ⇒ Object
- #prev_tab ⇒ Object
Constructor Details
#initialize ⇒ TabManager
Returns a new instance of TabManager.
10 11 12 13 |
# File 'lib/yatte/tab_manager.rb', line 10 def initialize @tabs = [] @active_index = 0 end |
Instance Attribute Details
#active_index ⇒ Object (readonly)
Returns the value of attribute active_index.
8 9 10 |
# File 'lib/yatte/tab_manager.rb', line 8 def active_index @active_index end |
#tabs ⇒ Object (readonly)
Returns the value of attribute tabs.
8 9 10 |
# File 'lib/yatte/tab_manager.rb', line 8 def tabs @tabs end |
Instance Method Details
#activate(index) ⇒ Object
55 56 57 58 59 |
# File 'lib/yatte/tab_manager.rb', line 55 def activate(index) return if @tabs.empty? @active_index = index.clamp(0, @tabs.length - 1) active end |
#active ⇒ Object
71 72 73 |
# File 'lib/yatte/tab_manager.rb', line 71 def active @tabs[@active_index] end |
#close(index) ⇒ Object
47 48 49 50 51 52 53 |
# File 'lib/yatte/tab_manager.rb', line 47 def close(index) @tabs.delete_at(index) return nil if @tabs.empty? @active_index = [index, @tabs.length - 1].min active end |
#count ⇒ Object
75 76 77 |
# File 'lib/yatte/tab_manager.rb', line 75 def count @tabs.length end |
#next_tab ⇒ Object
61 62 63 64 |
# File 'lib/yatte/tab_manager.rb', line 61 def next_tab return if @tabs.length <= 1 @active_index = (@active_index + 1) % @tabs.length end |
#open(filename) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/yatte/tab_manager.rb', line 15 def open(filename) existing = @tabs.index { |t| t.filename == filename } if existing @active_index = existing return active end tab = create_tab(filename) if filename && File.exist?(filename) lines, error = FileIO.read(filename) if lines tab.buffer = Buffer.new(lines) tab.buffer.undo_stack = tab.undo_stack tab.cursor = Cursor.new(tab.buffer) tab.buffer.mark_clean else return error end end @tabs << tab @active_index = @tabs.length - 1 active end |
#open_empty ⇒ Object
40 41 42 43 44 45 |
# File 'lib/yatte/tab_manager.rb', line 40 def open_empty tab = create_tab(nil) @tabs << tab @active_index = @tabs.length - 1 active end |
#prev_tab ⇒ Object
66 67 68 69 |
# File 'lib/yatte/tab_manager.rb', line 66 def prev_tab return if @tabs.length <= 1 @active_index = (@active_index - 1) % @tabs.length end |