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 instance.MainForm.AddNotification(new ntfInventoryOffer(instance, e.IM));
448 case InstantMessageDialog.TaskInventoryOffered:
449 // Is the object muted by name?
450 if (null != client.Self.MuteList.Find(me => me.Type == MuteType.ByName && me.Name == e.IM.FromAgentName)) break;
452 instance.MainForm.AddNotification(new ntfInventoryOffer(instance, e.IM));
458 /// Make default tab (chat) active
460 public void SelectDefaultTab()
462 if (IsHandleCreated && TabExists("chat"))
463 tabs["chat"].Select();
467 /// Displays notification in the main chat tab
469 /// <param name="msg">Message to be printed in the chat tab</param>
470 public void DisplayNotificationInChat(string msg)
472 DisplayNotificationInChat(msg, ChatBufferTextStyle.ObjectChat);
476 /// Displays notification in the main chat tab
478 /// <param name="msg">Message to be printed in the chat tab</param>
479 /// <param name="style">Style of the message to be printed, normal, object, etc.</param>
480 public void DisplayNotificationInChat(string msg, ChatBufferTextStyle style)
482 DisplayNotificationInChat(msg, style, true);
486 /// Displays notification in the main chat tab
488 /// <param name="msg">Message to be printed in the chat tab</param>
489 /// <param name="style">Style of the message to be printed, normal, object, etc.</param>
490 /// <param name="highlightChatTab">Highligt (and flash in taskbar) chat tab if not selected</param>
491 public void DisplayNotificationInChat(string msg, ChatBufferTextStyle style, bool highlightChatTab)
495 if (!instance.MonoRuntime || IsHandleCreated)
496 BeginInvoke(new MethodInvoker(() => DisplayNotificationInChat(msg, style, highlightChatTab)));
500 if (style != ChatBufferTextStyle.Invisible)
502 ChatBufferItem line = new ChatBufferItem(
512 mainChatManger.ProcessBufferItem(line, true);
513 if (highlightChatTab)
515 tabs["chat"].Highlight();
518 catch (Exception) { }
521 if (OnChatNotification != null)
523 try { OnChatNotification(this, new ChatNotificationEventArgs(msg, style)); }
528 private void HandleIMFromObject(InstantMessageEventArgs e)
530 // Is the object or the owner muted?
531 if (null != client.Self.MuteList.Find(m => (m.Type == MuteType.Object && m.ID == e.IM.IMSessionID) // muted object by id
532 || (m.Type == MuteType.ByName && m.Name == e.IM.FromAgentName) // object muted by name
533 || (m.Type == MuteType.Resident && m.ID == e.IM.FromAgentID) // object's owner muted
536 DisplayNotificationInChat(e.IM.FromAgentName + ": " + e.IM.Message);
539 private void HandleIM(InstantMessageEventArgs e)
541 if (TabExists(e.IM.IMSessionID.ToString()))
543 RadegastTab tab = tabs[e.IM.IMSessionID.ToString()];
544 if (!tab.Selected) tab.Highlight();
548 instance.MediaManager.PlayUISound(UISounds.IM);
550 IMTabWindow imTab = AddIMTab(e);
551 tabs[e.IM.IMSessionID.ToString()].Highlight();
554 private void HandleConferenceIM(InstantMessageEventArgs e)
556 if (TabExists(e.IM.IMSessionID.ToString()))
558 RadegastTab tab = tabs[e.IM.IMSessionID.ToString()];
559 if (!tab.Selected) tab.Highlight();
563 instance.MediaManager.PlayUISound(UISounds.IM);
565 ConferenceIMTabWindow imTab = AddConferenceIMTab(e);
566 tabs[e.IM.IMSessionID.ToString()].Highlight();
569 private void HandleGroupIM(InstantMessageEventArgs e)
571 // Ignore group IM from a muted group
572 if (null != client.Self.MuteList.Find(me => me.Type == MuteType.Group && (me.ID == e.IM.IMSessionID || me.ID == e.IM.FromAgentID))) return;
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 GroupIMTabWindow imTab = AddGroupIMTab(e);
584 tabs[e.IM.IMSessionID.ToString()].Highlight();
587 private void InitializeMainTab()
589 LoginConsole loginConsole = new LoginConsole(instance);
591 RadegastTab tab = AddTab("login", "Login", loginConsole);
592 tab.AllowClose = false;
593 tab.AllowDetach = false;
594 tab.AllowMerge = false;
595 tab.AllowHide = false;
597 loginConsole.RegisterTab(tab);
600 private void InitializeChatTab()
602 chatConsole = new ChatConsole(instance);
603 mainChatManger = chatConsole.ChatManager;
605 RadegastTab tab = AddTab("chat", "Chat", chatConsole);
606 tab.AllowClose = false;
607 tab.AllowDetach = false;
608 tab.AllowHide = false;
613 /// Create Tabs that only make sense when connected
615 private void InitializeOnlineTabs()
617 RadegastTab tab = AddTab("friends", "Friends", new FriendsConsole(instance));
618 tab.AllowClose = false;
619 tab.AllowDetach = true;
622 tab = AddTab("groups", "Groups", new GroupsConsole(instance));
623 tab.AllowClose = false;
624 tab.AllowDetach = true;
627 // Ugly workaround for a mono bug
628 InventoryConsole inv = new InventoryConsole(instance);
629 if (instance.MonoRuntime) inv.invTree.Scrollable = false;
630 tab = AddTab("inventory", "Inventory", inv);
631 if (instance.MonoRuntime) inv.invTree.Scrollable = true;
632 tab.AllowClose = false;
633 tab.AllowDetach = true;
636 tab = AddTab("search", "Search", new SearchConsole(instance));
637 tab.AllowClose = false;
638 tab.AllowDetach = true;
641 tab = AddTab("map", "Map", new MapConsole(instance));
642 tab.AllowClose = false;
643 tab.AllowDetach = true;
646 tab = AddTab("voice", "Voice", new VoiceConsole(instance));
647 tab.AllowClose = false;
648 tab.AllowDetach = true;
653 /// Close tabs that make no sense when not connected
655 private void DisposeOnlineTabs()
659 ForceCloseTab("voice");
660 ForceCloseTab("map");
661 ForceCloseTab("search");
662 ForceCloseTab("inventory");
663 ForceCloseTab("groups");
664 ForceCloseTab("friends");
668 private void ForceCloseTab(string name)
670 if (!TabExists(name)) return;
672 RadegastTab tab = tabs[name];
673 if (tab.Merged) SplitTab(tab);
675 tab.AllowClose = true;
681 public void RegisterContextAction(Type libomvType, String label, EventHandler handler)
683 instance.ContextActionManager.RegisterContextAction(libomvType, label, handler);
686 public void RegisterContextAction(ContextAction handler)
688 instance.ContextActionManager.RegisterContextAction(handler);
691 public void AddTab(RadegastTab tab)
693 ToolStripButton button = (ToolStripButton)tstTabs.Items.Add(tab.Label);
694 button.DisplayStyle = ToolStripItemDisplayStyle.ImageAndText;
696 button.AutoToolTip = false;
697 button.Tag = tab.Name;
698 button.Click += new EventHandler(TabButtonClick);
700 tabs.Add(tab.Name, tab);
702 if (OnTabAdded != null)
704 try { OnTabAdded(this, new TabEventArgs(tab)); }
705 catch (Exception) { }
709 public RadegastTab AddTab(string name, string label, Control control)
711 // WORKAROUND: one should never add tab that alrady exists
712 // but under some weird conditions disconnect/connect
713 // fire in the wrong order
716 Logger.Log("Force closing tab '" + name + "'", Helpers.LogLevel.Warning, client);
720 control.Visible = false;
721 control.Dock = DockStyle.Fill;
722 toolStripContainer1.ContentPanel.Controls.Add(control);
724 ToolStripButton button = (ToolStripButton)tstTabs.Items.Add(label);
725 button.DisplayStyle = ToolStripItemDisplayStyle.ImageAndText;
727 button.AutoToolTip = false;
728 button.Tag = name.ToLower();
729 button.AllowDrop = true;
730 button.Click += new EventHandler(TabButtonClick);
732 RadegastTab tab = new RadegastTab(instance, button, control, name.ToLower(), label);
733 if (control is RadegastTabControl)
734 ((RadegastTabControl)control).RadegastTab = tab;
735 tab.TabAttached += new EventHandler(tab_TabAttached);
736 tab.TabDetached += new EventHandler(tab_TabDetached);
737 tab.TabSelected += new EventHandler(tab_TabSelected);
738 tab.TabClosed += new EventHandler(tab_TabClosed);
739 tab.TabHidden += new EventHandler(tab_TabHidden);
740 tabs.Add(name.ToLower(), tab);
742 if (OnTabAdded != null)
744 try { OnTabAdded(this, new TabEventArgs(tab)); }
745 catch (Exception) { }
748 button.MouseDown += (msender, margs) =>
750 if (margs.Button == MouseButtons.Middle)
756 else if (tab.AllowHide)
766 private void tab_TabAttached(object sender, EventArgs e)
768 RadegastTab tab = (RadegastTab)sender;
772 private void tab_TabDetached(object sender, EventArgs e)
774 RadegastTab tab = (RadegastTab)sender;
775 frmDetachedTab form = (frmDetachedTab)tab.Owner;
777 form.ReattachStrip = tstTabs;
778 form.ReattachContainer = toolStripContainer1.ContentPanel;
781 private void tab_TabSelected(object sender, EventArgs e)
783 RadegastTab tab = (RadegastTab)sender;
785 if (selectedTab != null &&
787 { selectedTab.Deselect(); }
791 tbtnCloseTab.Enabled = tab.AllowClose || tab.AllowHide;
795 owner.AcceptButton = tab.DefaultControlButton;
798 if (OnTabSelected != null)
800 try { OnTabSelected(this, new TabEventArgs(selectedTab)); }
801 catch (Exception) { }
805 void tab_TabHidden(object sender, EventArgs e)
807 RadegastTab tab = (RadegastTab)sender;
809 if (selectedTab != null && selectedTab == tab)
816 private void tab_TabClosed(object sender, EventArgs e)
818 RadegastTab tab = (RadegastTab)sender;
820 if (selectedTab != null && selectedTab == tab && tab.Name != "chat")
826 tabs.Remove(tab.Name);
828 if (OnTabRemoved != null)
830 try { OnTabRemoved(this, new TabEventArgs(tab)); }
831 catch (Exception) { }
837 private void TabButtonClick(object sender, EventArgs e)
839 ToolStripButton button = (ToolStripButton)sender;
841 RadegastTab tab = tabs[button.Tag.ToString()];
845 public void RemoveTabEntry(RadegastTab tab)
847 if (tstTabs.Items.Contains(tab.Button))
849 tstTabs.Items.Remove(tab.Button);
852 tab.Button.Dispose();
853 tabs.Remove(tab.Name);
856 public void RemoveTab(string name)
858 if (tabs.ContainsKey(name))
864 //Used for outside classes that have a reference to TabsConsole
865 public void SelectTab(string name)
867 if (TabExists(name.ToLower()))
868 tabs[name.ToLower()].Select();
871 public bool TabExists(string name)
873 return tabs.ContainsKey(name.ToLower());
876 public RadegastTab GetTab(string name)
878 if (TabExists(name.ToLower()))
879 return tabs[name.ToLower()];
884 public List<RadegastTab> GetOtherTabs()
886 List<RadegastTab> otherTabs = new List<RadegastTab>();
888 foreach (ToolStripItem item in tstTabs.Items)
890 if (item.Tag == null) continue;
891 if ((ToolStripItem)item == selectedTab.Button) continue;
893 RadegastTab tab = tabs[item.Tag.ToString()];
894 if (!tab.AllowMerge) continue;
895 if (tab.Merged) continue;
904 /// Activates the next tab
906 public void SelectNextTab()
908 List<ToolStripItem> buttons = new List<ToolStripItem>();
910 foreach (ToolStripItem item in tstTabs.Items)
912 if (item.Tag == null || !item.Visible) continue;
919 for (int i = 0; i < buttons.Count; i++)
921 if (buttons[i] == selectedTab.Button)
930 if (current == buttons.Count)
933 SelectTab(tabs[buttons[current].Tag.ToString()].Name);
937 /// Activates the previous tab
939 public void SelectPreviousTab()
941 List<ToolStripItem> buttons = new List<ToolStripItem>();
943 foreach (ToolStripItem item in tstTabs.Items)
945 if (item.Tag == null || !item.Visible) continue;
952 for (int i = 0; i < buttons.Count; i++)
954 if (buttons[i] == selectedTab.Button)
964 current = buttons.Count - 1;
966 SelectTab(tabs[buttons[current].Tag.ToString()].Name);
970 public IMTabWindow AddIMTab(UUID target, UUID session, string targetName)
972 IMTabWindow imTab = new IMTabWindow(instance, target, session, targetName);
974 RadegastTab tab = AddTab(session.ToString(), "IM: " + targetName, imTab);
975 imTab.SelectIMInput();
981 public ConferenceIMTabWindow AddConferenceIMTab(UUID session, string name)
983 ConferenceIMTabWindow imTab = new ConferenceIMTabWindow(instance, session, name);
985 RadegastTab tab = AddTab(session.ToString(), name, imTab);
986 imTab.SelectIMInput();
992 public ConferenceIMTabWindow AddConferenceIMTab(InstantMessageEventArgs e)
994 ConferenceIMTabWindow imTab = AddConferenceIMTab(e.IM.IMSessionID, Utils.BytesToString(e.IM.BinaryBucket));
995 imTab.TextManager.ProcessIM(e);
999 public GroupIMTabWindow AddGroupIMTab(UUID session, string name)
1001 GroupIMTabWindow imTab = new GroupIMTabWindow(instance, session, name);
1003 RadegastTab tab = AddTab(session.ToString(), name, imTab);
1004 imTab.SelectIMInput();
1009 public GroupIMTabWindow AddGroupIMTab(InstantMessageEventArgs e)
1011 GroupIMTabWindow imTab = AddGroupIMTab(e.IM.IMSessionID, Utils.BytesToString(e.IM.BinaryBucket));
1012 imTab.TextManager.ProcessIM(e);
1016 public IMTabWindow AddIMTab(InstantMessageEventArgs e)
1018 IMTabWindow imTab = AddIMTab(e.IM.FromAgentID, e.IM.IMSessionID, e.IM.FromAgentName);
1019 imTab.TextManager.ProcessIM(e);
1023 public OutfitTextures AddOTTab(Avatar avatar)
1025 OutfitTextures otTab = new OutfitTextures(instance, avatar);
1027 RadegastTab tab = AddTab("OT: " + avatar.Name, "OT: " + avatar.Name, otTab);
1028 otTab.GetTextures();
1032 public MasterTab AddMSTab(Avatar avatar)
1034 MasterTab msTab = new MasterTab(instance, avatar);
1036 RadegastTab tab = AddTab("MS: " + avatar.Name, "MS: " + avatar.Name, msTab);
1040 public AnimTab AddAnimTab(Avatar avatar)
1042 AnimTab animTab = new AnimTab(instance, avatar);
1044 RadegastTab tab = AddTab("Anim: " + avatar.Name, "Anim: " + avatar.Name, animTab);
1048 private void tbtnTabOptions_Click(object sender, EventArgs e)
1050 tmnuMergeWith.Enabled = selectedTab.AllowMerge;
1051 tmnuDetachTab.Enabled = selectedTab.AllowDetach;
1053 tmnuMergeWith.DropDown.Items.Clear();
1055 if (!selectedTab.AllowMerge) return;
1056 if (!selectedTab.Merged)
1058 tmnuMergeWith.Text = "Merge With";
1060 List<RadegastTab> otherTabs = GetOtherTabs();
1062 tmnuMergeWith.Enabled = (otherTabs.Count > 0);
1063 if (!tmnuMergeWith.Enabled) return;
1065 foreach (RadegastTab tab in otherTabs)
1067 ToolStripItem item = tmnuMergeWith.DropDown.Items.Add(tab.Label);
1068 item.Tag = tab.Name;
1069 item.Click += new EventHandler(MergeItemClick);
1074 tmnuMergeWith.Text = "Split";
1075 tmnuMergeWith.Click += new EventHandler(SplitClick);
1079 private void MergeItemClick(object sender, EventArgs e)
1081 ToolStripItem item = (ToolStripItem)sender;
1082 RadegastTab tab = tabs[item.Tag.ToString()];
1084 selectedTab.MergeWith(tab);
1086 SplitContainer container = (SplitContainer)selectedTab.Control;
1087 toolStripContainer1.ContentPanel.Controls.Add(container);
1089 selectedTab.Select();
1090 RemoveTabEntry(tab);
1092 tabs.Add(tab.Name, selectedTab);
1095 private void SplitClick(object sender, EventArgs e)
1097 SplitTab(selectedTab);
1098 selectedTab.Select();
1101 public void SplitTab(RadegastTab tab)
1103 RadegastTab otherTab = tab.Split();
1104 if (otherTab == null) return;
1106 toolStripContainer1.ContentPanel.Controls.Add(tab.Control);
1107 toolStripContainer1.ContentPanel.Controls.Add(otherTab.Control);
1109 tabs.Remove(otherTab.Name);
1113 private void tmnuDetachTab_Click(object sender, EventArgs e)
1115 if (!selectedTab.AllowDetach) return;
1116 RadegastTab tab = selectedTab;
1118 tab.Detach(instance);
1121 private void tbtnCloseTab_Click(object sender, EventArgs e)
1123 RadegastTab tab = selectedTab;
1126 else if (tab.AllowHide)
1130 private void TabsConsole_Load(object sender, EventArgs e)
1132 owner = this.FindForm();
1135 private void ctxTabs_Opening(object sender, CancelEventArgs e)
1139 Point pt = this.PointToClient(Cursor.Position);
1140 ToolStripItem stripItem = tstTabs.GetItemAt(pt);
1142 if (stripItem == null)
1148 tabs[stripItem.Tag.ToString()].Select();
1150 ctxBtnClose.Enabled = !selectedTab.Merged && (selectedTab.AllowClose || selectedTab.AllowHide);
1151 ctxBtnDetach.Enabled = selectedTab.AllowDetach;
1152 ctxBtnMerge.Enabled = selectedTab.AllowMerge;
1153 ctxBtnMerge.DropDown.Items.Clear();
1155 if (!ctxBtnClose.Enabled && !ctxBtnDetach.Enabled && !ctxBtnMerge.Enabled)
1161 if (!selectedTab.AllowMerge) return;
1162 if (!selectedTab.Merged)
1164 ctxBtnMerge.Text = "Merge With";
1166 List<RadegastTab> otherTabs = GetOtherTabs();
1168 ctxBtnMerge.Enabled = (otherTabs.Count > 0);
1169 if (!ctxBtnMerge.Enabled) return;
1171 foreach (RadegastTab tab in otherTabs)
1173 ToolStripItem item = ctxBtnMerge.DropDown.Items.Add(tab.Label);
1174 item.Tag = tab.Name;
1175 item.Click += new EventHandler(MergeItemClick);
1180 ctxBtnMerge.Text = "Split";
1181 ctxBtnMerge.Click += new EventHandler(SplitClick);
1190 /// Arguments for tab events
1192 public class TabEventArgs : EventArgs
1195 /// Tab that was manipulated in the event
1197 public RadegastTab Tab;
1199 public TabEventArgs()
1204 public TabEventArgs(RadegastTab tab)
1212 /// Argument for chat notification events
1214 public class ChatNotificationEventArgs : EventArgs
1216 public string Message;
1217 public ChatBufferTextStyle Style;
1219 public ChatNotificationEventArgs(string message, ChatBufferTextStyle style)
1227 /// Element of list of nearby avatars
1229 public class NearbyAvatar
1231 public UUID ID { get; set; }
1232 public string Name { get; set; }