OSDN Git Service

Adjust to the introduction of FolderType ENUM in libomv
[radegast/radegast.git] / Radegast / GUI / Consoles / Assets / Notecard.cs
index 514282e..5ec07c9 100644 (file)
@@ -1,6 +1,6 @@
 // 
 // Radegast Metaverse Client
-// Copyright (c) 2009, Radegast Development Team
+// Copyright (c) 2009-2014, Radegast Development Team
 // All rights reserved.
 // 
 // Redistribution and use in source and binary forms, with or without
@@ -41,7 +41,7 @@ namespace Radegast
         private RadegastInstance instance;
         private GridClient client { get { return instance.Client; } }
         private InventoryNotecard notecard;
-        private AssetNotecard recievedNotecard;
+        private AssetNotecard receivedNotecard;
         private Primitive prim;
 
         public Notecard(RadegastInstance instance, InventoryNotecard notecard)
@@ -91,11 +91,8 @@ namespace Radegast
         {
             if (InvokeRequired)
             {
-                BeginInvoke(new MethodInvoker(delegate()
-                    {
-                        Assets_OnAssetReceived(transfer, asset);
-                    }
-                ));
+                if (!instance.MonoRuntime || IsHandleCreated)
+                    BeginInvoke(new MethodInvoker(() => Assets_OnAssetReceived(transfer, asset)));
                 return;
             }
 
@@ -103,7 +100,7 @@ namespace Radegast
             {
                 AssetNotecard n = (AssetNotecard)asset;
                 n.Decode();
-                recievedNotecard = n;
+                receivedNotecard = n;
 
                 string noteText = string.Empty;
                 rtbContent.Clear();
@@ -150,6 +147,18 @@ namespace Radegast
                         titem.Name = item.UUID.ToString(); ;
                         titem.Tag = item;
                         titem.Click += new EventHandler(attachmentMenuItem_Click);
+
+                        var saveToInv = new ToolStripMenuItem("Save to inventory");
+                        saveToInv.Click += (object xsender, EventArgs xe) =>
+                            {
+                                client.Inventory.RequestCopyItemFromNotecard(UUID.Zero,
+                                    notecard.UUID,
+                                    client.Inventory.FindFolderForType(item.AssetType),
+                                    item.UUID,
+                                    Inventory_OnInventoryItemCopied);
+                            };
+
+                        titem.DropDownItems.Add(saveToInv);
                         tbtnAttachments.DropDownItems.Add(titem);
                     }
                 }
@@ -159,7 +168,32 @@ namespace Radegast
             else
             {
                 UpdateStatus("Failed");
-                rtbContent.Text = "Failed to download notecard.";
+                rtbContent.Text = "Failed to download notecard. " + transfer.Status;
+            }
+        }
+
+        private void Inventory_OnInventoryItemCopied(InventoryBase item)
+        {
+            if (InvokeRequired)
+            {
+                if (!instance.MonoRuntime || IsHandleCreated)
+                    BeginInvoke(new MethodInvoker(() => Inventory_OnInventoryItemCopied(item)));
+                return;
+            }
+
+            if (null == item) return;
+
+            instance.TabConsole.DisplayNotificationInChat(
+                string.Format("{0} saved to inventory", item.Name),
+                ChatBufferTextStyle.Invisible);
+
+            tlblStatus.Text = "Saved";
+            
+            if (item is InventoryNotecard)
+            {
+                Notecard nc = new Notecard(instance, (InventoryNotecard)item);
+                nc.pnlKeepDiscard.Visible = true;
+                nc.ShowDetached();
             }
         }
 
@@ -182,6 +216,14 @@ namespace Radegast
                         Landmark ln = new Landmark(instance, (InventoryLandmark)item);
                         ln.ShowDetached();
                         break;
+
+                    case AssetType.Notecard:
+                        client.Inventory.RequestCopyItemFromNotecard(UUID.Zero,
+                            notecard.UUID,
+                            notecard.ParentUUID,
+                            item.UUID,
+                            Inventory_OnInventoryItemCopied);
+                        break;
                 }
             }
         }
@@ -249,11 +291,11 @@ namespace Radegast
             n.BodyText = rtbContent.Text;
             n.EmbeddedItems = new List<InventoryItem>();
 
-            if (recievedNotecard != null)
+            if (receivedNotecard != null)
             {
-                for (int i = 0; i < recievedNotecard.EmbeddedItems.Count; i++)
+                for (int i = 0; i < receivedNotecard.EmbeddedItems.Count; i++)
                 {
-                    n.EmbeddedItems.Add(recievedNotecard.EmbeddedItems[i]);
+                    n.EmbeddedItems.Add(receivedNotecard.EmbeddedItems[i]);
                     int indexChar = 0xdc00 + i;
                     n.BodyText += (char)0xdbc0;
                     n.BodyText += (char)indexChar;
@@ -297,7 +339,8 @@ namespace Radegast
         {
             if (InvokeRequired)
             {
-                BeginInvoke(new MethodInvoker(delegate() { UpdateStatus(status); }));
+                if (!instance.MonoRuntime || IsHandleCreated)
+                    BeginInvoke(new MethodInvoker(() => UpdateStatus(status)));
                 return;
             }
             instance.TabConsole.DisplayNotificationInChat("Notecard status: " + status, ChatBufferTextStyle.Invisible);
@@ -325,5 +368,15 @@ namespace Radegast
             instance.TabConsole.DisplayNotificationInChat("Editing notecard", ChatBufferTextStyle.Invisible);
         }
 
+        private void btnKeep_Click(object sender, EventArgs e)
+        {
+            Retach();
+        }
+
+        private void btnDiscard_Click(object sender, EventArgs e)
+        {
+            client.Inventory.MoveItem(notecard.UUID, client.Inventory.FindFolderForType(FolderType.Trash), notecard.Name);
+            Retach();
+        }
     }
 }