class Groonga::DatabaseViewerGtk::Window

Constants

RAW_QUERY_MODE

Public Class Methods

new(db_path, options={}) click to toggle source
Calls superclass method
# File lib/groonga/database-viewer-gtk/window.rb, line 28
def initialize(db_path, options={})
  super()
  self.title = db_path
  set_default_size(640, 480)
  @grn_database = Database.open(db_path)
  signal_connect("destroy") do
    @grn_database.close unless @grn_database.closed?
    Gtk.main_quit
  end

  vbox = Gtk::VBox.new
  add(vbox)

  search_hbox = create_search_hbox
  vbox.pack_start(search_hbox, false, false, 4)

  @notebook = create_notebook(options)
  vbox.pack_start(@notebook, true, true, 0)

  label = Gtk::Label.new
  label.text = "Double Click or Press Return: Copy to Clipboard"
  vbox.pack_end(label, false, false, 0)
end

Public Instance Methods

run() click to toggle source
# File lib/groonga/database-viewer-gtk/window.rb, line 52
def run
  show_all
  Gtk.main
end

Private Instance Methods

create_notebook(options) click to toggle source
# File lib/groonga/database-viewer-gtk/window.rb, line 144
def create_notebook(options)
  notebook = Gtk::Notebook.new

  #label = Gtk::Label.new("Groonga")
  #notebook.append_page(Gtk::Label.new, label)

  @grn_database.tables.each do |grn_table|
    scrolled_window = Gtk::ScrolledWindow.new
    scrolled_window.set_policy(:automatic, :automatic)

    table = Table.new(grn_table, @grn_database.path, options)
    scrolled_window.add(table)

    table.signal_connect("row-activated") do |tree_view, path, column|
      Clipboard.copy_to_clipboard(table.selected_text)
    end


    label = Gtk::Label.new(grn_table.name)
    notebook.append_page(scrolled_window, label)
  end

  notebook.signal_connect("switch-page") do |_notebook, page, page_num|
    init_view(page_num)
    update_combo_box(page_num)
  end

  notebook
end
create_search_hbox() click to toggle source
# File lib/groonga/database-viewer-gtk/window.rb, line 94
def create_search_hbox
  hbox = Gtk::HBox.new

  @combo_box = Gtk::ComboBox.new
  hbox.pack_start(@combo_box, false, false, 4)

  @entry = Gtk::Entry.new
  @entry.signal_connect("activate") do |_entry|
    select(@combo_box.active_text, _entry.text)
  end
  hbox.pack_start(@entry, false, false, 0)

  @search_button = Gtk::Button.new("Search")
  @search_button.signal_connect("clicked") do
    select(@combo_box.active_text, @entry.text)
  end
  hbox.pack_start(@search_button, false, false, 0)

  @limit_combo = Gtk::ComboBox.new
  9.times do |i|
    text = (10 ** i).to_s.reverse.gsub(/(\d{3})(?=\d)/, '\1,').reverse
    @limit_combo.append_text(text)
  end
  @limit_combo.append_text("268,435,455")
  @limit_combo.active = 2
  hbox.pack_end(@limit_combo, false, false, 4)

  label = Gtk::Label.new("Limit:")
  hbox.pack_end(label, false, false, 0)

  hbox
end
get_tree_view(page_num) click to toggle source
# File lib/groonga/database-viewer-gtk/window.rb, line 82
def get_tree_view(page_num)
  page_widget = @notebook.children[page_num]
  if page_widget.is_a?(Gtk::ScrolledWindow)
    page_widget.each do |child|
      if child.is_a?(Table)
        return child
      end
    end
  end
  return nil
end
init_view(page_num) click to toggle source
# File lib/groonga/database-viewer-gtk/window.rb, line 58
def init_view(page_num)
  target = get_tree_view(page_num)
  return unless target
  return if target.updated
  limit = @limit_combo.active_text.delete(",").to_i
  target.update_model(limit)
end
select(column, word) click to toggle source
# File lib/groonga/database-viewer-gtk/window.rb, line 66
def select(column, word)
  if word.empty?
    query = nil
  elsif column == RAW_QUERY_MODE
    query = word
  elsif column == "_id"
    query = "#{column}:#{word}"
  else
    query = "#{column}:@#{word}"
  end
  target = get_tree_view(@notebook.page)
  return unless target
  limit = @limit_combo.active_text.delete(",").to_i
  target.update_model(limit, query)
end
update_combo_box(page_num) click to toggle source
# File lib/groonga/database-viewer-gtk/window.rb, line 127
def update_combo_box(page_num)
  # TODO
  100.times do
    @combo_box.remove_text(0)
  end
  target = get_tree_view(page_num)
  if target
    @combo_box.append_text("_id")
    @combo_box.append_text("_key")
    target.grn_table.columns.each do |column|
      @combo_box.append_text(column.local_name)
    end
    @combo_box.append_text(RAW_QUERY_MODE)
    @combo_box.active = 1
  end
end