Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VS 2010 mouse processor extension - not working

I am experimenting with a Visual Studio 2010 extension, where I need to work with the events exposed by IMouseProcessor.

As far as I can tell from the docs, I should create an IMouseProcessorProvider and export is using MEF, so that it can be automatically picked up by Visual Studio.

I created this class:

[Export(typeof(IMouseProcessorProvider))]
[ContentType("code")]
internal sealed class MouseProcessorFactory : IMouseProcessorProvider
{        
    public IMouseProcessor GetAssociatedProcessor(IWpfTextView wpfTextView)
    {
        return new MouseProcessor();
    }
}

When I run the experimental instance of Visual Studio, my extension is visible in the extension manager. But my custom mouse processor provider is never being called. Am I missing something / What am I doing wrong ?

like image 444
driis Avatar asked Nov 22 '09 14:11

driis


3 Answers

Taken directly from this (not mine) site:

Extending Visual Studio 2010 UML Designers – Part 1: Getting Started

VSSDK Beta 2 Bug Workarounds

Unfortunately there are a couple of bugs in the current VSSDK Beta 2 that we have to work around. I’ve been told they will be fixed in an update release but until then, let me take you through the project cleanup required to make this work:

Step 1 – Tweak the .csproj file

  1. Right click on your project and choose "Unload Project".
  2. Right click again on your project and choose "Edit Yourprojectname.csproj"
  3. In the topmost property group, look for the XML tag <IncludeAssemblyInVSIXContainer>. It will be set to false. Change it to true.
  4. Save the .csproj file and reload it into Visual Studio.

Step 2 – Tweak the .vsixmanifest file

  1. Right click on the file "source.extension.vsixmanifest" and choose View Code
  2. At the bottom of the file in the section called add the following line. (Yes, those vertical bars are important.)

    <MefComponent>|Yourprojectname|</MefComponent>

  3. Save and close the file.

like image 177
Sam Harwell Avatar answered Oct 20 '22 21:10

Sam Harwell


It took me a while to find the complete solution to this problem, so I will post the complete solution here:

  1. As suggested by 280Z28, there is a bug in the SDK for Beta 2. You need to edit the .csproj manually to ensure that your assembly is included in the generated VSIX file.
  2. As JaredPar answered, the TextViewRole attribtute should be added to the IMouseProcessorProvider implementation.
  3. Lastly, the IMouseProcessorProvider should also be decorated with a Name attribute.

All in all, this code works:

[Export(typeof(IMouseProcessorProvider))]
[ContentType("code")]
[TextViewRole(PredefinedTextViewRoles.Editable)]
[Name("mouseproc")]
internal sealed class MouseProcessorFactory : IMouseProcessorProvider
{        
    public IMouseProcessor GetAssociatedProcessor(IWpfTextView wpfTextView)
    {            
        return new MouseProcessor();
    }
}
like image 24
driis Avatar answered Oct 20 '22 22:10

driis


I believe you need to add a TextViewRole attribute as well.

[TextViewRole(PredefinedTextViewRoles.Editable)]
like image 25
JaredPar Avatar answered Oct 20 '22 22:10

JaredPar