Class: SearchWindow

Inherits:
Gtk::Window
  • Object
show all
Defined in:
lib/RelationBuilder/SearchWindow.rb

Overview

this file is part of manqod manqod is distributed under the CDDL licence the author of manqod is Dobai-Pataky Balint([email protected])

Instance Method Summary collapse

Constructor Details

#initialize(rb) ⇒ SearchWindow

Returns a new instance of SearchWindow.



6
7
8
9
10
11
12
13
14
15
16
17
18
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
# File 'lib/RelationBuilder/SearchWindow.rb', line 6

def initialize(rb)
	@rb=rb
	super(Gtk::Window::POPUP)
	add(
		Gtk::Table.new(3,2).
			attach(@search_entry=Gtk::Entry.new.set_can_default(true),0,3,0,1).
			attach(@left_arrow=Gtk::Button.new.set_image(Gtk::Image.new(Gtk::Stock::GO_BACK,Gtk::IconSize::SMALL_TOOLBAR)).set_can_focus(false).set_can_default(false),0,1,1,2,Gtk::EXPAND,Gtk::EXPAND).
			attach(@combo=Gtk::ComboBox.new(Gtk::TreeModelFilter.new(Gtk::ListStore.new(String,TrueClass))).set_width_request(300).set_can_focus(false).set_can_default(false),1,2,1,2).
			attach(@right_arrow=Gtk::Button.new.set_image(Gtk::Image.new(Gtk::Stock::GO_FORWARD,Gtk::IconSize::SMALL_TOOLBAR)).set_can_focus(false).set_can_default(false),2,3,1,2)
	)
	set_destroy_with_parent(true)
	set_modal(true)
	set_window_position(Gtk::Window::POS_CENTER_ON_PARENT)
	set_decorated(false)
	@combo.pack_start(renderer=Gtk::CellRendererText.new,true).add_attribute(renderer,:text,0)
	@combo.model.set_visible_column(1)
	@combo.signal_connect("changed"){
		if @combo.active_iter and @rb.tables.has_key?(@combo.active_iter[0])
			@rb.tables[@combo.active_iter[0]].center_on_me
			@rb.set_focused_item(@rb.tables[@combo.active_iter[0]])
		end
	}
	#hide on escape
	@search_entry.signal_connect("key-release-event"){|me,ev| hide if ev.keyval == Gdk::Keyval::GDK_KEY_Escape}
	@combo.signal_connect("key-release-event"){|me,ev| hide if ev.keyval == Gdk::Keyval::GDK_KEY_Escape}
	#step left
	@left_arrow.signal_connect("pressed"){|me| 
		unless i=@combo.active_iter then i=@combo.model.iter_first end
		ii=@combo.model.iter_first
		iip=ii.clone
		until ii == i do iip=ii.clone;ii.next!;end
		@combo.set_active_iter(iip)
	}
	#step right
	@right_arrow.signal_connect("pressed"){|me| 
		if i=@combo.active_iter then i.next! else i=@combo.model.iter_first end
		@combo.set_active_iter(i)
	}
	@search_entry.signal_connect("key-release-event"){|me,ev|
		@combo.model.child_model.each{|model,path,iter|
			iter[1]=!iter[0].upcase.index(me.text.upcase).nil?
		}
	}

	@ag=Gtk::AccelGroup.new
	@ag.connect(Gdk::Keyval::GDK_KEY_f, Gdk::Window::CONTROL_MASK, Gtk::ACCEL_VISIBLE){
		show_all
	}
end

Instance Method Details

#hideObject



56
57
58
59
# File 'lib/RelationBuilder/SearchWindow.rb', line 56

def hide
	super
	@rb.set_focused_item(nil)
end

#update(win) ⇒ Object



61
62
63
64
65
66
67
68
69
70
# File 'lib/RelationBuilder/SearchWindow.rb', line 61

def update(win)
	win.add_accel_group(@ag)
	set_transient_for(win)
	@combo.model.child_model.clear
	@rb.tables.each_key{|tname|
		iter=@combo.model.child_model.append()# if tname.upcase.index(me.text.upcase)
		iter[0]=tname
	}
	
end