2 // Radegast Metaverse Client
3 // Copyright (c) 2009-2011, Radegast Development Team
4 // All rights reserved.
6 // Redistribution and use in source and binary forms, with or without
7 // modification, are permitted provided that the following conditions are met:
9 // * Redistributions of source code must retain the above copyright notice,
10 // this list of conditions and the following disclaimer.
11 // * Redistributions in binary form must reproduce the above copyright
12 // notice, this list of conditions and the following disclaimer in the
13 // documentation and/or other materials provided with the distribution.
14 // * Neither the name of the application "Radegast", nor the names of its
15 // contributors may be used to endorse or promote products derived from
16 // this software without specific prior written permission.
18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21 // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
22 // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24 // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
25 // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26 // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 using System.Collections.Generic;
33 using System.ComponentModel;
35 using System.Windows.Forms;
36 using Radegast.Netcom;
41 public partial class TabsConsole : UserControl
45 /// List of nearby avatars (radar data)
47 public List<NearbyAvatar> NearbyAvatars
51 List<NearbyAvatar> res = new List<NearbyAvatar>();
53 if (TabExists("chat"))
55 ChatConsole c = (ChatConsole)Tabs["chat"].Control;
56 lock (c.agentSimHandle)
58 foreach (ListViewItem item in c.lvwObjects.Items)
60 if (item.Name != client.Self.AgentID.ToString())
62 res.Add(new NearbyAvatar() { ID = new UUID(item.Name), Name = item.Text });
73 /// Delegate invoked on tab operations
75 /// <param name="sender">Event sender</param>
76 /// <param name="e">Event arguments</param>
77 public delegate void TabCallback(object sender, TabEventArgs e);
80 /// Fired when a tab is selected
82 public event TabCallback OnTabSelected;
86 /// Delegate invoked when chat notification is printed
88 /// <param name="sender">Event sender</param>
89 /// <param name="e">Event arguments</param>
90 public delegate void ChatNotificationCallback(object sender, ChatNotificationEventArgs e);
93 /// Fired when a tab is selected
95 public event ChatNotificationCallback OnChatNotification;
98 /// Fired when a new tab is added
100 public event TabCallback OnTabAdded;
103 /// Fired when a tab is removed
105 public event TabCallback OnTabRemoved;
107 private RadegastInstance instance;
108 private GridClient client { get { return instance.Client; } }
109 private RadegastNetcom netcom { get { return instance.Netcom; } }
110 private ChatTextManager mainChatManger;
111 public ChatTextManager MainChatManger { get { return mainChatManger; } }
113 private Dictionary<string, RadegastTab> tabs = new Dictionary<string, RadegastTab>();
114 public Dictionary<string, RadegastTab> Tabs { get { return tabs; } }
116 private ChatConsole chatConsole;
118 private RadegastTab selectedTab;
121 /// Currently selected tab
123 public RadegastTab SelectedTab
133 public TabsConsole(RadegastInstance instance)
135 InitializeComponent();
136 Disposed += new EventHandler(TabsConsole_Disposed);
138 this.instance = instance;
139 this.instance.ClientChanged += new EventHandler<ClientChangedEventArgs>(instance_ClientChanged);
147 RegisterClientEvents(client);
150 private void RegisterClientEvents(GridClient client)
152 client.Self.ScriptQuestion += new EventHandler<ScriptQuestionEventArgs>(Self_ScriptQuestion);
153 client.Self.ScriptDialog += new EventHandler<ScriptDialogEventArgs>(Self_ScriptDialog);
154 client.Self.LoadURL += new EventHandler<LoadUrlEventArgs>(Self_LoadURL);
155 client.Self.SetDisplayNameReply += new EventHandler<SetDisplayNameReplyEventArgs>(Self_SetDisplayNameReply);
156 client.Avatars.DisplayNameUpdate += new EventHandler<DisplayNameUpdateEventArgs>(Avatars_DisplayNameUpdate);
157 client.Network.EventQueueRunning += new EventHandler<EventQueueRunningEventArgs>(Network_EventQueueRunning);
158 client.Network.RegisterCallback(OpenMetaverse.Packets.PacketType.ScriptTeleportRequest, ScriptTeleportRequestHandler);
161 private void UnregisterClientEvents(GridClient client)
163 client.Self.ScriptQuestion -= new EventHandler<ScriptQuestionEventArgs>(Self_ScriptQuestion);
164 client.Self.ScriptDialog -= new EventHandler<ScriptDialogEventArgs>(Self_ScriptDialog);
165 client.Self.LoadURL -= new EventHandler<LoadUrlEventArgs>(Self_LoadURL);
166 client.Self.SetDisplayNameReply -= new EventHandler<SetDisplayNameReplyEventArgs>(Self_SetDisplayNameReply);
167 client.Avatars.DisplayNameUpdate -= new EventHandler<DisplayNameUpdateEventArgs>(Avatars_DisplayNameUpdate);
168 client.Network.EventQueueRunning -= new EventHandler<EventQueueRunningEventArgs>(Network_EventQueueRunning);
169 client.Network.UnregisterCallback(OpenMetaverse.Packets.PacketType.ScriptTeleportRequest, ScriptTeleportRequestHandler);
172 void instance_ClientChanged(object sender, ClientChangedEventArgs e)
174 UnregisterClientEvents(e.OldClient);
175 RegisterClientEvents(client);
178 void TabsConsole_Disposed(object sender, EventArgs e)
180 RemoveNetcomEvents();
181 UnregisterClientEvents(client);
184 private void AddNetcomEvents()
186 netcom.ClientLoginStatus += new EventHandler<LoginProgressEventArgs>(netcom_ClientLoginStatus);
187 netcom.ClientLoggedOut += new EventHandler(netcom_ClientLoggedOut);
188 netcom.ClientDisconnected += new EventHandler<DisconnectedEventArgs>(netcom_ClientDisconnected);
189 netcom.ChatSent += new EventHandler<ChatSentEventArgs>(netcom_ChatSent);
190 netcom.AlertMessageReceived += new EventHandler<AlertMessageEventArgs>(netcom_AlertMessageReceived);
191 netcom.InstantMessageReceived += new EventHandler<InstantMessageEventArgs>(netcom_InstantMessageReceived);
194 private void RemoveNetcomEvents()
196 netcom.ClientLoginStatus -= new EventHandler<LoginProgressEventArgs>(netcom_ClientLoginStatus);
197 netcom.ClientLoggedOut -= new EventHandler(netcom_ClientLoggedOut);
198 netcom.ClientDisconnected -= new EventHandler<DisconnectedEventArgs>(netcom_ClientDisconnected);
199 netcom.ChatSent -= new EventHandler<ChatSentEventArgs>(netcom_ChatSent);
200 netcom.AlertMessageReceived -= new EventHandler<AlertMessageEventArgs>(netcom_AlertMessageReceived);
201 netcom.InstantMessageReceived -= new EventHandler<InstantMessageEventArgs>(netcom_InstantMessageReceived);
204 void ScriptTeleportRequestHandler(object sender, PacketReceivedEventArgs e)
208 if (IsHandleCreated || !instance.MonoRuntime)
209 BeginInvoke(new MethodInvoker(() => ScriptTeleportRequestHandler(sender, e)));
213 var msg = (OpenMetaverse.Packets.ScriptTeleportRequestPacket)e.Packet;
215 if (TabExists("map"))
217 Tabs["map"].Select();
218 ((MapConsole)Tabs["map"].Control).CenterOnGlobalPos(
219 (float)(client.Self.GlobalPosition.X - client.Self.SimPosition.X) + msg.Data.SimPosition.X,
220 (float)(client.Self.GlobalPosition.Y - client.Self.SimPosition.Y) + msg.Data.SimPosition.Y,
221 msg.Data.SimPosition.Z);
225 void Network_EventQueueRunning(object sender, EventQueueRunningEventArgs e)
229 BeginInvoke(new MethodInvoker(() => Network_EventQueueRunning(sender, e)));
233 if (TabExists("friends")) return;
234 if (e.Simulator == client.Network.CurrentSim)
236 client.Self.UpdateAgentLanguage("en", true);
237 InitializeOnlineTabs();
241 void Self_ScriptDialog(object sender, ScriptDialogEventArgs e)
243 // Is this object muted
244 if (null != client.Self.MuteList.Find(m => (m.Type == MuteType.Object && m.ID == e.ObjectID) // muted object by id
245 || (m.Type == MuteType.ByName && m.Name == e.ObjectName) // object muted by name
248 instance.MainForm.AddNotification(new ntfScriptDialog(instance, e.Message, e.ObjectName, e.ImageID, e.ObjectID, e.FirstName, e.LastName, e.Channel, e.ButtonLabels));
251 void Self_ScriptQuestion(object sender, ScriptQuestionEventArgs e)
253 // Is this object muted
254 if (null != client.Self.MuteList.Find(m => (m.Type == MuteType.Object && m.ID == e.TaskID) // muted object by id
255 || (m.Type == MuteType.ByName && m.Name == e.ObjectName) // object muted by name
258 instance.MainForm.AddNotification(new ntfPermissions(instance, e.Simulator, e.TaskID, e.ItemID, e.ObjectName, e.ObjectOwnerName, e.Questions));
261 private void netcom_ClientLoginStatus(object sender, LoginProgressEventArgs e)
263 if (e.Status == LoginStatus.Failed)
265 DisplayNotificationInChat("Login error: " + e.Message, ChatBufferTextStyle.Error);
267 else if (e.Status == LoginStatus.Success)
269 DisplayNotificationInChat("Logged in as " + netcom.LoginOptions.FullName + ".", ChatBufferTextStyle.StatusDarkBlue);
270 DisplayNotificationInChat("Login reply: " + e.Message, ChatBufferTextStyle.StatusDarkBlue);
272 if (tabs.ContainsKey("login"))
274 if (selectedTab.Name == "login")
276 ForceCloseTab("login");
279 client.Self.RetrieveInstantMessages();
283 private void netcom_ClientLoggedOut(object sender, EventArgs e)
288 DisplayNotificationInChat("Logged out.");
292 private void netcom_ClientDisconnected(object sender, DisconnectedEventArgs e)
294 if (e.Reason == NetworkManager.DisconnectType.ClientInitiated) return;
298 DisplayNotificationInChat("Disconnected: " + e.Message, ChatBufferTextStyle.Error);
301 void Avatars_DisplayNameUpdate(object sender, DisplayNameUpdateEventArgs e)
303 DisplayNotificationInChat(string.Format("({0}) is now known as {1}", e.DisplayName.UserName, e.DisplayName.DisplayName));
306 void Self_SetDisplayNameReply(object sender, SetDisplayNameReplyEventArgs e)
310 DisplayNotificationInChat("You are now knows as " + e.DisplayName.DisplayName);
314 DisplayNotificationInChat("Failed to set a new display name: " + e.Reason, ChatBufferTextStyle.Error);
318 private void netcom_AlertMessageReceived(object sender, AlertMessageEventArgs e)
320 tabs["chat"].Highlight();
323 private void netcom_ChatSent(object sender, ChatSentEventArgs e)
325 tabs["chat"].Highlight();
328 void Self_LoadURL(object sender, LoadUrlEventArgs e)
330 // Is the object or the owner muted?
331 if (null != client.Self.MuteList.Find(m => (m.Type == MuteType.Object && m.ID == e.ObjectID) // muted object by id
332 || (m.Type == MuteType.ByName && m.Name == e.ObjectName) // object muted by name
333 || (m.Type == MuteType.Resident && m.ID == e.OwnerID) // object's owner muted
336 instance.MainForm.AddNotification(new ntfLoadURL(instance, e));
339 private void netcom_InstantMessageReceived(object sender, InstantMessageEventArgs e)
341 // Messaage from someone we muted?
342 if (null != client.Self.MuteList.Find(me => me.Type == MuteType.Resident && me.ID == e.IM.FromAgentID)) return;
346 case InstantMessageDialog.SessionSend:
347 if (instance.Groups.ContainsKey(e.IM.IMSessionID))
353 HandleConferenceIM(e);
357 case InstantMessageDialog.MessageFromAgent:
358 if (e.IM.FromAgentName == "Second Life")
360 HandleIMFromObject(e);
362 else if (e.IM.GroupIM || instance.Groups.ContainsKey(e.IM.IMSessionID))
366 else if (e.IM.BinaryBucket.Length > 1)
368 HandleConferenceIM(e);
376 case InstantMessageDialog.MessageFromObject:
377 HandleIMFromObject(e);
380 case InstantMessageDialog.StartTyping:
381 if (TabExists(e.IM.FromAgentName))
383 RadegastTab tab = tabs[e.IM.FromAgentName.ToLower()];
384 if (!tab.Highlighted) tab.PartialHighlight();
389 case InstantMessageDialog.StopTyping:
390 if (TabExists(e.IM.FromAgentName))
392 RadegastTab tab = tabs[e.IM.FromAgentName.ToLower()];
393 if (!tab.Highlighted) tab.Unhighlight();
398 case InstantMessageDialog.MessageBox:
399 instance.MainForm.AddNotification(new ntfGeneric(instance, e.IM.Message));
402 case InstantMessageDialog.RequestTeleport:
403 if (instance.RLV.AutoAcceptTP(e.IM.FromAgentID))
405 DisplayNotificationInChat("Auto accepting teleprot from " + e.IM.FromAgentName);
406 instance.Client.Self.TeleportLureRespond(e.IM.FromAgentID, e.IM.IMSessionID, true);
410 instance.MainForm.AddNotification(new ntfTeleport(instance, e.IM));
414 case InstantMessageDialog.GroupInvitation:
415 instance.MainForm.AddNotification(new ntfGroupInvitation(instance, e.IM));
418 case InstantMessageDialog.FriendshipOffered:
419 if (e.IM.FromAgentName == "Second Life")
421 HandleIMFromObject(e);
425 instance.MainForm.AddNotification(new ntfFriendshipOffer(instance, e.IM));
429 case InstantMessageDialog.InventoryAccepted:
430 DisplayNotificationInChat(e.IM.FromAgentName + " accepted your inventory offer.");
433 case InstantMessageDialog.InventoryDeclined:
434 DisplayNotificationInChat(e.IM.FromAgentName + " declined your inventory offer.");
437 case InstantMessageDialog.GroupNotice:
438 // Is this group muted?
439 if (null != client.Self.MuteList.Find(me => me.Type == MuteType.Group && me.ID == e.IM.FromAgentID)) break;
441 instance.MainForm.AddNotification(new ntfGroupNotice(instance, e.IM));
444 case InstantMessageDialog.InventoryOffered:
445 var ion = new ntfInventoryOffer(instance, e.IM);
446 instance.MainForm.AddNotification(ion);
447 if (instance.GlobalSettings["inv_auto_accept_mode"].AsInteger() == 1)
449 ion.btnAccept.PerformClick();
451 else if (instance.GlobalSettings["inv_auto_accept_mode"].AsInteger() == 2)
453 ion.btnDiscard.PerformClick();
457 case InstantMessageDialog.TaskInventoryOffered:
458 // Is the object muted by name?
459 if (null != client.Self.MuteList.Find(me => me.Type == MuteType.ByName && me.Name == e.IM.FromAgentName)) break;
461 var iont = new ntfInventoryOffer(instance, e.IM);
462 instance.MainForm.AddNotification(iont);
463 if (instance.GlobalSettings["inv_auto_accept_mode"].AsInteger() == 1)
465 iont.btnAccept.PerformClick();
467 else if (instance.GlobalSettings["inv_auto_accept_mode"].AsInteger() == 2)
469 iont.btnDiscard.PerformClick();
476 /// Make default tab (chat) active
478 public void SelectDefaultTab()
480 if (IsHandleCreated && TabExists("chat"))
481 tabs["chat"].Select();
485 /// Displays notification in the main chat tab
487 /// <param name="msg">Message to be printed in the chat tab</param>
488 public void DisplayNotificationInChat(string msg)
490 DisplayNotificationInChat(msg, ChatBufferTextStyle.ObjectChat);
494 /// Displays notification in the main chat tab
496 /// <param name="msg">Message to be printed in the chat tab</param>
497 /// <param name="style">Style of the message to be printed, normal, object, etc.</param>
498 public void DisplayNotificationInChat(string msg, ChatBufferTextStyle style)
500 DisplayNotificationInChat(msg, style, true);
504 /// Displays notification in the main chat tab
506 /// <param name="msg">Message to be printed in the chat tab</param>
507 /// <param name="style">Style of the message to be printed, normal, object, etc.</param>
508 /// <param name="highlightChatTab">Highligt (and flash in taskbar) chat tab if not selected</param>
509 public void DisplayNotificationInChat(string msg, ChatBufferTextStyle style, bool highlightChatTab)
513 if (!instance.MonoRuntime || IsHandleCreated)
514 BeginInvoke(new MethodInvoker(() => DisplayNotificationInChat(msg, style, highlightChatTab)));
518 if (style != ChatBufferTextStyle.Invisible)
520 ChatBufferItem line = new ChatBufferItem(
530 mainChatManger.ProcessBufferItem(line, true);
531 if (highlightChatTab)
533 tabs["chat"].Highlight();
536 catch (Exception) { }
539 if (OnChatNotification != null)
541 try { OnChatNotification(this, new ChatNotificationEventArgs(msg, style)); }
546 private void HandleIMFromObject(InstantMessageEventArgs e)
548 // Is the object or the owner muted?
549 if (null != client.Self.MuteList.Find(m => (m.Type == MuteType.Object && m.ID == e.IM.IMSessionID) // muted object by id
550 || (m.Type == MuteType.ByName && m.Name == e.IM.FromAgentName) // object muted by name
551 || (m.Type == MuteType.Resident && m.ID == e.IM.FromAgentID) // object's owner muted
554 DisplayNotificationInChat(e.IM.FromAgentName + ": " + e.IM.Message);
557 private void HandleIM(InstantMessageEventArgs e)
559 if (TabExists(e.IM.IMSessionID.ToString()))
561 RadegastTab tab = tabs[e.IM.IMSessionID.ToString()];
562 if (!tab.Selected) tab.Highlight();
566 instance.MediaManager.PlayUISound(UISounds.IM);
568 IMTabWindow imTab = AddIMTab(e);
569 tabs[e.IM.IMSessionID.ToString()].Highlight();
572 private void HandleConferenceIM(InstantMessageEventArgs e)
574 if (TabExists(e.IM.IMSessionID.ToString()))
576 RadegastTab tab = tabs[e.IM.IMSessionID.ToString()];
577 if (!tab.Selected) tab.Highlight();
581 instance.MediaManager.PlayUISound(UISounds.IM);
583 ConferenceIMTabWindow imTab = AddConferenceIMTab(e);
584 tabs[e.IM.IMSessionID.ToString()].Highlight();
587 private void HandleGroupIM(InstantMessageEventArgs e)
589 // Ignore group IM from a muted group
590 if (null != client.Self.MuteList.Find(me => me.Type == MuteType.Group && (me.ID == e.IM.IMSessionID || me.ID == e.IM.FromAgentID))) return;
592 if (TabExists(e.IM.IMSessionID.ToString()))
594 RadegastTab tab = tabs[e.IM.IMSessionID.ToString()];
595 if (!tab.Selected) tab.Highlight();
599 instance.MediaManager.PlayUISound(UISounds.IM);
601 GroupIMTabWindow imTab = AddGroupIMTab(e);
602 tabs[e.IM.IMSessionID.ToString()].Highlight();
605 private void InitializeMainTab()
607 LoginConsole loginConsole = new LoginConsole(instance);
609 RadegastTab tab = AddTab("login", "Login", loginConsole);
610 tab.AllowClose = false;
611 tab.AllowDetach = false;
612 tab.AllowMerge = false;
613 tab.AllowHide = false;
615 loginConsole.RegisterTab(tab);
618 private void InitializeChatTab()
620 chatConsole = new ChatConsole(instance);
621 mainChatManger = chatConsole.ChatManager;
623 RadegastTab tab = AddTab("chat", "Chat", chatConsole);
624 tab.AllowClose = false;
625 tab.AllowDetach = false;
626 tab.AllowHide = false;
631 /// Create Tabs that only make sense when connected
633 private void InitializeOnlineTabs()
635 RadegastTab tab = AddTab("friends", "Friends", new FriendsConsole(instance));
636 tab.AllowClose = false;
637 tab.AllowDetach = true;
640 tab = AddTab("groups", "Groups", new GroupsConsole(instance));
641 tab.AllowClose = false;
642 tab.AllowDetach = true;
645 // Ugly workaround for a mono bug
646 InventoryConsole inv = new InventoryConsole(instance);
647 if (instance.MonoRuntime) inv.invTree.Scrollable = false;
648 tab = AddTab("inventory", "Inventory", inv);
649 if (instance.MonoRuntime) inv.invTree.Scrollable = true;
650 tab.AllowClose = false;
651 tab.AllowDetach = true;
654 tab = AddTab("search", "Search", new SearchConsole(instance));
655 tab.AllowClose = false;
656 tab.AllowDetach = true;
659 tab = AddTab("map", "Map", new MapConsole(instance));
660 tab.AllowClose = false;
661 tab.AllowDetach = true;
664 tab = AddTab("voice", "Voice", new VoiceConsole(instance));
665 tab.AllowClose = false;
666 tab.AllowDetach = true;
671 /// Close tabs that make no sense when not connected
673 private void DisposeOnlineTabs()
677 ForceCloseTab("voice");
678 ForceCloseTab("map");
679 ForceCloseTab("search");
680 ForceCloseTab("inventory");
681 ForceCloseTab("groups");
682 ForceCloseTab("friends");
686 private void ForceCloseTab(string name)
688 if (!TabExists(name)) return;
690 RadegastTab tab = tabs[name];
691 if (tab.Merged) SplitTab(tab);
693 tab.AllowClose = true;
699 public void RegisterContextAction(Type libomvType, String label, EventHandler handler)
701 instance.ContextActionManager.RegisterContextAction(libomvType, label, handler);
704 public void RegisterContextAction(ContextAction handler)
706 instance.ContextActionManager.RegisterContextAction(handler);
709 public void AddTab(RadegastTab tab)
711 ToolStripButton button = (ToolStripButton)tstTabs.Items.Add(tab.Label);
712 button.DisplayStyle = ToolStripItemDisplayStyle.ImageAndText;
714 button.AutoToolTip = false;
715 button.Tag = tab.Name;
716 button.Click += new EventHandler(TabButtonClick);
718 tabs.Add(tab.Name, tab);
720 if (OnTabAdded != null)
722 try { OnTabAdded(this, new TabEventArgs(tab)); }
723 catch (Exception) { }
727 public RadegastTab AddTab(string name, string label, Control control)
729 // WORKAROUND: one should never add tab that alrady exists
730 // but under some weird conditions disconnect/connect
731 // fire in the wrong order
734 Logger.Log("Force closing tab '" + name + "'", Helpers.LogLevel.Warning, client);
738 control.Visible = false;
739 control.Dock = DockStyle.Fill;
740 toolStripContainer1.ContentPanel.Controls.Add(control);
742 ToolStripButton button = (ToolStripButton)tstTabs.Items.Add(label);
743 button.DisplayStyle = ToolStripItemDisplayStyle.ImageAndText;
745 button.AutoToolTip = false;
746 button.Tag = name.ToLower();
747 button.AllowDrop = true;
748 button.Click += new EventHandler(TabButtonClick);
750 RadegastTab tab = new RadegastTab(instance, button, control, name.ToLower(), label);
751 if (control is RadegastTabControl)
752 ((RadegastTabControl)control).RadegastTab = tab;
753 tab.TabAttached += new EventHandler(tab_TabAttached);
754 tab.TabDetached += new EventHandler(tab_TabDetached);
755 tab.TabSelected += new EventHandler(tab_TabSelected);
756 tab.TabClosed += new EventHandler(tab_TabClosed);
757 tab.TabHidden += new EventHandler(tab_TabHidden);
758 tabs.Add(name.ToLower(), tab);
760 if (OnTabAdded != null)
762 try { OnTabAdded(this, new TabEventArgs(tab)); }
763 catch (Exception) { }
766 button.MouseDown += (msender, margs) =>
768 if (margs.Button == MouseButtons.Middle)
774 else if (tab.AllowHide)
784 private void tab_TabAttached(object sender, EventArgs e)
786 RadegastTab tab = (RadegastTab)sender;
790 private void tab_TabDetached(object sender, EventArgs e)
792 RadegastTab tab = (RadegastTab)sender;
793 frmDetachedTab form = (frmDetachedTab)tab.Owner;
795 form.ReattachStrip = tstTabs;
796 form.ReattachContainer = toolStripContainer1.ContentPanel;
799 private void tab_TabSelected(object sender, EventArgs e)
801 RadegastTab tab = (RadegastTab)sender;
803 if (selectedTab != null &&
805 { selectedTab.Deselect(); }
809 tbtnCloseTab.Enabled = !tab.Merged && (tab.AllowClose || tab.AllowHide);
813 owner.AcceptButton = tab.DefaultControlButton;
816 if (OnTabSelected != null)
818 try { OnTabSelected(this, new TabEventArgs(selectedTab)); }
819 catch (Exception) { }
823 void tab_TabHidden(object sender, EventArgs e)
825 RadegastTab tab = (RadegastTab)sender;
827 if (selectedTab != null && selectedTab == tab)
834 private void tab_TabClosed(object sender, EventArgs e)
836 RadegastTab tab = (RadegastTab)sender;
838 if (selectedTab != null && selectedTab == tab && tab.Name != "chat")
844 tabs.Remove(tab.Name);
846 if (OnTabRemoved != null)
848 try { OnTabRemoved(this, new TabEventArgs(tab)); }
849 catch (Exception) { }
855 private void TabButtonClick(object sender, EventArgs e)
857 ToolStripButton button = (ToolStripButton)sender;
859 RadegastTab tab = tabs[button.Tag.ToString()];
863 public void RemoveTabEntry(RadegastTab tab)
865 if (tstTabs.Items.Contains(tab.Button))
867 tstTabs.Items.Remove(tab.Button);
870 tab.Button.Dispose();
871 tabs.Remove(tab.Name);
874 public void RemoveTab(string name)
876 if (tabs.ContainsKey(name))
882 //Used for outside classes that have a reference to TabsConsole
883 public void SelectTab(string name)
885 if (TabExists(name.ToLower()))
886 tabs[name.ToLower()].Select();
889 public bool TabExists(string name)
891 return tabs.ContainsKey(name.ToLower());
894 public RadegastTab GetTab(string name)
896 if (TabExists(name.ToLower()))
897 return tabs[name.ToLower()];
902 public List<RadegastTab> GetOtherTabs()
904 List<RadegastTab> otherTabs = new List<RadegastTab>();
906 foreach (ToolStripItem item in tstTabs.Items)
908 if (item.Tag == null) continue;
909 if ((ToolStripItem)item == selectedTab.Button) continue;
911 RadegastTab tab = tabs[item.Tag.ToString()];
912 if (!tab.AllowMerge) continue;
913 if (tab.Merged) continue;
922 /// Activates the next tab
924 public void SelectNextTab()
926 List<ToolStripItem> buttons = new List<ToolStripItem>();
928 foreach (ToolStripItem item in tstTabs.Items)
930 if (item.Tag == null || !item.Visible) continue;
937 for (int i = 0; i < buttons.Count; i++)
939 if (buttons[i] == selectedTab.Button)
948 if (current == buttons.Count)
951 SelectTab(tabs[buttons[current].Tag.ToString()].Name);
955 /// Activates the previous tab
957 public void SelectPreviousTab()
959 List<ToolStripItem> buttons = new List<ToolStripItem>();
961 foreach (ToolStripItem item in tstTabs.Items)
963 if (item.Tag == null || !item.Visible) continue;
970 for (int i = 0; i < buttons.Count; i++)
972 if (buttons[i] == selectedTab.Button)
982 current = buttons.Count - 1;
984 SelectTab(tabs[buttons[current].Tag.ToString()].Name);
988 public IMTabWindow AddIMTab(UUID target, UUID session, string targetName)
990 IMTabWindow imTab = new IMTabWindow(instance, target, session, targetName);
992 RadegastTab tab = AddTab(session.ToString(), "IM: " + targetName, imTab);
993 imTab.SelectIMInput();
999 public ConferenceIMTabWindow AddConferenceIMTab(UUID session, string name)
1001 ConferenceIMTabWindow imTab = new ConferenceIMTabWindow(instance, session, name);
1003 RadegastTab tab = AddTab(session.ToString(), name, imTab);
1004 imTab.SelectIMInput();
1010 public ConferenceIMTabWindow AddConferenceIMTab(InstantMessageEventArgs e)
1012 ConferenceIMTabWindow imTab = AddConferenceIMTab(e.IM.IMSessionID, Utils.BytesToString(e.IM.BinaryBucket));
1013 imTab.TextManager.ProcessIM(e);
1017 public GroupIMTabWindow AddGroupIMTab(UUID session, string name)
1019 GroupIMTabWindow imTab = new GroupIMTabWindow(instance, session, name);
1021 RadegastTab tab = AddTab(session.ToString(), name, imTab);
1022 imTab.SelectIMInput();
1027 public GroupIMTabWindow AddGroupIMTab(InstantMessageEventArgs e)
1029 GroupIMTabWindow imTab = AddGroupIMTab(e.IM.IMSessionID, Utils.BytesToString(e.IM.BinaryBucket));
1030 imTab.TextManager.ProcessIM(e);
1034 public IMTabWindow AddIMTab(InstantMessageEventArgs e)
1036 IMTabWindow imTab = AddIMTab(e.IM.FromAgentID, e.IM.IMSessionID, e.IM.FromAgentName);
1037 imTab.TextManager.ProcessIM(e);
1041 public OutfitTextures AddOTTab(Avatar avatar)
1043 OutfitTextures otTab = new OutfitTextures(instance, avatar);
1045 RadegastTab tab = AddTab("OT: " + avatar.Name, "OT: " + avatar.Name, otTab);
1046 otTab.GetTextures();
1050 public MasterTab AddMSTab(Avatar avatar)
1052 MasterTab msTab = new MasterTab(instance, avatar);
1054 RadegastTab tab = AddTab("MS: " + avatar.Name, "MS: " + avatar.Name, msTab);
1058 public AnimTab AddAnimTab(Avatar avatar)
1060 AnimTab animTab = new AnimTab(instance, avatar);
1062 RadegastTab tab = AddTab("Anim: " + avatar.Name, "Anim: " + avatar.Name, animTab);
1066 private void tbtnTabOptions_Click(object sender, EventArgs e)
1068 tmnuMergeWith.Enabled = selectedTab.AllowMerge;
1069 tmnuDetachTab.Enabled = selectedTab.AllowDetach;
1071 tmnuMergeWith.DropDown.Items.Clear();
1073 if (!selectedTab.AllowMerge) return;
1074 if (!selectedTab.Merged)
1076 tmnuMergeWith.Text = "Merge With";
1078 List<RadegastTab> otherTabs = GetOtherTabs();
1080 tmnuMergeWith.Enabled = (otherTabs.Count > 0);
1081 if (!tmnuMergeWith.Enabled) return;
1083 foreach (RadegastTab tab in otherTabs)
1085 ToolStripItem item = tmnuMergeWith.DropDown.Items.Add(tab.Label);
1086 item.Tag = tab.Name;
1087 item.Click += new EventHandler(MergeItemClick);
1092 tmnuMergeWith.Text = "Split";
1093 tmnuMergeWith.Click += new EventHandler(SplitClick);
1097 private void MergeItemClick(object sender, EventArgs e)
1099 ToolStripItem item = (ToolStripItem)sender;
1100 RadegastTab tab = tabs[item.Tag.ToString()];
1102 selectedTab.MergeWith(tab);
1104 SplitContainer container = (SplitContainer)selectedTab.Control;
1105 toolStripContainer1.ContentPanel.Controls.Add(container);
1107 selectedTab.Select();
1108 RemoveTabEntry(tab);
1110 tabs.Add(tab.Name, selectedTab);
1113 private void SplitClick(object sender, EventArgs e)
1115 SplitTab(selectedTab);
1116 selectedTab.Select();
1119 public void SplitTab(RadegastTab tab)
1121 RadegastTab otherTab = tab.Split();
1122 if (otherTab == null) return;
1124 toolStripContainer1.ContentPanel.Controls.Add(tab.Control);
1125 toolStripContainer1.ContentPanel.Controls.Add(otherTab.Control);
1127 tabs.Remove(otherTab.Name);
1131 private void tmnuDetachTab_Click(object sender, EventArgs e)
1133 if (!selectedTab.AllowDetach) return;
1134 RadegastTab tab = selectedTab;
1136 tab.Detach(instance);
1139 private void tbtnCloseTab_Click(object sender, EventArgs e)
1141 RadegastTab tab = selectedTab;
1144 else if (tab.AllowClose)
1146 else if (tab.AllowHide)
1150 private void TabsConsole_Load(object sender, EventArgs e)
1152 owner = this.FindForm();
1155 private void ctxTabs_Opening(object sender, CancelEventArgs e)
1159 Point pt = this.PointToClient(Cursor.Position);
1160 ToolStripItem stripItem = tstTabs.GetItemAt(pt);
1162 if (stripItem == null)
1168 tabs[stripItem.Tag.ToString()].Select();
1170 ctxBtnClose.Enabled = !selectedTab.Merged && (selectedTab.AllowClose || selectedTab.AllowHide);
1171 ctxBtnDetach.Enabled = selectedTab.AllowDetach;
1172 ctxBtnMerge.Enabled = selectedTab.AllowMerge;
1173 ctxBtnMerge.DropDown.Items.Clear();
1175 if (!ctxBtnClose.Enabled && !ctxBtnDetach.Enabled && !ctxBtnMerge.Enabled)
1181 if (!selectedTab.AllowMerge) return;
1182 if (!selectedTab.Merged)
1184 ctxBtnMerge.Text = "Merge With";
1186 List<RadegastTab> otherTabs = GetOtherTabs();
1188 ctxBtnMerge.Enabled = (otherTabs.Count > 0);
1189 if (!ctxBtnMerge.Enabled) return;
1191 foreach (RadegastTab tab in otherTabs)
1193 ToolStripItem item = ctxBtnMerge.DropDown.Items.Add(tab.Label);
1194 item.Tag = tab.Name;
1195 item.Click += new EventHandler(MergeItemClick);
1200 ctxBtnMerge.Text = "Split";
1201 ctxBtnMerge.Click += new EventHandler(SplitClick);
1210 /// Arguments for tab events
1212 public class TabEventArgs : EventArgs
1215 /// Tab that was manipulated in the event
1217 public RadegastTab Tab;
1219 public TabEventArgs()
1224 public TabEventArgs(RadegastTab tab)
1232 /// Argument for chat notification events
1234 public class ChatNotificationEventArgs : EventArgs
1236 public string Message;
1237 public ChatBufferTextStyle Style;
1239 public ChatNotificationEventArgs(string message, ChatBufferTextStyle style)
1247 /// Element of list of nearby avatars
1249 public class NearbyAvatar
1251 public UUID ID { get; set; }
1252 public string Name { get; set; }