プロジェクト

全般

プロフィール

提案 #1255 » 1255-1.patch

Yuto Tokunaga, 2018-05-27 19:51

差分を表示:

core/plugin/gtk/world_shifter.rb
4 4

  
5 5
class Gtk::WorldShifter < Gtk::EventBox
6 6
  UserConfig[:gtk_accountbox_geometry] ||= 32
7
  UserConfig[:gtk_last_world_slug] ||= nil
7 8

  
8 9
  def initialize
9 10
    super
......
15 16
      refresh
16 17
    end
17 18
    pluggaloid_event_listener
19
    restore_last_world
18 20
  end
19 21

  
20 22
  def refresh
......
23 25
    modify_face
24 26
  end
25 27

  
28
  def restore_last_world
29
    slug = UserConfig[:gtk_last_world_slug]
30
    world = Enumerator.new do |y|
31
      Plugin.filtering :worlds, y
32
    end.select { |w| w.slug == slug } &.first
33
    Plugin.call(:world_change_current, world) if world
34
  end
35

  
36
  def save_current_world
37
    world = Plugin.filtering(:world_current, nil).first
38
    UserConfig[:gtk_last_world_slug] = world.slug
39
  end
40

  
26 41
  def open_menu(event)
27 42
    @menu ||= Gtk::Menu.new.tap do |menu|
28 43
      Enumerator.new{|y|
......
55 70

  
56 71
  def pluggaloid_event_listener
57 72
    tag = Plugin[:gtk].handler_tag(:world_shifter) do
58
      Plugin[:gtk].on_world_change_current{ refresh }
73
      Plugin[:gtk].on_world_change_current do
74
        refresh
75
        save_current_world
76
      end
59 77
      Plugin[:gtk].on_userconfig_modify do |key, newval|
60 78
        refresh if key == :world_shifter_visibility
61 79
      end
62 80
      Plugin[:gtk].on_world_after_created do |world|
63 81
        refresh
82
        save_current_world
64 83
      end
65 84
      Plugin[:gtk].on_world_destroy do |world|
66 85
        refresh
86
        save_current_world
67 87
      end
68 88
    end
69 89
    ssc(:destroy) do
(1-1/2)