[Tween-svn] [1641] Growl通知で、通知をクリックされたら該当発言を選択してアクティブに

アーカイブの一覧に戻る

svnno****@sourc***** svnno****@sourc*****
2011年 10月 24日 (月) 19:32:20 JST


Revision: 1641
          http://sourceforge.jp/projects/tween/svn/view?view=rev&revision=1641
Author:   kiri_feather
Date:     2011-10-24 19:32:19 +0900 (Mon, 24 Oct 2011)

Log Message:
-----------
Growl通知で、通知をクリックされたら該当発言を選択してアクティブに

Modified Paths:
--------------
    trunk/Tween/Growl.vb
    trunk/Tween/Tween.vb


-------------- next part --------------
Modified: trunk/Tween/Growl.vb
===================================================================
--- trunk/Tween/Growl.vb	2011-10-24 09:22:50 UTC (rev 1640)
+++ trunk/Tween/Growl.vb	2011-10-24 10:32:19 UTC (rev 1641)
@@ -20,8 +20,20 @@
     Private _appName As String = ""
     Dim _initialized As Boolean = False
 
-    Public Event Callback(ByVal sender As Object, ByVal e As EventArgs)
+    Public Class NotifyCallbackEventArgs
+        Inherits EventArgs
+        Public Property StatusId As Long
+        Public Property NotifyType As NotifyType
+        Public Sub New(ByVal notifyType As NotifyType, ByVal statusId As String)
+            If statusId.Length > 1 Then
+                Me.StatusId = CLng(statusId)
+                Me.NotifyType = notifyType
+            End If
+        End Sub
+    End Class
 
+    Public Event Callback(ByVal sender As Object, ByVal e As NotifyCallbackEventArgs)
+
     Public ReadOnly Property AppName As String
         Get
             Return _appName
@@ -196,7 +208,7 @@
         Return True
     End Function
 
-    Public Sub Notify(ByVal notificationType As NotifyType, ByVal id As String, ByVal title As String, ByVal text As String, Optional ByVal icon As Image = Nothing)
+    Public Sub Notify(ByVal notificationType As NotifyType, ByVal id As String, ByVal title As String, ByVal text As String, Optional ByVal icon As Image = Nothing, Optional ByVal url As String = "")
         If Not _initialized Then Return
         Dim notificationName As String = ""
         Select Case notificationType
@@ -210,13 +222,22 @@
                 notificationName = "USERSTREAM_EVENT"
         End Select
         Dim n As Object = Nothing
-        If icon IsNot Nothing Then
+        If icon IsNot Nothing OrElse Not String.IsNullOrEmpty(url) Then
             Dim gCore As Type = _core.GetType("Growl.CoreLibrary.Resource")
-            Dim res As Object = gCore.InvokeMember("op_Implicit",
+            Dim res As Object = Nothing
+            If icon IsNot Nothing Then
+                res = gCore.InvokeMember("op_Implicit",
                                                    BindingFlags.Public Or BindingFlags.Static Or BindingFlags.InvokeMethod,
                                                    Nothing,
                                                    Nothing,
                                                    New Object() {icon})
+            Else
+                res = gCore.InvokeMember("op_Implicit",
+                                                   BindingFlags.Public Or BindingFlags.Static Or BindingFlags.InvokeMethod,
+                                                   Nothing,
+                                                   Nothing,
+                                                   New Object() {url})
+            End If
             Dim priority As Object =
                     _connector.GetType("Growl.Connector.Priority").InvokeMember(
                         "Normal", BindingFlags.GetField, Nothing, Nothing, Nothing)
@@ -249,7 +270,7 @@
         '_targetConnector.GetType.InvokeMember("Notify", BindingFlags.InvokeMethod, Nothing, _targetConnector, New Object() {n})
         Dim cc As Object = _connector.GetType("Growl.Connector.CallbackContext").InvokeMember(
             Nothing, BindingFlags.CreateInstance, Nothing, _connector,
-            New Object() {"some fake information", "fake data"})
+            New Object() {"some fake information", notificationName})
         _targetConnector.GetType.InvokeMember("Notify", BindingFlags.InvokeMethod, Nothing, _targetConnector, New Object() {n, cc})
     End Sub
 
@@ -263,13 +284,23 @@
             ' 実際の値
             Dim vResult As Object = callbackData.GetType.GetProperty(
                         "Result",
-                        BindingFlags.Public Or BindingFlags.Instance).
-            GetGetMethod.
-            Invoke(callbackData, Nothing)
+                        BindingFlags.Public Or BindingFlags.Instance).GetGetMethod.Invoke(callbackData, Nothing)
             vResult = CType(vResult, Integer)
-
+            Dim notifyId As String = CStr(callbackData.GetType.GetProperty("NotificationID").GetGetMethod.Invoke(callbackData, Nothing))
+            Dim notifyName As String = CStr(callbackData.GetType.GetProperty("Type").GetGetMethod.Invoke(callbackData, Nothing))
             If vCLICK.Equals(vResult) Then
-                RaiseEvent Callback(Me, New EventArgs)
+                Dim nt As NotifyType
+                Select Case notifyName
+                    Case "REPLY"
+                        nt = NotifyType.Reply
+                    Case "DIRECT_MESSAGE"
+                        nt = NotifyType.DirectMessage
+                    Case "NOTIFY"
+                        nt = NotifyType.Notify
+                    Case "USERSTREAM_EVENT"
+                        nt = NotifyType.UserStreamEvent
+                End Select
+                RaiseEvent Callback(Me, New NotifyCallbackEventArgs(nt, notifyId))
             End If
         Catch ex As Exception
             Exit Sub

Modified: trunk/Tween/Tween.vb
===================================================================
--- trunk/Tween/Tween.vb	2011-10-24 09:22:50 UTC (rev 1640)
+++ trunk/Tween/Tween.vb	2011-10-24 10:32:19 UTC (rev 1641)
@@ -1606,7 +1606,7 @@
                         Dim bText As String = sb.ToString
                         If String.IsNullOrEmpty(bText) Then Exit Sub
 
-                        gh.Notify(nt, DateTime.Now.Ticks.ToString(), title.ToString(), bText, Me.TIconDic(post.ImageUrl))
+                        gh.Notify(nt, post.StatusId.ToString, title.ToString(), bText, Me.TIconDic(post.ImageUrl), post.ImageUrl)
                     Next
                 Else
                     Dim sb As New StringBuilder
@@ -6348,6 +6348,36 @@
         Next
     End Sub
 
+    Private Function GoStatus(ByVal statusId As Long) As Boolean
+        If statusId = 0 Then Return False
+        For tabidx As Integer = 0 To ListTab.TabCount - 1
+            If _statuses.Tabs(ListTab.TabPages(tabidx).Text).TabType <> TabUsageType.DirectMessage AndAlso _statuses.Tabs(ListTab.TabPages(tabidx).Text).Contains(statusId) Then
+                Dim idx = _statuses.Tabs(ListTab.TabPages(tabidx).Text).IndexOf(statusId)
+                ListTab.SelectedIndex = tabidx
+                ListTabSelect(ListTab.TabPages(tabidx))
+                SelectListItem(_curList, idx)
+                _curList.EnsureVisible(idx)
+                Return True
+            End If
+        Next
+        Return False
+    End Function
+
+    Private Function GoDirectMessage(ByVal statusId As Long) As Boolean
+        If statusId = 0 Then Return False
+        For tabidx As Integer = 0 To ListTab.TabCount - 1
+            If _statuses.Tabs(ListTab.TabPages(tabidx).Text).TabType = TabUsageType.DirectMessage AndAlso _statuses.Tabs(ListTab.TabPages(tabidx).Text).Contains(statusId) Then
+                Dim idx = _statuses.Tabs(ListTab.TabPages(tabidx).Text).IndexOf(statusId)
+                ListTab.SelectedIndex = tabidx
+                ListTabSelect(ListTab.TabPages(tabidx))
+                SelectListItem(_curList, idx)
+                _curList.EnsureVisible(idx)
+                Return True
+            End If
+        Next
+        Return False
+    End Function
+
     Private Sub MyList_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs)
         _anchorFlag = False
     End Sub
@@ -10616,7 +10646,7 @@
             'NotifyIcon1.ShowBalloonTip(500)
             If SettingDialog.IsNotifyUseGrowl Then
                 gh.Notify(GrowlHelper.NotifyType.UserStreamEvent,
-                          DateTime.Now.Ticks.ToString(), title.ToString(), text)
+                          ev.Id.ToString(), title.ToString(), text)
             Else
                 NotifyIcon1.BalloonTipIcon = ToolTipIcon.Warning
                 NotifyIcon1.BalloonTipTitle = title.ToString()
@@ -10896,14 +10926,18 @@
         End If
     End Sub
 
-    Private Sub GrowlHelper_Callback(ByVal sender As Object, ByVal e As EventArgs) Handles gh.Callback
+    Private Sub GrowlHelper_Callback(ByVal sender As Object, ByVal e As GrowlHelper.NotifyCallbackEventArgs) Handles gh.Callback
         If Form.ActiveForm Is Nothing Then
             Me.BeginInvoke(Sub()
                                Me.Visible = True
                                If Me.WindowState = FormWindowState.Minimized Then Me.WindowState = FormWindowState.Normal
                                Me.Activate()
                                Me.BringToFront()
-                               Me.StatusText.Focus()
+                               If e.NotifyType = GrowlHelper.NotifyType.DirectMessage Then
+                                   If Not Me.GoDirectMessage(e.StatusId) Then Me.StatusText.Focus()
+                               Else
+                                   If Not Me.GoStatus(e.StatusId) Then Me.StatusText.Focus()
+                               End If
                            End Sub)
         End If
     End Sub



Tween-svn メーリングリストの案内
アーカイブの一覧に戻る