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;
112 private Dictionary<string, RadegastTab> tabs = new Dictionary<string, RadegastTab>();
113 public Dictionary<string, RadegastTab> Tabs { get { return tabs; } }
115 private ChatConsole chatConsole;
117 private RadegastTab selectedTab;
120 /// Currently selected tab
122 public RadegastTab SelectedTab
132 public TabsConsole(RadegastInstance instance)
134 InitializeComponent();
135 Disposed += new EventHandler(TabsConsole_Disposed);
137 this.instance = instance;
138 this.instance.ClientChanged += new EventHandler<ClientChangedEventArgs>(instance_ClientChanged);
146 RegisterClientEvents(client);
149 private void RegisterClientEvents(GridClient client)
151 client.Self.ScriptQuestion += new EventHandler<ScriptQuestionEventArgs>(Self_ScriptQuestion);
152 client.Self.ScriptDialog += new EventHandler<ScriptDialogEventArgs>(Self_ScriptDialog);
153 client.Self.LoadURL += new EventHandler<LoadUrlEventArgs>(Self_LoadURL);
154 client.Self.SetDisplayNameReply += new EventHandler<SetDisplayNameReplyEventArgs>(Self_SetDisplayNameReply);
155 client.Avatars.DisplayNameUpdate += new EventHandler<DisplayNameUpdateEventArgs>(Avatars_DisplayNameUpdate);
158 private void UnregisterClientEvents(GridClient client)
160 client.Self.ScriptQuestion -= new EventHandler<ScriptQuestionEventArgs>(Self_ScriptQuestion);
161 client.Self.ScriptDialog -= new EventHandler<ScriptDialogEventArgs>(Self_ScriptDialog);
162 client.Self.LoadURL -= new EventHandler<LoadUrlEventArgs>(Self_LoadURL);
163 client.Self.SetDisplayNameReply -= new EventHandler<SetDisplayNameReplyEventArgs>(Self_SetDisplayNameReply);
164 client.Avatars.DisplayNameUpdate -= new EventHandler<DisplayNameUpdateEventArgs>(Avatars_DisplayNameUpdate);
167 void instance_ClientChanged(object sender, ClientChangedEventArgs e)
169 UnregisterClientEvents(e.OldClient);
170 RegisterClientEvents(client);
173 void TabsConsole_Disposed(object sender, EventArgs e)
175 RemoveNetcomEvents();
176 UnregisterClientEvents(client);
179 private void AddNetcomEvents()
181 netcom.ClientLoginStatus += new EventHandler<LoginProgressEventArgs>(netcom_ClientLoginStatus);
182 netcom.ClientLoggedOut += new EventHandler(netcom_ClientLoggedOut);
183 netcom.ClientDisconnected += new EventHandler<DisconnectedEventArgs>(netcom_ClientDisconnected);
184 netcom.ChatSent += new EventHandler<ChatSentEventArgs>(netcom_ChatSent);
185 netcom.AlertMessageReceived += new EventHandler<AlertMessageEventArgs>(netcom_AlertMessageReceived);
186 netcom.InstantMessageReceived += new EventHandler<InstantMessageEventArgs>(netcom_InstantMessageReceived);
189 private void RemoveNetcomEvents()
191 netcom.ClientLoginStatus -= new EventHandler<LoginProgressEventArgs>(netcom_ClientLoginStatus);
192 netcom.ClientLoggedOut -= new EventHandler(netcom_ClientLoggedOut);
193 netcom.ClientDisconnected -= new EventHandler<DisconnectedEventArgs>(netcom_ClientDisconnected);
194 netcom.ChatSent -= new EventHandler<ChatSentEventArgs>(netcom_ChatSent);
195 netcom.AlertMessageReceived -= new EventHandler<AlertMessageEventArgs>(netcom_AlertMessageReceived);
196 netcom.InstantMessageReceived -= new EventHandler<InstantMessageEventArgs>(netcom_InstantMessageReceived);
199 void Self_ScriptDialog(object sender, ScriptDialogEventArgs e)
201 // Is this object muted
202 if (null != client.Self.MuteList.Find(m => (m.Type == MuteType.Object && m.ID == e.ObjectID) // muted object by id
203 || (m.Type == MuteType.ByName && m.Name == e.ObjectName) // object muted by name
206 instance.MainForm.AddNotification(new ntfScriptDialog(instance, e.Message, e.ObjectName, e.ImageID, e.ObjectID, e.FirstName, e.LastName, e.Channel, e.ButtonLabels));
209 void Self_ScriptQuestion(object sender, ScriptQuestionEventArgs e)
211 // Is this object muted
212 if (null != client.Self.MuteList.Find(m => (m.Type == MuteType.Object && m.ID == e.TaskID) // muted object by id
213 || (m.Type == MuteType.ByName && m.Name == e.ObjectName) // object muted by name
216 instance.MainForm.AddNotification(new ntfPermissions(instance, e.Simulator, e.TaskID, e.ItemID, e.ObjectName, e.ObjectOwnerName, e.Questions));
219 private void netcom_ClientLoginStatus(object sender, LoginProgressEventArgs e)
221 if (e.Status == LoginStatus.Failed)
223 DisplayNotificationInChat("Login error: " + e.Message, ChatBufferTextStyle.Error);
225 else if (e.Status == LoginStatus.Success)
227 DisplayNotificationInChat("Logged in as " + netcom.LoginOptions.FullName + ".", ChatBufferTextStyle.StatusDarkBlue);
228 DisplayNotificationInChat("Login reply: " + e.Message, ChatBufferTextStyle.StatusDarkBlue);
230 InitializeOnlineTabs();
232 if (tabs.ContainsKey("login"))
234 if (selectedTab.Name == "login")
236 ForceCloseTab("login");
239 client.Self.RetrieveInstantMessages();
243 private void netcom_ClientLoggedOut(object sender, EventArgs e)
248 DisplayNotificationInChat("Logged out.");
252 private void netcom_ClientDisconnected(object sender, DisconnectedEventArgs e)
254 if (e.Reason == NetworkManager.DisconnectType.ClientInitiated) return;
258 DisplayNotificationInChat("Disconnected: " + e.Message, ChatBufferTextStyle.Error);
261 void Avatars_DisplayNameUpdate(object sender, DisplayNameUpdateEventArgs e)
263 DisplayNotificationInChat(string.Format("({0}) is now known as {1}", e.DisplayName.UserName, e.DisplayName.DisplayName));
266 void Self_SetDisplayNameReply(object sender, SetDisplayNameReplyEventArgs e)
270 DisplayNotificationInChat("You are now knows as " + e.DisplayName.DisplayName);
274 DisplayNotificationInChat("Failed to set a new display name: " + e.Reason, ChatBufferTextStyle.Error);
278 private void netcom_AlertMessageReceived(object sender, AlertMessageEventArgs e)
280 tabs["chat"].Highlight();
283 private void netcom_ChatSent(object sender, ChatSentEventArgs e)
285 tabs["chat"].Highlight();
288 void Self_LoadURL(object sender, LoadUrlEventArgs e)
290 // Is the object or the owner muted?
291 if (null != client.Self.MuteList.Find(m => (m.Type == MuteType.Object && m.ID == e.ObjectID) // muted object by id
292 || (m.Type == MuteType.ByName && m.Name == e.ObjectName) // object muted by name
293 || (m.Type == MuteType.Resident && m.ID == e.OwnerID) // object's owner muted
296 instance.MainForm.AddNotification(new ntfLoadURL(instance, e));
299 private void netcom_InstantMessageReceived(object sender, InstantMessageEventArgs e)
301 // Messaage from someone we muted?
302 if (null != client.Self.MuteList.Find(me => me.Type == MuteType.Resident && me.ID == e.IM.FromAgentID)) return;
306 case InstantMessageDialog.SessionSend:
307 if (instance.Groups.ContainsKey(e.IM.IMSessionID))
313 HandleConferenceIM(e);
317 case InstantMessageDialog.MessageFromAgent:
318 if (e.IM.FromAgentName == "Second Life")
320 HandleIMFromObject(e);
322 else if (e.IM.GroupIM || instance.Groups.ContainsKey(e.IM.IMSessionID))
326 else if (e.IM.BinaryBucket.Length > 1)
328 HandleConferenceIM(e);
336 case InstantMessageDialog.MessageFromObject:
337 HandleIMFromObject(e);
340 case InstantMessageDialog.StartTyping:
341 if (TabExists(e.IM.FromAgentName))
343 RadegastTab tab = tabs[e.IM.FromAgentName.ToLower()];
344 if (!tab.Highlighted) tab.PartialHighlight();
349 case InstantMessageDialog.StopTyping:
350 if (TabExists(e.IM.FromAgentName))
352 RadegastTab tab = tabs[e.IM.FromAgentName.ToLower()];
353 if (!tab.Highlighted) tab.Unhighlight();
358 case InstantMessageDialog.MessageBox:
359 instance.MainForm.AddNotification(new ntfGeneric(instance, e.IM.Message));
362 case InstantMessageDialog.RequestTeleport:
363 if (instance.RLV.AutoAcceptTP(e.IM.FromAgentID))
365 DisplayNotificationInChat("Auto accepting teleprot from " + e.IM.FromAgentName);
366 instance.Client.Self.TeleportLureRespond(e.IM.FromAgentID, e.IM.IMSessionID, true);
370 instance.MainForm.AddNotification(new ntfTeleport(instance, e.IM));
374 case InstantMessageDialog.GroupInvitation:
375 instance.MainForm.AddNotification(new ntfGroupInvitation(instance, e.IM));
378 case InstantMessageDialog.FriendshipOffered:
379 if (e.IM.FromAgentName == "Second Life")
381 HandleIMFromObject(e);
385 instance.MainForm.AddNotification(new ntfFriendshipOffer(instance, e.IM));
389 case InstantMessageDialog.InventoryAccepted:
390 DisplayNotificationInChat(e.IM.FromAgentName + " accepted your inventory offer.");
393 case InstantMessageDialog.InventoryDeclined:
394 DisplayNotificationInChat(e.IM.FromAgentName + " declined your inventory offer.");
397 case InstantMessageDialog.GroupNotice:
398 instance.MainForm.AddNotification(new ntfGroupNotice(instance, e.IM));
401 case InstantMessageDialog.InventoryOffered:
402 instance.MainForm.AddNotification(new ntfInventoryOffer(instance, e.IM));
405 case InstantMessageDialog.TaskInventoryOffered:
406 // Is the object muted by name?
407 if (null != client.Self.MuteList.Find(me => me.Type == MuteType.ByName && me.Name == e.IM.FromAgentName)) break;
409 instance.MainForm.AddNotification(new ntfInventoryOffer(instance, e.IM));
415 /// Make default tab (chat) active
417 public void SelectDefaultTab()
419 if (TabExists("chat"))
420 tabs["chat"].Select();
424 /// Displays notification in the main chat tab
426 /// <param name="msg">Message to be printed in the chat tab</param>
427 public void DisplayNotificationInChat(string msg)
429 DisplayNotificationInChat(msg, ChatBufferTextStyle.ObjectChat);
433 /// Displays notification in the main chat tab
435 /// <param name="msg">Message to be printed in the chat tab</param>
436 /// <param name="style">Style of the message to be printed, normal, object, etc.</param>
437 public void DisplayNotificationInChat(string msg, ChatBufferTextStyle style)
439 DisplayNotificationInChat(msg, style, true);
443 /// Displays notification in the main chat tab
445 /// <param name="msg">Message to be printed in the chat tab</param>
446 /// <param name="style">Style of the message to be printed, normal, object, etc.</param>
447 /// <param name="highlightChatTab">Highligt (and flash in taskbar) chat tab if not selected</param>
448 public void DisplayNotificationInChat(string msg, ChatBufferTextStyle style, bool highlightChatTab)
452 if (!instance.MonoRuntime || IsHandleCreated)
453 BeginInvoke(new MethodInvoker(() => DisplayNotificationInChat(msg, style, highlightChatTab)));
457 if (style != ChatBufferTextStyle.Invisible)
459 ChatBufferItem line = new ChatBufferItem(
467 mainChatManger.ProcessBufferItem(line, true);
468 if (highlightChatTab)
470 tabs["chat"].Highlight();
473 catch (Exception) { }
476 if (OnChatNotification != null)
478 try { OnChatNotification(this, new ChatNotificationEventArgs(msg, style)); }
483 private void HandleIMFromObject(InstantMessageEventArgs e)
485 // Is the object or the owner muted?
486 if (null != client.Self.MuteList.Find(m => (m.Type == MuteType.Object && m.ID == e.IM.IMSessionID) // muted object by id
487 || (m.Type == MuteType.ByName && m.Name == e.IM.FromAgentName) // object muted by name
488 || (m.Type == MuteType.Resident && m.ID == e.IM.FromAgentID) // object's owner muted
491 DisplayNotificationInChat(e.IM.FromAgentName + ": " + e.IM.Message);
494 private void HandleIM(InstantMessageEventArgs e)
496 if (TabExists(e.IM.IMSessionID.ToString()))
498 RadegastTab tab = tabs[e.IM.IMSessionID.ToString()];
499 if (!tab.Selected) tab.Highlight();
503 instance.MediaManager.PlayUISound(UISounds.IM);
505 IMTabWindow imTab = AddIMTab(e);
506 tabs[e.IM.IMSessionID.ToString()].Highlight();
509 private void HandleConferenceIM(InstantMessageEventArgs e)
511 if (TabExists(e.IM.IMSessionID.ToString()))
513 RadegastTab tab = tabs[e.IM.IMSessionID.ToString()];
514 if (!tab.Selected) tab.Highlight();
518 instance.MediaManager.PlayUISound(UISounds.IM);
520 ConferenceIMTabWindow imTab = AddConferenceIMTab(e);
521 tabs[e.IM.IMSessionID.ToString()].Highlight();
524 private void HandleGroupIM(InstantMessageEventArgs e)
526 if (TabExists(e.IM.IMSessionID.ToString()))
528 RadegastTab tab = tabs[e.IM.IMSessionID.ToString()];
529 if (!tab.Selected) tab.Highlight();
533 instance.MediaManager.PlayUISound(UISounds.IM);
535 GroupIMTabWindow imTab = AddGroupIMTab(e);
536 tabs[e.IM.IMSessionID.ToString()].Highlight();
539 private void InitializeMainTab()
541 LoginConsole loginConsole = new LoginConsole(instance);
543 RadegastTab tab = AddTab("login", "Login", loginConsole);
544 tab.AllowClose = false;
545 tab.AllowDetach = false;
546 tab.AllowMerge = false;
547 tab.AllowHide = false;
549 loginConsole.RegisterTab(tab);
552 private void InitializeChatTab()
554 chatConsole = new ChatConsole(instance);
555 mainChatManger = chatConsole.ChatManager;
557 RadegastTab tab = AddTab("chat", "Chat", chatConsole);
558 tab.AllowClose = false;
559 tab.AllowDetach = false;
560 tab.AllowHide = false;
565 /// Create Tabs that only make sense when connected
567 private void InitializeOnlineTabs()
569 RadegastTab tab = AddTab("friends", "Friends", new FriendsConsole(instance));
570 tab.AllowClose = false;
571 tab.AllowDetach = true;
574 tab = AddTab("groups", "Groups", new GroupsConsole(instance));
575 tab.AllowClose = false;
576 tab.AllowDetach = true;
579 // Ugly workaround for a mono bug
580 InventoryConsole inv = new InventoryConsole(instance);
581 if (instance.MonoRuntime) inv.invTree.Scrollable = false;
582 tab = AddTab("inventory", "Inventory", inv);
583 if (instance.MonoRuntime) inv.invTree.Scrollable = true;
584 tab.AllowClose = false;
585 tab.AllowDetach = true;
588 tab = AddTab("search", "Search", new SearchConsole(instance));
589 tab.AllowClose = false;
590 tab.AllowDetach = true;
593 tab = AddTab("map", "Map", new MapConsole(instance));
594 tab.AllowClose = false;
595 tab.AllowDetach = true;
598 tab = AddTab("voice", "Voice", new VoiceConsole(instance));
599 tab.AllowClose = false;
600 tab.AllowDetach = true;
605 /// Close tabs that make no sense when not connected
607 private void DisposeOnlineTabs()
611 ForceCloseTab("voice");
612 ForceCloseTab("map");
613 ForceCloseTab("search");
614 ForceCloseTab("inventory");
615 ForceCloseTab("groups");
616 ForceCloseTab("friends");
620 private void ForceCloseTab(string name)
622 if (!TabExists(name)) return;
624 RadegastTab tab = tabs[name];
625 if (tab.Merged) SplitTab(tab);
627 tab.AllowClose = true;
633 public void RegisterContextAction(Type libomvType, String label, EventHandler handler)
635 instance.ContextActionManager.RegisterContextAction(libomvType, label, handler);
638 public void RegisterContextAction(ContextAction handler)
640 instance.ContextActionManager.RegisterContextAction(handler);
643 public void AddTab(RadegastTab tab)
645 ToolStripButton button = (ToolStripButton)tstTabs.Items.Add(tab.Label);
646 button.DisplayStyle = ToolStripItemDisplayStyle.ImageAndText;
648 button.AutoToolTip = false;
649 button.Tag = tab.Name;
650 button.Click += new EventHandler(TabButtonClick);
652 tabs.Add(tab.Name, tab);
654 if (OnTabAdded != null)
656 try { OnTabAdded(this, new TabEventArgs(tab)); }
657 catch (Exception) { }
661 public RadegastTab AddTab(string name, string label, Control control)
663 // WORKAROUND: one should never add tab that alrady exists
664 // but under some weird conditions disconnect/connect
665 // fire in the wrong order
668 Logger.Log("Force closing tab '" + name + "'", Helpers.LogLevel.Warning, client);
672 control.Visible = false;
673 control.Dock = DockStyle.Fill;
674 toolStripContainer1.ContentPanel.Controls.Add(control);
676 ToolStripButton button = (ToolStripButton)tstTabs.Items.Add(label);
677 button.DisplayStyle = ToolStripItemDisplayStyle.ImageAndText;
679 button.AutoToolTip = false;
680 button.Tag = name.ToLower();
681 button.Click += new EventHandler(TabButtonClick);
683 RadegastTab tab = new RadegastTab(instance, button, control, name.ToLower(), label);
684 if (control is RadegastTabControl)
685 ((RadegastTabControl)control).RadegastTab = tab;
686 tab.TabAttached += new EventHandler(tab_TabAttached);
687 tab.TabDetached += new EventHandler(tab_TabDetached);
688 tab.TabSelected += new EventHandler(tab_TabSelected);
689 tab.TabClosed += new EventHandler(tab_TabClosed);
690 tab.TabHidden += new EventHandler(tab_TabHidden);
691 tabs.Add(name.ToLower(), tab);
693 if (OnTabAdded != null)
695 try { OnTabAdded(this, new TabEventArgs(tab)); }
696 catch (Exception) { }
702 private void tab_TabAttached(object sender, EventArgs e)
704 RadegastTab tab = (RadegastTab)sender;
708 private void tab_TabDetached(object sender, EventArgs e)
710 RadegastTab tab = (RadegastTab)sender;
711 frmDetachedTab form = (frmDetachedTab)tab.Owner;
713 form.ReattachStrip = tstTabs;
714 form.ReattachContainer = toolStripContainer1.ContentPanel;
717 private void tab_TabSelected(object sender, EventArgs e)
719 RadegastTab tab = (RadegastTab)sender;
721 if (selectedTab != null &&
723 { selectedTab.Deselect(); }
727 tbtnCloseTab.Enabled = tab.AllowClose || tab.AllowHide;
731 owner.AcceptButton = tab.DefaultControlButton;
734 if (OnTabSelected != null)
736 try { OnTabSelected(this, new TabEventArgs(selectedTab)); }
737 catch (Exception) { }
741 void tab_TabHidden(object sender, EventArgs e)
743 RadegastTab tab = (RadegastTab)sender;
745 if (selectedTab != null && selectedTab == tab)
752 private void tab_TabClosed(object sender, EventArgs e)
754 RadegastTab tab = (RadegastTab)sender;
756 if (selectedTab != null && selectedTab == tab && tab.Name != "chat")
762 tabs.Remove(tab.Name);
764 if (OnTabRemoved != null)
766 try { OnTabRemoved(this, new TabEventArgs(tab)); }
767 catch (Exception) { }
773 private void TabButtonClick(object sender, EventArgs e)
775 ToolStripButton button = (ToolStripButton)sender;
777 RadegastTab tab = tabs[button.Tag.ToString()];
781 public void RemoveTabEntry(RadegastTab tab)
783 if (tstTabs.Items.Contains(tab.Button))
785 tstTabs.Items.Remove(tab.Button);
788 tab.Button.Dispose();
789 tabs.Remove(tab.Name);
792 public void RemoveTab(string name)
794 if (tabs.ContainsKey(name))
800 //Used for outside classes that have a reference to TabsConsole
801 public void SelectTab(string name)
803 if (TabExists(name.ToLower()))
804 tabs[name.ToLower()].Select();
807 public bool TabExists(string name)
809 return tabs.ContainsKey(name.ToLower());
812 public RadegastTab GetTab(string name)
814 if (TabExists(name.ToLower()))
815 return tabs[name.ToLower()];
820 public List<RadegastTab> GetOtherTabs()
822 List<RadegastTab> otherTabs = new List<RadegastTab>();
824 foreach (ToolStripItem item in tstTabs.Items)
826 if (item.Tag == null) continue;
827 if ((ToolStripItem)item == selectedTab.Button) continue;
829 RadegastTab tab = tabs[item.Tag.ToString()];
830 if (!tab.AllowMerge) continue;
831 if (tab.Merged) continue;
840 /// Activates the next tab
842 public void SelectNextTab()
844 List<ToolStripItem> buttons = new List<ToolStripItem>();
846 foreach (ToolStripItem item in tstTabs.Items)
848 if (item.Tag == null || !item.Visible) continue;
855 for (int i = 0; i < buttons.Count; i++)
857 if (buttons[i] == selectedTab.Button)
866 if (current == buttons.Count)
869 SelectTab(tabs[buttons[current].Tag.ToString()].Name);
873 /// Activates the previous tab
875 public void SelectPreviousTab()
877 List<ToolStripItem> buttons = new List<ToolStripItem>();
879 foreach (ToolStripItem item in tstTabs.Items)
881 if (item.Tag == null || !item.Visible) continue;
888 for (int i = 0; i < buttons.Count; i++)
890 if (buttons[i] == selectedTab.Button)
900 current = buttons.Count - 1;
902 SelectTab(tabs[buttons[current].Tag.ToString()].Name);
906 public IMTabWindow AddIMTab(UUID target, UUID session, string targetName)
908 IMTabWindow imTab = new IMTabWindow(instance, target, session, targetName);
910 RadegastTab tab = AddTab(session.ToString(), "IM: " + targetName, imTab);
911 imTab.SelectIMInput();
917 public ConferenceIMTabWindow AddConferenceIMTab(UUID session, string name)
919 ConferenceIMTabWindow imTab = new ConferenceIMTabWindow(instance, session, name);
921 RadegastTab tab = AddTab(session.ToString(), name, imTab);
922 imTab.SelectIMInput();
928 public ConferenceIMTabWindow AddConferenceIMTab(InstantMessageEventArgs e)
930 ConferenceIMTabWindow imTab = AddConferenceIMTab(e.IM.IMSessionID, Utils.BytesToString(e.IM.BinaryBucket));
931 imTab.TextManager.ProcessIM(e);
935 public GroupIMTabWindow AddGroupIMTab(UUID session, string name)
937 GroupIMTabWindow imTab = new GroupIMTabWindow(instance, session, name);
939 RadegastTab tab = AddTab(session.ToString(), name, imTab);
940 imTab.SelectIMInput();
945 public GroupIMTabWindow AddGroupIMTab(InstantMessageEventArgs e)
947 GroupIMTabWindow imTab = AddGroupIMTab(e.IM.IMSessionID, Utils.BytesToString(e.IM.BinaryBucket));
948 imTab.TextManager.ProcessIM(e);
952 public IMTabWindow AddIMTab(InstantMessageEventArgs e)
954 IMTabWindow imTab = AddIMTab(e.IM.FromAgentID, e.IM.IMSessionID, e.IM.FromAgentName);
955 imTab.TextManager.ProcessIM(e);
959 public OutfitTextures AddOTTab(Avatar avatar)
961 OutfitTextures otTab = new OutfitTextures(instance, avatar);
963 RadegastTab tab = AddTab("OT: " + avatar.Name, "OT: " + avatar.Name, otTab);
968 public MasterTab AddMSTab(Avatar avatar)
970 MasterTab msTab = new MasterTab(instance, avatar);
972 RadegastTab tab = AddTab("MS: " + avatar.Name, "MS: " + avatar.Name, msTab);
976 public AttachmentTab AddATTab(Avatar avatar)
978 AttachmentTab atTab = new AttachmentTab(instance, avatar);
980 RadegastTab tab = AddTab("AT: " + avatar.Name, "AT: " + avatar.Name, atTab);
984 public AnimTab AddAnimTab(Avatar avatar)
986 AnimTab animTab = new AnimTab(instance, avatar);
988 RadegastTab tab = AddTab("Anim: " + avatar.Name, "Anim: " + avatar.Name, animTab);
992 private void tbtnTabOptions_Click(object sender, EventArgs e)
994 tmnuMergeWith.Enabled = selectedTab.AllowMerge;
995 tmnuDetachTab.Enabled = selectedTab.AllowDetach;
997 tmnuMergeWith.DropDown.Items.Clear();
999 if (!selectedTab.AllowMerge) return;
1000 if (!selectedTab.Merged)
1002 tmnuMergeWith.Text = "Merge With";
1004 List<RadegastTab> otherTabs = GetOtherTabs();
1006 tmnuMergeWith.Enabled = (otherTabs.Count > 0);
1007 if (!tmnuMergeWith.Enabled) return;
1009 foreach (RadegastTab tab in otherTabs)
1011 ToolStripItem item = tmnuMergeWith.DropDown.Items.Add(tab.Label);
1012 item.Tag = tab.Name;
1013 item.Click += new EventHandler(MergeItemClick);
1018 tmnuMergeWith.Text = "Split";
1019 tmnuMergeWith.Click += new EventHandler(SplitClick);
1023 private void MergeItemClick(object sender, EventArgs e)
1025 ToolStripItem item = (ToolStripItem)sender;
1026 RadegastTab tab = tabs[item.Tag.ToString()];
1028 selectedTab.MergeWith(tab);
1030 SplitContainer container = (SplitContainer)selectedTab.Control;
1031 toolStripContainer1.ContentPanel.Controls.Add(container);
1033 selectedTab.Select();
1034 RemoveTabEntry(tab);
1036 tabs.Add(tab.Name, selectedTab);
1039 private void SplitClick(object sender, EventArgs e)
1041 SplitTab(selectedTab);
1042 selectedTab.Select();
1045 public void SplitTab(RadegastTab tab)
1047 RadegastTab otherTab = tab.Split();
1048 if (otherTab == null) return;
1050 toolStripContainer1.ContentPanel.Controls.Add(tab.Control);
1051 toolStripContainer1.ContentPanel.Controls.Add(otherTab.Control);
1053 tabs.Remove(otherTab.Name);
1057 private void tmnuDetachTab_Click(object sender, EventArgs e)
1059 if (!selectedTab.AllowDetach) return;
1060 RadegastTab tab = selectedTab;
1062 tab.Detach(instance);
1065 private void tbtnCloseTab_Click(object sender, EventArgs e)
1067 RadegastTab tab = selectedTab;
1070 else if (tab.AllowHide)
1074 private void TabsConsole_Load(object sender, EventArgs e)
1076 owner = this.FindForm();
1079 private void ctxTabs_Opening(object sender, CancelEventArgs e)
1081 Point pt = this.PointToClient(Cursor.Position);
1082 ToolStripItem stripItem = tstTabs.GetItemAt(pt);
1084 if (stripItem == null)
1090 tabs[stripItem.Tag.ToString()].Select();
1092 ctxBtnClose.Enabled = selectedTab.AllowClose || selectedTab.AllowHide;
1093 ctxBtnDetach.Enabled = selectedTab.AllowDetach;
1094 ctxBtnMerge.Enabled = selectedTab.AllowMerge;
1095 ctxBtnMerge.DropDown.Items.Clear();
1097 if (!ctxBtnClose.Enabled && !ctxBtnDetach.Enabled && !ctxBtnMerge.Enabled)
1103 if (!selectedTab.AllowMerge) return;
1104 if (!selectedTab.Merged)
1106 ctxBtnMerge.Text = "Merge With";
1108 List<RadegastTab> otherTabs = GetOtherTabs();
1110 ctxBtnMerge.Enabled = (otherTabs.Count > 0);
1111 if (!ctxBtnMerge.Enabled) return;
1113 foreach (RadegastTab tab in otherTabs)
1115 ToolStripItem item = ctxBtnMerge.DropDown.Items.Add(tab.Label);
1116 item.Tag = tab.Name;
1117 item.Click += new EventHandler(MergeItemClick);
1122 ctxBtnMerge.Text = "Split";
1123 ctxBtnMerge.Click += new EventHandler(SplitClick);
1132 /// Arguments for tab events
1134 public class TabEventArgs : EventArgs
1137 /// Tab that was manipulated in the event
1139 public RadegastTab Tab;
1141 public TabEventArgs()
1146 public TabEventArgs(RadegastTab tab)
1154 /// Argument for chat notification events
1156 public class ChatNotificationEventArgs : EventArgs
1158 public string Message;
1159 public ChatBufferTextStyle Style;
1161 public ChatNotificationEventArgs(string message, ChatBufferTextStyle style)
1169 /// Element of list of nearby avatars
1171 public class NearbyAvatar
1173 public UUID ID { get; set; }
1174 public string Name { get; set; }