Module: Gui

Defined in:
lib/vimamsa/gui_text.rb,
lib/vimamsa/gui_dialog.rb

Class Method Summary collapse

Class Method Details

.confirm(title, callback, param: nil) ⇒ Object



2
3
4
5
6
7
8
9
# File 'lib/vimamsa/gui_dialog.rb', line 2

def self.confirm(title, callback, param: nil)
  params = {}
  params["title"] = title
  params["inputs"] = {}
  params["inputs"]["yes_btn"] = { :label => "Yes", :type => :button, :default_focus => true }
  params[:callback] = callback
  PopupFormGenerator.new(params).run
end

.highlight_match(bf, str, color: "#aa0000ff", weight: 650) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
# File 'lib/vimamsa/gui_text.rb', line 16

def self.highlight_match(bf, str, color: "#aa0000ff", weight: 650)
  r = Regexp.new(Regexp.escape(str), Regexp::IGNORECASE)
  tag = vma.gui.view.buffer.create_tag
  tag.weight = weight
  tag.foreground = color
  ind = scan_indexes(bf, r)
  ind.each { |x|
    r = x..(x + str.size)
    self.hilight_range(bf, r, tag: tag)
  }
end

.highlight_match_old(bf, str, color: "#aa0000ff") ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/vimamsa/gui_text.rb', line 28

def self.highlight_match_old(bf, str, color: "#aa0000ff")
  vbuf = bf.view.buffer
  r = Regexp.new(Regexp.escape(str), Regexp::IGNORECASE)

  hlparts = []

  tt = vma.gui.view.buffer.tag_table.lookup("highlight_match_tag")
  if tt.nil?
    tt = vma.gui.view.buffer.create_tag("highlight_match_tag")
  end

  tt.weight = 650
  tt.foreground = color

  ind = scan_indexes(bf, r)
  ind.each { |x|
    itr = vbuf.get_iter_at(:offset => x)
    itr2 = vbuf.get_iter_at(:offset => x + str.size)
    vbuf.apply_tag(tt, itr, itr2)
  }
end

.hilight_range(bf, r, color: "#aa0000ff", weight: nil, tag: nil) ⇒ Object



2
3
4
5
6
7
8
9
10
11
12
13
14
# File 'lib/vimamsa/gui_text.rb', line 2

def self.hilight_range(bf, r, color: "#aa0000ff", weight: nil, tag: nil)
  vbuf = bf.view.buffer

  if tag.nil?
    tag = vma.gui.view.buffer.create_tag
    tag.weight = weight if !weight.nil?
    tag.foreground = color
  end

  itr = vbuf.get_iter_at(:offset => r.begin)
  itr2 = vbuf.get_iter_at(:offset => r.last)
  vbuf.apply_tag(tag, itr, itr2)
end