Exemple #1
0
        public override bool IsApplicable(EditableView pnlView)
        {
            DataObject data = (DataObject)Clipboard.GetDataObject();

            if (data != null)
            {
                if (data.GetDataPresent("Splash shapes", false) || data.ContainsImage() || ContainsFileImage(data))
                {
                    return(true);
                }
#if SAW && !SPLASH
                if (data.GetDataPresent("Splash scripts", false))
                {
                    return(CopyScripts.PasteApplicable(data));
                }
                if (data.GetDataPresent("Splash presentation", false))
                {
                    return(CopyPresentation.PasteApplicable(data));
                }
#endif
                if (data.ContainsText())
                {
                    if (CurrentPage.SelectedCount == 1 && CurrentPage.SelectedShapes[0].SupportsTextLabel)
                    {
                        return(true);
                    }
                    Shape shape = pnlView.TypingShape();
                    if (shape != null && shape.SupportsTextLabel)
                    {
                        return(true);                        // Second condition is needed because some "typing" shapes only actually do custom processing of certain keys
                    }
                }
            }
            return(false);
        }
Exemple #2
0
        public override void Trigger(EditableView.ClickPosition.Sources source, EditableView pnlView, Transaction transaction)
        {
            try
            {
                DataObject data = (DataObject)Clipboard.GetDataObject();
                if (data.GetDataPresent("Splash data", false))
                {
                    PasteSplashData(transaction, pnlView);
                }
#if SAW && !SPLASH
                else if (data.GetDataPresent("Splash scripts", false))
                {
                    CopyScripts.Paste(transaction);
                }
                else if (data.GetDataPresent("Splash presentation", false))
                {
                    CopyPresentation.Paste(transaction, pnlView);
                }
#endif
                else if (data.ContainsImage())
                {
                    Image        image      = data.GetImage();
                    MemoryStream strmMemory = new MemoryStream(10000);
                    image.Save(strmMemory, ImageFormat.Png);
                    image.Dispose();
                    ImportedImage objImported = new ImportedImage(strmMemory, CurrentDocument, transaction);                     //= ImportedImage.CreateForPaste(strmMemory)
                    transaction.Create(objImported);
                    objImported.PlaceAt(pnlView.ViewableArea().Centre());
                    //  strmMemory.Dispose()
                    CurrentPage.AddNew(objImported, transaction);
                }
                else if (ContainsFileImage(data))
                {
                    ImportedImage imported = new ImportedImage(data.GetFileDropList()[0], CurrentDocument, transaction);
                    transaction.Create(imported);
                    imported.PlaceAt(pnlView.ViewableArea().Centre());
                    CurrentPage.AddNew(imported, transaction);
                    CurrentPage.SelectOnly(imported);
                }
                else if (data.ContainsText())
                {
                    string text = data.GetText();
                    if (!string.IsNullOrEmpty(text))
                    {
                        // try and apply it to a shape - only if there is one and only one selected
                        Shape shape = pnlView.TypingShape();
                        if (shape != null && shape.SupportsTextLabel)                         // Second condition is needed because some "typing" shapes only actually do custom processing of certain keys
                        {
                            transaction.Edit(shape);
                            shape.TextType(text);
                        }
                        else if (CurrentPage.SelectedCount == 1)
                        {
                            shape = CurrentPage.SelectedShapes[0];
                            if (shape.SupportsTextLabel)
                            {
                                // When pasting in without the cursor, the entire current text is replaced, if any
                                transaction.Edit(shape);
                                if (!shape.HasText(true))
                                {
                                    shape.CreateLabel((Shape.TextStyleC)Editor.StyleParameterDefaultObject(Parameters.FontFace));
                                }
                                // StyleParameterDefaultObject returns the object for that param - which will be all the text styles
                                shape.LabelText = text.Replace("\r\n", "\r");
                            }
                        }
                    }
                }
            }
            catch (Exception ex) when(!Globals.Root.IsDebug)
            {
                Utilities.LogSubError(ex);
                transaction.Cancel();                 // must be before message box
                MessageBox.Show(Strings.Item("Paste_Failed"));
            }
        }