/// <summary> /// Implementation of "paste" action using 2 delegates for the concrete action on JToken tree and TreeView. /// </summary> /// <param name="node"></param> /// <param name="pasteJTokenImplementation">Implementation of paste action in the JToken tree.</param> /// <param name="pasteTreeNodeImplementation">Implementation of paste action in the treeView.</param> private static void ClipboardPaste(this JTokenTreeNode node, Action <JToken> pasteJTokenImplementation, Action <TreeNode> pasteTreeNodeImplementation) { var sourceJTokenTreeNode = EditorClipboard <JTokenTreeNode> .Get(); var jTokenSource = sourceJTokenTreeNode.JTokenTag.DeepClone(); try { pasteJTokenImplementation(jTokenSource); } catch (Exception exception) { // If cut was asked, the clipboard is now empty and source should be inserted again in clipboard if (EditorClipboard <JTokenTreeNode> .IsEmpty()) { EditorClipboard <JTokenTreeNode> .Set(sourceJTokenTreeNode, false); } throw new JTokenTreeNodePasteException(exception); } var treeView = node.TreeView; treeView.BeginUpdate(); pasteTreeNodeImplementation(JsonTreeNodeFactory.Create(jTokenSource)); treeView.EndUpdate(); // If cut was asked, the clipboard is now empty and source should be removed from treeview if (EditorClipboard <JTokenTreeNode> .IsEmpty()) { sourceJTokenTreeNode.EditDelete(); } }
/// <inheritdoc /> protected override void OnVisibleChanged(EventArgs e) { if (Visible) { JTokenNode = FindSourceTreeNode <JTokenTreeNode>(); // Collapse item shown if node is expanded and has children CollapseAllToolStripItem.Visible = JTokenNode.IsExpanded && JTokenNode.Nodes.Cast <TreeNode>().Any(); // Expand item shown if node if not expanded or has a children not expanded ExpandAllToolStripItem.Visible = !JTokenNode.IsExpanded || JTokenNode.Nodes.Cast <TreeNode>().Any(t => !t.IsExpanded); // Remove item enabled if it is not the root or the value of a property DeleteNodeToolStripItem.Enabled = (JTokenNode.Parent != null) && !(JTokenNode.Parent is JPropertyTreeNode); // Cut item enabled if delete is CutNodeToolStripItem.Enabled = DeleteNodeToolStripItem.Enabled; // Paste items enabled only when a copy or cut operation is pending PasteNodeAfterToolStripItem.Enabled = !EditorClipboard <JTokenTreeNode> .IsEmpty() && (JTokenNode.Parent != null) && !(JTokenNode.Parent is JPropertyTreeNode); PasteNodeBeforeToolStripItem.Enabled = !EditorClipboard <JTokenTreeNode> .IsEmpty() && (JTokenNode.Parent != null) && !(JTokenNode.Parent is JPropertyTreeNode); PasteNodeReplaceToolStripItem.Enabled = !EditorClipboard <JTokenTreeNode> .IsEmpty() && (JTokenNode.Parent != null); } base.OnVisibleChanged(e); }
/// <summary> /// Overridden function to paste clipboard content /// </summary> /// <param name="Clipboard"></param> /// <param name="opHint">optional parameter that provides additional information for pasting the data (e.g. ShapeCollection.PasteHint)</param> /// <returns></returns> public override bool PasteClipboardContent(EditorClipboard Clipboard, object opHint) { if (!Clipboard.HasData()) return false; // the data object class might know how to paste? (not by default though) if (Clipboard.Data.TryPaste(opHint)) return true; object obj = Clipboard.Data.Object; Layer layer; // single shape in clipboard? ShapeBase singleshape = obj as ShapeBase; if (singleshape != null) { layer = ActiveLayer; ShapeBase parent = layer.ActiveShape; // Override the parent if a hint structure has been passed if (opHint != null && opHint is ShapeCollection.PasteHint) parent = (opHint as ShapeCollection.PasteHint).Parent; if (parent != null) { if (!singleshape.AllowsToSetParent(parent) || !parent.AllowsToAddChild(singleshape)) { return false; } } EditorManager.Actions.Add(AddShapeAction.CreateAddShapeAction(singleshape.Clone(), layer.ActiveShape, layer, true)); return true; } // shape collection in clipboard? ShapeCollection shapes = obj as ShapeCollection; if (shapes != null) { layer = ActiveLayer; ShapeBase parent = layer.ActiveShape; // Override the parent if a hint structure has been passed if (opHint != null && opHint is ShapeCollection.PasteHint) parent = (opHint as ShapeCollection.PasteHint).Parent; shapes = (ShapeCollection)shapes.CloneForClipboard(); // clone all shapes (necessary) //check if it is allowed to set shape as parent foreach (ShapeBase shape in shapes) { if (parent != null) { if (!shape.AllowsToSetParent(parent) || !parent.AllowsToAddChild(shape)) { return false; } } } IAction action = AddShapesAction.CreateAddShapesAction(shapes, parent, layer, true, "paste"); EditorManager.Actions.Add(action); // set this collection as new selection in the Gizmo // (we can't do this in the loop above, because the ItemChange actions set a new selected item in the gizmo) EditorApp.ActiveView.Gizmo.Clear(); foreach (ShapeBase shape in shapes) if ((shape as Shape3D) != null) EditorApp.ActiveView.Gizmo.AddShape(shape, false); return true; } // layer in clipboard? layer = obj as Layer; if (layer != null) { Layer newLayer = (Layer)layer.Clone(); newLayer.SetLayerNameInternal(EditorManager.Scene.Layers.GetUniqueLayerName(newLayer.LayerName, null)); EditorManager.Actions.Add(new AddLayerAction(newLayer)); return true; } // more than one layer? LayerCollection layers = obj as LayerCollection; if (layers != null && layers.Count > 0) { if (layers.Count > 1) EditorManager.Actions.StartGroup("Paste layers"); foreach (Layer newLayer in layers) EditorManager.Actions.Add(new AddLayerAction((Layer)newLayer.Clone())); if (layers.Count > 1) EditorManager.Actions.EndGroup(); } // a zone? Zone zone = obj as Zone; if (zone != null) { // the action takes care to generate a unique (file-)name EditorManager.Actions.Add(new AddZoneAction((Zone)zone.Clone(), true)); } // more than one zone? ZoneCollection zones = obj as ZoneCollection; if (zones != null && zones.Count > 0) { if (zones.Count > 1) EditorManager.Actions.StartGroup("Paste zones"); foreach (Zone newZone in zones) EditorManager.Actions.Add(new AddZoneAction((Zone)newZone.Clone(), true)); if (zones.Count > 1) EditorManager.Actions.EndGroup(); } // sky config in clipboard? SkyConfig sky = obj as SkyConfig; if (sky != null) { if (V3DLayer != null) EditorManager.Actions.Add(new SkyConfigChangedAction(V3DLayer, (SkyConfig)sky.Clone())); return true; } // property values in clipboard (copied via property tree)? PropertyDictionary propDict = EditorManager.Clipboard.DataObject as PropertyDictionary; if (propDict != null) { // Apply the properties to the selected shapes IAction propAction = propDict.CreateAction(EditorManager.SelectedShapes); if (propAction != null) EditorManager.Actions.Add(propAction); return true; } // single property value in clipboard (copied via property tree)? PropertyKeyValuePair propertyData = EditorManager.Clipboard.DataObject as PropertyKeyValuePair; if (propertyData != null) { IAction propAction = propertyData.CreateAction(EditorManager.SelectedShapes); if (propAction != null) EditorManager.Actions.Add(propAction); return true; } return false; }
private void load(EditorClipboard clipboard) { this.clipboard = clipboard.Content.GetBoundCopy(); }
private void toolStripButton_CopyConfig_Click(object sender, EventArgs e) { EditorManager.Clipboard.Data = EditorClipboard.CreateDataObject(this.SkyConfig.Clone(), "Sky config"); button_Paste.Enabled = true; }
/// <inheritdoc /> protected override void OnVisibleChanged(EventArgs e) { var type = ""; if (Visible) { JTokenNode = FindSourceTreeNode <JTokenTreeNode>(); // Collapse item shown if node is expanded and has children CollapseAllToolStripItem.Visible = JTokenNode.IsExpanded && JTokenNode.Nodes.Cast <TreeNode>().Any(); // Expand item shown if node if not expanded or has a children not expanded ExpandAllToolStripItem.Visible = !JTokenNode.IsExpanded || JTokenNode.Nodes.Cast <TreeNode>().Any(t => !t.IsExpanded); // Remove item enabled if it is not the root or the value of a property DeleteNodeToolStripItem.Enabled = (JTokenNode.Parent != null) && !(JTokenNode.Parent is JPropertyTreeNode); // Cut item enabled if delete is CutNodeToolStripItem.Enabled = DeleteNodeToolStripItem.Enabled; // Paste items enabled only when a copy or cut operation is pending PasteNodeAfterToolStripItem.Enabled = !EditorClipboard <JTokenTreeNode> .IsEmpty() && (JTokenNode.Parent != null) && !(JTokenNode.Parent is JPropertyTreeNode); PasteNodeBeforeToolStripItem.Enabled = !EditorClipboard <JTokenTreeNode> .IsEmpty() && (JTokenNode.Parent != null) && !(JTokenNode.Parent is JPropertyTreeNode); PasteNodeReplaceToolStripItem.Enabled = !EditorClipboard <JTokenTreeNode> .IsEmpty() && (JTokenNode.Parent != null); AddWizardStepToolStripItem.Visible = (JTokenNode.Level == 0 && JTokenNode.Text.StartsWith("[Array]")); AddWizardItemToolStripItem.Visible = (JTokenNode.Level == 3 && JTokenNode.Text.StartsWith("[Array]")); AddWizardSubitemToolStripItem.Visible = (JTokenNode.Level == 6 && JTokenNode.Text.StartsWith("[Array]")); if (AddWizardSubitemToolStripItem.Visible) { try { type = JTokenNode.Parent.Parent.FirstNode.FirstNode.Text; } catch { MessageBox.Show(this, "Type of Item cannot be found. Did you modify the json? Possibly recreate this item!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } type = Helper.GetSubItemType(type); if (type != "") { AddWizardSubitemToolStripItem.Text = "Add a " + type; } } RemoveWizardStepToolStripItem.Visible = (JTokenNode.Level == 1 && JTokenNode.Text.StartsWith("{Object}")); if (RemoveWizardStepToolStripItem.Visible) { try { RemoveWizardStepToolStripItem.Text = string.Format("Remove '{0}'", JTokenNode.FirstNode.FirstNode.Text); } catch { MessageBox.Show(this, "Type of Item cannot be found. Did you modify the json? Possibly recreate this item!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } RemoveWizardItemToolStripItem.Visible = (JTokenNode.Level == 4 && JTokenNode.Text.StartsWith("{Object}")); if (RemoveWizardItemToolStripItem.Visible) { try { RemoveWizardItemToolStripItem.Text = string.Format("Remove '{0}'", JTokenNode.Nodes[1].FirstNode.Text); } catch { MessageBox.Show(this, "Type of Item cannot be found. Did you modify the json? Possibly recreate this item!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } RemoveWizardSubitemToolStripItem.Visible = (JTokenNode.Level == 7 && JTokenNode.Text.StartsWith("{Object}")); if (RemoveWizardSubitemToolStripItem.Visible) { try { RemoveWizardSubitemToolStripItem.Text = string.Format("Remove '{0}'", JTokenNode.Nodes[1].FirstNode.Text); } catch { MessageBox.Show(this, "Type of Item cannot be found. Did you modify the json? Possibly recreate this item!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } base.OnVisibleChanged(e); }
/// <summary> /// Implementation of "cut" action /// </summary> /// <param name="node"></param> public static JTokenTreeNode ClipboardCut(this JTokenTreeNode node) { EditorClipboard <JTokenTreeNode> .Set(node, false); return(node); }
private bool CopyProperties() { PropertyDictionary propDict = new PropertyDictionary(); // Check whether the user has selected a category item GridItem selItem = propertyGrid.SelectedGridItem; if (selItem == null) { return(false); } if (selItem.GridItemType == GridItemType.Category) { // Collect all properties of this category foreach (GridItem propertyItem in selItem.GridItems) { if (propertyItem.GridItemType != GridItemType.Property) { continue; } // Skip empty property values (which typically corresponds to a "mixed" value when multiple // shapes are selected) if (propertyItem.Value == null) { continue; } // Skip read-only properties if (propertyItem.PropertyDescriptor != null && propertyItem.PropertyDescriptor.IsReadOnly) { continue; } propDict.AddProperty(propertyItem.Label, propertyItem.Value); } if (!propDict.Empty) { // Copy the property values to the clipboard EditorManager.Clipboard.Data = EditorClipboard.CreateDataObject(propDict, "Shape Properties"); } return(true); } else if (selItem.GridItemType == GridItemType.Property) { // Do not copy properties for layer if (SelectedObject is Layer) { EditorManager.Clipboard.Data = null; //clear clipboarddata return(true); } // Skip empty property values (which typically corresponds to a "mixed" value when multiple // shapes are selected) if (selItem.Value != null) { // Do not copy dynamicproperties if (selItem.Value is CSharpFramework.DynamicProperties.DynamicPropertyCollection) { EditorManager.Clipboard.Data = null; //clear clipboarddata return(true); } EditorManager.Clipboard.Data = EditorClipboard.CreateDataObject(new PropertyKeyValuePair(selItem.Label, selItem.Value), "Shape Single Property"); } return(true); } else { EditorManager.Clipboard.Data = null; //clear clipboarddata return(true); } }