2 // Radegast Metaverse Client
3 // Copyright (c) 2009-2013, 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 if (instance.MainForm.InvokeRequired)
245 instance.MainForm.BeginInvoke(new MethodInvoker(() => Self_ScriptDialog(sender, e)));
249 // Is this object muted
250 if (null != client.Self.MuteList.Find(m => (m.Type == MuteType.Object && m.ID == e.ObjectID) // muted object by id
251 || (m.Type == MuteType.ByName && m.Name == e.ObjectName) // object muted by name
254 instance.MainForm.AddNotification(new ntfScriptDialog(instance, e.Message, e.ObjectName, e.ImageID, e.ObjectID, e.FirstName, e.LastName, e.Channel, e.ButtonLabels));
257 void Self_ScriptQuestion(object sender, ScriptQuestionEventArgs e)
259 // Is this object muted
260 if (null != client.Self.MuteList.Find(m => (m.Type == MuteType.Object && m.ID == e.TaskID) // muted object by id
261 || (m.Type == MuteType.ByName && m.Name == e.ObjectName) // object muted by name
264 instance.MainForm.AddNotification(new ntfPermissions(instance, e.Simulator, e.TaskID, e.ItemID, e.ObjectName, e.ObjectOwnerName, e.Questions));
267 private void netcom_ClientLoginStatus(object sender, LoginProgressEventArgs e)
269 if (e.Status == LoginStatus.Failed)
271 DisplayNotificationInChat("Login error: " + e.Message, ChatBufferTextStyle.Error);
273 else if (e.Status == LoginStatus.Success)
275 DisplayNotificationInChat("Logged in as " + netcom.LoginOptions.FullName + ".", ChatBufferTextStyle.StatusDarkBlue);
276 DisplayNotificationInChat("Login reply: " + e.Message, ChatBufferTextStyle.StatusDarkBlue);
278 if (tabs.ContainsKey("login"))
280 if (selectedTab.Name == "login")
282 ForceCloseTab("login");
285 client.Self.RetrieveInstantMessages();
289 private void netcom_ClientLoggedOut(object sender, EventArgs e)
294 DisplayNotificationInChat("Logged out.");
298 private void netcom_ClientDisconnected(object sender, DisconnectedEventArgs e)
300 if (e.Reason == NetworkManager.DisconnectType.ClientInitiated) return;
304 DisplayNotificationInChat("Disconnected: " + e.Message, ChatBufferTextStyle.Error);
307 void Avatars_DisplayNameUpdate(object sender, DisplayNameUpdateEventArgs e)
309 DisplayNotificationInChat(string.Format("({0}) is now known as {1}", e.DisplayName.UserName, e.DisplayName.DisplayName));
312 void Self_SetDisplayNameReply(object sender, SetDisplayNameReplyEventArgs e)
316 DisplayNotificationInChat("You are now knows as " + e.DisplayName.DisplayName);
320 DisplayNotificationInChat("Failed to set a new display name: " + e.Reason, ChatBufferTextStyle.Error);
324 private void netcom_AlertMessageReceived(object sender, AlertMessageEventArgs e)
326 tabs["chat"].Highlight();
329 private void netcom_ChatSent(object sender, ChatSentEventArgs e)
331 tabs["chat"].Highlight();
334 void Self_LoadURL(object sender, LoadUrlEventArgs e)
336 // Is the object or the owner muted?
337 if (null != client.Self.MuteList.Find(m => (m.Type == MuteType.Object && m.ID == e.ObjectID) // muted object by id
338 || (m.Type == MuteType.ByName && m.Name == e.ObjectName) // object muted by name
339 || (m.Type == MuteType.Resident && m.ID == e.OwnerID) // object's owner muted
342 instance.MainForm.AddNotification(new ntfLoadURL(instance, e));
345 private void netcom_InstantMessageReceived(object sender, InstantMessageEventArgs e)
347 // Messaage from someone we muted?
348 if (null != client.Self.MuteList.Find(me => me.Type == MuteType.Resident && me.ID == e.IM.FromAgentID)) return;
350 if (instance.State.LSLHelper.ProcessIM(e))
357 case InstantMessageDialog.SessionSend:
358 if (instance.Groups.ContainsKey(e.IM.IMSessionID))
364 HandleConferenceIM(e);
368 case InstantMessageDialog.MessageFromAgent:
369 if (e.IM.FromAgentName == "Second Life")
371 HandleIMFromObject(e);
373 else if (e.IM.FromAgentID == UUID.Zero)
375 instance.MainForm.AddNotification(new ntfGeneric(instance, e.IM.Message));
377 else if (e.IM.GroupIM || instance.Groups.ContainsKey(e.IM.IMSessionID))
381 else if (e.IM.BinaryBucket.Length > 1)
383 HandleConferenceIM(e);
385 else if (e.IM.IMSessionID == UUID.Zero)
387 String msg = string.Format("Region message from {0}: {1}", instance.Names.Get(e.IM.FromAgentID, e.IM.FromAgentName), e.IM.Message);
388 instance.MainForm.AddNotification(new ntfGeneric(instance, msg));
389 DisplayNotificationInChat(msg);
397 case InstantMessageDialog.MessageFromObject:
398 HandleIMFromObject(e);
401 case InstantMessageDialog.StartTyping:
402 if (TabExists(e.IM.FromAgentName))
404 RadegastTab tab = tabs[e.IM.FromAgentName.ToLower()];
405 if (!tab.Highlighted) tab.PartialHighlight();
410 case InstantMessageDialog.StopTyping:
411 if (TabExists(e.IM.FromAgentName))
413 RadegastTab tab = tabs[e.IM.FromAgentName.ToLower()];
414 if (!tab.Highlighted) tab.Unhighlight();
419 case InstantMessageDialog.MessageBox:
420 instance.MainForm.AddNotification(new ntfGeneric(instance, e.IM.Message));
423 case InstantMessageDialog.RequestTeleport:
424 if (instance.RLV.AutoAcceptTP(e.IM.FromAgentID))
426 DisplayNotificationInChat("Auto accepting teleprot from " + e.IM.FromAgentName);
427 instance.Client.Self.TeleportLureRespond(e.IM.FromAgentID, e.IM.IMSessionID, true);
431 instance.MainForm.AddNotification(new ntfTeleport(instance, e.IM));
435 case InstantMessageDialog.RequestLure:
436 instance.MainForm.AddNotification(new ntfRequestLure(instance, e.IM));
439 case InstantMessageDialog.GroupInvitation:
440 instance.MainForm.AddNotification(new ntfGroupInvitation(instance, e.IM));
443 case InstantMessageDialog.FriendshipOffered:
444 if (e.IM.FromAgentName == "Second Life")
446 HandleIMFromObject(e);
450 instance.MainForm.AddNotification(new ntfFriendshipOffer(instance, e.IM));
454 case InstantMessageDialog.InventoryAccepted:
455 DisplayNotificationInChat(e.IM.FromAgentName + " accepted your inventory offer.");
458 case InstantMessageDialog.InventoryDeclined:
459 DisplayNotificationInChat(e.IM.FromAgentName + " declined your inventory offer.");
462 case InstantMessageDialog.GroupNotice:
463 // Is this group muted?
464 if (null != client.Self.MuteList.Find(me => me.Type == MuteType.Group && me.ID == e.IM.FromAgentID)) break;
466 instance.MainForm.AddNotification(new ntfGroupNotice(instance, e.IM));
469 case InstantMessageDialog.InventoryOffered:
470 var ion = new ntfInventoryOffer(instance, e.IM);
471 instance.MainForm.AddNotification(ion);
472 if (instance.GlobalSettings["inv_auto_accept_mode"].AsInteger() == 1)
474 ion.btnAccept.PerformClick();
476 else if (instance.GlobalSettings["inv_auto_accept_mode"].AsInteger() == 2)
478 ion.btnDiscard.PerformClick();
482 case InstantMessageDialog.TaskInventoryOffered:
483 // Is the object muted by name?
484 if (null != client.Self.MuteList.Find(me => me.Type == MuteType.ByName && me.Name == e.IM.FromAgentName)) break;
486 var iont = new ntfInventoryOffer(instance, e.IM);
487 instance.MainForm.AddNotification(iont);
488 if (instance.GlobalSettings["inv_auto_accept_mode"].AsInteger() == 1)
490 iont.btnAccept.PerformClick();
492 else if (instance.GlobalSettings["inv_auto_accept_mode"].AsInteger() == 2)
494 iont.btnDiscard.PerformClick();
501 /// Make default tab (chat) active
503 public void SelectDefaultTab()
505 if (IsHandleCreated && TabExists("chat"))
506 tabs["chat"].Select();
510 /// Displays notification in the main chat tab
512 /// <param name="msg">Message to be printed in the chat tab</param>
513 public void DisplayNotificationInChat(string msg)
515 DisplayNotificationInChat(msg, ChatBufferTextStyle.ObjectChat);
519 /// Displays notification in the main chat tab
521 /// <param name="msg">Message to be printed in the chat tab</param>
522 /// <param name="style">Style of the message to be printed, normal, object, etc.</param>
523 public void DisplayNotificationInChat(string msg, ChatBufferTextStyle style)
525 DisplayNotificationInChat(msg, style, true);
529 /// Displays notification in the main chat tab
531 /// <param name="msg">Message to be printed in the chat tab</param>
532 /// <param name="style">Style of the message to be printed, normal, object, etc.</param>
533 /// <param name="highlightChatTab">Highligt (and flash in taskbar) chat tab if not selected</param>
534 public void DisplayNotificationInChat(string msg, ChatBufferTextStyle style, bool highlightChatTab)
538 if (!instance.MonoRuntime || IsHandleCreated)
539 BeginInvoke(new MethodInvoker(() => DisplayNotificationInChat(msg, style, highlightChatTab)));
543 if (style != ChatBufferTextStyle.Invisible)
545 ChatBufferItem line = new ChatBufferItem(
555 mainChatManger.ProcessBufferItem(line, true);
556 if (highlightChatTab)
558 tabs["chat"].Highlight();
561 catch (Exception) { }
564 if (OnChatNotification != null)
566 try { OnChatNotification(this, new ChatNotificationEventArgs(msg, style)); }
571 private void HandleIMFromObject(InstantMessageEventArgs e)
573 // Is the object or the owner muted?
574 if (null != client.Self.MuteList.Find(m => (m.Type == MuteType.Object && m.ID == e.IM.IMSessionID) // muted object by id
575 || (m.Type == MuteType.ByName && m.Name == e.IM.FromAgentName) // object muted by name
576 || (m.Type == MuteType.Resident && m.ID == e.IM.FromAgentID) // object's owner muted
579 DisplayNotificationInChat(e.IM.FromAgentName + ": " + e.IM.Message);
582 public static Control FindFocusedControl(Control control)
584 var container = control as ContainerControl;
585 while (container != null)
587 control = container.ActiveControl;
588 container = control as ContainerControl;
594 /// Creates new IM tab if needed
596 /// <param name="agentID">IM session with agentID</param>
597 /// <param name="label">Tab label</param>
598 /// <param name="makeActive">Should tab be selected and focused</param>
599 /// <returns>True if there was an existing IM tab, false if it was created</returns>
600 public bool ShowIMTab(UUID agentID, string label, bool makeActive)
602 if (instance.TabConsole.TabExists((client.Self.AgentID ^ agentID).ToString()))
606 instance.TabConsole.SelectTab((client.Self.AgentID ^ agentID).ToString());
613 instance.MediaManager.PlayUISound(UISounds.IMWindow);
617 instance.MediaManager.PlayUISound(UISounds.IM);
620 Control active = FindFocusedControl(instance.MainForm);
622 instance.TabConsole.AddIMTab(agentID, client.Self.AgentID ^ agentID, label);
626 instance.TabConsole.SelectTab((client.Self.AgentID ^ agentID).ToString());
628 else if (active != null)
636 private void HandleIM(InstantMessageEventArgs e)
638 bool isNew = ShowIMTab(e.IM.FromAgentID, e.IM.FromAgentName, false);
639 if (!TabExists(e.IM.IMSessionID.ToString())) return; // this should now exist. sanity check anyway
640 RadegastTab tab = tabs[e.IM.IMSessionID.ToString()];
645 ((IMTabWindow)tab.Control).TextManager.ProcessIM(e);
649 private void HandleConferenceIM(InstantMessageEventArgs e)
651 if (TabExists(e.IM.IMSessionID.ToString()))
653 RadegastTab tab = tabs[e.IM.IMSessionID.ToString()];
658 instance.MediaManager.PlayUISound(UISounds.IM);
660 Control active = FindFocusedControl(instance.MainForm);
662 ConferenceIMTabWindow imTab = AddConferenceIMTab(e.IM.IMSessionID, Utils.BytesToString(e.IM.BinaryBucket));
663 tabs[e.IM.IMSessionID.ToString()].Highlight();
664 imTab.TextManager.ProcessIM(e);
672 private void HandleGroupIM(InstantMessageEventArgs e)
674 // Ignore group IM from a muted group
675 if (null != client.Self.MuteList.Find(me => me.Type == MuteType.Group && (me.ID == e.IM.IMSessionID || me.ID == e.IM.FromAgentID))) return;
677 if (TabExists(e.IM.IMSessionID.ToString()))
679 RadegastTab tab = tabs[e.IM.IMSessionID.ToString()];
684 instance.MediaManager.PlayUISound(UISounds.IM);
686 Control active = FindFocusedControl(instance.MainForm);
688 GroupIMTabWindow imTab = AddGroupIMTab(e.IM.IMSessionID, Utils.BytesToString(e.IM.BinaryBucket));
689 imTab.TextManager.ProcessIM(e);
690 tabs[e.IM.IMSessionID.ToString()].Highlight();
698 public void InitializeMainTab()
700 if (TabExists("login"))
702 ForceCloseTab("login");
705 LoginConsole loginConsole = new LoginConsole(instance);
707 RadegastTab tab = AddTab("login", "Login", loginConsole);
708 tab.AllowClose = false;
709 tab.AllowDetach = false;
710 tab.AllowMerge = false;
711 tab.AllowHide = false;
713 loginConsole.RegisterTab(tab);
716 private void InitializeChatTab()
718 chatConsole = new ChatConsole(instance);
719 mainChatManger = chatConsole.ChatManager;
721 RadegastTab tab = AddTab("chat", "Chat", chatConsole);
722 tab.AllowClose = false;
723 tab.AllowDetach = false;
724 tab.AllowHide = false;
729 /// Create Tabs that only make sense when connected
731 private void InitializeOnlineTabs()
733 RadegastTab tab = AddTab("friends", "Friends", new FriendsConsole(instance));
734 tab.AllowClose = false;
735 tab.AllowDetach = true;
738 tab = AddTab("groups", "Groups", new GroupsConsole(instance));
739 tab.AllowClose = false;
740 tab.AllowDetach = true;
743 // Ugly workaround for a mono bug
744 InventoryConsole inv = new InventoryConsole(instance);
745 if (instance.MonoRuntime) inv.invTree.Scrollable = false;
746 tab = AddTab("inventory", "Inventory", inv);
747 if (instance.MonoRuntime) inv.invTree.Scrollable = true;
748 tab.AllowClose = false;
749 tab.AllowDetach = true;
752 tab = AddTab("search", "Search", new SearchConsole(instance));
753 tab.AllowClose = false;
754 tab.AllowDetach = true;
757 tab = AddTab("map", "Map", new MapConsole(instance));
758 tab.AllowClose = false;
759 tab.AllowDetach = true;
762 tab = AddTab("voice", "Voice", new VoiceConsole(instance));
763 tab.AllowClose = false;
764 tab.AllowDetach = true;
769 /// Close tabs that make no sense when not connected
771 private void DisposeOnlineTabs()
775 ForceCloseTab("voice");
776 ForceCloseTab("map");
777 ForceCloseTab("search");
778 ForceCloseTab("inventory");
779 ForceCloseTab("groups");
780 ForceCloseTab("friends");
784 private void ForceCloseTab(string name)
786 if (!TabExists(name)) return;
788 RadegastTab tab = tabs[name];
789 if (tab.Merged) SplitTab(tab);
791 tab.AllowClose = true;
797 public void RegisterContextAction(Type libomvType, String label, EventHandler handler)
799 instance.ContextActionManager.RegisterContextAction(libomvType, label, handler);
802 public void RegisterContextAction(ContextAction handler)
804 instance.ContextActionManager.RegisterContextAction(handler);
807 public void AddTab(RadegastTab tab)
809 ToolStripButton button = (ToolStripButton)tstTabs.Items.Add(tab.Label);
810 button.DisplayStyle = ToolStripItemDisplayStyle.ImageAndText;
812 button.AutoToolTip = false;
813 button.Tag = tab.Name;
814 button.Click += new EventHandler(TabButtonClick);
816 tabs.Add(tab.Name, tab);
818 if (OnTabAdded != null)
820 try { OnTabAdded(this, new TabEventArgs(tab)); }
821 catch (Exception) { }
825 public RadegastTab AddTab(string name, string label, Control control)
827 // WORKAROUND: one should never add tab that alrady exists
828 // but under some weird conditions disconnect/connect
829 // fire in the wrong order
832 Logger.Log("Force closing tab '" + name + "'", Helpers.LogLevel.Warning, client);
836 control.Visible = false;
837 control.Dock = DockStyle.Fill;
838 toolStripContainer1.ContentPanel.Controls.Add(control);
840 ToolStripButton button = (ToolStripButton)tstTabs.Items.Add(label);
841 button.DisplayStyle = ToolStripItemDisplayStyle.ImageAndText;
843 button.AutoToolTip = false;
844 button.Tag = name.ToLower();
845 button.AllowDrop = true;
846 button.Click += new EventHandler(TabButtonClick);
848 RadegastTab tab = new RadegastTab(instance, button, control, name.ToLower(), label);
849 if (control is RadegastTabControl)
850 ((RadegastTabControl)control).RadegastTab = tab;
851 tab.TabAttached += new EventHandler(tab_TabAttached);
852 tab.TabDetached += new EventHandler(tab_TabDetached);
853 tab.TabSelected += new EventHandler(tab_TabSelected);
854 tab.TabClosed += new EventHandler(tab_TabClosed);
855 tab.TabHidden += new EventHandler(tab_TabHidden);
856 tabs.Add(name.ToLower(), tab);
858 if (OnTabAdded != null)
860 try { OnTabAdded(this, new TabEventArgs(tab)); }
861 catch (Exception) { }
864 button.MouseDown += (msender, margs) =>
866 if (margs.Button == MouseButtons.Middle)
872 else if (tab.AllowHide)
882 private void tab_TabAttached(object sender, EventArgs e)
884 RadegastTab tab = (RadegastTab)sender;
888 private void tab_TabDetached(object sender, EventArgs e)
890 RadegastTab tab = (RadegastTab)sender;
891 frmDetachedTab form = (frmDetachedTab)tab.Owner;
893 form.ReattachStrip = tstTabs;
894 form.ReattachContainer = toolStripContainer1.ContentPanel;
897 private void tab_TabSelected(object sender, EventArgs e)
899 RadegastTab tab = (RadegastTab)sender;
901 if (selectedTab != null &&
903 { selectedTab.Deselect(); }
907 tbtnCloseTab.Enabled = !tab.Merged && (tab.AllowClose || tab.AllowHide);
911 owner.AcceptButton = tab.DefaultControlButton;
914 if (OnTabSelected != null)
916 try { OnTabSelected(this, new TabEventArgs(selectedTab)); }
917 catch (Exception) { }
921 void tab_TabHidden(object sender, EventArgs e)
923 RadegastTab tab = (RadegastTab)sender;
925 if (selectedTab != null && selectedTab == tab)
932 private void tab_TabClosed(object sender, EventArgs e)
934 RadegastTab tab = (RadegastTab)sender;
936 if (selectedTab != null && selectedTab == tab && tab.Name != "chat")
942 tabs.Remove(tab.Name);
944 if (OnTabRemoved != null)
946 try { OnTabRemoved(this, new TabEventArgs(tab)); }
947 catch (Exception) { }
953 private void TabButtonClick(object sender, EventArgs e)
955 ToolStripButton button = (ToolStripButton)sender;
957 RadegastTab tab = tabs[button.Tag.ToString()];
961 public void RemoveTabEntry(RadegastTab tab)
963 if (tstTabs.Items.Contains(tab.Button))
965 tstTabs.Items.Remove(tab.Button);
968 tab.Button.Dispose();
969 tabs.Remove(tab.Name);
972 public void RemoveTab(string name)
974 if (tabs.ContainsKey(name))
980 //Used for outside classes that have a reference to TabsConsole
981 public void SelectTab(string name)
983 if (TabExists(name.ToLower()))
984 tabs[name.ToLower()].Select();
987 public bool TabExists(string name)
989 return tabs.ContainsKey(name.ToLower());
992 public RadegastTab GetTab(string name)
994 if (TabExists(name.ToLower()))
995 return tabs[name.ToLower()];
1000 public List<RadegastTab> GetOtherTabs()
1002 List<RadegastTab> otherTabs = new List<RadegastTab>();
1004 foreach (ToolStripItem item in tstTabs.Items)
1006 if (item.Tag == null) continue;
1007 if ((ToolStripItem)item == selectedTab.Button) continue;
1009 RadegastTab tab = tabs[item.Tag.ToString()];
1010 if (!tab.AllowMerge) continue;
1011 if (tab.Merged) continue;
1020 /// Activates the next tab
1022 public void SelectNextTab()
1024 List<ToolStripItem> buttons = new List<ToolStripItem>();
1026 foreach (ToolStripItem item in tstTabs.Items)
1028 if (item.Tag == null || !item.Visible) continue;
1035 for (int i = 0; i < buttons.Count; i++)
1037 if (buttons[i] == selectedTab.Button)
1046 if (current == buttons.Count)
1049 SelectTab(tabs[buttons[current].Tag.ToString()].Name);
1053 /// Activates the previous tab
1055 public void SelectPreviousTab()
1057 List<ToolStripItem> buttons = new List<ToolStripItem>();
1059 foreach (ToolStripItem item in tstTabs.Items)
1061 if (item.Tag == null || !item.Visible) continue;
1068 for (int i = 0; i < buttons.Count; i++)
1070 if (buttons[i] == selectedTab.Button)
1080 current = buttons.Count - 1;
1082 SelectTab(tabs[buttons[current].Tag.ToString()].Name);
1086 public IMTabWindow AddIMTab(UUID target, UUID session, string targetName)
1088 IMTabWindow imTab = new IMTabWindow(instance, target, session, targetName);
1090 RadegastTab tab = AddTab(session.ToString(), "IM: " + targetName, imTab);
1091 imTab.SelectIMInput();
1096 public ConferenceIMTabWindow AddConferenceIMTab(UUID session, string name)
1098 ConferenceIMTabWindow imTab = new ConferenceIMTabWindow(instance, session, name);
1100 RadegastTab tab = AddTab(session.ToString(), name, imTab);
1101 imTab.SelectIMInput();
1106 public GroupIMTabWindow AddGroupIMTab(UUID session, string name)
1108 GroupIMTabWindow imTab = new GroupIMTabWindow(instance, session, name);
1110 RadegastTab tab = AddTab(session.ToString(), name, imTab);
1111 imTab.SelectIMInput();
1116 public OutfitTextures AddOTTab(Avatar avatar)
1118 OutfitTextures otTab = new OutfitTextures(instance, avatar);
1120 RadegastTab tab = AddTab("OT: " + avatar.Name, "OT: " + avatar.Name, otTab);
1121 otTab.GetTextures();
1125 public MasterTab AddMSTab(Avatar avatar)
1127 MasterTab msTab = new MasterTab(instance, avatar);
1129 RadegastTab tab = AddTab("MS: " + avatar.Name, "MS: " + avatar.Name, msTab);
1133 public AnimTab AddAnimTab(Avatar avatar)
1135 AnimTab animTab = new AnimTab(instance, avatar);
1137 RadegastTab tab = AddTab("Anim: " + avatar.Name, "Anim: " + avatar.Name, animTab);
1141 private void tbtnTabOptions_Click(object sender, EventArgs e)
1143 tmnuMergeWith.Enabled = selectedTab.AllowMerge;
1144 tmnuDetachTab.Enabled = selectedTab.AllowDetach;
1146 tmnuMergeWith.DropDown.Items.Clear();
1148 if (!selectedTab.AllowMerge) return;
1149 if (!selectedTab.Merged)
1151 tmnuMergeWith.Text = "Merge With";
1153 List<RadegastTab> otherTabs = GetOtherTabs();
1155 tmnuMergeWith.Enabled = (otherTabs.Count > 0);
1156 if (!tmnuMergeWith.Enabled) return;
1158 foreach (RadegastTab tab in otherTabs)
1160 ToolStripItem item = tmnuMergeWith.DropDown.Items.Add(tab.Label);
1161 item.Tag = tab.Name;
1162 item.Click += new EventHandler(MergeItemClick);
1167 tmnuMergeWith.Text = "Split";
1168 tmnuMergeWith.Click += new EventHandler(SplitClick);
1172 private void MergeItemClick(object sender, EventArgs e)
1174 ToolStripItem item = (ToolStripItem)sender;
1175 RadegastTab tab = tabs[item.Tag.ToString()];
1177 selectedTab.MergeWith(tab);
1179 SplitContainer container = (SplitContainer)selectedTab.Control;
1180 toolStripContainer1.ContentPanel.Controls.Add(container);
1182 selectedTab.Select();
1183 RemoveTabEntry(tab);
1185 tabs.Add(tab.Name, selectedTab);
1188 private void SplitClick(object sender, EventArgs e)
1190 SplitTab(selectedTab);
1191 selectedTab.Select();
1194 public void SplitTab(RadegastTab tab)
1196 RadegastTab otherTab = tab.Split();
1197 if (otherTab == null) return;
1199 toolStripContainer1.ContentPanel.Controls.Add(tab.Control);
1200 toolStripContainer1.ContentPanel.Controls.Add(otherTab.Control);
1202 tabs.Remove(otherTab.Name);
1206 private void tmnuDetachTab_Click(object sender, EventArgs e)
1208 if (!selectedTab.AllowDetach) return;
1209 RadegastTab tab = selectedTab;
1211 tab.Detach(instance);
1214 private void tbtnCloseTab_Click(object sender, EventArgs e)
1216 RadegastTab tab = selectedTab;
1219 else if (tab.AllowClose)
1221 else if (tab.AllowHide)
1225 private void TabsConsole_Load(object sender, EventArgs e)
1227 owner = this.FindForm();
1230 private void ctxTabs_Opening(object sender, CancelEventArgs e)
1234 Point pt = this.PointToClient(Cursor.Position);
1235 ToolStripItem stripItem = tstTabs.GetItemAt(pt);
1237 if (stripItem == null)
1243 tabs[stripItem.Tag.ToString()].Select();
1245 ctxBtnClose.Enabled = !selectedTab.Merged && (selectedTab.AllowClose || selectedTab.AllowHide);
1246 ctxBtnDetach.Enabled = selectedTab.AllowDetach;
1247 ctxBtnMerge.Enabled = selectedTab.AllowMerge;
1248 ctxBtnMerge.DropDown.Items.Clear();
1250 if (!ctxBtnClose.Enabled && !ctxBtnDetach.Enabled && !ctxBtnMerge.Enabled)
1256 if (!selectedTab.AllowMerge) return;
1257 if (!selectedTab.Merged)
1259 ctxBtnMerge.Text = "Merge With";
1261 List<RadegastTab> otherTabs = GetOtherTabs();
1263 ctxBtnMerge.Enabled = (otherTabs.Count > 0);
1264 if (!ctxBtnMerge.Enabled) return;
1266 foreach (RadegastTab tab in otherTabs)
1268 ToolStripItem item = ctxBtnMerge.DropDown.Items.Add(tab.Label);
1269 item.Tag = tab.Name;
1270 item.Click += new EventHandler(MergeItemClick);
1275 ctxBtnMerge.Text = "Split";
1276 ctxBtnMerge.Click += new EventHandler(SplitClick);
1285 /// Arguments for tab events
1287 public class TabEventArgs : EventArgs
1290 /// Tab that was manipulated in the event
1292 public RadegastTab Tab;
1294 public TabEventArgs()
1299 public TabEventArgs(RadegastTab tab)
1307 /// Argument for chat notification events
1309 public class ChatNotificationEventArgs : EventArgs
1311 public string Message;
1312 public ChatBufferTextStyle Style;
1314 public ChatNotificationEventArgs(string message, ChatBufferTextStyle style)
1322 /// Element of list of nearby avatars
1324 public class NearbyAvatar
1326 public UUID ID { get; set; }
1327 public string Name { get; set; }