private protected virtual string GetFocusedCommentText(IFocusCommentFocus commentFocus) { IFocusCommentCellView CellView = commentFocus.CellView; Document Documentation = CellView.StateView.State.Node.Documentation; return(CommentHelper.Get(Documentation)); }
/// <summary> /// Measures a cell created with this frame. /// </summary> /// <param name="measureContext">The context used to measure the cell.</param> /// <param name="cellView">The cell to measure.</param> /// <param name="collectionWithSeparator">A collection that can draw separators around the cell.</param> /// <param name="referenceContainer">The cell view in <paramref name="collectionWithSeparator"/> that contains this cell.</param> /// <param name="separatorLength">The length of the separator in <paramref name="collectionWithSeparator"/>.</param> /// <param name="size">The cell size upon return, padding included.</param> /// <param name="padding">The cell padding.</param> public virtual void Measure(ILayoutMeasureContext measureContext, ILayoutCellView cellView, ILayoutCellViewCollection collectionWithSeparator, ILayoutCellView referenceContainer, Measure separatorLength, out Size size, out Padding padding) { padding = Padding.Empty; ILayoutCommentCellView CommentCellView = cellView as ILayoutCommentCellView; Debug.Assert(CommentCellView != null); string Text = CommentHelper.Get(CommentCellView.Documentation); CommentDisplayModes DisplayMode = cellView.StateView.ControllerView.CommentDisplayMode; Debug.Assert(DisplayMode == CommentDisplayModes.OnFocus || DisplayMode == CommentDisplayModes.All); bool IsFocused = cellView.StateView.ControllerView.Focus.CellView == cellView; if (IsFocused && Text == null) { Text = string.Empty; } bool IsDisplayed = Text != null && ((DisplayMode == CommentDisplayModes.OnFocus && IsFocused) || DisplayMode == CommentDisplayModes.All); if (IsDisplayed) { size = measureContext.MeasureText(Text, TextStyles.Comment, Controller.Measure.Floating); } else { size = Size.Empty; } Debug.Assert(RegionHelper.IsValid(size)); }
private void CutOrDelete(IDataObject dataObject, out bool isDeleted) { isDeleted = false; string Content = CommentHelper.Get(StateView.State.Node.Documentation); Debug.Assert(Content != null); Debug.Assert(Start <= End); Debug.Assert(End <= Content.Length); if (Start < End) { if (dataObject != null) { dataObject.SetData(typeof(string), Content.Substring(Start, End - Start)); } Content = Content.Substring(0, Start) + Content.Substring(End); FocusController Controller = StateView.ControllerView.Controller; int OldCaretPosition = StateView.ControllerView.CaretPosition; int NewCaretPosition = Start; Controller.ChangeCommentAndCaretPosition(StateView.State.ParentIndex, Content, OldCaretPosition, NewCaretPosition, true); StateView.ControllerView.ClearSelection(); isDeleted = true; } }
/// <summary> /// Create cells for the provided state view. /// </summary> /// <param name="context">Context used to build the cell view tree.</param> /// <param name="parentCellView">The parent cell view.</param> public virtual IFrameCellView BuildNodeCells(IFrameCellViewTreeContext context, IFrameCellViewCollection parentCellView) { IDocument Documentation = context.StateView.State.Node.Documentation; string Text = CommentHelper.Get(Documentation); if (IsDisplayed(context, Text)) { IFrameVisibleCellView CellView = CreateCommentCellView(context.StateView, parentCellView, context.StateView.State.Node.Documentation); ValidateVisibleCellView(context, CellView); if (context.StateView.State is IFrameOptionalNodeState AsOptionalNodeState) { Debug.Assert(AsOptionalNodeState.ParentInner.IsAssigned); } return(CellView); } else { IFrameEmptyCellView CellView = CreateEmptyCellView(context.StateView, parentCellView); ValidateEmptyCellView(context, CellView); return(CellView); } }
/// <summary> /// Force the comment attached to the node with the focus to show, if empty, and move the focus to this comment. /// </summary> public virtual void ForceShowComment(out bool isMoved) { IFocusNodeState State = Focus.CellView.StateView.State; Document Documentation; if (State is IFocusOptionalNodeState AsOptionalNodeState) { Debug.Assert(AsOptionalNodeState.ParentInner.IsAssigned); Documentation = AsOptionalNodeState.Node.Documentation; } else { Documentation = State.Node.Documentation; } isMoved = false; ulong OldFocusHash = FocusHash; if (!(Focus is IFocusCommentFocus)) { string Text = CommentHelper.Get(Documentation); if (Text == null) { IFocusNodeStateView StateView = Focus.CellView.StateView; ForcedCommentStateView = StateView; Refresh(Controller.RootState); Debug.Assert(ForcedCommentStateView == null); for (int i = 0; i < FocusChain.Count; i++) { if (FocusChain[i] is IFocusCommentFocus AsCommentFocus && AsCommentFocus.CellView.StateView == StateView) { int OldFocusIndex = FocusChain.IndexOf(Focus); Debug.Assert(OldFocusIndex >= 0); // The old focus must have been preserved. int NewFocusIndex = i; ChangeFocus(NewFocusIndex - OldFocusIndex, OldFocusIndex, NewFocusIndex, true, out bool IsRefreshed); Debug.Assert(!IsRefreshed); // Refresh must not be done twice. isMoved = true; break; } } Debug.Assert(isMoved); } } if (isMoved) { ResetSelection(); } Debug.Assert(isMoved || OldFocusHash == FocusHash); }
/// <summary> /// Copy the selection in the clipboard. /// </summary> /// <param name="dataObject">The clipboard data object that can already contain other custom formats.</param> public override void Copy(IDataObject dataObject) { string Content = CommentHelper.Get(StateView.State.Node.Documentation); Debug.Assert(Content != null); Debug.Assert(Start <= End); Debug.Assert(End <= Content.Length); dataObject.SetData(typeof(string), Content.Substring(Start, End - Start)); }
private protected void DrawCommentCaret(ILayoutCommentFocus commentFocus) { ILayoutCommentCellView CellView = commentFocus.CellView; string Text = CommentHelper.Get(CellView.Documentation); if (Text == null) { Text = string.Empty; } Point CellOrigin = CellView.CellOrigin; Padding CellPadding = CellView.CellPadding; Point OriginWithPadding = CellOrigin.Moved(CellPadding.Left, CellPadding.Top); DrawContext.ShowCaret(OriginWithPadding, Text, TextStyles.Comment, ActualCaretMode, CaretPosition); }
/// <summary> /// Draws a cell created with this frame. /// </summary> /// <param name="drawContext">The context used to draw the cell.</param> /// <param name="cellView">The cell to draw.</param> /// <param name="origin">The location where to start drawing.</param> /// <param name="size">The drawing size, padding included.</param> /// <param name="padding">The padding to use when drawing.</param> public virtual void Draw(ILayoutDrawContext drawContext, ILayoutCellView cellView, Point origin, Size size, Padding padding) { ILayoutCommentCellView CommentCellView = cellView as ILayoutCommentCellView; Debug.Assert(CommentCellView != null); string Text = CommentHelper.Get(CommentCellView.Documentation); CommentDisplayModes DisplayMode = cellView.StateView.ControllerView.CommentDisplayMode; Debug.Assert(DisplayMode == CommentDisplayModes.OnFocus || DisplayMode == CommentDisplayModes.All); bool IsFocused = cellView.StateView.ControllerView.Focus.CellView == cellView; if (IsFocused && Text == null) { Text = string.Empty; } if (Text != null) { if ((DisplayMode == CommentDisplayModes.OnFocus && IsFocused) || DisplayMode == CommentDisplayModes.All) { Point OriginWithPadding = origin.Moved(padding.Left, padding.Top); drawContext.DrawTextBackground(Text, OriginWithPadding, TextStyles.Comment); LayoutControllerView ControllerView = cellView.StateView.ControllerView; if (ControllerView.Selection is ILayoutCommentSelection AsCommentSelection && AsCommentSelection.StateView == cellView.StateView) { int Start = AsCommentSelection.Start; int End = AsCommentSelection.End; Debug.Assert(Start <= End); drawContext.DrawSelectionText(Text, OriginWithPadding, TextStyles.Comment, Start, End); } drawContext.DrawText(Text, OriginWithPadding, TextStyles.Comment, isFocused: false); // The caret is drawn separately. } else if (DisplayMode == CommentDisplayModes.OnFocus && cellView.StateView.ControllerView.ShowUnfocusedComments) { drawContext.DrawCommentIcon(new Rect(cellView.CellOrigin, Size.Empty)); } } }
/// <summary> /// Prints a cell created with this frame. /// </summary> /// <param name="printContext">The context used to print the cell.</param> /// <param name="cellView">The cell to print.</param> /// <param name="origin">The location where to start printing.</param> /// <param name="size">The printing size, padding included.</param> /// <param name="padding">The padding to use when printing.</param> public virtual void Print(ILayoutPrintContext printContext, ILayoutCellView cellView, Point origin, Size size, Padding padding) { ILayoutCommentCellView CommentCellView = cellView as ILayoutCommentCellView; Debug.Assert(CommentCellView != null); string Text = CommentHelper.Get(CommentCellView.Documentation); if (Text != null) { CommentDisplayModes DisplayMode = cellView.StateView.ControllerView.CommentDisplayMode; Debug.Assert(DisplayMode == CommentDisplayModes.OnFocus || DisplayMode == CommentDisplayModes.All); if (DisplayMode == CommentDisplayModes.All) { Point OriginWithPadding = origin.Moved(padding.Left, padding.Top); printContext.PrintText(Text, OriginWithPadding, TextStyles.Comment); } } }
/// <summary> /// Create cells for the provided state view. /// </summary> /// <param name="context">Context used to build the cell view tree.</param> /// <param name="parentCellView">The collection of cell views containing this view. Null for the root of the cell tree.</param> public virtual IFrameCellView BuildBlockCells(IFrameCellViewTreeContext context, IFrameCellViewCollection parentCellView) { IDocument Documentation = context.BlockStateView.BlockState.ChildBlock.Documentation; string Text = CommentHelper.Get(Documentation); if (IsDisplayed(context, Text)) { IFrameVisibleCellView CellView = CreateCommentCellView(context.StateView, parentCellView, Documentation); ValidateVisibleCellView(context, CellView); return(CellView); } else { IFrameEmptyCellView CellView = CreateEmptyCellView(context.StateView, parentCellView); ValidateEmptyCellView(context, CellView); return(CellView); } }
/// <summary> /// Replaces the selection with the content of the clipboard. /// </summary> /// <param name="isChanged">True if something was replaced or added.</param> public override void Paste(out bool isChanged) { isChanged = false; if (ClipboardHelper.TryReadText(out string Text) && Text.Length > 0) { string Content = CommentHelper.Get(StateView.State.Node.Documentation); Debug.Assert(Content != null); Debug.Assert(Start <= End); Debug.Assert(End <= Content.Length); Content = Content.Substring(0, Start) + Text + Content.Substring(End); FocusController Controller = StateView.ControllerView.Controller; int OldCaretPosition = StateView.ControllerView.CaretPosition; int NewCaretPosition = Start + Text.Length; Controller.ChangeCommentAndCaretPosition(StateView.State.ParentIndex, Content, OldCaretPosition, NewCaretPosition, false); StateView.ControllerView.ClearSelection(); isChanged = true; } }
/// <summary> /// Prints the selection. /// </summary> public virtual void Print() { LayoutControllerView ControllerView = StateView.ControllerView; Debug.Assert(ControllerView.PrintContext != null); ControllerView.UpdateLayout(); Debug.Assert(RegionHelper.IsValid(StateView.ActualCellSize)); ILayoutTemplateSet TemplateSet = ControllerView.TemplateSet; IList <FocusFrameSelectorList> SelectorStack = StateView.GetSelectorStack(); ILayoutCommentFrame Frame = (ILayoutCommentFrame)TemplateSet.GetCommentFrame(StateView.State, SelectorStack); Debug.Assert(Frame != null); string Text = CommentHelper.Get(StateView.State.Node.Documentation); Debug.Assert(Text != null); Debug.Assert(Start <= End); Debug.Assert(End <= Text.Length); Frame.Print(ControllerView.PrintContext, Text.Substring(Start, End - Start), Point.Origin); }