class Plugin::Shortcutkey::ShortcutKeyListView

Constants

COLUMN_COMMAND
COLUMN_COMMAND_ICON
COLUMN_ID
COLUMN_KEYBIND
COLUMN_SLUG

Attributes

filter_entry[RW]

Public Class Methods

new(plugin) click to toggle source
Calls superclass method Gtk::CRUD.new
# File core/plugin/shortcutkey/shortcutkey_listview.rb, line 13
def initialize(plugin)
  type_strict plugin => Plugin
  @plugin = plugin
  super()
  set_model(Gtk::TreeModelFilter.new(model))
  model.set_visible_func{ |model, iter|
    if defined?(@filter_entry) and @filter_entry
      [COLUMN_KEYBIND, COLUMN_COMMAND, COLUMN_SLUG].any?{ |column| iter[column].to_s.include?(@filter_entry.text) }
    else
      true end }
  commands = Plugin.filtering(:command, Hash.new).first
  shortcutkeys.each{ |id, behavior|
    slug = behavior[:slug]
    iter = model.model.append
    iter[COLUMN_ID] = id
    iter[COLUMN_KEYBIND] = behavior[:key]
    iter[COLUMN_COMMAND] = behavior[:name]
    iter[COLUMN_SLUG] = slug
    if commands[slug]
      icon = commands[slug][:icon]
      icon = icon.call(nil) if icon.is_a? Proc
      icon = Diva::Model(:photo)[icon] if icon
      if icon
        iter[COLUMN_COMMAND_ICON] = icon.load_pixbuf(width: 16, height: 16){ |pixbuf|
          if not destroyed?
            iter[COLUMN_COMMAND_ICON] = pixbuf end } end end } end

Public Instance Methods

column_schemer() click to toggle source
# File core/plugin/shortcutkey/shortcutkey_listview.rb, line 40
def column_schemer
  [{:kind => :text, :widget => :keyconfig, :type => String, :label => @plugin._('キーバインド')},
   [{:kind => :pixbuf, :type => GdkPixbuf::Pixbuf, :label => @plugin._('機能名')},
    {:kind => :text, :type => String, :expand => true}],
   {:kind => :text, :widget => :chooseone, :args => [Hash[Plugin.filtering(:command, Hash.new).first.values.map{ |x|
                                                        [x[:slug], x[:name]]
                                                      }].freeze],
     :type => Symbol},
   {:type => Integer},
  ].freeze
end
command_box(results) click to toggle source
# File core/plugin/shortcutkey/shortcutkey_listview.rb, line 137
def command_box(results)
  treeview = CommandList.new(@plugin, results)
  scrollbar = ::Gtk::VScrollbar.new(treeview.vadjustment)
  filter_entry = treeview.filter_entry = Gtk::Entry.new
  filter_entry.primary_icon_pixbuf = Skin['search.png'].pixbuf(width: 24, height: 24)
  filter_entry.ssc(:changed){
    treeview.model.refilter
    false }
  return ::Gtk::VBox.new(false, 0)
  .closeup(filter_entry)
  .add(::Gtk::HBox.new(false, 0).
       add(treeview).
       closeup(scrollbar))
end
key_box(results) click to toggle source
# File core/plugin/shortcutkey/shortcutkey_listview.rb, line 129
def key_box(results)
  container = ::Gtk::VBox.new(false, 16)
  button = ::Gtk::KeyConfig.new(@plugin._('キーバインド'), results[COLUMN_KEYBIND])
  button.change_hook = lambda { |new| results[COLUMN_KEYBIND] = new }
  container.
    closeup(::Gtk::Label.new(@plugin._('キーバインド'))).
    closeup(button) end
new_serial() click to toggle source
# File core/plugin/shortcutkey/shortcutkey_listview.rb, line 55
def new_serial
  @new_serial ||= (shortcutkeys.keys.max || 0)
  @new_serial += 1 end
on_created(iter) click to toggle source
# File core/plugin/shortcutkey/shortcutkey_listview.rb, line 59
def on_created(iter)
  bind = shortcutkeys
  name = Plugin.filtering(:command, Hash.new).first[iter[COLUMN_SLUG].to_sym][:name]
  name = name.call(nil) if name.is_a? Proc
  iter[COLUMN_ID] = new_serial
  bind[iter[COLUMN_ID]] = {
    :key => iter[COLUMN_KEYBIND].to_s,
    :name => name,
    :slug => iter[COLUMN_SLUG].to_sym }
  iter[COLUMN_COMMAND] = name
  UserConfig[:shortcutkey_keybinds] = bind
end
on_deleted(iter) click to toggle source
# File core/plugin/shortcutkey/shortcutkey_listview.rb, line 84
def on_deleted(iter)
  bind = shortcutkeys
  bind.delete(iter[COLUMN_ID].to_i)
  UserConfig[:shortcutkey_keybinds] = bind
end
on_updated(iter) click to toggle source
# File core/plugin/shortcutkey/shortcutkey_listview.rb, line 72
def on_updated(iter)
  bind = shortcutkeys
  name = Plugin.filtering(:command, Hash.new).first[iter[COLUMN_SLUG].to_sym][:name]
  name = name.call(nil) if name.is_a? Proc
  bind[iter[COLUMN_ID].to_i] = {
    :key => iter[COLUMN_KEYBIND].to_s,
    :name => name,
    :slug => iter[COLUMN_SLUG].to_sym }
  iter[COLUMN_COMMAND] = name
  UserConfig[:shortcutkey_keybinds] = bind
end
popup_input_window(defaults = []) click to toggle source
shortcutkeys() click to toggle source
# File core/plugin/shortcutkey/shortcutkey_listview.rb, line 52
def shortcutkeys
  (UserConfig[:shortcutkey_keybinds] || Hash.new).dup end