public override void Trigger(EditableView.ClickPosition.Sources source, EditableView pnlView, Transaction transaction) { List <FreeText> shapes = CurrentPage.SelectedShapes.OfType <FreeText>().ToList(); // new copy so we don't have problems editing while iterating if (shapes.Count == 0) { return; } CurrentPage.DeleteSelected(transaction); List <Shape> newList = new List <Shape>(); foreach (FreeText shp in shapes) { TextLine textLine = TextLine.FromFreeText(shp); transaction.Create(textLine); newList.Add(textLine); CurrentPage.AddNew(textLine, transaction); } CurrentPage.SelectOnly(newList); }
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")); } }