class Plugin::Shortcutkey::ShortcutKeyListView::CommandList

Constants

COL_ICON
COL_NAME
COL_SLUG

Attributes

filter_entry[RW]

Public Class Methods

new(plugin, results) click to toggle source
Calls superclass method Gtk::TreeViewPrettyScroll.new
# File core/plugin/shortcutkey/shortcutkey_listview.rb, line 169
def initialize(plugin, results)
  type_strict plugin => Plugin
  @plugin = plugin
  super(::Gtk::TreeModelFilter.new(::Gtk::TreeStore.new(::GdkPixbuf::Pixbuf, String, Symbol)))
  model.set_visible_func{ |model, iter|
    if defined?(@filter_entry) and @filter_entry
      iter_match(iter, @filter_entry.text)
    else
      true end }
  append_column ::Gtk::TreeViewColumn.new("", ::Gtk::CellRendererPixbuf.new, pixbuf: COL_ICON)
  append_column ::Gtk::TreeViewColumn.new(@plugin._("コマンド名"), ::Gtk::CellRendererText.new, text: COL_NAME)
  append_column ::Gtk::TreeViewColumn.new(@plugin._("スラッグ"), ::Gtk::CellRendererText.new, text: COL_SLUG)
  parents = Hash.new{ |h, k| # role => TreeIter
    h[k] = iter = model.model.append(nil)
    iter[COL_NAME] = k.to_s
    iter
  }
  Plugin.filtering(:command, Hash.new).first.map{ |slug, command|
    iter = model.model.append(parents[command[:role]])
    icon = icon_model(command[:icon])
    if icon
      iter[COL_ICON] = icon.load_pixbuf(width: 16, height: 16) do |pixbuf|
        iter[COL_ICON] = pixbuf if not destroyed?
      end
    end
    name = command[:name]
    name = name.call(nil) if name.is_a? Proc
    iter[COL_NAME] = name
    iter[COL_SLUG] = slug
    if results[Plugin::Shortcutkey::ShortcutKeyListView::COLUMN_SLUG].to_s == slug.to_s
      expand_row(iter.parent.path, true)
      selection.select_iter(iter)
    end
  }
  signal_connect("cursor-changed"){
    iter = selection.selected
    if iter
      results[Plugin::Shortcutkey::ShortcutKeyListView::COLUMN_COMMAND] = iter[COL_NAME]
      results[Plugin::Shortcutkey::ShortcutKeyListView::COLUMN_SLUG] = iter[COL_SLUG]
    end
    false }
  selected = selection.selected
  if selected
    scroll_to_cell(selected.path, nil, false, 0.5, 0) end
end