Class: VimMate::TerminalsWindow

Inherits:
Object
  • Object
show all
Defined in:
lib/vim_mate/terminals_window.rb

Overview

The window that contains the terminals

Instance Method Summary collapse

Constructor Details

#initializeTerminalsWindow

Create a TerminalsWindow



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/vim_mate/terminals_window.rb', line 42

def initialize
  @expander_signal = Set.new
  
  # Create the tabbed page
  @gtk_notebook = Gtk::Notebook.new
  @gtk_notebook.scrollable = true
  # Add a terminal at startup
  @gtk_notebook.append_page(new_terminal)
  # The last page is just an icon to create new tabs
  @gtk_notebook.append_page(Gtk::EventBox.new,
                            Gtk::Image.new(Gtk::Stock::NEW, Gtk::IconSize::MENU))
  # When we try to go to the last page, we create a new terminal instead
  @gtk_notebook.signal_connect_after("switch-page") do |notebook, page, page_num|
    add_new_terminal if page_num == (@gtk_notebook.n_pages - 1)
  end
  @gtk_notebook.set_size_request(0, Config[:terminals_height])
end

Instance Method Details

#add_expander_signal(&block) ⇒ Object

Add a block that will be called when the user choose to expand or close the expander. The block takes one argument: if the expander is opened or closed



68
69
70
# File 'lib/vim_mate/terminals_window.rb', line 68

def add_expander_signal(&block)
  @expander_signal << block
end

#add_new_terminalObject

Add a new terminal at the left of the tab bar.



79
80
81
82
83
# File 'lib/vim_mate/terminals_window.rb', line 79

def add_new_terminal
  page_num = @gtk_notebook.n_pages - 1
  @gtk_notebook.insert_page(page_num, new_terminal)
  @gtk_notebook.page = page_num
end

#delete_current_terminalObject

Deletes terminal with number page_num, defaults to current page number.



86
87
88
89
90
# File 'lib/vim_mate/terminals_window.rb', line 86

def delete_current_terminal
  page = @gtk_notebook.get_nth_page(@gtk_notebook.page)
  prev_terminal
  Process.kill 'HUP', page.pid
end

#focus_terminalObject

Set the focus to the current terminal



73
74
75
76
# File 'lib/vim_mate/terminals_window.rb', line 73

def focus_terminal
  page = @gtk_notebook.get_nth_page(@gtk_notebook.page)
  page.has_focus = true if page
end

#gtk_windowObject

The “window” for this object



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

def gtk_window
  @gtk_notebook
end

#next_terminalObject

Switch the next (right) terminal, if there exists one. Otherwise start again with the first terminal on the left.



94
95
96
97
98
99
100
# File 'lib/vim_mate/terminals_window.rb', line 94

def next_terminal
  if @gtk_notebook.page < @gtk_notebook.n_pages - 2
    @gtk_notebook.next_page
  else
    @gtk_notebook.page = 0
  end
end

#prev_terminalObject

Switch the previous (left) terminal, if there exists one. Otherwise start with again with the last terminal on the right.



104
105
106
107
108
109
110
# File 'lib/vim_mate/terminals_window.rb', line 104

def prev_terminal
  if @gtk_notebook.page > 0
    @gtk_notebook.prev_page
  else
    @gtk_notebook.page = @gtk_notebook.n_pages - 2
  end
end