| 1 |
|
| 2 |
|
| 3 |
Plugin.create :skin do |
| 4 |
ーアイコンのリスト |
| 5 |
def preview_icons(dir) |
| 6 |
famous_icons = [ "timeline.png", "reply.png", "activity.png", "directmessage.png" ] |
| 7 |
skin_icons = Dir.glob(File.join(dir, "*.png")).sort.map { |_| File.basename(_) } |
| 8 |
|
| 9 |
(famous_icons + skin_icons).uniq.select { |_| File.exist?(File.join(dir, _)) }[0, 12] |
| 10 |
end |
| 11 |
|
| 12 |
ーを表示するウィジェットを生成する |
| 13 |
def preview_widget(info) |
| 14 |
fix = Gtk::Fixed.new |
| 15 |
frame = Gtk::Frame.new |
| 16 |
grid = Gtk::Grid.new |
| 17 |
|
| 18 |
preview_icons(info[:dir]).each do |path| |
| 19 |
image = Gtk::WebIcon.new(File.join(info[:dir], path), 32, 32) |
| 20 |
grid << image |
| 21 |
end |
| 22 |
|
| 23 |
fix.put(frame.add(grid), 17, 0) |
| 24 |
end |
| 25 |
|
| 26 |
ル済みスキンのリスト |
| 27 |
def skin_list() |
| 28 |
dirs = Dir.glob(File.join(Skin::SKIN_ROOT, "*")).select { |_| |
| 29 |
File.directory?(_) |
| 30 |
}.select { |_| |
| 31 |
Dir.glob(File.join(_, "*.png")).length != 0 |
| 32 |
}.map { |_| |
| 33 |
_.gsub(/^#{Skin::SKIN_ROOT}\//, "") |
| 34 |
} |
| 35 |
|
| 36 |
dirs |
| 37 |
end |
| 38 |
|
| 39 |
の情報を得る |
| 40 |
def skin_infos() |
| 41 |
default_info = { :vanilla => { :face => _("(デフォルト)"), :dir => Skin::default_dir } } |
| 42 |
|
| 43 |
skin_infos_tmp = skin_list.inject({}) { |hash, _| |
| 44 |
hash[_] = { :face => _, :dir => File.join(Skin::SKIN_ROOT, _) } |
| 45 |
hash |
| 46 |
} |
| 47 |
|
| 48 |
default_info.merge(skin_infos_tmp) |
| 49 |
end |
| 50 |
|
| 51 |
設定 |
| 52 |
settings(_("スキン")) do |
| 53 |
grid = Gtk::Grid.new |
| 54 |
current_radio = nil |
| 55 |
|
| 56 |
skin_infos.each { |slug, info| |
| 57 |
button = if current_radio |
| 58 |
Gtk::RadioButton.new(member: current_radio, label: info[:face]) |
| 59 |
else |
| 60 |
Gtk::RadioButton.new(label: info[:face]) |
| 61 |
end |
| 62 |
|
| 63 |
if slug == UserConfig[:skin_dir] |
| 64 |
button.active = true |
| 65 |
end |
| 66 |
|
| 67 |
button.ssc(:toggled) { |
| 68 |
if button.active? |
| 69 |
UserConfig[:skin_dir] = slug |
| 70 |
end |
| 71 |
} |
| 72 |
|
| 73 |
grid.attach_next_to button, nil, :bottom, 1, 1 |
| 74 |
grid.attach_next_to preview_widget(info), button, :right, 1, 1 |
| 75 |
|
| 76 |
current_radio = button |
| 77 |
} |
| 78 |
|
| 79 |
native grid |
| 80 |
end |
| 81 |
end |