views:

67

answers:

1

The list of extensibility points for the VS2010 Editor mentios creating EditorOptionDefinitions along with a small sample. When I attempt to do this I cannot find the options anywhere in the VS2010 UI. How do I create these so that they are surfaced in the UI?

+1  A: 

To define a new Editor option in Vs2010 you need to do the following

  1. Create a class which derives from EditorOPtionDefinition or EditorOptionDefinition<T>
  2. Add an export of EditorOptionDefinition.
  3. Make sure the assembly where this is defined is listed as a MEF component

Example

[Export(typeof(EditorOptionDefinition))]
public sealed class SomeNewOption : EditorOptionDefinition<string> {
  public override Default { get ... } 
  public override EditorOptionKey<string> Key { get ... }
}
JaredPar
OK. And then what? What does that actually do? If I want to get the user to set a value or get the value that a user has set what do I actually need to do? I'm assuming that I need to build my own UI for this but it isn't clear.
Wolfbyte
@Wolfbyte, the options are only useful really for other extensions. If you want to have a UI you indeed have to build one yourself
JaredPar
@JaredPar Thanks for your answer. So then does exporting this class offer persistance of the options within visual studio or something? I'm struggling to figure out WHY I want to create one of these and export it. Also, your answer is correct so I'm marking it so.
Wolfbyte
@Wolfbyte, I'm not sure on the persistance angle (I don't believe they are by default). The purpose of this class is to expose settings which would be useful to other extensions. For instance the editor exports items like NewLine charactor, TabSize, DisplayUrlsAsHyperLinks.
JaredPar
@JaredPar So then in order to use these options that others define do we need to [ImportMany] EditorOptionDefinition[] Options? I don't really see what this class provides as I guess I could export a string or a boolean value. I suppose it's because the value for the option can change and so you need export a container for it rather than the value itself.
Wolfbyte
To use them, you `[Import]` an `IEditorOptionsFactoryService` to get options for a specific buffer or view (or the global options), or use `ITextView.Options` for the options specific to a view.
Noah Richards