Forums

How do I draw a Refactor Preview to the screen.

Last post 11/26/2008 11:20 AM by Kevin Wolf. 2 replies.
Sort Posts: Previous Next
  • Kevin Wolf

    How do I draw a Refactor Preview to the screen.

    11/26/2008 9:37 AM
    • Not Ranked
    • Joined on 6/4/2007
    • Posts 3

     I'm suspect it's a combination of "PreparePreview", "HidePreview" and possibley "EditorPaintLanguageElement", but can't find any documentation on how to pull all three of these together.  Any help would be appreciated.

    Kevin

    Tampa FL

  • AlexS - DevExpress

    Re: How do I draw a Refactor Preview to the screen.

    11/26/2008 9:57 AM
    • Top 25 Contributor
    • Joined on 5/4/2007
    • Posts 1,662
    Answer
    Hi Kevin,
     
    Use may use "EditorPaintForeground". Here's some sample code:
     

    private bool _HandlingEditorForegroundPaint;

    private DevExpress.CodeRush.UserControls.CodePreviewWindow _PreviewWindow;

    private SourceRange _PreviewRange;

     

    private void RefactoringProvider_PreparePreview(object sender, DevExpress.Refactor.Core.PrepareRefactoringPreviewEventArgs ea)

    {

      Variable variable = ea.Element as Variable;

      if (variable == null)

        return;

     

      _PreviewRange = variable.Range.Clone();

     

      if (!_HandlingEditorForegroundPaint)

      {

        _HandlingEditorForegroundPaint = true;

        EventNexus.EditorPaintForeground += new EditorPaintEventHandler(EventNexus_EditorPaintForeground);

      }

      InvalidatePreviews(ea);

      CreatePreviewWindow(ea, variable);

    }

                   

    private void RefactoringProvider_HidePreview(object sender, DevExpress.Refactor.Core.HideRefactoringPreviewEventArgs ea)

    {

      if (_PreviewWindow != null)

      {

        _PreviewWindow.HidePreview();

        _PreviewWindow = null;

      }

     

      if (_HandlingEditorForegroundPaint)

      {

        _HandlingEditorForegroundPaint = false;

        EventNexus.EditorPaintForeground -= new EditorPaintEventHandler(EventNexus_EditorPaintForeground);

      }

      InvalidatePreviews(ea);

      _PreviewRange = SourceRange.Empty;

    }

     

    private void CreatePreviewWindow(PrepareRefactoringPreviewEventArgs ea, Variable variable)

    {

      string varCode = GenerateElement(variable);

      _PreviewWindow = new CodePreviewWindow(ea.TextView, _PreviewRange.Top);

      _PreviewWindow.AddCode(varCode);

      _PreviewWindow.ShowPreview();

    }

     

    private void InvalidatePreviews(RefactoringPreviewEventArgs ea)

    {

      if (_PreviewRange.IsEmpty)

        return;

     

      int doubleSpaceWidth = ea.TextView.SpaceWidth * 2;

      int textViewLineHeight = ea.TextView.LineHeight;

     

      Rectangle previewRect = ea.TextView.GetRectangleFromRange(_PreviewRange);

      previewRect.Inflate(doubleSpaceWidth, textViewLineHeight);

      ea.TextView.Invalidate(previewRect);

    }

                   

    private void EventNexus_EditorPaintForeground(EditorPaintEventArgs ea)

    {

      if (_PreviewRange.IsEmpty)

        return;

     

      using (StrikeThrough strikeThrough = new StrikeThrough())

      {

        strikeThrough.TextView = ea.TextView;

        strikeThrough.FillColor = RefactorColors.StrikeThrough;

        strikeThrough.Range = _PreviewRange;

        strikeThrough.Paint(ea.Graphics);

      }

    }


    --
    Thanks, Alex S
     
    R&D, IDE Team Developer Express Inc.
     
    PS. If you wish to receive direct assistance from our Support Team, use
    Support Center at http://www.devexpress.com/Support/Center
    Please take a look at our Knowledge Base at: http://www.devexpress.com/kb.
    It contains useful information on our products that may save time.
  • Kevin Wolf

    Re: How do I draw a Refactor Preview to the screen.

    11/26/2008 11:20 AM
    • Not Ranked
    • Joined on 6/4/2007
    • Posts 3

     Thanks - that was too easy Big Smile

More from DevExpress
Live Chat
Have a pre-sales question?
Need assistance with your evaluation?
We are here to help.
Chat is one of the many ways you can contact members of the DevExpress Team. We are available Monday-Friday between 8:30am and 5:00pm Pacific Time.
If you need additional product information, require pre-sales assistance, or want help with your order, write to us at info@devexpress.com or call us at
+1 (818) 844-3383.