fantasdic r383 - in trunk: . data/fantasdic/ui lib/fantasdic/ui
- From: mblondel svn gnome org
- To: svn-commits-list gnome org
- Subject: fantasdic r383 - in trunk: . data/fantasdic/ui lib/fantasdic/ui
- Date: Wed, 7 Jan 2009 20:20:00 +0000 (UTC)
Author: mblondel
Date: Wed Jan 7 20:20:00 2009
New Revision: 383
URL: http://svn.gnome.org/viewvc/fantasdic?rev=383&view=rev
Log:
* lib/fantasdic/ui/main_app.rb:
* lib/fantasdic/ui/result_text_view.rb:
* data/fantasdic/ui/menus.xml: Added buttons to directly jump to a
definition or a database.
Modified:
trunk/ChangeLog
trunk/data/fantasdic/ui/menus.xml
trunk/lib/fantasdic/ui/main_app.rb
trunk/lib/fantasdic/ui/result_text_view.rb
Modified: trunk/data/fantasdic/ui/menus.xml
==============================================================================
--- trunk/data/fantasdic/ui/menus.xml (original)
+++ trunk/data/fantasdic/ui/menus.xml Wed Jan 7 20:20:00 2009
@@ -45,6 +45,8 @@
<menuitem action="Preferences"/>
</menu>
<menu action="ViewMenu">
+ <menuitem action="Stop"/>
+ <separator/>
<menu action="TextSizeMenu">
<menuitem action="ZoomPlus"/>
<menuitem action="ZoomMinus"/>
@@ -60,6 +62,16 @@
<menu action="GoMenu">
<menuitem action="GoBack"/>
<menuitem action="GoForward"/>
+ <separator/>
+ <menuitem action="GoPrevDefinition"/>
+ <menuitem action="GoNextDefinition"/>
+ <menuitem action="GoFirstDefinition"/>
+ <menuitem action="GoLastDefinition"/>
+ <separator/>
+ <menuitem action="GoPrevDatabase"/>
+ <menuitem action="GoNextDatabase"/>
+ <menuitem action="GoFirstDatabase"/>
+ <menuitem action="GoLastDatabase"/>
</menu>
<menu action="HelpMenu">
<menuitem action="Help"/>
Modified: trunk/lib/fantasdic/ui/main_app.rb
==============================================================================
--- trunk/lib/fantasdic/ui/main_app.rb (original)
+++ trunk/lib/fantasdic/ui/main_app.rb Wed Jan 7 20:20:00 2009
@@ -689,7 +689,13 @@
sensitize_go_buttons
end
- def sensitize_go_buttons
+ def sensitize_go_buttons
+ sensitize_go_page_buttons
+ sensitize_go_definition_buttons
+ sensitize_go_database_buttons
+ end
+
+ def sensitize_go_page_buttons
@global_actions["GoBack"].sensitive = \
(@current_page == 0) ? false : true
@global_actions["GoForward"].sensitive = \
@@ -697,6 +703,42 @@
@current_page == @pages_seen.length - 1) ? false : true
end
+ def sensitize_go_definition_buttons
+ sensitize_go_def_db_buttons(@buf.n_definitions,
+ @buf.curr_definition,
+ "Definition")
+ end
+
+ def sensitize_go_database_buttons
+ sensitize_go_def_db_buttons(@buf.n_databases,
+ @buf.curr_database,
+ "Database")
+ end
+
+ def sensitize_go_def_db_buttons(count, curr, str)
+ if count <= 1
+ sensitize = []
+ unsensitize = ["Prev", "Next", "First", "Last"]
+ else
+ if curr == 0
+ sensitize = ["Next", "Last"]
+ unsensitize = ["Prev", "First"]
+ elsif curr == count - 1
+ unsensitize = ["Next", "Last"]
+ sensitize = ["Prev", "First"]
+ else
+ sensitize = ["Prev", "Next", "First", "Last"]
+ unsensitize = []
+ end
+ end
+
+ [[sensitize, true], [unsensitize, false]].each do |arr, bool|
+ arr.each do |a|
+ @global_actions["Go#{a}#{str}"].sensitive = bool
+ end
+ end
+ end
+
# Save
def disable_save
@global_actions["Save"].sensitive = false
@@ -929,6 +971,46 @@
sensitize_go_buttons
end
+ on_go_prev_def = Proc.new do
+ @result_text_view.jump_to_prev_definition
+ sensitize_go_buttons
+ end
+
+ on_go_next_def = Proc.new do
+ @result_text_view.jump_to_next_definition
+ sensitize_go_buttons
+ end
+
+ on_go_first_def = Proc.new do
+ @result_text_view.jump_to_first_definition
+ sensitize_go_buttons
+ end
+
+ on_go_last_def = Proc.new do
+ @result_text_view.jump_to_last_definition
+ sensitize_go_buttons
+ end
+
+ on_go_prev_db = Proc.new do
+ @result_text_view.jump_to_prev_database
+ sensitize_go_buttons
+ end
+
+ on_go_next_db = Proc.new do
+ @result_text_view.jump_to_next_database
+ sensitize_go_buttons
+ end
+
+ on_go_first_db = Proc.new do
+ @result_text_view.jump_to_first_database
+ sensitize_go_buttons
+ end
+
+ on_go_last_db = Proc.new do
+ @result_text_view.jump_to_last_database
+ sensitize_go_buttons
+ end
+
# Help
on_help = Proc.new do
@@ -980,6 +1062,7 @@
on_zoom_minus],
["ZoomNormal", nil, _("Zoom normal"), "<ctrl>0", nil,
on_zoom_normal],
+ ["Stop", Gtk::Stock::STOP, nil, nil, nil, on_stop],
# Go
["GoMenu", nil, _("_Go")],
@@ -987,8 +1070,22 @@
on_go_back],
["GoForward", Gtk::Stock::GO_FORWARD, nil, "<alt>Right", nil,
on_go_forward],
-
- ["Stop", Gtk::Stock::STOP, nil, nil, nil, on_stop],
+ ["GoPrevDefinition", nil, _("_Previous Definition"),
+ "<ctrl>Page_Up", nil, on_go_prev_def],
+ ["GoNextDefinition", nil, _("_Next Definition"),
+ "<ctrl>Page_Down", nil, on_go_next_def],
+ ["GoFirstDefinition", nil, _("_First Definition"),
+ "<ctrl>Home", nil, on_go_first_def],
+ ["GoLastDefinition", nil, _("_Last Definition"),
+ "<ctrl>End", nil, on_go_last_def],
+ ["GoPrevDatabase", nil, _("Previous Database"),
+ "<ctrl><shift>Page_Up", nil, on_go_prev_db],
+ ["GoNextDatabase", nil, _("Next Database"),
+ "<ctrl><shift>Page_Down", nil, on_go_next_db],
+ ["GoFirstDatabase", nil, _("First Database"),
+ "<ctrl><shift>Home", nil, on_go_first_db],
+ ["GoLastDatabase", nil, _("Last Database"),
+ "<ctrl><shift>End", nil, on_go_last_db],
# Help
["HelpMenu", nil, _("_Help")],
@@ -1215,6 +1312,20 @@
end
end
+
+ @result_sw.vadjustment.signal_connect("value-changed") do
+ # Sensitize Go buttons according to
+ # the vertical scroll position
+ adj = @result_sw.vadjustment
+ height = (adj.upper - adj.lower - adj.page_size)
+ percent = height == 0 ? 0.0 : adj.value / height
+ length = @buf.end_iter.offset - @buf.start_iter.offset
+ curr_offset = (percent * length).to_i + @buf.start_iter.offset
+ i = @buf.get_definition_at_offset(curr_offset)
+ @buf.curr_definition = i
+ sensitize_go_buttons
+ end
+
end
end # class MainApp
Modified: trunk/lib/fantasdic/ui/result_text_view.rb
==============================================================================
--- trunk/lib/fantasdic/ui/result_text_view.rb (original)
+++ trunk/lib/fantasdic/ui/result_text_view.rb Wed Jan 7 20:20:00 2009
@@ -70,10 +70,6 @@
class LinkBuffer < Gtk::TextBuffer
- HEADER = 0
- TEXT = 1
- LINK = 2
-
MAX_FONT_SIZE = 24
MIN_FONT_SIZE = 8
@@ -86,7 +82,7 @@
DEFAULT_HEADER_FONT = DEFAULT_FONT.dup
DEFAULT_HEADER_FONT.size_points = DEFAULT_HEADER_FONT_SIZE
- attr_accessor :scrolled_window, :definitions
+ attr_accessor :scrolled_window, :definitions, :curr_definition
def initialize
super
@@ -112,28 +108,74 @@
["last-search-prev", "last-search-next"].each do |mark|
delete_mark(mark) unless get_mark(mark).nil?
end
- @entries = []
- @iter = get_iter_at_offset(0)
+ tag_table.each { |t| tag_table.remove(t) unless t.name }
+ @iter = get_iter_at_offset(0)
+
+
+ @definitions = []
+ @def_offsets = [] # iter offsets
+ @db_offsets = [] # definition offsets (position in @def_offsets)
+ @curr_definition = 0
+
# Make the scroll go up
# scrolled_window vadjustment value = \
- # @scrolled_window.vadjustment.lower
+ # @scrolled_window.vadjustment.lower
+ end
+
+ def n_definitions
+ @def_offsets.length
+ end
+
+ def get_iter_for_definition(i)
+ if i < n_definitions
+ self.get_iter_at_offset(@def_offsets[i])
+ else
+ nil
+ end
+ end
+
+ def get_definition_for_iter(iter)
+ get_definition_at_offset(iter.offset)
+ end
+
+ def get_definition_at_offset(offset)
+ value = @def_offsets.find_all { |v| offset >= v }.last
+ @def_offsets.index(value)
+ end
+
+ def n_databases
+ @db_offsets.length
+ end
+
+ def get_iter_for_database(i)
+ if i < n_databases
+ self.get_iter_at_offset(@def_offsets[ db_offsets[i]])
+ else
+ nil
+ end
+ end
+
+ def curr_database
+ value = @db_offsets.find_all { |v| @curr_definition >= v }.last
+ @db_offsets.index(value)
+ end
+
+ def curr_database=(i)
+ @curr_definition = @db_offsets[i]
end
# Display methods
def insert_header(txt)
- @entries << [HEADER, txt]
insert(@iter, txt, "header")
end
def insert_text(txt)
- @entries << [TEXT, txt]
insert_pango_markup(@iter, txt, "text")
end
def insert_link(word)
# Removes bad chars that may appear in links
word = word.gsub(/(\n|\r)/, "").gsub(/(\s)+/, " ")
- @entries << [LINK, word]
insert(@iter, word, "link")
end
@@ -141,7 +183,9 @@
@definitions = definitions
last_db = ""
definitions.each_with_index do |d, i|
+ @def_offsets << @iter.offset
if last_db != d.database
+ @db_offsets << @def_offsets.length - 1
t_format = i == 0 ? "%s [%s]\n" : "\n%s [%s]\n"
insert_header(t_format %
[d.description, d.database])
@@ -170,10 +214,11 @@
text_size = text_tag.size_points
unless text_size >= MAX_FONT_SIZE
self.tag_table.each do |tag|
- if tag.name == "header"
- tag.size_points = header_font_size(text_size + 2)
- else
- tag.size_points += 2
+ case tag.name
+ when "header"
+ tag.size_points = header_font_size(text_size + 2)
+ when "text", "link"
+ tag.size_points += 2
end
end
redisplay
@@ -185,10 +230,11 @@
text_size = text_tag.size_points
unless text_size <= MIN_FONT_SIZE
self.tag_table.each do |tag|
- if tag.name == "header"
- tag.size_points = header_font_size(text_size - 2)
- else
- tag.size_points -= 2
+ case tag.name
+ when "header"
+ tag.size_points = header_font_size(text_size - 2)
+ when "text", "link"
+ tag.size_points -= 2
end
end
redisplay
@@ -243,26 +289,18 @@
:font_desc => DEFAULT_FONT)
create_tag("link", :foreground => 'blue',
- :underline => Pango::AttrUnderline::SINGLE)
+ :underline => Pango::AttrUnderline::SINGLE,
+ :font_desc => DEFAULT_FONT)
end
def header_font_size(font_size)
- (font_size * RATIO).round
+ (font_size * RATIO).round.to_i
end
def redisplay
- entries = @entries.dup
+ definitions = @definitions.dup
self.clear
- entries.each do |type, txt|
- case type
- when HEADER
- insert_header(txt)
- when TEXT
- insert_text(txt)
- when LINK
- insert_link(txt)
- end
- end
+ insert_definitions(definitions)
end
end
@@ -298,6 +336,62 @@
show_all
end
+ # Jump to definition
+
+ def jump_to_definition(i)
+ unless i < 0 or i >= self.buffer.n_definitions
+ iter = self.buffer.get_iter_for_definition(i)
+ if iter
+ scroll_to_iter(iter, 0.0, true, 0.0, 0.0)
+ self.buffer.curr_definition = i
+ end
+ end
+ end
+
+ def jump_to_first_definition
+ jump_to_definition(0)
+ end
+
+ def jump_to_last_definition
+ jump_to_definition(self.buffer.n_definitions - 1)
+ end
+
+ def jump_to_prev_definition
+ jump_to_definition(self.buffer.curr_definition - 1)
+ end
+
+ def jump_to_next_definition
+ jump_to_definition(self.buffer.curr_definition + 1)
+ end
+
+ # Jump to database
+
+ def jump_to_database(i)
+ unless i < 0 or i >= self.buffer.n_databases
+ iter = self.buffer.get_iter_for_database(i)
+ if iter
+ scroll_to_iter(iter, 0.0, true, 0.0, 0.0)
+ self.buffer.curr_database = i
+ end
+ end
+ end
+
+ def jump_to_first_database
+ jump_to_database(0)
+ end
+
+ def jump_to_last_database
+ jump_to_database(self.buffer.n_databases - 1)
+ end
+
+ def jump_to_prev_database
+ jump_to_database(self.buffer.curr_database - 1)
+ end
+
+ def jump_to_next_database
+ jump_to_database(self.buffer.curr_database + 1)
+ end
+
private
def initialize_signals
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]