Recently, a VS plug-in is written, the main function is to insert a standard annotation segment and some common code segments. During the development process, I have encountered some problems, and I have also looked through some information, I have made a study. Here is some of the small issues to be a simple record, I hope to help.
(1) In OnConnection, when determining ConnectMode, be sure to add extra_cm_afterStartup
if (connectMode == Extensibility.ext_ConnectMode.ext_cm_UISetup || connectMode == Extensibility.ext_ConnectMode.ext_cm_Startup || connectMode == Extensibility.ext_ConnectMode.ext_cm_AfterStartup) // this line will work when u choose addin in addin manager like this, vs in the When the plugin is selected in Addin Manager, the plugin will be redisplayed, and in the general example, only the first two judgments
(2) In QueryState, set the following statement when settings State.
if (you join command) {(conditions shown) if status = (vsCommandStatus) vsCommandStatus.vsCommandStatusSupported | vsCommandStatus.vsCommandStatusEnabled; else status = (vsCommandStatus) vsCommandStatus.vsCommandStatusSupported;} else status = (vsCommandStatus) vsCommandStatus.vsCommandStatusUnsupported; Doing so, when the conditions are not satisfied, the menu of the plugin is grayed.
(3) The method of judging the existence of the code window is
(ApplicationObject.ActiveWindow! = null) && (ApplicationObject.activeWindow.Type == vswindowType.vsWindowTypedocument)
That is to say, there is an active window, and its type is the type of document.
(4) The method of inserting characters in the document window is
TextSelection TS = (TextSelection) ApplicationObject.activeDocument.selection; EditPoint EP = Ts.ActivePoint.createEditPoint (); Ep.insert (strcode); of course, other methods of editpoint can also be called to implement deletion, replacement, etc.
Almost like sauce, feeling with C # to do plug-in, simultaneous, simultaneous, the object model of Microsoft design is really comfortable, if you can design such a good system when you develop, how much, haha