locked
Get IWpfTextView that calls ITextParagraphPropertiesFactoryService.Create to format RRS feed

  • Question

  • While debuging ITextParagraphPropertiesFactoryService.Create method, I found in stack trace that private WpfTextView.PerformLayout method calls this method to get line text properties(tab stops and etc.),

    In my extension I want to get reference to exactly that WpfTextView, that call Create method, is it possible to achive this? I can try to go up untill WpfTextView, but don't want to use a dirty hack

    Is there any method to get this WpfTextView, since I need this in my calculations? In another post I have suggested to use IVsTextManager.GetActiveView, but I need the fiew that cause re-formation, not an active or not active view

    Hope in your help

    Thanks in advance

    Arsen

    Sunday, July 15, 2012 9:30 PM

Answers

  • There are 3 views open. If they are views of different files they will have their own IVsTextBuffer objects and calling GetActiveView passing in each unique IVsTextBuffer will return a unique IVsTextView that is associated with THAT TextBuffer. You seem to be saying/thinking that it will ALWAYS return ONE IVsTextView no matter what IVsTextBuffer you pass in to it. Is that what you are seeing or have you not tried this at all?

    Ryan

    • Marked as answer by Ego Jiang Monday, July 23, 2012 9:58 AM
    Monday, July 16, 2012 11:17 PM
  • GetActiveView returns the last active view for the text buffer you give it. If there is only a single view per text buffer it should return that view regardless of it is has focus currently or not (assuming you pass false for fMustHasFocus. If there are multiple (which is definetly not the normal scenario) it would return the last one the user interacted with.

    Ryan

    • Marked as answer by Ego Jiang Monday, July 23, 2012 9:57 AM
    Monday, July 16, 2012 10:00 PM
  • There is a way Ryan,

    Menu command window->New Window, or Split and etc. will create as many view as you want to the same buffer, I am not sure if it is possible to change font only for particular view

    Thanks,

    Arsen

    • Marked as answer by Ego Jiang Monday, July 23, 2012 9:58 AM
    Tuesday, July 17, 2012 7:05 AM

All replies

  • Hi Arsen,

    ITextView and IWpfTextView which control the set of text lines that are to be displayed, and also the caret, the selection, and the facilities for adorning the text by using WPF UI elements.

    Here is a thread is about how to get document name of an IWpfTextView which may be useful to you.

    http://social.msdn.microsoft.com/Forums/en-US/vseditor/thread/0f6ef03a-df6b-4670-856e-f4a539fbfbe1

    Best regards,


    Ego [MSFT]
    MSDN Community Support | Feedback to us


    • Edited by Ego Jiang Tuesday, July 17, 2012 5:59 AM
    Monday, July 16, 2012 8:06 AM
  • As far as I know the editor would only make such formatting requests on views that are visible and/or active. Since you can have multiple views over the same buffer the concept of ActiveView in the text manager just means the last activated view for the given buffer. Have you run into a situation where that ISN'T the view that triggered the Create call?

    Ryan

    Monday, July 16, 2012 4:46 PM
  • Hi Ryan,

    As I understand if there is more than one visible views in the screens, all views will request TextProperties to re-draw, will not them? GetActiveView returns view that contains cursor, not the one that did request, am I miss something?

    Thanks,

    Arsen 

    Monday, July 16, 2012 8:58 PM
  • Hi Ego,

    Seems you forgot to attach link, could you please drop link?

    Thanks, Arsen

    Monday, July 16, 2012 8:59 PM
  • GetActiveView returns the last active view for the text buffer you give it. If there is only a single view per text buffer it should return that view regardless of it is has focus currently or not (assuming you pass false for fMustHasFocus. If there are multiple (which is definetly not the normal scenario) it would return the last one the user interacted with.

    Ryan

    • Marked as answer by Ego Jiang Monday, July 23, 2012 9:57 AM
    Monday, July 16, 2012 10:00 PM
  • Yea, but the question is that I want to get not the active view, but the view that call ITextParagraphPropertiesFactoryService.Create method

    for example if there is 3 view opened, all of them will do call to ITextParagraphPropertiesFactoryService.Create method, and all of them could have different properties(zoom level, fontsize and etc.) and I need to return different properties for different views

    I am thinking to create a service, which stores all views, and return view by FormattedLineSource if requested, something like FirstOrDefault(View.FormattedLineSource = formattedLineSource), where formattedLineSource passed from Create method, will this work? since there is no 2 views pointing to the same formattedLineSource?

    Thanks,

    Arsen

    Monday, July 16, 2012 10:07 PM
  • There are 3 views open. If they are views of different files they will have their own IVsTextBuffer objects and calling GetActiveView passing in each unique IVsTextBuffer will return a unique IVsTextView that is associated with THAT TextBuffer. You seem to be saying/thinking that it will ALWAYS return ONE IVsTextView no matter what IVsTextBuffer you pass in to it. Is that what you are seeing or have you not tried this at all?

    Ryan

    • Marked as answer by Ego Jiang Monday, July 23, 2012 9:58 AM
    Monday, July 16, 2012 11:17 PM
  • Hi Arsen,

    I'm sorry for my mistake. I have added it to my reply.

    Best regards,


    Ego [MSFT]
    MSDN Community Support | Feedback to us

    Tuesday, July 17, 2012 6:09 AM
  • What about if the same file rendered in 3 different views, do they share the TextBuffer? I mean it returns same view if the buffer have 3 different views, it returns allways active view.

    Arsen

    Tuesday, July 17, 2012 6:25 AM
  • Yes, that is the case I mentioned, and also the least likely case of all. I believe the only way to achieve that is with view splitting, you can't open the same file using the same buffer in multiple unique views in any other way that I am aware of.

    Ryan

    Tuesday, July 17, 2012 6:59 AM
  • There is a way Ryan,

    Menu command window->New Window, or Split and etc. will create as many view as you want to the same buffer, I am not sure if it is possible to change font only for particular view

    Thanks,

    Arsen

    • Marked as answer by Ego Jiang Monday, July 23, 2012 9:58 AM
    Tuesday, July 17, 2012 7:05 AM
  • Yes, that is what I mentioned (view splitting), no you can't change the font per view.

    Ryan

    Tuesday, July 17, 2012 2:46 PM
  • Hi Arsen,

    I will mark Ryan's replies and yours as answers.

    Please unmark it, if you feel it is not the answer.

    Thank you for your understanding and support.
     
    Best regards,


    Ego [MSFT]
    MSDN Community Support | Feedback to us


    • Edited by Ego Jiang Monday, July 23, 2012 9:58 AM
    Monday, July 23, 2012 9:57 AM
  • I think it's ok Ego, 

    His answer put me to the right way

    Thanks

    Arsen

    Monday, July 23, 2012 6:48 PM