Class: TopinambourSearchBar

Inherits:
Gtk::SearchBar
  • Object
show all
Defined in:
lib/searchbar.rb

Overview

Copyright 2016 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 Method Summary collapse

Constructor Details

#initialize(window) ⇒ TopinambourSearchBar

Returns a new instance of TopinambourSearchBar.



18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/searchbar.rb', line 18

def initialize(window)
  super()

  generate_search_entry(window)
  set_halign(:center)
  set_valign(:start)
  set_hexpand(false)
  set_vexpand(true)
  connect_entry(@entry)
  set_show_close_button = true
  add(@entry)
end

Instance Method Details

#generate_search_entry(window) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/searchbar.rb', line 31

def generate_search_entry(window)
  @entry = Gtk::SearchEntry.new
  term = window.notebook.current.term
  @entry.signal_connect "next-match" do |entry|
    term.search_find_next if @regex
  end

  @entry.signal_connect("previous-match") do |entry|
    term.search_find_previous if @regex
  end

  @entry.signal_connect "search-changed" do |entry|
    pattern = entry.buffer.text
    if pattern != ""
      @regex = GLib::Regex.new(pattern)
      term.search_set_gregex(@regex, @regex.match_flags)
      term.search_find_next
    end
  end
end