0
[ContentType("Code")]
[Export(typeof(IWpfTextViewCreationListener))]
[TextViewRole(PredefinedTextViewRoles.Editable)]
internal sealed class TextViewCreationListener : IWpfTextViewCreationListener
{
    public void TextViewCreated(IWpfTextView textView)
    {
         ClassTemplateWriter.initializeFromParent(textView);
    }
}



public static void initializeMembers(string className)
{
     ClassTemplateWriterMembers.className = className;
     ClassTemplateWriterMembers.resetSnapshotLength();
     ClassTemplateWriterMembers.edit = ClassTemplateWriterMembers.view.TextBuffer.CreateEdit();
}

I'm trying to make a Visual Studio Extension adding code in the active document's editor(or buffer). So far everything was good except,

I select file1 and run the command, select file2 and run the command there. Now if I select the previous file and run the command the code is added in file1 not file2.

The problem is after the view for file1 and file2 is created using the TextViewCreate, If I want to reset 'edit' with the active document's view, (using the function above 'initializeMembers') ClassTemplateWriter's view member isn't the active document's view but the lastly created view.

How can I reset the member view with the active document's view?

(By active document I mean the document I'm currently running the command on. which is dte.ActiveDocument)

Ray Kim
  • 33
  • 2
  • 8
  • I really don't understand your question, or why you're trying to use a IWpfTextViewCreationListener at all. – Jason Malinowski Nov 02 '16 at 22:29
  • I Need to use the text buffer in order to insert text in the editor. The only example I found on stack overflow was using IWpfTextViewCreationListener – Ray Kim Nov 03 '16 at 01:09
  • You might be better off rephrasing your question to state your desired problem without necessarily pulling in whatever random bits you found, and we can go from there. If your real question is how to get an ITextBuffer for the active document, there's a number of questions already on stack overflow doing precisely that. – Jason Malinowski Nov 03 '16 at 19:10
  • Could you please provide a demo via OneDrive, I’ll reproduce your issue on my side. In addition, If you want to get Current ActiveDocument, please check the following solution http://stackoverflow.com/questions/24163986/how-to-get-current-activedocument-in-visual-studio-extension-using-mef – starian chen-MSFT Nov 04 '16 at 01:17
  • A that's what I neede thanks starain. I'm fairly new to VS SDK and this stufd pretty complicated I didn't know what I had to ask. Thanks – Ray Kim Nov 04 '16 at 02:35

0 Answers0