Class: Tkri::Tabs

Inherits:
TkFrame
  • Object
show all
Includes:
Enumerable
Defined in:
lib/tkri.rb

Overview

A ‘Tabs’ object holds several child objects of class ‘Tab’ and switches their visibility so that only one is visible at one time.

Instance Method Summary collapse

Constructor Details

#initialize(tk_parent, app, configuration = {}) ⇒ Tabs

Returns a new instance of Tabs.



709
710
711
712
713
714
# File 'lib/tkri.rb', line 709

def initialize(tk_parent, app, configuration = {})
  @app = app
  super(tk_parent, configuration)
  @tabs = []
  new_tab
end

Instance Method Details

#close(tab) ⇒ Object



731
732
733
734
735
736
737
738
# File 'lib/tkri.rb', line 731

def close(tab)
  if (@tabs.size > 1 and i = @tabs.index(tab))
    @tabs.delete_at i
    tab.destroy
    set_current_tab_by_index(@current - 1) if @current >= i and @current > 0
    @app.refresh_tabsbar
  end
end

#current_tabObject



787
788
789
# File 'lib/tkri.rb', line 787

def current_tab
  @tabs[current_tab_as_index]
end

#current_tab_as_indexObject



783
784
785
# File 'lib/tkri.rb', line 783

def current_tab_as_index
  return @current
end

#eachObject



795
796
797
798
799
# File 'lib/tkri.rb', line 795

def each
  @tabs.each do |tab|
    yield tab
  end
end

#get(i) ⇒ Object



727
728
729
# File 'lib/tkri.rb', line 727

def get(i)
  @tabs[i]
end

#interactive_close_tab(e) ⇒ Object



791
792
793
# File 'lib/tkri.rb', line 791

def interactive_close_tab e
  close current_tab
end

#interactive_new_tab(e) ⇒ Object



723
724
725
# File 'lib/tkri.rb', line 723

def interactive_new_tab e
  new_tab
end

#interactive_switch_to_next_tab(e) ⇒ Object



777
778
779
780
781
# File 'lib/tkri.rb', line 777

def interactive_switch_to_next_tab e
  new = current_tab_as_index + 1
  new = 0 if new >= @tabs.size
  set_current_tab_by_index(new, true)
end

#interactive_switch_to_prev_tab(e) ⇒ Object



771
772
773
774
775
# File 'lib/tkri.rb', line 771

def interactive_switch_to_prev_tab e
  new = current_tab_as_index - 1
  new = @tabs.size - 1 if new < 0
  set_current_tab_by_index(new, true)
end

#interactive_switch_to_tab_0(e) ⇒ Object



760
# File 'lib/tkri.rb', line 760

def interactive_switch_to_tab_0 e; switch_to 0; end

#interactive_switch_to_tab_1(e) ⇒ Object



761
# File 'lib/tkri.rb', line 761

def interactive_switch_to_tab_1 e; switch_to 1; end

#interactive_switch_to_tab_2(e) ⇒ Object



762
# File 'lib/tkri.rb', line 762

def interactive_switch_to_tab_2 e; switch_to 2; end

#interactive_switch_to_tab_3(e) ⇒ Object



763
# File 'lib/tkri.rb', line 763

def interactive_switch_to_tab_3 e; switch_to 3; end

#interactive_switch_to_tab_4(e) ⇒ Object



764
# File 'lib/tkri.rb', line 764

def interactive_switch_to_tab_4 e; switch_to 4; end

#interactive_switch_to_tab_5(e) ⇒ Object



765
# File 'lib/tkri.rb', line 765

def interactive_switch_to_tab_5 e; switch_to 5; end

#interactive_switch_to_tab_6(e) ⇒ Object



766
# File 'lib/tkri.rb', line 766

def interactive_switch_to_tab_6 e; switch_to 6; end

#interactive_switch_to_tab_7(e) ⇒ Object



767
# File 'lib/tkri.rb', line 767

def interactive_switch_to_tab_7 e; switch_to 7; end

#interactive_switch_to_tab_8(e) ⇒ Object



768
# File 'lib/tkri.rb', line 768

def interactive_switch_to_tab_8 e; switch_to 8; end

#interactive_switch_to_tab_9(e) ⇒ Object



769
# File 'lib/tkri.rb', line 769

def interactive_switch_to_tab_9 e; switch_to 9; end

#new_tabObject



716
717
718
719
720
721
# File 'lib/tkri.rb', line 716

def new_tab
  tab = Tab.new(self, @app)
  tab.focus_address
  @tabs << tab
  set_current_tab_by_index(@tabs.size - 1, true)
end

#set_current_tab_by_index(tab_index, refresh = false) ⇒ Object



740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
# File 'lib/tkri.rb', line 740

def set_current_tab_by_index(tab_index, refresh=false)
  if tab_index < @tabs.size
    self.each_with_index do |tab, i|
      if i == tab_index;
        tab.show
        # Unless we focus on the new tab, the focus may stay at the old tab's address box.
        tab.focus
      else
        tab.hide
      end
    end
    @current = tab_index
  end
  @app.refresh_tabsbar if refresh
end

#switch_to(tab_index) ⇒ Object



756
757
758
# File 'lib/tkri.rb', line 756

def switch_to(tab_index)
  set_current_tab_by_index(tab_index, true)
end