~marco-92/do-plugins/XChat

« back to all changes in this revision

Viewing changes to XChat/src/XChatMessageAction.cs

  • Committer: marco_92 at bellsouth
  • Date: 2009-06-04 23:12:50 UTC
  • Revision ID: marco_92@bellsouth.net-20090604231250-bj95l1ykz83bz17b
Allow Text and Channel/User to be either item or moditem in Message action

Show diffs side-by-side

added added

removed removed

Lines of Context:
48
48
                        get {
49
49
                                return new Type[] {
50
50
                                        typeof (XChatChannelItem),
51
 
                                        typeof (XChatUserItem)
 
51
                                        typeof (XChatUserItem),
 
52
                                        typeof (ITextItem)
52
53
                                };
53
54
                        }
54
55
                }
56
57
                public override IEnumerable<Type> SupportedModifierItemTypes {
57
58
                        get { 
58
59
                                return new Type[] {
59
 
                                        typeof (ITextItem)
 
60
                                        typeof (ITextItem),
 
61
                                        typeof (XChatChannelItem),
 
62
                                        typeof (XChatUserItem)
60
63
                                };
61
64
                        }
62
65
                }
63
66
                
 
67
                public override bool SupportsModifierItemForItems (IEnumerable<Item> items, Item modItem)
 
68
                {
 
69
                        Item item = items.First ();
 
70
                        if(item is ITextItem)
 
71
                        {
 
72
                                if(modItem is XChatChannelItem || modItem is XChatUserItem)
 
73
                                        return true;
 
74
                                else
 
75
                                        return false;
 
76
                        }
 
77
                        else if(item is XChatChannelItem || item is XChatUserItem)
 
78
                        {
 
79
                                if(modItem is ITextItem)
 
80
                                        return true;
 
81
                                else
 
82
                                        return false;
 
83
                        }
 
84
                        return false;
 
85
                }
 
86
                
 
87
                
64
88
                public override IEnumerable<Item> Perform (IEnumerable<Item> items, IEnumerable<Item> modItems)
65
 
                {
 
89
                { 
 
90
                        Item item = items.First ();
 
91
                        Item destinationItem;
 
92
                        ITextItem text;
 
93
                        if (item is ITextItem)
 
94
                        {
 
95
                                text = item as ITextItem;
 
96
                                destinationItem = modItems.First();
 
97
                        }
 
98
                        else // if (item is XChatChannelItem || item is XChatUserItem)
 
99
                        {
 
100
                                text = modItems.First() as ITextItem;
 
101
                                destinationItem = item;
 
102
                        }
 
103
                        
66
104
                        XChat.IXChatPlugin xchat = XChat.GetXChatObject();
67
105
                        if(xchat == null)
68
106
                                yield break;
69
107
                        
70
 
                        Item destinationItem = items.First ();
71
 
                        
72
108
                        string destination;
73
109
                        string server;
74
110
                        
75
 
                        if(destinationItem is XChatChannelItem)
 
111
                        if (destinationItem is XChatChannelItem)
76
112
                        {
77
113
                                destination = (destinationItem as XChatChannelItem).Channel;
78
114
                                server = (destinationItem as XChatChannelItem).Server;
83
119
                                server = (destinationItem as XChatUserItem).Server;
84
120
                        }
85
121
                        
86
 
                        ITextItem text = modItems.First () as ITextItem;
87
 
                        
88
122
                        xchat.SetContext(xchat.FindContext(server, ""));
89
123
                        
90
124
                        xchat.Command("msg " + destination + " " + text.Text);