I need to provide a way to edit the JavaScript source in Visual Studio. The challenge here is that the source is in a CouchDB database. I know how to get the source from there and how to save it back.
My question is how can I hook to the Editor, so that when an attempt is made to read the source the request is passed to me object, and the same for save? I was thinking about IVsUIShellOpenDocument.OpenStandardEditor, but a hit a roadblock there.
The new VSEditor architecture promises additional options - I tried ITextDocumentFactoryService, it looks like it does exactly what I need, but as soon as I exported and object implementing it, I got an error from MEF complaining about missing dependency to ITextBufferFactoryService. Apparently just exporting the DocumentFactory is not enough. What else is necessary to make it work?
Microsoft Developer Network >
Forums Home
>
Microsoft Visual Studio 2010 Beta 2 Forums
>
Visual Studio Editor
>
Using ITextDocumentFactoryService interface
Using ITextDocumentFactoryService interface
All Replies
- There isn't really a way to do that, per se. The ITextDocumentFactoryService (and anything else ending in "Service") aren't meant to be implemented by extenders; they are there for you to [Import] and use.
You could use the existing ITextDocument events to get around this:1) (However you are hooking into opening the content) - Save a local copy on disk, and use OpenStandardEditor to open that instance.2) Hook the document saved events and reflect the saved data to the CouchDB instance.The way other things handle this (like Venus, when handling files that are out on a web server) is a bit more complicated. I think the short story for that is that they:1) Have an (IVs*) editor factory registered for a file extension2) When they are asked to open an editor for that extension for a file stored somewhere else, they stream the file from its source and use IVsTextBuffer.InitializeContent() to set up the editor.3) I think (but am not sure) that they use COM aggregation to aggregate the buffer adapter's save events so that they can write the buffer contents back out to the DB.As I said, though, I'm not certain about #3, or if there is a more "official" way for editor factories to handle this and have documents work correctly with the running document table.Thanks,-Noah- Proposed As Answer byBrittany BehrensMSFT, ModeratorThursday, November 05, 2009 6:46 PM
- This is too bad. I would love to come up with something really seamless. If I save a copy and then do OpenStandardEditor, I will have all sorts of small problems like the name of the file shown by the Editor, or in the save dialog. I spent some time exploring the way to do it with a custom editor factory.
I can create an instance of VsTextBufferClass, populate it (from a string), and create an editor using the OpenStandardEditor. I also can intercept the save through the IVsHierarchy object associated with the text buffer. So I am almost there, but here is where I am stuck:
- As soon as the document moniker I pass to the OpenStadardEditor has .js extension, when the editor window opens it does not respond to the regular keyboard keys: pressing letters has no effect, but I can select text and do CTRL-C or CTRL-V. Once I insert some text with CTRL-V It starts working normally. The funny thing is that if I give the moniker an extension of .txt, it responds to the keypresses properly. Unfortunately if I do that I will loose the JavaScript syntax highlighting.
- The modifying the text in the buffer does not set the dirty flag - there is no '*' on the editor tab next to the file name and closing the editor does not prompt to save it

