in
Forums
Blogs
DevExpress.com
Client Center
Support Center
DevExpress Channel

How do I draw a Refactor Preview to the screen.

Last post 11/26/2008 11:20 AM by Kevin Wolf. 2 replies.
Page 1 of 1 (3 items)
Sort Posts: Previous Next
  • 11/26/2008 9:37 AM

    How do I draw a Refactor Preview to the screen.

     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

  • 11/26/2008 9:57 AM In reply to

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

    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.
  • 11/26/2008 11:20 AM In reply to

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

     Thanks - that was too easy Big Smile

Page 1 of 1 (3 items)
Copyright © 1998-2009 Developer Express Inc.
ALL RIGHTS RESERVED