Beispiel #1
0
        /// <summary>Used by the Paste verb to do the paste in this case</summary>
        public static void Paste(Transaction transaction)
        {
            DataObject data = (DataObject)Clipboard.GetDataObject();

            byte[] buffer = (byte[])data.GetData("Splash scripts", false);
            if (buffer == null)
            {
                Debug.Fail("Deserialisation failed");
                return;
            }
            using (MemoryStream stream = new MemoryStream(buffer, false))
                using (DataReader reader = new DataReader(stream, (FileMarkers)Shape.Shapes.Scriptable))
                {
                    Scriptable copied = (Scriptable)reader.ReadData((FileMarkers)Shape.Shapes.Scriptable);
                    foreach (Scriptable target in CurrentPage.SelectedShapes.OfType <Scriptable>())
                    {
                        transaction.Edit(target);
                        target.RepeatTimeout = copied.RepeatTimeout;
                        foreach (Scriptable.ScriptTypes type in Enum.GetValues(typeof(Scriptable.ScriptTypes)))
                        {
                            target.SetScript(type, copied.GetScript(type));
                        }
                    }
                }
        }
Beispiel #2
0
        public override void Trigger(EditableView.ClickPosition.Sources source, EditableView pnlView, Transaction transaction)
        {
            Scriptable scriptable = pnlView.CurrentPage.SelectedShapes.First() as Scriptable;

            if (scriptable == null)
            {
                return;
            }
            // write the list of shapes into a byte buffer; this way we control the serialisation
            DataObject data = new DataObject();

            using (MemoryStream buffer = new MemoryStream(1000))
                using (DataWriter writer = new DataWriter(buffer, (FileMarkers)Shape.Shapes.Scriptable))
                {
                    writer.Write(scriptable);
                    data.SetData("Splash scripts", false, buffer.GetBuffer());
                }

            IndentStringBuilder output = new IndentStringBuilder();

            // store as text as well
            foreach (Scriptable.ScriptTypes type in Enum.GetValues(typeof(Scriptable.ScriptTypes)))
            {
                Script script = scriptable.GetScript(type);
                script?.WriteExportText(output, Strings.Item("SAW_ScriptType_" + type));
            }

            if (output.Length > 0)
            {
                data.SetText(output.ToString());
            }

            // store result on clipboard
            Clipboard.SetDataObject(data);
        }