Ejemplo n.º 1
0
        protected void DragDropEvent(object sender, DragEventArgs args)
        {
            bool once = true;
            bool receptorsRegistered = false;

            View.DropPoint = View.NegativeSurfaceOffsetAdjust(new Point(args.X, args.Y));
            View.StartDrop = true;
            IMembrane dropInto = View.FindInnermostSelectedMembrane(View.DropPoint, Program.Skin);

            dropInto.IfNull(() => dropInto = Program.Skin);
            IReceptor droppedReceptor = null;

            if (args.Data.GetFormats().Contains("FileDrop"))
            {
                string[] files = args.Data.GetData("FileDrop") as string[];

                foreach (string fn in files)
                {
                    // Attempt to load a receptor.
                    if (fn.ToLower().EndsWith(".dll"))
                    {
                        if (once)
                        {
                            Say("Loading receptors.");
                            once = false;
                        }

                        droppedReceptor     = dropInto.RegisterReceptor(fn);
                        receptorsRegistered = true;
                    }
                    else if (fn.ToLower().EndsWith(".jpg"))
                    {
                        if (once)
                        {
                            Say("Processing files.");
                            once = false;
                        }

                        // Create carriers for each of our images.
                        ISemanticTypeStruct protocol = Program.SemanticTypeSystem.GetSemanticTypeStruct("ImageFilename");
                        dynamic             signal   = Program.SemanticTypeSystem.Create("ImageFilename");
                        signal.Filename = fn;
                        dropInto.CreateCarrier(Program.Skin["DropReceptor"].Instance, protocol, signal);
                    }
                    else if (fn.ToLower().EndsWith(".xml"))
                    {
                        // We assume these are carriers we're going to drop.
                        if (once)
                        {
                            Say("Processing carriers.");
                            once = false;
                        }
                        XDocument xdoc = XDocument.Load(fn);
                        CreateCarriers(dropInto, xdoc.Element("Carriers"));
                    }
                }
            }

            if (receptorsRegistered)
            {
                dropInto.LoadReceptors();
                droppedReceptor.Instance.EndSystemInit();
            }

            View.StartDrop = false;
        }
Ejemplo n.º 2
0
        protected void DragDropEvent(object sender, DragEventArgs args)
        {
            bool once = true;
            bool receptorsRegistered = false;

            View.DropPoint = View.NegativeSurfaceOffsetAdjust(new Point(args.X, args.Y));
            View.StartDrop = true;
            IMembrane dropInto = View.FindInnermostSelectedMembrane(View.DropPoint, Program.Skin, false);

            dropInto.IfNull(() => dropInto = Program.Skin);
            IReceptor droppedReceptor = null;

            if (args.Data.GetFormats().Contains("FileDrop"))
            {
                string[] files = args.Data.GetData("FileDrop") as string[];

                foreach (string fn in files)
                {
                    // Attempt to load a receptor.
                    if (fn.ToLower().EndsWith(".dll"))
                    {
                        if (once)
                        {
                            Say("Loading receptors.");
                            once = false;
                        }

                        droppedReceptor     = dropInto.RegisterReceptor(fn);
                        receptorsRegistered = true;
                    }
                    else if (fn.ToLower().RightOfRightmostOf('.').ToLower().Contains(new string[] { "jpg", "png", "bmp", "gif" }) != String.Empty)
                    {
                        if (once)
                        {
                            Say("Processing files.");
                            once = false;
                        }

                        // Create carriers for each of our images.
                        ISemanticTypeStruct protocol = Program.SemanticTypeSystem.GetSemanticTypeStruct("ImageFilename");
                        dynamic             signal   = Program.SemanticTypeSystem.Create("ImageFilename");
                        // TODO: We need to figure out how to do computed types, so that I can assign a fully qualified name and set the discrete sub-types Path, Name, and FileExtension.
                        // The reverse would also be nice, a "getter" on "FullyQualifiedName" would combine the Path, Name, and FileExtension.
                        signal.Filename.Path.Text.Value          = Path.GetDirectoryName(fn);
                        signal.Filename.Name.Text.Value          = Path.GetFileNameWithoutExtension(fn);
                        signal.Filename.FileExtension.Text.Value = Path.GetExtension(fn);
                        dropInto.CreateCarrier(Program.Skin["DropReceptor"].Instance, protocol, signal);
                    }
                    else if (fn.ToLower().EndsWith(".xml"))
                    {
                        // We assume these are carriers we're going to drop.
                        if (once)
                        {
                            Say("Processing carriers.");
                            once = false;
                        }
                        XDocument xdoc = XDocument.Load(fn);
                        CreateCarriers(dropInto, xdoc.Element("Carriers"));
                    }
                }
            }

            if (receptorsRegistered)
            {
                dropInto.LoadReceptors();
                droppedReceptor.Instance.EndSystemInit();
            }

            View.StartDrop = false;
        }