public SnippetInstance(Snippet snippet, SnippetInstance parent) { Debug.Assert(!snippet.IsTopLevel); this.Snippet = snippet; this.Snippet.UI.SnippetInstances.Add(this); this.parent = parent; this.node = new SnippetTNode(snippet.Title, this); }
/// <summary> /// /// </summary> /// <param name="eventOnLinkSelection"></param> /// <param name="eventAfterLinkSelection">can be null</param> public void SelectSnippetLinkStart(SomeSnippetEventHandler eventOnLinkSelection, Control controlReceivesFocus) { // what to do when it's selected OnLinkSelection = eventOnLinkSelection; this.controlReceivesFocus = controlReceivesFocus; selectionBeforeSnipetLinkSelection = SingleSelectedNode as SnippetTNode; SelectingSnippetLink = true; selectSnippetForm.Visible = true; SuppressNoneSelect = true; suppressShiftAndControlSelections = true; }
public void PasteFromLocalClipboard(SnippetTNode to) { // note that the PoppedUpNode does not have to be a value. It might be a "root" // node if (localClipboard == null || localClipboard.Contains(to)) return; // on move, clear the clipboard if (localClipboard.IsMove) { MoveNodes(localClipboard, to); Clipboard.SetDataObject(new SerializableUniverse()); // clear the clipboard, can't use null localClipboard = null; } else CopyNodes(localClipboard, to); }
/// <summary> /// </summary> /// <param name="who">This is the node that we're copying, the original.</param> /// <param name="to">The new parent.</param> /// <param name="changeSelection"></param> public TreeNode MoveNode(SnippetTNode who, SnippetTNode to, bool changeSelection) { Snippet destination = null; if (to == null) destination = Universe.Instance.ModelGateway.TopLevelSnippet; else destination = to.Snippet; try { // yes, this is tricky, but what are the alternatives? We have to pass information // on our position in the tree Snippet from = who.SnippetInstance.parent.Snippet; who.Snippet.MoveSnippet(from, destination); SnippetInstance reselect = null; if (to == null) { reselect = who.Snippet.UI.GetInstanceUnderTopLevel(); } else { reselect = who.Snippet.UI.GetInstanceUnder(to.SnippetInstance); } TreeNode node = reselect.node; // select the new node in its location if (changeSelection) ReplaceSelectionWith(node); return node; } catch (NewChildIsAncestorException) { string msg; if (to == null) { msg = String.Format("Illegal move (top level {0} already exists)", who.Text); } else { msg = String.Format("Illegal move ({0} is an ancestor of {1} or {1} already has a {0})", who.Text, to.Text); } MessageBox.Show(msg, MainForm.DialogCaption, MessageBoxButtons.OK); } return null; }
public void DeleteNode(SnippetTNode node, bool changeSelection) { if (node.Snippet.WillDeleteRemoveSnippet()) { DialogResult okay = MessageBox.Show( "Deleting will permanently remove one or more Snippets (including \"" + node.Text + "\"). Delete anyway?", MainForm.DialogCaption, MessageBoxButtons.YesNo); if (okay == DialogResult.Yes) Delete(node, changeSelection); } else Delete(node, changeSelection); }
public void Delete(SnippetTNode node, bool changeSelection) { SnippetTNode nextNode = null; // this stuff to find the next node is a little sloppy because it might get wiped out // in the node.Remove() if it's a twin or even a child of a twin (of course). // Problems of multiple hierarchies :) if (changeSelection) { nextNode = (SnippetTNode)node.NextVisibleNode; if (nextNode == null) nextNode = (SnippetTNode)node.PrevVisibleNode; } node.Snippet.DeleteSnippet(node.SnippetInstance.parent.Snippet); if (changeSelection) { if (nextNode != null && !nextNode.Dead) ReplaceSelectionWith(nextNode); else if (Nodes.Count > 0) ReplaceSelectionWith(Nodes[0]); } }
/// <summary> /// </summary> /// <param name="who">This is the node that we're copying, the original.</param> /// <param name="to">The new parent.</param> /// <param name="changeSelection"></param> /// <returns></returns> public SnippetTNode CopyNode(SnippetTNode who, SnippetTNode to, bool changeSelection) { Snippet destination = null; if (to == null) destination = Universe.Instance.ModelGateway.TopLevelSnippet; else destination = to.Snippet; try { who.Snippet.CopySnippet(destination); SnippetInstance reselect = null; if (to == null) { reselect = who.Snippet.UI.GetInstanceUnderTopLevel(); } else { reselect = who.Snippet.UI.GetInstanceUnder(to.SnippetInstance); } TreeNode node = reselect.node; // select the new node in its location if (changeSelection) ReplaceSelectionWith(node); return reselect.node; } catch (NewChildIsAncestorException) { string msg; if (to == null) { msg = String.Format("Illegal copy (top level {0} already exists)", who.Text); } else { msg = String.Format("Illegal copy ({0} is an ancestor of {1} or {1} already has a {0})", who.Text, to.Text); } MessageBox.Show(msg, MainForm.DialogCaption, MessageBoxButtons.OK); } return null; }
/// <summary> /// Paste text as nodes! Massive snippet insertion, also /// </summary> /// <param name="wholeText"></param> /// <param name="to"></param> void Paste(string wholeText, SnippetTNode to) { char[] split = { (char)13, (char)10 }; string[] snippetTexts = wholeText.Split(split); foreach (string text in snippetTexts) { if (text.Length > 0) { Snippet snippet = null; if (to != null) snippet = to.Snippet.AddChildSnippet(); else snippet = Universe.Instance.ModelGateway.TopLevelSnippet.AddChildSnippet(); snippet.Title = text; } } }
private void MoveNodes(ICollection nodes, SnippetTNode to) { if (nodes == null) return; RemoveAllCachedNodes(); ArrayList newSelection = new ArrayList(nodes.Count); foreach (SnippetTNode node in nodes) { TreeNode selectMe = MoveNode(node, to, false); newSelection.Add(selectMe); } ReplaceSelectionWith(newSelection); }
private void CopyNodes(ICollection nodes, SnippetTNode to) { if (nodes == null) return; ArrayList newSelection = new ArrayList(nodes.Count); foreach (SnippetTNode node in nodes) { TreeNode newNode = CopyNode(node, to, false); if (newNode != null) newSelection.Add(newNode); } // replace the selection ReplaceSelectionWith(newSelection); }
void BeginNameEdit(SnippetTNode node) { if (node == null) return; if (LabelEdit) { node.BeginEdit(); } else // if client server, really { Universe.Instance.propertiesPane.BeginEdit();// Focus(); } }