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
- Create a class which derives from
EditorOPtionDefinition
orEditorOptionDefinition<T>
- Add an export of
EditorOptionDefinition
. - 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
2010-02-06 16:26:11
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
2010-02-06 16:44:29
@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
2010-02-06 17:32:02
@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
2010-02-06 17:36:27
@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
2010-02-06 18:10:24
@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
2010-02-07 00:11:52
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
2010-02-14 08:57:20