From 919ff29e67d6deebb58af4e897f1c4ab056a451f Mon Sep 17 00:00:00 2001 From: Latif Khalifa Date: Wed, 24 Mar 2010 04:30:02 +0000 Subject: [PATCH] A lot of massaging required by mono. git-svn-id: https://radegast.googlecode.com/svn/trunk@542 f7a694da-4d33-11de-9ad6-1127a62b9fcd --- Radegast/GUI/Consoles/Assets/Notecard.cs | 17 ++--- Radegast/GUI/Consoles/Assets/ScriptEditor.cs | 5 +- Radegast/GUI/Consoles/ChatConsole.cs | 7 +- Radegast/GUI/Consoles/MapConsole.cs | 103 ++++++++++++++++++++------- Radegast/GUI/Consoles/TabsConsole.cs | 12 +--- 5 files changed, 91 insertions(+), 53 deletions(-) diff --git a/Radegast/GUI/Consoles/Assets/Notecard.cs b/Radegast/GUI/Consoles/Assets/Notecard.cs index 6ef13de..ab8bb18 100644 --- a/Radegast/GUI/Consoles/Assets/Notecard.cs +++ b/Radegast/GUI/Consoles/Assets/Notecard.cs @@ -91,11 +91,8 @@ namespace Radegast { if (InvokeRequired) { - BeginInvoke(new MethodInvoker(delegate() - { - Assets_OnAssetReceived(transfer, asset); - } - )); + if (IsHandleCreated) + BeginInvoke(new MethodInvoker(() => Assets_OnAssetReceived(transfer, asset))); return; } @@ -167,11 +164,8 @@ namespace Radegast { if (InvokeRequired) { - BeginInvoke(new MethodInvoker(delegate() - { - Inventory_OnInventoryItemCopied(item); - } - )); + if (IsHandleCreated) + BeginInvoke(new MethodInvoker(() => Inventory_OnInventoryItemCopied(item))); return; } @@ -327,7 +321,8 @@ namespace Radegast { if (InvokeRequired) { - BeginInvoke(new MethodInvoker(delegate() { UpdateStatus(status); })); + if (IsHandleCreated) + BeginInvoke(new MethodInvoker(() => UpdateStatus(status))); return; } instance.TabConsole.DisplayNotificationInChat("Notecard status: " + status, ChatBufferTextStyle.Invisible); diff --git a/Radegast/GUI/Consoles/Assets/ScriptEditor.cs b/Radegast/GUI/Consoles/Assets/ScriptEditor.cs index 239ddf4..9f87caa 100644 --- a/Radegast/GUI/Consoles/Assets/ScriptEditor.cs +++ b/Radegast/GUI/Consoles/Assets/ScriptEditor.cs @@ -108,7 +108,8 @@ namespace Radegast { if (InvokeRequired) { - BeginInvoke(new MethodInvoker(delegate() { Assets_OnAssetReceived(transfer, asset); })); + if (IsHandleCreated) + BeginInvoke(new MethodInvoker(() => Assets_OnAssetReceived(transfer, asset))); return; } @@ -679,6 +680,8 @@ namespace Radegast { InventoryManager.ScriptUpdatedCallback handler = (bool uploadSuccess, string uploadStatus, bool compileSuccess, List compileMessages, UUID itemID, UUID assetID) => { + if (!IsHandleCreated) return; + BeginInvoke(new MethodInvoker(() => { if (uploadSuccess && compileSuccess) diff --git a/Radegast/GUI/Consoles/ChatConsole.cs b/Radegast/GUI/Consoles/ChatConsole.cs index c791b8c..674480e 100644 --- a/Radegast/GUI/Consoles/ChatConsole.cs +++ b/Radegast/GUI/Consoles/ChatConsole.cs @@ -160,11 +160,8 @@ namespace Radegast if (InvokeRequired) { - - BeginInvoke(new MethodInvoker(delegate() - { - Grid_CoarseLocationUpdate(sender, e); - })); + if (IsHandleCreated) + BeginInvoke(new MethodInvoker(() => Grid_CoarseLocationUpdate(sender, e))); return; } diff --git a/Radegast/GUI/Consoles/MapConsole.cs b/Radegast/GUI/Consoles/MapConsole.cs index b087ac4..9a11a85 100644 --- a/Radegast/GUI/Consoles/MapConsole.cs +++ b/Radegast/GUI/Consoles/MapConsole.cs @@ -49,37 +49,18 @@ namespace Radegast WebBrowser map; Regex slscheme = new Regex("^secondlife://(.+)/([0-9]+)/([0-9]+)"); bool InTeleport = false; + bool mapCreated = false; - public MapConsole(RadegastInstance i) + public MapConsole(RadegastInstance inst) { InitializeComponent(); Disposed += new EventHandler(frmMap_Disposed); - instance = i; + this.instance = inst; instance.ClientChanged += new EventHandler(instance_ClientChanged); - try - { - map = new WebBrowser(); - map.Dock = DockStyle.Fill; - map.AllowWebBrowserDrop = false; - map.Navigate(Path.GetDirectoryName(Application.ExecutablePath) + @"/worldmap.html"); - map.WebBrowserShortcutsEnabled = false; - map.ScriptErrorsSuppressed = true; - map.ObjectForScripting = this; - map.AllowNavigation = false; - if (instance.MonoRuntime) - { - map.Navigating += new WebBrowserNavigatingEventHandler(map_Navigating); - } - pnlMap.Controls.Add(map); - } - catch (Exception e) - { - Logger.Log(e.Message, Helpers.LogLevel.Warning, client, e); - pnlMap.Visible = false; - map = null; - } + Visible = false; + VisibleChanged += new EventHandler(MapConsole_VisibleChanged); // Register callbacks RegisterClientEvents(client); @@ -105,6 +86,57 @@ namespace Radegast RegisterClientEvents(client); } + void createMap() + { + try + { + map = new WebBrowser(); + map.Dock = DockStyle.Fill; + map.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(map_DocumentCompleted); + map.Navigate(Path.GetDirectoryName(Application.ExecutablePath) + @"/worldmap.html"); + pnlMap.Controls.Add(map); + } + catch (Exception e) + { + Logger.Log(e.Message, Helpers.LogLevel.Warning, client, e); + pnlMap.Visible = false; + map = null; + } + } + + void map_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e) + { + map.DocumentCompleted -= new WebBrowserDocumentCompletedEventHandler(map_DocumentCompleted); + map.AllowWebBrowserDrop = false; + map.WebBrowserShortcutsEnabled = false; + map.ScriptErrorsSuppressed = true; + map.ObjectForScripting = this; + map.AllowNavigation = false; + + if (instance.MonoRuntime) + { + map.Navigating += new WebBrowserNavigatingEventHandler(map_Navigating); + } + + ThreadPool.QueueUserWorkItem(sync => + { + Thread.Sleep(1000); + if (InvokeRequired && IsHandleCreated) + BeginInvoke(new MethodInvoker(() => + { + if (savedRegion != null) + { + gotoRegion(savedRegion, savedX, savedY); + } + else if (Active) + { + gotoRegion(client.Network.CurrentSim.Name, 128, 128); + } + } + )); + } + ); + } void frmMap_Disposed(object sender, EventArgs e) { @@ -261,7 +293,7 @@ namespace Radegast { if (!Active) return; - if (instance.MonoRuntime) + if (instance.MonoRuntime && map != null) { map.Navigate(Path.GetDirectoryName(Application.ExecutablePath) + @"/worldmap.html"); } @@ -281,8 +313,15 @@ namespace Radegast } #region JavascriptHooks + string savedRegion = null; + int savedX, savedY; + void gotoRegion(string regionName, int simX, int simY) { + savedRegion = regionName; + savedX = simX; + savedY = simY; + if (!Visible || map == null || map.Document == null) return; if (instance.MonoRuntime) { @@ -367,6 +406,20 @@ namespace Radegast } } + private void MapConsole_VisibleChanged(object sender, EventArgs e) + { + if (!mapCreated && Visible) + { + createMap(); + mapCreated = true; + } + else if (Visible && instance.MonoRuntime && savedRegion != null) + { + gotoRegion(savedRegion, savedX, savedY); + } + } + #endregion GUIEvents + } } diff --git a/Radegast/GUI/Consoles/TabsConsole.cs b/Radegast/GUI/Consoles/TabsConsole.cs index f832250..5d7b57b 100644 --- a/Radegast/GUI/Consoles/TabsConsole.cs +++ b/Radegast/GUI/Consoles/TabsConsole.cs @@ -529,17 +529,7 @@ namespace Radegast tab = AddTab("map", "Map", new MapConsole(instance)); tab.AllowClose = false; tab.AllowDetach = true; - if (instance.MonoRuntime) - { - tab.Visible = true; - SelectTab("map"); - SelectTab("chat"); - tab.Visible = false; - } - else - { - tab.Visible = false; - } + tab.Visible = false; } tab = AddTab("voice", "Voice", new VoiceConsole(instance)); -- 2.11.0