aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorToshiaki Asai <toshi.alternative@gmail.com>2017-12-18 22:03:12 +0900
committerToshiaki Asai <toshi.alternative@gmail.com>2017-12-18 22:03:12 +0900
commitcb61ce1f3043b916756d2d8b5a6c0dd323b1ec45 (patch)
treeb9d0938ad770af481b6705574b0351d301e4e2f9
parentfaffe8a9ffd05dd3aa7e22ed429880c0ec612d76 (diff)
downloadmikutter-cb61ce1f3043b916756d2d8b5a6c0dd323b1ec45.tar.gz
World ShifterにWorld追加メニューを追加
-rw-r--r--core/plugin/change_account/change_account.rb4
-rw-r--r--core/plugin/gtk/world_shifter.rb122
-rw-r--r--core/skin/data/add.pngbin0 -> 1436 bytes
-rw-r--r--core/userconfig.rb13
4 files changed, 86 insertions, 53 deletions
diff --git a/core/plugin/change_account/change_account.rb b/core/plugin/change_account/change_account.rb
index dfe0f8f2..80472b25 100644
--- a/core/plugin/change_account/change_account.rb
+++ b/core/plugin/change_account/change_account.rb
@@ -54,7 +54,7 @@ Plugin.create :change_account do
btn_add = Gtk::Button.new(Gtk::Stock::ADD)
btn_delete = Gtk::Button.new(Gtk::Stock::DELETE)
btn_add.ssc(:clicked) do
- boot_wizard
+ Plugin.call(:request_world_add)
true
end
btn_delete.ssc(:clicked) do
@@ -70,7 +70,7 @@ Plugin.create :change_account do
add(btn_add)))
end
- def boot_wizard
+ on_request_world_add do
dialog(_('アカウント追加')){
select 'Select world', :world do
worlds, = Plugin.filtering(:world_setting_list, Hash.new)
diff --git a/core/plugin/gtk/world_shifter.rb b/core/plugin/gtk/world_shifter.rb
index b0ecffd9..7839e40c 100644
--- a/core/plugin/gtk/world_shifter.rb
+++ b/core/plugin/gtk/world_shifter.rb
@@ -6,60 +6,24 @@ class Gtk::WorldShifter < Gtk::EventBox
UserConfig[:gtk_accountbox_geometry] ||= 32
def initialize
- Plugin[:gtk].on_primary_service_changed(&method(:travel))
super
- Plugin[:gtk].on_userconfig_modify do |key, newval|
- refresh if key == :world_shifter_visibility
- end
- Plugin[:gtk].on_service_registered do |service|
- refresh
- end
- Plugin[:gtk].on_service_destroyed do |service|
- refresh
- end
ssc(:button_press_event) do |this,event|
open_menu event if 3 >= event.button
false
end
ssc_atonce(:realize) do
- travel Service.primary
+ refresh
end
+ pluggaloid_event_listener
end
def refresh
- if visible?
- if not @face
- @face = Gtk::Image.new(Skin['loading.png'].pixbuf(width: UserConfig[:gtk_accountbox_geometry], height: UserConfig[:gtk_accountbox_geometry]))
- self.add(@face).show_all
- end
- else
- if @face
- self.remove(@face)
- @face.destroy
- @face = nil
- end
- end
- end
-
- def travel(world)
- refresh
- if @face
- transaction = @world_transaction = SecureRandom.uuid
- rect = { width: UserConfig[:gtk_accountbox_geometry],
- height: UserConfig[:gtk_accountbox_geometry] }
- @face.pixbuf = world&.icon&.load_pixbuf(**rect) do |pixbuf|
- if transaction == @world_transaction
- @face.pixbuf = pixbuf
- end
- end || Skin['notfound.png'].pixbuf(**rect)
- end
+ destroy_menu
+ put_face
+ modify_face
end
def open_menu(event)
- @menu_last_services ||= Service.to_a.hash
- if @menu_last_services != Service.to_a.hash
- @menu.destroy if @menu
- @menu_last_services = @menu = nil end
@menu ||= Gtk::Menu.new.tap do |menu|
Enumerator.new{|y|
Plugin.filtering(:worlds, y)
@@ -69,9 +33,50 @@ class Gtk::WorldShifter < Gtk::EventBox
item.ssc(:activate) { |w|
Plugin.call(:world_change_current, world)
false }
- menu.append item end
- menu end
- @menu.show_all.popup(nil, nil, event.button, event.time) end
+ menu.append item
+ end
+ menu.append Gtk::SeparatorMenuItem.new
+ item = Gtk::ImageMenuItem.new(Plugin[:gtk]._('Worldを追加'), false)
+ item.set_image Gtk::WebIcon.new(Skin['add.png'], UserConfig[:gtk_accountbox_geometry], UserConfig[:gtk_accountbox_geometry])
+ item.ssc(:activate) { |w|
+ Plugin.call(:request_world_add)
+ false }
+ menu.append item
+ menu
+ end
+ @menu.show_all.popup(nil, nil, event.button, event.time)
+ end
+
+ def destroy_menu
+ @menu&.destroy
+ @menu = nil
+ end
+
+ def pluggaloid_event_listener
+ tag = Plugin[:gtk].handler_tag(:world_shifter) do
+ Plugin[:gtk].on_world_change_current(&method(:refresh))
+ Plugin[:gtk].on_userconfig_modify do |key, newval|
+ refresh if key == :world_shifter_visibility
+ end
+ Plugin[:gtk].on_world_create do |world|
+ refresh
+ end
+ Plugin[:gtk].on_world_destroy do |world|
+ refresh
+ end
+ end
+ ssc(:destroy) do
+ Plugin[:gtk].detach(tag)
+ end
+ end
+
+ def put_face
+ if visible?
+ add_face_widget_ifn
+ else
+ remove_face_widget_ifn
+ end
+ end
def visible?
case UserConfig[:world_shifter_visibility]
@@ -83,4 +88,33 @@ class Gtk::WorldShifter < Gtk::EventBox
false
end
end
+
+ def modify_face
+ if @face
+ world, = Plugin.filtering(:world_current, nil)
+ transaction = @world_transaction = SecureRandom.uuid
+ rect = { width: UserConfig[:gtk_accountbox_geometry],
+ height: UserConfig[:gtk_accountbox_geometry] }
+ @face.pixbuf = world&.icon&.load_pixbuf(**rect) do |pixbuf|
+ if transaction == @world_transaction
+ @face.pixbuf = pixbuf
+ end
+ end || Skin['add.png'].pixbuf(**rect)
+ end
+ end
+
+ def add_face_widget_ifn
+ if not @face
+ @face = Gtk::Image.new(Skin['loading.png'].pixbuf(width: UserConfig[:gtk_accountbox_geometry], height: UserConfig[:gtk_accountbox_geometry]))
+ self.add(@face).show_all
+ end
+ end
+
+ def remove_face_widget_ifn
+ if @face
+ self.remove(@face)
+ @face.destroy
+ @face = nil
+ end
+ end
end
diff --git a/core/skin/data/add.png b/core/skin/data/add.png
new file mode 100644
index 00000000..e0198c04
--- /dev/null
+++ b/core/skin/data/add.png
Binary files differ
diff --git a/core/userconfig.rb b/core/userconfig.rb
index 3e946dd1..b2424c9d 100644
--- a/core/userconfig.rb
+++ b/core/userconfig.rb
@@ -151,8 +151,8 @@ class UserConfig
:str=>"https://twitter.com/",
:rule=>"start"}],
- :postbox_visibility => :always,
- :world_shifter_visibility => :always,
+ :postbox_visibility => :auto,
+ :world_shifter_visibility => :auto,
}
@@watcher = Hash.new{ [] }
@@ -218,7 +218,10 @@ class UserConfig
if last_boot_version < Environment::VERSION.to_a
UserConfig[:last_boot_version] = Environment::VERSION.to_a
if last_boot_version == [0, 0, 0, 0]
- key_add "Alt + x", "コンソールを開く", :console_open end
+ key_add "Alt + x", "コンソールを開く", :console_open
+ UserConfig[:postbox_visibility] = :always
+ UserConfig[:world_shifter_visibility] = :always
+ end
if last_boot_version < [3, 3, 0, 0]
UserConfig[:notification_enable] = true
activity_show_statusbar = (UserConfig[:activity_show_statusbar] || []).map(&:to_s)
@@ -239,10 +242,6 @@ class UserConfig
UserConfig[:reply_clicked_action] = nil
UserConfig[:quote_clicked_action] = :smartthread
end
- if last_boot_version < [3, 6, 0, 0]
- UserConfig[:postbox_visibility] = :auto
- UserConfig[:world_shifter_visibility] = :auto
- end
end
end