Class: GerminalNotebook

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

Overview

Copyright 2015-2016 Cédric LE MOIGNE, [email protected] This file is part of Germinal.

Germinal 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.

Germinal 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 Germinal. If not, see <www.gnu.org/licenses/>.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeGerminalNotebook

Returns a new instance of GerminalNotebook.



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
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/notebook.rb', line 19

def initialize
  super()
  @gen_preview = true
  signal_connect "hide" do |widget|
    @visible = false
  end
  signal_connect "show" do |widget|
    @visible = true
  end

  signal_connect "switch-page" do |widget, next_page, next_page_num|
    if next_page.tab_label
      toplevel.current_label.text = next_page.tab_label
    else
      next_label = get_tab_label(next_page)
      toplevel.current_label.text = next_label.text 
    end
    toplevel.current_tab.text = "#{next_page_num + 1}/#{n_pages}"
    
    if page >= 0 && @gen_preview 
      current.queue_draw
      _x,_y,w,h = current.allocation.to_a
      pix = current.window.to_pixbuf(0, 0, w, h)
      current.preview = pix if pix
    elsif !@gen_preview
      @gen_preview = true
    end    
  end
  
  signal_connect "page-reordered" do |widget, child, new_page_num|
    toplevel.current_tab.text = "#{page + 1}/#{n_pages}"
  end
  
  signal_connect "page-removed" do 
    toplevel.current_tab.text = "#{page + 1}/#{n_pages}" if toplevel.class == GerminalWindow
  end
  
  set_show_tabs(false)
end

Instance Attribute Details

#gen_previewObject

Returns the value of attribute gen_preview.



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

def gen_preview
  @gen_preview
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



74
75
76
# File 'lib/notebook.rb', line 74

def current
  get_nth_page(page)
end

#cycle_next_pageObject



66
67
68
# File 'lib/notebook.rb', line 66

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

#cycle_prev_pageObject



70
71
72
# File 'lib/notebook.rb', line 70

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

#remove_all_pagesObject



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

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

#remove_current_pageObject



78
79
80
81
82
83
84
85
# File 'lib/notebook.rb', line 78

def remove_current_page
  if n_pages == 1
    toplevel.quit_gracefully
  else
    remove(current)
    current.grab_focus
  end
end

#toggle_visibilityObject



87
88
89
# File 'lib/notebook.rb', line 87

def toggle_visibility
  @visible ? hide : show
end