Class: TopinambourNotebook

Inherits:
Gtk::Notebook
  • Object
show all
Defined in:
lib/notebook.rb

Overview

Copyright 2015-2017 Cedric LE MOIGNE, [email protected] This file is part of Topinambour.

Topinambour is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or any later version.

Topinambour is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with Topinambour. If not, see <www.gnu.org/licenses/>.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeTopinambourNotebook

Returns a new instance of TopinambourNotebook.



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/notebook.rb', line 19

def initialize
  super()
  @hidden = []
  signal_connect("hide") { @visible = false }

  signal_connect("show") { @visible = true }

  signal_connect "switch-page" do |_widget, next_page, next_page_num|
    toplevel.current_label.text = next_page.term.terminal_title
    toplevel.current_tab.text = "#{next_page_num + 1}/#{n_pages}"
    generate_tab_preview if page >= 0
  end

  signal_connect "page-reordered" do
    toplevel.current_tab.text = "#{page + 1}/#{n_pages}"
  end

  signal_connect "page-removed" do |_widget, _child, page_num|
    if toplevel.class == TopinambourWindow
      toplevel.current_tab.text = "#{page + 1}/#{n_pages}"
    end
  end
  set_name("topinambour-notebook")
  set_show_tabs(false)
  set_show_border(false)
end

Instance Attribute Details

#hiddenObject (readonly)

Returns the value of attribute hidden.



17
18
19
# File 'lib/notebook.rb', line 17

def hidden
  @hidden
end

#visibleObject (readonly)

Returns the value of attribute visible.



17
18
19
# File 'lib/notebook.rb', line 17

def visible
  @visible
end

Instance Method Details

#currentObject



61
62
63
# File 'lib/notebook.rb', line 61

def current
  get_nth_page(page)
end

#cycle_next_pageObject



53
54
55
# File 'lib/notebook.rb', line 53

def cycle_next_page
  page < (n_pages - 1) ? next_page : set_page(0)
end

#cycle_prev_pageObject



57
58
59
# File 'lib/notebook.rb', line 57

def cycle_prev_page
  page > 0 ? prev_page : set_page(n_pages - 1)
end

#generate_tab_previewObject



83
84
85
86
87
88
89
90
91
# File 'lib/notebook.rb', line 83

def generate_tab_preview
  _x, _y, w, h = current.term.allocation.to_a
  surface = Cairo::ImageSurface.new(Cairo::FORMAT_ARGB32,
                                    w, h)
  cr = Cairo::Context.new(surface)
  current.term.draw(cr)
  pix = surface.to_pixbuf(:src_x => 0, :src_y => 0, :width => w, :height => h)
  current.term.preview = pix if pix
end

#hide(index) ⇒ Object



99
100
101
102
103
# File 'lib/notebook.rb', line 99

def hide(index)
  child = get_nth_page(index)
  @hidden << child
  remove_page(index)
end

#remove_all_pagesObject



46
47
48
49
50
51
# File 'lib/notebook.rb', line 46

def remove_all_pages
  each do |widget|
    index = page_num(widget)
    remove_page(index)
  end
end

#remove_current_pageObject



65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/notebook.rb', line 65

def remove_current_page
  if n_pages == 1
    if @hidden.empty?
      toplevel.quit_gracefully
    else
      append_page(@hidden.pop)
      remove_current_page
    end
  else
    remove(current)
    current.term.grab_focus
  end
end

#send_to_all_terminals(method_name, values) ⇒ Object



93
94
95
96
97
# File 'lib/notebook.rb', line 93

def send_to_all_terminals(method_name, values)
  each do |tab|
    tab.term.send(method_name, *values)
  end
end

#toggle_visibilityObject



79
80
81
# File 'lib/notebook.rb', line 79

def toggle_visibility
  @visible ? hide : show
end

#unhide(index) ⇒ Object



105
106
107
108
# File 'lib/notebook.rb', line 105

def unhide(index)
  append_page(@hidden.delete_at(index))
  toplevel.current_tab.text = "#{current_page + 1}/#{n_pages}"
end