Imports EnvDTE Imports System.Diagnostics Imports Microsoft.Office.Core Public Module Editing Sub ListCommands() Dim cmds As Commands = DTE.Commands Dim owp As OutputWindowPane Dim cmdobj As Command owp = GetOutputWindowPane("Command List") owp.Clear() For Each cmdobj In cmds If Not cmdobj.Name Is Nothing Then owp.OutputString(cmdobj.Name & vbCrLf) End If Next End Sub Sub aaAddToolbarAndButtons() Dim commandBar As CommandBar Dim cmds As Commands cmds = DTE.Commands ' Create a toolbar if it does not exist ' Unfortunately, catch does not work, nor the is condition, so there is no way to tell 'Try ' commandBar = DTE.CommandBars("Editing Macros") 'Catch e As System.Exception 'End Try 'If Not commandBar Is GetType(CommandBar) Then commandBar = cmds.AddCommandBar("Editing Macros", vsCommandBarType.vsCommandBarTypeToolbar) 'End If Dim menu As CommandBar ' NOTE: add somwhere: ' base ' primitive data types ' explicit, implicit, operator menu = cmds.AddCommandBar("etc", vsCommandBarType.vsCommandBarTypeMenu, commandBar) AddToolbarButton(menu, "TypeDouble", "double") AddToolbarButton(menu, "TypeFloat", "float") AddToolbarButton(menu, "TypeInt", "int") AddToolbarButton(menu, "TypeBool", "bool") AddToolbarButton(menu, "TypeString", "string") AddToolbarButton(menu, "TypeObject", "object") AddToolbarButton(menu, "TypeVoid", "void") AddToolbarButton(menu, "LiteralThis", "this") AddToolbarButton(menu, "LiteralString", """""") AddToolbarButton(menu, "LiteralNull", "null") menu = cmds.AddCommandBar("pp", vsCommandBarType.vsCommandBarTypeMenu, commandBar) AddToolbarButton(menu, "PreprocessorDefine", "#define") AddToolbarButton(menu, "PreprocessorEndif", "#endif") AddToolbarButton(menu, "PreprocessorElse", "#else") AddToolbarButton(menu, "PreprocessorIf", "#if") AddToolbarButton(menu, "PreprocessorRegion", "#region") ' NOTE: add elif ' NOTE: add undef ' NOTE: add warning, error, line, endregion menu = cmds.AddCommandBar("mod", vsCommandBarType.vsCommandBarTypeMenu, commandBar) AddToolbarButton(menu, "ModifierSealed", "sealed") AddToolbarButton(menu, "ModifierAbstract", "abstract") AddToolbarButton(menu, "ModifierOverride", "override") AddToolbarButton(menu, "ModifierVirtual", "virtual") AddToolbarButton(menu, "ModifierConst", "const") AddToolbarButton(menu, "ModifierStatic", "static") AddToolbarButton(menu, "AccessSpecifierPrivate", "private") AddToolbarButton(menu, "AccessSpecifierProtectedInternal", "protected internal") AddToolbarButton(menu, "AccessSpecifierInternal", "internal") AddToolbarButton(menu, "AccessSpecifierProtected", "protected") AddToolbarButton(menu, "AccessSpecifierPublic", "public") ' NOTE: add extern ' NOTE: add event, readonly, unsafe, volatile ' NOTE: add ref, out, params ' A catch-all for all operators not in the other categories menu = cmds.AddCommandBar("op", vsCommandBarType.vsCommandBarTypeMenu, commandBar) AddToolbarButton(menu, "ExpressionAddressof", "addressof &&") AddToolbarButton(menu, "ExpressionDereference", "deref *") AddToolbarButton(menu, "ExpressionSizeof", "sizeof") AddToolbarButton(menu, "ExpressionTypeof", "typeof") AddToolbarButton(menu, "ExpressionConditionalParen", "(?:)") AddToolbarButton(menu, "ExpressionConditional", "?:") 'AddToolbarButton(menu, "ExpressionNew", "new") ' NOTE: think this is not possible in C# AddToolbarButton(menu, "ExpressionNewArray", "new []") AddToolbarButton(menu, "ExpressionNewInitialize", "new ()") ' NOTE: missing statement to declare and init on one line AddToolbarButton(menu, "ExpressionBrackets", "[]") AddToolbarButton(menu, "ExpressionParen", "()") ' NOTE add as operator menu = cmds.AddCommandBar("lop", vsCommandBarType.vsCommandBarTypeMenu, commandBar) AddToolbarButton(menu, "ExpressionBitNot", "~") AddToolbarButton(menu, "BinaryExpressionBitXOrParen", "(^)") AddToolbarButton(menu, "BinaryExpressionBitXOr", "^") AddToolbarButton(menu, "BinaryExpressionBitOrParen", "(|)") AddToolbarButton(menu, "BinaryExpressionBitOr", "|") AddToolbarButton(menu, "BinaryExpressionBitAndParen", "(&&)") AddToolbarButton(menu, "BinaryExpressionBitAnd", "&&") AddToolbarButton(menu, "BinaryExpressionOrParen", "(||)") AddToolbarButton(menu, "BinaryExpressionOr", "||") AddToolbarButton(menu, "BinaryExpressionAndParen", "(&&&&)") AddToolbarButton(menu, "BinaryExpressionAnd", "&&&&") AddToolbarButton(menu, "ExpressionNot", "!") AddToolbarButton(menu, "LiteralFalse", "false") AddToolbarButton(menu, "LiteralTrue", "true") ' NOTE: add is operator menu = cmds.AddCommandBar("rop", vsCommandBarType.vsCommandBarTypeMenu, commandBar) AddToolbarButton(menu, "BinaryExpressionIs", "is") AddToolbarButton(menu, "BinaryExpressionLessEqualParen", "(<=)") AddToolbarButton(menu, "BinaryExpressionLessEqual", "<=") AddToolbarButton(menu, "BinaryExpressionLessThanParen", "(<)") AddToolbarButton(menu, "BinaryExpressionLessThan", "<") AddToolbarButton(menu, "BinaryExpressionGreaterThanParen", "(>)") AddToolbarButton(menu, "BinaryExpressionGreaterEqualParen", "(>=)") AddToolbarButton(menu, "BinaryExpressionGreaterEqual", ">=") AddToolbarButton(menu, "BinaryExpressionGreaterThan", ">") AddToolbarButton(menu, "BinaryExpressionUnequalParen", "(!=)") AddToolbarButton(menu, "BinaryExpressionUnequal", "!=") AddToolbarButton(menu, "BinaryExpressionEqualParen", "(==)") AddToolbarButton(menu, "BinaryExpressionEqual", "==") AddToolbarButton(menu, "BinaryExpressionUnequalNull", "!= null") AddToolbarButton(menu, "BinaryExpressionEqualNull", "== null") menu = cmds.AddCommandBar("aop", vsCommandBarType.vsCommandBarTypeMenu, commandBar) AddToolbarButton(menu, "BinaryExpressionShiftRightParen", "(>>)") AddToolbarButton(menu, "BinaryExpressionShiftLeftParen", "(<<)") AddToolbarButton(menu, "BinaryExpressionShiftLeft", "<<") AddToolbarButton(menu, "BinaryExpressionShiftRight", ">>") AddToolbarButton(menu, "BinaryExpressionModuloParen", "(%)") AddToolbarButton(menu, "BinaryExpressionModulo", "%") AddToolbarButton(menu, "BinaryExpressionDivideParen", "(/)") AddToolbarButton(menu, "BinaryExpressionDivide", "/") AddToolbarButton(menu, "BinaryExpressionTimesParen", "(*)") AddToolbarButton(menu, "BinaryExpressionTimes", "*") AddToolbarButton(menu, "BinaryExpressionMinusParen", "(-)") AddToolbarButton(menu, "BinaryExpressionMinus", "-") AddToolbarButton(menu, "BinaryExpressionPlusParen", "(+)") AddToolbarButton(menu, "BinaryExpressionPlus", "+") AddToolbarButton(menu, "ExpressionNegative", "neg") AddToolbarButton(menu, "ExpressionPostDecrement", "x--") AddToolbarButton(menu, "ExpressionDecrement", "--x") AddToolbarButton(menu, "ExpressionPostIncrement", "x++") AddToolbarButton(menu, "ExpressionIncrement", "++x") menu = cmds.AddCommandBar("com", vsCommandBarType.vsCommandBarTypeMenu, commandBar) AddToolbarButton(menu, "CommentBlock", "/* */") AddToolbarButton(menu, "XmlCommentValue", "/// ") AddToolbarButton(menu, "XmlCommentSeeSealed", "") AddToolbarButton(menu, "XmlCommentSeeAbstract", "") AddToolbarButton(menu, "XmlCommentSeeVirtual", "") AddToolbarButton(menu, "XmlCommentSeeStatic", "") AddToolbarButton(menu, "XmlCommentSeeNull", "") AddToolbarButton(menu, "XmlCommentSeeFalse", "") AddToolbarButton(menu, "XmlCommentSeeTrue", "") AddToolbarButton(menu, "XmlCommentParamref", "") AddToolbarButton(menu, "XmlCommentSee", "") AddToolbarButton(menu, "CommentInstanceMembers", "// instance members") AddToolbarButton(menu, "CommentStaticMembers", "// static members") AddToolbarButton(menu, "CommentNote", "// NOTE:") AddToolbarButton(menu, "CommentTodo", "// TODO:") menu = cmds.AddCommandBar("cnt", vsCommandBarType.vsCommandBarTypeMenu, commandBar) AddToolbarButton(menu, "StatementEmpty", ";") AddToolbarButton(menu, "StatementContinue", "continue") AddToolbarButton(menu, "LoopDoBrace", "do {}") AddToolbarButton(menu, "LoopWhileBrace", "while {}") AddToolbarButton(menu, "LoopForEachBrace", "foreach {}") AddToolbarButton(menu, "LoopForBrace", "for {}") AddToolbarButton(menu, "LoopFor", "for") AddToolbarButton(menu, "StatementThrow", "throw") AddToolbarButton(menu, "StatementCatch", "catch") AddToolbarButton(menu, "StatementFinally", "finally") AddToolbarButton(menu, "StatementTryCatch", "try catch") AddToolbarButton(menu, "StatementTryFinally", "try finally") AddToolbarButton(menu, "StatementDefault", "default") AddToolbarButton(menu, "StatementBreak", "break") AddToolbarButton(menu, "StatementCase", "case") AddToolbarButton(menu, "StatementSwitch", "switch") AddToolbarButton(menu, "StatementElseBrace", "else {}") AddToolbarButton(menu, "StatementElse", "else") AddToolbarButton(menu, "StatementIfBrace", "if {}") AddToolbarButton(menu, "StatementIf", "if") AddToolbarButton(menu, "StatementReturn", "return") AddToolbarButton(menu, "StatementBrace", "{}") ' NOTE: add fixed, even though ti is not a control statement ' NOTE: add using statement (to dispose object at end) menu = cmds.AddCommandBar("asn", vsCommandBarType.vsCommandBarTypeMenu, commandBar) AddToolbarButton(menu, "StatementBitXOrAssign", "^=") AddToolbarButton(menu, "StatementBitOrAssign", "|=") AddToolbarButton(menu, "StatementBitAndAssign", "&&=") AddToolbarButton(menu, "StatementShiftRightAssign", "<<=") AddToolbarButton(menu, "StatementShiftLeftAssign", ">>=") AddToolbarButton(menu, "StatementModuloAssign", "%=") AddToolbarButton(menu, "StatementDivideAssign", "/=") AddToolbarButton(menu, "StatementMultiplyAssign", "*=") AddToolbarButton(menu, "StatementMinusAssign", "-=") AddToolbarButton(menu, "StatementPlusAssign", "+=") AddToolbarButton(menu, "StatementAssignAs", "= as") AddToolbarButton(menu, "StatementAssign", "=") menu = cmds.AddCommandBar("dcl", vsCommandBarType.vsCommandBarTypeMenu, commandBar) AddToolbarButton(menu, "DefinitionSet", "set {}") AddToolbarButton(menu, "DefinitionGet", "get {}") AddToolbarButton(menu, "DefinitionFunction", "f() {}") ' NOTE: add properties, delegates, and events ' NOTE: add struct AddToolbarButton(menu, "DefinitionEnum", "enum {}") AddToolbarButton(menu, "DefinitionClass", "class {}") AddToolbarButton(menu, "DefinitionNamespace", "namespace {}") AddToolbarButton(menu, "DeclarationUsing", "using") ' formatting menu = cmds.AddCommandBar("fmt", vsCommandBarType.vsCommandBarTypeMenu, commandBar) AddToolbarButton(menu, "FormatCollapseExpandGetSet", "Collapse/Expand get/set") ' NOTE: need assertion statements ' NOTE: these are not valid for C# 'AddToolbarButton(menu, "PreprocessorIfdef", "") 'AddToolbarButton(menu, "PreprocessorIfndef", "") 'AddToolbarButton(menu, "PreprocessorUndef", "") 'AddToolbarButton(menu, "StatementAssert", "") 'AddToolbarButton(menu, "StatementAssertxArg", "") 'AddToolbarButton(menu, "StatementAssertxPost", "") 'AddToolbarButton(menu, "StatementAssertxPre", "") End Sub Private Sub AddToolbarButton(ByVal commandBar As CommandBar, ByVal macroName As String, ByVal caption As String) Dim cmds As Commands Dim ctl As CommandBarControl cmds = DTE.Commands ctl = cmds.Item("Macros.Frank.Editing." & macroName).AddControl(commandBar) ctl.Caption = caption ctl.TooltipText = macroName End Sub Sub aaRemoveToolbar() Dim cmds As Commands Dim cmdbar As CommandBar cmds = DTE.Commands cmdbar = DTE.CommandBars("Editing Macros") cmds.RemoveCommandBar(cmdbar) End Sub ' from samples Private Function GetOutputWindowPane(ByVal Name As String, Optional ByVal show As Boolean = True) As OutputWindowPane Dim win As Window = DTE.Windows.Item(EnvDTE.Constants.vsWindowKindOutput) If show Then win.Visible = True Dim ow As OutputWindow = win.Object Dim owpane As OutputWindowPane Try owpane = ow.OutputWindowPanes.Item(Name) Catch e As System.Exception owpane = ow.OutputWindowPanes.Add(Name) End Try owpane.Activate() Return owpane End Function Private Sub aaInitializeKeyBindings() ' NOTE: this code is no longer valid 'DESCRIPTION: Set up key bindings for all macros in Frank Macros.dsm. 'Application.AddKeyBinding("Ctrl+Alt+Shift+F2", "BinaryExpressionAnd", "Text") 'Application.AddKeyBinding("Ctrl+Alt+Shift+F3", "BinaryExpressionAndParen", "Text") 'Application.AddKeyBinding("Ctrl+Alt+Shift+F4", "BinaryExpressionBitAnd", "Text") 'Application.AddKeyBinding("Ctrl+Alt+Shift+F5", "BinaryExpressionBitAndParen", "Text") 'Application.AddKeyBinding("Ctrl+Alt+Shift+F6", "BinaryExpressionBitOr", "Text") 'Application.AddKeyBinding("Ctrl+Alt+Shift+F7", "BinaryExpressionBitOrParen", "Text") 'Application.AddKeyBinding("Ctrl+Alt+Shift+F8", "BinaryExpressionBitXOr", "Text") 'Application.AddKeyBinding("Ctrl+Alt+Shift+F9", "BinaryExpressionBitXOrParen", "Text") 'Application.AddKeyBinding("Ctrl+Alt+Shift+1", "BinaryExpressionGreaterEqual", "Text") 'Application.AddKeyBinding("Ctrl+Alt+Shift+2", "BinaryExpressionGreaterEqualParen", "Text") 'Application.AddKeyBinding("Ctrl+Alt+Shift+3", "BinaryExpressionGreaterThan", "Text") 'Application.AddKeyBinding("Ctrl+Alt+Shift+4", "BinaryExpressionGreaterThanParen", "Text") 'Application.AddKeyBinding("Ctrl+Alt+Shift+5", "BinaryExpressionLessEqual", "Text") 'Application.AddKeyBinding("Ctrl+Alt+Shift+6", "BinaryExpressionLessEqualParen", "Text") 'Application.AddKeyBinding("Ctrl+Alt+Shift+7", "BinaryExpressionLessThan", "Text") 'Application.AddKeyBinding("Ctrl+Alt+Shift+8", "BinaryExpressionLessThanParen", "Text") 'Application.AddKeyBinding("Ctrl+Alt+Shift+9", "BinaryExpressionMinus", "Text") 'Application.AddKeyBinding("Ctrl+Alt+Shift+0", "BinaryExpressionMinusParen", "Text") 'Application.AddKeyBinding("Ctrl+Alt+Shift+Tab", "BinaryExpressionModuloParen", "Text") 'Application.AddKeyBinding("Ctrl+Alt+Shift+Q", "BinaryExpressionOr", "Text") 'Application.AddKeyBinding("Ctrl+Alt+Shift+W", "BinaryExpressionOrParen", "Text") 'Application.AddKeyBinding("Ctrl+Alt+Shift+E", "BinaryExpressionPlus", "Text") 'Application.AddKeyBinding("Ctrl+Alt+Shift+R", "BinaryExpressionPlusParen", "Text") 'Application.AddKeyBinding("Ctrl+Alt+Shift+T", "BinaryExpressionShiftLeft", "Text") 'Application.AddKeyBinding("Ctrl+Alt+Shift+Y", "BinaryExpressionShiftLeftParen", "Text") 'Application.AddKeyBinding("Ctrl+Alt+Shift+U", "BinaryExpressionShiftRight", "Text") 'Application.AddKeyBinding("Ctrl+Alt+Shift+I", "BinaryExpressionShiftRightParen", "Text") 'Application.AddKeyBinding("Ctrl+Alt+Shift+O", "BinaryExpressionTimes", "Text") 'Application.AddKeyBinding("Ctrl+Alt+Shift+P", "BinaryExpressionTimesParen", "Text") 'Application.AddKeyBinding("Ctrl+Alt+Shift+A", "BinaryExpressionUnequalParen", "Text") 'Application.AddKeyBinding("Ctrl+Alt+Shift+S", "DeclarationFunction", "Text") 'Application.AddKeyBinding("Ctrl+Alt+Shift+D", "DeclarationFunctionPureVirtual", "Text") 'Application.AddKeyBinding("Ctrl+Alt+Shift+F", "DeclarationFunctionVirtual", "Text") 'Application.AddKeyBinding("Ctrl+Alt+Shift+G", "DeclarationUsing", "Text") 'Application.AddKeyBinding("Ctrl+Alt+Shift+H", "DeclarationUsingNamespace", "Text") 'Application.AddKeyBinding("Ctrl+Alt+Shift+J", "DefinitionClass", "Text") 'Application.AddKeyBinding("Ctrl+Alt+Shift+K", "DefinitionEnum", "Text") 'Application.AddKeyBinding("Ctrl+Alt+Shift+L", "DefinitionFunction", "Text") 'Application.AddKeyBinding("Ctrl+Alt+Shift+Z", "DefinitionTemplateClass", "Text") 'Application.AddKeyBinding("Ctrl+Alt+Shift+X", "DefinitionTemplateFunction", "Text") 'Application.AddKeyBinding("Ctrl+Alt+Shift+C", "DefinitionUnion", "Text") 'Application.AddKeyBinding("Ctrl+Alt+Shift+V", "ExpressionAddressof", "Text") 'Application.AddKeyBinding("Ctrl+Alt+Shift+B", "ExpressionBitNot", "Text") 'Application.AddKeyBinding("Ctrl+Alt+Shift+N", "ExpressionBrackets", "Text") 'Application.AddKeyBinding("Ctrl+Alt+Shift+M", "ExpressionCastConst", "Text") 'Application.AddKeyBinding("Ctrl+Alt+Shift+Ins", "ExpressionConditionalParen", "Text") 'Application.AddKeyBinding("Ctrl+Alt+Shift+Left Arrow", "ExpressionDecrement", "Text") 'Application.AddKeyBinding("Ctrl+Alt+Shift+Right Arrow", "ExpressionDelete", "Text") 'Application.AddKeyBinding("Ctrl+Alt+Shift+Up Arrow", "ExpressionDeleteArray", "Text") 'Application.AddKeyBinding("Ctrl+Alt+Shift+Down Arrow", "ExpressionDereference", "Text") 'Application.AddKeyBinding("Ctrl+Alt+Shift+Backspace", "ExpressionNegative", "Text") 'Application.AddKeyBinding("Ctrl+Alt+Shift+Home", "ExpressionNew", "Text") 'Application.AddKeyBinding("Ctrl+Alt+Shift+End", "ExpressionNewArray", "Text") 'Application.AddKeyBinding("Ctrl+Alt+Shift+Page Up", "ExpressionNewInitialize", "Text") 'Application.AddKeyBinding("Ctrl+Alt+Shift+Page Down", "ExpressionNot", "Text") 'Application.AddKeyBinding("Ctrl+Alt+Shift+Enter", "ExpressionParen", "Text") 'Application.AddKeyBinding("Ctrl+Alt+Shift+Space", "ExpressionPostDecrement", "Text") 'Application.AddKeyBinding("Alt+Shift+F2", "ExpressionPostIncrement", "Text") 'Application.AddKeyBinding("Alt+Shift+F3", "ExpressionSizeof", "Text") 'Application.AddKeyBinding("Alt+Shift+F4", "ExpressionTypeid", "Text") 'Application.AddKeyBinding("Alt+Shift+F5", "FileClassHAndCpp", "Text") 'Application.AddKeyBinding("Alt+Shift+F7", "FileDequeTypedefH", "Text") 'Application.AddKeyBinding("Alt+Shift+F8", "FileEnumHAndCpp", "Text") 'Application.AddKeyBinding("Alt+Shift+F9", "FileListTypedefH", "Text") 'Application.AddKeyBinding("Alt+Shift+1", "FileSetTypedefH", "Text") 'Application.AddKeyBinding("Alt+Shift+2", "FileVectorTypedefH", "Text") 'Application.AddKeyBinding("Alt+Shift+3", "GlobalReplace", "Text") 'Application.AddKeyBinding("Alt+Shift+4", "LoopDoBrace", "Text") 'Application.AddKeyBinding("Alt+Shift+5", "LoopFor", "Text") 'Application.AddKeyBinding("Alt+Shift+6", "LoopForBrace", "Text") 'Application.AddKeyBinding("Alt+Shift+7", "LoopForEachBrace", "Text") 'Application.AddKeyBinding("Alt+Shift+8", "LoopWhileBrace", "Text") 'Application.AddKeyBinding("Alt+Shift+9", "PreprocessorDefine", "Text") 'Application.AddKeyBinding("Alt+Shift+0", "PreprocessorElse", "Text") 'Application.AddKeyBinding("Alt+Shift+Q", "PreprocessorIf", "Text") 'Application.AddKeyBinding("Alt+Shift+W", "PreprocessorIfdef", "Text") 'Application.AddKeyBinding("Alt+Shift+E", "PreprocessorIfndef", "Text") 'Application.AddKeyBinding("Alt+Shift+R", "PreprocessorIncludeDiamond", "Text") 'Application.AddKeyBinding("Alt+Shift+Y", "PreprocessorIncludeQuoted", "Text") 'Application.AddKeyBinding("Alt+Shift+U", "PreprocessorUndef", "Text") 'Application.AddKeyBinding("Alt+Shift+I", "QualifierConst", "Text") 'Application.AddKeyBinding("Alt+Shift+O", "QualifierConstReference", "Text") 'Application.AddKeyBinding("Alt+Shift+P", "SpecifierInline", "Text") 'Application.AddKeyBinding("Alt+Shift+A", "SpecifierProtected", "Text") 'Application.AddKeyBinding("Alt+Shift+S", "SpecifierPublic", "Text") 'Application.AddKeyBinding("Alt+Shift+D", "SpecifierThrow", "Text") 'Application.AddKeyBinding("Alt+Shift+F", "StatementAssert", "Text") 'Application.AddKeyBinding("Alt+Shift+G", "StatementAssertxArg", "Text") 'Application.AddKeyBinding("Alt+Shift+H", "StatementAssertxPost", "Text") 'Application.AddKeyBinding("Alt+Shift+J", "StatementAssertxPre", "Text") 'Application.AddKeyBinding("Alt+Shift+K", "StatementAssign", "Text") 'Application.AddKeyBinding("Alt+Shift+Z", "StatementBitXOrAssign", "Text") 'Application.AddKeyBinding("Alt+Shift+X", "StatementBrace", "Text") 'Application.AddKeyBinding("Alt+Shift+C", "StatementBreak", "Text") 'Application.AddKeyBinding("Alt+Shift+V", "StatementCase", "Text") 'Application.AddKeyBinding("Alt+Shift+B", "StatementCatch", "Text") 'Application.AddKeyBinding("Alt+Shift+N", "StatementContinue", "Text") 'Application.AddKeyBinding("Alt+Shift+M", "StatementDefault", "Text") 'Application.AddKeyBinding("Alt+Shift+Ins", "StatementIf", "Text") 'Application.AddKeyBinding("Alt+Shift+Left Arrow", "StatementIfBrace", "Text") 'Application.AddKeyBinding("Alt+Shift+Right Arrow", "StatementMinusAssign", "Text") 'Application.AddKeyBinding("Alt+Shift+Up Arrow", "StatementModuloAssign", "Text") 'Application.AddKeyBinding("Alt+Shift+Down Arrow", "StatementMultiplyAssign", "Text") 'Application.AddKeyBinding("Alt+Shift+Backspace", "StatementShiftLeftAssign", "Text") 'Application.AddKeyBinding("Alt+Shift+Del", "StatementShiftRightAssign", "Text") 'Application.AddKeyBinding("Alt+Shift+Home", "StatementSwitch", "Text") 'Application.AddKeyBinding("Alt+Shift+End", "StatementThrow", "Text") 'Application.AddKeyBinding("Alt+Shift+Page Up", "StatementTryCatch", "Text") 'Application.AddKeyBinding("Alt+Shift+Page Down", "BinaryExpressionDivide", "Text") 'Application.AddKeyBinding("Alt+Shift+Enter", "BinaryExpressionDivideParen", "Text") 'Application.AddKeyBinding("Alt+Shift+Space", "BinaryExpressionEqual", "Text") 'Application.AddKeyBinding("Shift+F7", "FileMapTypedefH", "Text") 'Application.AddKeyBinding("Shift+F8", "FileMultimapTypedefH", "Text") 'Application.AddKeyBinding("Ctrl+Alt+1", "BinaryExpressionEqualParen", "Text") 'Application.AddKeyBinding("Ctrl+Alt+2", "BinaryExpressionModulo", "Text") 'Application.AddKeyBinding("Ctrl+Alt+3", "DefinitionFunctionFromPrototype", "Text") 'Application.AddKeyBinding("Ctrl+Alt+4", "DefinitionNamespace", "Text") 'Application.AddKeyBinding("Ctrl+Alt+5", "FileMultisetTypedefH", "Text") 'Application.AddKeyBinding("Ctrl+Alt+6", "PreprocessorEndif", "Text") 'Application.AddKeyBinding("Ctrl+Alt+7", "StatementBitAndAssign", "Text") 'Application.AddKeyBinding("Ctrl+Alt+8", "StatementBitOrAssign", "Text") 'Application.AddKeyBinding("Ctrl+Alt+9", "StatementElse", "Text") 'Application.AddKeyBinding("Ctrl+Alt+0", "CommentNote", "Text") 'Application.AddKeyBinding("Ctrl+Alt+Q", "CommentBlock", "Text") 'Application.AddKeyBinding("Ctrl+Alt+W", "ExpressionCastDynamic", "Text") 'Application.AddKeyBinding("Ctrl+Alt+E", "ExpressionCastReinterpret", "Text") 'Application.AddKeyBinding("Ctrl+Alt+R", "ExpressionCastStatic", "Text") 'Application.AddKeyBinding("Ctrl+Alt+Y", "ExpressionConditional", "Text") 'Application.AddKeyBinding("Ctrl+Alt+U", "ExpressionDiamond", "Text") 'Application.AddKeyBinding("Ctrl+Alt+I", "ExpressionIncrement", "Text") 'Application.AddKeyBinding("Ctrl+Alt+O", "StatementDivideAssign", "Text") 'Application.AddKeyBinding("Ctrl+Alt+A", "StatementElseBrace", "Text") 'Application.AddKeyBinding("Ctrl+Alt+S", "StatementEmpty", "Text") 'Application.AddKeyBinding("Ctrl+Alt+D", "StatementPlusAssign", "Text") 'Application.AddKeyBinding("Ctrl+Alt+F", "StatementReturn", "Text") 'Application.AddKeyBinding("Ctrl+Alt+G", "BinaryExpressionUnequal", "Text") 'Application.AddKeyBinding("Ctrl+Alt+H", "SpecifierPrivate", "Text") ' NOTE: These didn't work! ' F10 ' F11 ' F12 ' = ' - ' ' ' ; ' . ' , ' / ' ` ' [ ' ] ' \ End Sub Sub CommentTodo() InsertFormattedCode("// TODO: ", True, 1, 0, 0) End Sub Sub CommentNote() InsertFormattedCode("// NOTE: ", True, 1, 0, 0) End Sub Sub CommentStaticMembers() InsertFormattedCode("// -------- static members --------", False, 1, 0, 0) End Sub Sub CommentInstanceMembers() InsertFormattedCode("// -------- instance members --------", False, 1, 0, 0) End Sub Sub CommentBlock() InsertFormattedCode("/* " & vbLf & "*/", True, 2, 0, 0) End Sub Sub XmlCommentValue() InsertFormattedCode("/// ", False, 1, 8, 0) End Sub Sub XmlCommentParamref() ActiveDocument.Selection.Text = "" ActiveDocument.Selection.CharLeft(False, 1) End Sub Sub XmlCommentSee() ActiveDocument.Selection.Text = "" ActiveDocument.Selection.CharLeft(False, 1) End Sub Sub XmlCommentSeeTrue() XmlCommentSeeLangword("true") End Sub Sub XmlCommentSeeFalse() XmlCommentSeeLangword("false") End Sub Sub XmlCommentSeeNull() XmlCommentSeeLangword("null") End Sub Sub XmlCommentSeeStatic() XmlCommentSeeLangword("static") End Sub Sub XmlCommentSeeVirtual() XmlCommentSeeLangword("virtual") End Sub Sub XmlCommentSeeAbstract() XmlCommentSeeLangword("abstract") End Sub Sub XmlCommentSeeSealed() XmlCommentSeeLangword("sealed") End Sub Sub XmlCommentSeeLangword(ByVal Word As String) ActiveDocument.Selection.Text = "" ActiveDocument.Selection.CharLeft(False, 1) End Sub Sub PreprocessorIf() 'DESCRIPTION: Create a #if directive. InsertFormattedCode("#if " & vbLf & "#endif", True, 2, 0, 0) End Sub Sub PreprocessorIfdef() 'DESCRIPTION: Create a #ifdef directive. InsertFormattedCode("#ifdef " & vbLf & "#endif // " & ActiveDocument.Selection.Text, True, 2, 0, 0) End Sub Sub PreprocessorIfndef() 'DESCRIPTION: Create a #ifndef directive. InsertFormattedCode("#ifndef " & vbLf & "#endif // " & ActiveDocument.Selection.Text, True, 2, 0, 0) End Sub Sub PreprocessorElse() 'DESCRIPTION: Create a #else directive. InsertFormattedCode("#else", False, 1, 0, 0) End Sub Sub PreprocessorEndif() 'DESCRIPTION: Create a #endif directive. InsertFormattedCode("#endif // ", True, 1, 0, 0) End Sub Sub PreprocessorDefine() 'DESCRIPTION: Create a #define directive. InsertFormattedCode("#define ", True, 1, 0, 0) End Sub Sub PreprocessorUndef() 'DESCRIPTION: Create a #undef directive. InsertFormattedCode("#undef ", True, 1, 0, 0) End Sub Sub PreprocessorRegion() Dim comment As String = InputBox("Region comment:") InsertFormattedCode("#region " & comment & vbLf & "#endregion " & comment, False, 2, 0, 0) End Sub Sub DefinitionEnum() 'DESCRIPTION: Create an enum definition. InsertFormattedCode("public enum " & vbLf & "{" & vbLf & _ " = ," & vbLf & "};", True, 4, 0, 0) End Sub Sub DefinitionNamespace() 'DESCRIPTION: Create a namespace definition. InsertFormattedCode("namespace " & vbLf & "{" & vbLf & "}", True, 3, 0, 0) End Sub Sub DefinitionClass() 'DESCRIPTION: Create a class definition. InsertFormattedCode("public class " & vbLf & "{" & vbLf & "}", True, 3, 0, 0) End Sub Sub DeclarationUsing() 'DESCRIPTION: Create a using declaration. InsertFormattedCode("using ;", True, 1, 1, 0) End Sub Sub DefinitionGet() InsertFormattedCode("get { return ; }", True, 1, 3, 0) End Sub Sub DefinitionSet() InsertFormattedCode("set { = value; }", True, 1, 11, 0) End Sub Sub DefinitionFunction() 'DESCRIPTION: Create a function definition. InsertFunction("F", vsCMFunction.vsCMFunctionFunction, vsCMTypeRef.vsCMTypeRefVoid, _ vsCMAccess.vsCMAccessPrivate) End Sub Sub AccessSpecifierPublic() Dim ts As TextSelection = ActiveDocument.Selection ts.StartOfLine(vsStartOfLineOptions.vsStartOfLineOptionsFirstText) ts.WordRight(True, 1) If ts.Text = "public " Then ts.StartOfLine(vsStartOfLineOptions.vsStartOfLineOptionsFirstText) Return End If If ts.Text = "protected " Then ts.WordRight(True, 1) If ts.Text <> "protected internal " Then ts.StartOfLine(vsStartOfLineOptions.vsStartOfLineOptionsFirstText) ts.WordRight(True, 1) End If ElseIf Not (ts.Text = "private " Or ts.Text = "internal ") Then ts.StartOfLine(vsStartOfLineOptions.vsStartOfLineOptionsFirstText) End If ts.Text = "public " End Sub Sub AccessSpecifierPrivate() Dim ts As TextSelection = ActiveDocument.Selection ts.StartOfLine(vsStartOfLineOptions.vsStartOfLineOptionsFirstText) ts.WordRight(True, 1) If ts.Text = "private " Then ts.StartOfLine(vsStartOfLineOptions.vsStartOfLineOptionsFirstText) Return End If If ts.Text = "protected " Then ts.WordRight(True, 1) If ts.Text <> "protected internal " Then ts.StartOfLine(vsStartOfLineOptions.vsStartOfLineOptionsFirstText) ts.WordRight(True, 1) End If ElseIf Not (ts.Text = "public " Or ts.Text = "internal ") Then ts.StartOfLine(vsStartOfLineOptions.vsStartOfLineOptionsFirstText) End If ts.Text = "private " End Sub Sub AccessSpecifierProtected() Dim ts As TextSelection = ActiveDocument.Selection ts.StartOfLine(vsStartOfLineOptions.vsStartOfLineOptionsFirstText) ts.WordRight(True, 1) If (ts.Text = "protected ") Then ts.WordRight(True, 1) If Not ts.Text = "protected internal " Then ts.StartOfLine(vsStartOfLineOptions.vsStartOfLineOptionsFirstText) Return End If ElseIf Not (ts.Text = "public " Or ts.Text = "private " Or ts.Text = "internal ") Then ts.StartOfLine(vsStartOfLineOptions.vsStartOfLineOptionsFirstText) End If ts.Text = "protected " End Sub Sub AccessSpecifierInternal() Dim ts As TextSelection = ActiveDocument.Selection ts.StartOfLine(vsStartOfLineOptions.vsStartOfLineOptionsFirstText) ts.WordRight(True, 1) If ts.Text = "internal " Then ts.StartOfLine(vsStartOfLineOptions.vsStartOfLineOptionsFirstText) Return End If If ts.Text = "protected " Then ts.WordRight(True, 1) If ts.Text <> "protected internal " Then ts.StartOfLine(vsStartOfLineOptions.vsStartOfLineOptionsFirstText) ts.WordRight(True, 1) End If ElseIf Not (ts.Text = "public " Or ts.Text = "private ") Then ts.StartOfLine(vsStartOfLineOptions.vsStartOfLineOptionsFirstText) End If ts.Text = "internal " End Sub Sub AccessSpecifierProtectedInternal() Dim ts As TextSelection = ActiveDocument.Selection ts.StartOfLine(vsStartOfLineOptions.vsStartOfLineOptionsFirstText) ts.WordRight(True, 1) If (ts.Text = "protected ") Then ts.WordRight(True, 1) If ts.Text = "protected internal " Then ts.StartOfLine(vsStartOfLineOptions.vsStartOfLineOptionsFirstText) Return End If ts.StartOfLine(vsStartOfLineOptions.vsStartOfLineOptionsFirstText) ts.WordRight(True, 1) ElseIf Not (ts.Text = "public " Or ts.Text = "private " Or ts.Text = "internal ") Then ts.StartOfLine(vsStartOfLineOptions.vsStartOfLineOptionsFirstText) End If ts.Text = "protected internal " End Sub Private constSet As String() = {"static", "readonly"} Sub ModifierConst() ToggleModifierSet("const", constSet) End Sub Private staticSet As String() = {"const", "virtual", "override", "abstract"} Sub ModifierStatic() ToggleModifierSet("static", staticSet) End Sub Private functionType As String() = {"virtual", "override", "abstract", "static"} Sub ModifierVirtual() ToggleModifierSet("virtual", functionType) End Sub Sub ModifierOverride() ToggleModifierSet("override", functionType) End Sub Sub ModifierAbstract() ToggleModifierSet("abstract", functionType) End Sub ' should include abstract here, but we would have to look at the context and see if it is ' a class or a function Private classType As String() = {"sealed"} Sub ModifierSealed() ToggleModifierSet("sealed", classType) End Sub ' this works for modifiers just past access modifiers -- but not for readonly Private Sub ToggleModifierSet(ByVal modifier As String, ByVal values As String()) modifier = modifier & " " Dim ts As TextSelection = ActiveDocument.Selection Dim contextWasOpen As Boolean = DTE.UndoContext.IsOpen() If Not contextWasOpen Then ' Open the UndoContext object to put all operations in one transaction. DTE.UndoContext.Open("Toggle " & modifier) End If Try ts.StartOfLine(vsStartOfLineOptions.vsStartOfLineOptionsFirstText) ts.WordRight(True) MovePastAccessModifier() ' either toggle modifier on or off, or delete modifiers in set, and insert a different modifier If ts.Text = modifier Then ts.Delete() Else Dim s As String For Each s In values If Trim(ts.Text) = s Then ts.Delete() ts.WordRight(True) End If Next ts.MoveToPoint(ts.AnchorPoint) ts.Text = modifier End If Finally If Not contextWasOpen Then ' Close the UndoContext object to commit the changes. DTE.UndoContext.Close() End If End Try End Sub Private Sub MovePastAccessModifier() Dim ts As TextSelection = ActiveDocument.Selection Dim text As String = Trim(ts.Text) If (text = "public" Or text = "private" Or text = "protected" Or text = "internal") Then ts.MoveToPoint(ts.BottomPoint) ts.WordRight(True) If Trim(ts.Text) = "internal" Then ts.MoveToPoint(ts.BottomPoint) ts.WordRight(True) End If End If End Sub ' NOTE: this codes has not been useful, as GetCurrentMember usually returns nothing Private Sub ChangeAccess(ByVal access As vsCMAccess) Dim ce As CodeElement = GetCurrentMember() If ce.IsCodeType Then Dim ct As CodeType = ce ct.Access = access Exit Sub End If Select Case ce.Kind Case vsCMElement.vsCMElementFunction Dim f As CodeFunction = ce f.Access = access Case vsCMElement.vsCMElementProperty Dim p As CodeProperty = ce p.Access = access Case vsCMElement.vsCMElementVariable Dim v As CodeVariable = ce v.Access = access End Select End Sub Sub StatementEmpty() 'DESCRIPTION: Create an empty statement. InsertFormattedCode(";", True, 1, 1, 0) End Sub Sub StatementAssert() 'DESCRIPTION: Create an assertion disabled in the release build. InsertFormattedCode("ASSERT();", True, 1, 2, 0) End Sub Sub StatementAssertxArg() 'DESCRIPTION: Create an assertion to validate a selected argument. Dim Arg, AtBrace Arg = ActiveDocument.Selection.Text AtBrace = ActiveDocument.Selection.FindText("{") InsertFormattedCode("ASSERTX_ARG(" + Arg + ");", Not AtBrace, 1, 2, 0) End Sub Sub StatementAssertxPre() 'DESCRIPTION: Create an assertion to validate a pre-condition. InsertFormattedCode("ASSERTX_PRE();", True, 1, 2, 0) End Sub Sub StatementAssertxPost() 'DESCRIPTION: Create an assertion to validate a post-condition. InsertFormattedCode("ASSERTX_POST();", True, 1, 2, 0) End Sub Sub StatementBrace() 'DESCRIPTION: Add a pair of brace. InsertFormattedCode("{" & vbLf & "}", False, 2, 0, 0) End Sub Sub StatementIf() 'DESCRIPTION: Create an if statement. InsertFormattedCode("if ()", True, 1, 1, 0) End Sub Sub StatementIfBrace() 'DESCRIPTION: Create an if statement with brace. InsertFormattedCode("if ()" & vbLf & "{" & vbLf & "}", True, 3, 1, 0) End Sub Sub StatementElse() 'DESCRIPTION: Create an else statement. InsertFormattedCode("else", False, 1, 0, 0) End Sub Sub StatementElseBrace() 'DESCRIPTION: Create an else statement with brace. InsertFormattedCode("else" & vbLf & "{" & vbLf & "}", False, 3, 0, 1) End Sub Sub StatementSwitch() 'DESCRIPTION: Create a switch statement. InsertFormattedCode("switch ()" & vbLf & "{" & vbLf & _ "case :" & vbLf & "break;" & vbLf & "case :" & vbLf & "break;" & vbLf & _ "default:" & vbLf & "}", True, 8, 1, 0) End Sub Sub StatementCase() 'DESCRIPTION: Create a case statement. InsertFormattedCode("case :", True, 1, 1, 0) End Sub Sub StatementBreak() 'DESCRIPTION: Create a break statement. InsertFormattedCode("break;", False, 1, 0, 0) End Sub Sub StatementDefault() 'DESCRIPTION: Create a default statement. InsertFormattedCode("default:", False, 1, 0, 0) End Sub Sub StatementContinue() 'DESCRIPTION: Create a continue statement. InsertFormattedCode("continue;", False, 1, 0, 0) End Sub Sub StatementReturn() 'DESCRIPTION: Create an return statement. If ActiveDocument.Selection.Text <> "" Then InsertFormattedCode("return ;", True, 1, 1, 0) Else InsertFormattedCode("return;", False, 1, 1, 0) End If End Sub Sub StatementTryCatch() 'DESCRIPTION: Create a try-catch statement. InsertFormattedCode("try" & vbLf & "{" & vbLf & "}" & vbLf & _ "catch (Exception e)" & vbLf & "{" & vbLf & "}", True, 6, 0, 1) End Sub Sub StatementTryFinally() 'DESCRIPTION: Create a try-finally statement. InsertFormattedCode("try" & vbLf & "{" & vbLf & "}" & vbLf & _ "finally" & vbLf & "{" & vbLf & "}", True, 6, 0, 1) End Sub Sub StatementCatch() 'DESCRIPTION: Create a catch statement. InsertFormattedCode("catch (Exception e)" & vbLf & "{" & vbLf & "}", True, 3, 12, 0) End Sub Sub StatementFinally() 'DESCRIPTION: Create a finally statement. InsertFormattedCode("finally" & vbLf & "{" & vbLf & "}", True, 3, 0, 1) End Sub Sub StatementThrow() 'DESCRIPTION: Create a throw statement. InsertFormattedCode("throw new ApplicationException("", e);", False, 1, 23, 0) Dim ts As TextSelection = ActiveDocument.Selection ts.CharRight(True, Len("Application")) End Sub Sub StatementAssign() 'DESCRIPTION: Create an assignment statement. InsertFormattedAssignment("= ;", 3) End Sub Sub StatementAssignAs() InsertFormattedAssignment("= as ;", 6) End Sub Sub StatementMultiplyAssign() 'DESCRIPTION: Create an multiply-assignment statement. InsertFormattedAssignment("*= ;", 4) End Sub Sub StatementDivideAssign() 'DESCRIPTION: Create a divide-assignment statement. InsertFormattedAssignment("/= ;", 4) End Sub Sub StatementModuloAssign() 'DESCRIPTION: Create a modulo-assignment statement. InsertFormattedAssignment("%= ;", 4) End Sub Sub StatementPlusAssign() 'DESCRIPTION: Create an addition-assignment statement. InsertFormattedAssignment("+= ;", 4) End Sub Sub StatementMinusAssign() 'DESCRIPTION: Create a subtration-assignment statement. InsertFormattedAssignment("-= ;", 4) End Sub Sub StatementShiftRightAssign() 'DESCRIPTION: Create a right-shift-assignment statement. InsertFormattedAssignment(">>= ;", 5) End Sub Sub StatementShiftLeftAssign() 'DESCRIPTION: Create a left-shift-assignment statement. InsertFormattedAssignment("<<= ;", 5) End Sub Sub StatementBitAndAssign() 'DESCRIPTION: Create a bitwise-and-assignment statement. InsertFormattedAssignment("&= ;", 4) End Sub Sub StatementBitOrAssign() 'DESCRIPTION: Create a bitwise-or-assignment statement. InsertFormattedAssignment("|= ;", 4) End Sub Sub StatementBitXOrAssign() 'DESCRIPTION: Create a bitwise-xor-assignment statement. InsertFormattedAssignment("^= ;", 4) End Sub Sub InsertFormattedAssignment(ByVal Text, ByVal Length) 'DESCRIPTION: Insert an assignment statement and smart format it. If ActiveDocument.Selection.Text <> "" Then InsertFormattedCode(ActiveDocument.Selection.Text & " " & Text, False, 1, 1, 0) Else InsertFormattedCode(Text, False, 1, Length, 0) End If End Sub Sub LoopFor() 'DESCRIPTION: Create a for loop. InsertFormattedCode("for (; ; )", True, 1, 5, 0) End Sub Sub LoopForBrace() 'DESCRIPTION: Create a for loop with brace. InsertFormattedCode("for (; ; )" & vbLf & "{" & vbLf & "}", True, 3, 5, 0) End Sub Sub LoopWhileBrace() 'DESCRIPTION: Create a while loop with brace. InsertFormattedCode("while ()" & vbLf & "{" & vbLf & "}", True, 3, 1, 0) End Sub Sub LoopDoBrace() 'DESCRIPTION: Create a do loop with brace. InsertFormattedCode("do" & vbLf & "{" & vbLf & "}" & vbLf & "while ();", _ True, 4, 2, 3) End Sub Sub LoopForEachBrace() 'DESCRIPTION: Create a foreach loop with brace. InsertFormattedCode("foreach ( in )" & vbLf & "{" & vbLf & "}", True, 3, 1, 0) End Sub Private Sub InsertFormattedCode(ByVal Text As String, ByVal CopySelection As Boolean, ByVal NumLines As Integer, _ ByVal NumCharLeft As Integer, ByVal NumLinesDown As Integer) 'DESCRIPTION: Insert some code and smart format it. NumCharLeft, NumLinesDown is final selection point. Dim ts As TextSelection = ActiveDocument.Selection Dim OldSelection As String = ts.Text Dim contextWasOpen As Boolean = DTE.UndoContext.IsOpen() If Not contextWasOpen Then ' Open the UndoContext object to put all operations in one transaction. DTE.UndoContext.Open("Insert """ & Text.Replace(vbLf, "") & """") End If Try ' Insert text and smart format ts.StartOfLine(vsStartOfLineOptions.vsStartOfLineOptionsFirstColumn) ' to ensure selection does not move Dim epBegin As EditPoint = ts.ActivePoint.CreateEditPoint() Dim epEnd As EditPoint = ts.ActivePoint.CreateEditPoint() epBegin.EndOfLine() epEnd.EndOfLine() epEnd.Insert(vbCrLf & Text) epBegin.SmartFormat(epEnd) ' put cursor and old selection in correct location If epEnd.Line > ts.TopPoint.Line Then NumLinesDown += 1 End If ts.LineDown(False, NumLinesDown) ts.EndOfLine(False) If NumCharLeft <> 0 Then ts.CharLeft(False, NumCharLeft) End If If CopySelection Then ts.Insert(OldSelection, vsInsertFlags.vsInsertFlagsContainNewText) End If Finally If Not contextWasOpen Then ' Close the UndoContext object to commit the changes. DTE.UndoContext.Close() End If End Try End Sub Private Function InsertFunction(ByVal name As String, ByVal type As vsCMFunction, _ ByVal returnType As vsCMTypeRef, ByVal access As vsCMAccess) As CodeFunction Dim c As CodeClass = GetCurrentClass() If c Is Nothing Then MsgBox("AddFunction can only be used in a class.") Exit Function End If Dim currentFunction As CodeFunction = GetCurrentFunction() Dim newFunction As CodeFunction If currentFunction Is Nothing Then newFunction = c.AddFunction(name, type, returnType, 0, access) Else newFunction = c.AddFunction(name, type, returnType, currentFunction, access) End If Dim ts As TextSelection = ActiveDocument.Selection ts.MoveToPoint(newFunction.StartPoint(), False) Return newFunction End Function Private Function GetCurrentClass() As CodeClass Dim ts As TextSelection = ActiveDocument.Selection Dim ce As CodeElement = ts.ActivePoint.CodeElement(vsCMElement.vsCMElementNamespace) While (Not ce Is Nothing) And ce.Kind <> vsCMElement.vsCMElementClass ce = ce.Collection.Parent End While Return ce End Function Private Function GetCurrentFunction() As CodeFunction Dim ts As TextSelection = ActiveDocument.Selection Dim ce As CodeElement = ts.ActivePoint.CodeElement(vsCMElement.vsCMElementClass) If ce Is Nothing Then Return Nothing End If If ce.Kind <> vsCMElement.vsCMElementFunction Then Return Nothing End If Return ce End Function Private Function GetCurrentMember() As CodeElement Dim ts As TextSelection = ActiveDocument.Selection Dim ce As CodeElement ce = ts.ActivePoint.CodeElement(vsCMElement.vsCMElementVariable) If ce Is Nothing Then ce = ts.ActivePoint.CodeElement(vsCMElement.vsCMElementClass) End If If ce Is Nothing Then ce = ts.ActivePoint.CodeElement(vsCMElement.vsCMElementNamespace) End If Return ce End Function Sub BinaryExpressionAnd() 'DESCRIPTION: Insert an and expression. InsertBinaryExpression("&&") End Sub Sub BinaryExpressionAndParen() 'DESCRIPTION: Insert an and expression with parentheses. InsertBinaryExpressionParen("&&") End Sub Sub BinaryExpressionOr() 'DESCRIPTION: Insert an or expression. InsertBinaryExpression("||") End Sub Sub BinaryExpressionOrParen() 'DESCRIPTION: Insert an or expression with parentheses. InsertBinaryExpressionParen("||") End Sub Sub BinaryExpressionEqualNull() InsertBinaryExpressionAndValue("== null") End Sub Sub BinaryExpressionUnequalNull() InsertBinaryExpressionAndValue("!= null") End Sub Sub BinaryExpressionEqual() 'DESCRIPTION: Insert an equal expression. InsertBinaryExpression("==") End Sub Sub BinaryExpressionEqualParen() 'DESCRIPTION: Insert an equal expression with parentheses. InsertBinaryExpressionParen("==") End Sub Sub BinaryExpressionUnequal() 'DESCRIPTION: Insert an unequal expression. InsertBinaryExpression("!=") End Sub Sub BinaryExpressionUnequalParen() 'DESCRIPTION: Insert an unequal expression with parentheses. InsertBinaryExpressionParen("!=") End Sub Sub BinaryExpressionLessThan() 'DESCRIPTION: Insert a less-than expression. InsertBinaryExpression("<") End Sub Sub BinaryExpressionLessThanParen() 'DESCRIPTION: Insert a less-than expression with parentheses. InsertBinaryExpressionParen("<") End Sub Sub BinaryExpressionLessEqual() 'DESCRIPTION: Insert a less-than-or-equals expression. InsertBinaryExpression("<=") End Sub Sub BinaryExpressionLessEqualParen() 'DESCRIPTION: Insert a less-than-or-equals expression with parentheses. InsertBinaryExpressionParen("<=") End Sub Sub BinaryExpressionGreaterThan() 'DESCRIPTION: Insert a greater-than expression. InsertBinaryExpression(">") End Sub Sub BinaryExpressionGreaterThanParen() 'DESCRIPTION: Insert a greater-than expression with parentheses. InsertBinaryExpressionParen(">") End Sub Sub BinaryExpressionGreaterEqual() 'DESCRIPTION: Insert a greater-than-or-equals expression. InsertBinaryExpression(">=") End Sub Sub BinaryExpressionGreaterEqualParen() 'DESCRIPTION: Insert a greater-than-or-equals expression with parentheses. InsertBinaryExpressionParen(">=") End Sub Sub BinaryExpressionIs() InsertBinaryExpression("is") End Sub Sub BinaryExpressionBitAnd() 'DESCRIPTION: Insert a bitwise and expression. InsertBinaryExpression("&") End Sub Sub BinaryExpressionBitAndParen() 'DESCRIPTION: Insert a bitwise and expression with parentheses. InsertBinaryExpressionParen("&") End Sub Sub BinaryExpressionBitOr() 'DESCRIPTION: Insert a bitwise or expression. InsertBinaryExpression("|") End Sub Sub BinaryExpressionBitOrParen() 'DESCRIPTION: Insert a bitwise or expression with parentheses. InsertBinaryExpressionParen("|") End Sub Sub BinaryExpressionBitXOr() 'DESCRIPTION: Insert a bitwise xor expression. InsertBinaryExpression("^") End Sub Sub BinaryExpressionBitXOrParen() 'DESCRIPTION: Insert a bitwise xor expression with parentheses. InsertBinaryExpressionParen("^") End Sub Sub BinaryExpressionTimes() 'DESCRIPTION: Insert a multiplication expression. InsertBinaryExpression("*") End Sub Sub BinaryExpressionTimesParen() 'DESCRIPTION: Insert a multiplication expression with parentheses. InsertBinaryExpressionParen("*") End Sub Sub BinaryExpressionDivide() 'DESCRIPTION: Insert a division expression. InsertBinaryExpression("/") End Sub Sub BinaryExpressionDivideParen() 'DESCRIPTION: Insert a division expression with parentheses. InsertBinaryExpressionParen("/") End Sub Sub BinaryExpressionModulo() 'DESCRIPTION: Insert a modulo expression. InsertBinaryExpression("%") End Sub Sub BinaryExpressionModuloParen() 'DESCRIPTION: Insert a modulo expression with parentheses. InsertBinaryExpressionParen("%") End Sub Sub BinaryExpressionPlus() 'DESCRIPTION: Insert an addition expression. InsertBinaryExpression("+") End Sub Sub BinaryExpressionPlusParen() 'DESCRIPTION: Insert an addition expression with parentheses. InsertBinaryExpressionParen("+") End Sub Sub BinaryExpressionMinus() 'DESCRIPTION: Insert a subtraction expression. InsertBinaryExpression("-") End Sub Sub BinaryExpressionMinusParen() 'DESCRIPTION: Insert a subtraction expression with parentheses. InsertBinaryExpressionParen("-") End Sub Sub BinaryExpressionShiftLeft() 'DESCRIPTION: Insert a left-shift expression. InsertBinaryExpression("<<") End Sub Sub BinaryExpressionShiftLeftParen() 'DESCRIPTION: Insert a left-shift expression with parentheses. InsertBinaryExpressionParen("<<") End Sub Sub BinaryExpressionShiftRight() 'DESCRIPTION: Insert a right-shift expression. InsertBinaryExpression(">>") End Sub Sub BinaryExpressionShiftRightParen() 'DESCRIPTION: Insert a right-shift expression with parentheses. InsertBinaryExpressionParen(">>") End Sub Sub InsertBinaryExpression(ByVal Operator) 'DESCRIPTION: Insert a binary expression. Dim ts As TextSelection = ActiveDocument.Selection Dim lhs As String = ts.Text ts.Text = lhs & " " & Operator & " " End Sub Sub InsertBinaryExpressionAndValue(ByVal OperatorAndValue) Dim ts As TextSelection = ActiveDocument.Selection Dim lhs As String = ts.Text ts.Text = lhs & " " & OperatorAndValue End Sub Sub InsertBinaryExpressionParen(ByVal Operator) 'DESCRIPTION: Insert a binary expression with parentheses. Dim ts As TextSelection = ActiveDocument.Selection Dim lhs As String = ts.Text ts.Text = "(" & lhs & " " & Operator & " )" If lhs <> "" Then ts.CharLeft(False, 1) Else ts.CharLeft(False, (Len(Operator) + 3)) End If End Sub Sub ExpressionConditional() 'DESCRIPTION: Insert a conditional expression. Dim Sel Sel = ActiveDocument.Selection.Text ActiveDocument.Selection.Text = Sel & " ? : " ActiveDocument.Selection.CharLeft(False, 2) End Sub Sub ExpressionConditionalParen() 'DESCRIPTION: Insert a conditional expression with parentheses. Dim Sel Sel = ActiveDocument.Selection.Text ActiveDocument.Selection.Text = "(" & Sel & " ? : )" If Sel <> "" Then ActiveDocument.Selection.CharLeft(False, 3) Else ActiveDocument.Selection.CharLeft(False, 6) End If End Sub Sub ExpressionParen() 'DESCRIPTION: Insert a pair of parentheses. ActiveDocument.Selection.Text = "(" & ActiveDocument.Selection.Text & ")" ActiveDocument.Selection.CharLeft(False, 1) End Sub Sub ExpressionBrackets() 'DESCRIPTION: Insert a pair of brackets. ActiveDocument.Selection.Text = "[" & ActiveDocument.Selection.Text & "]" ActiveDocument.Selection.CharLeft(False, 1) End Sub Sub ExpressionIncrement() 'DESCRIPTION: Insert an increment expression. ActiveDocument.Selection.Text = "++" & ActiveDocument.Selection.Text End Sub Sub ExpressionDecrement() 'DESCRIPTION: Insert a decrement expression. ActiveDocument.Selection.Text = "--" & ActiveDocument.Selection.Text End Sub Sub ExpressionPostIncrement() 'DESCRIPTION: Insert a post-increment expression. ActiveDocument.Selection.Text = ActiveDocument.Selection.Text & "++" End Sub Sub ExpressionPostDecrement() 'DESCRIPTION: Insert a post-decrement expression. ActiveDocument.Selection.Text = ActiveDocument.Selection.Text & "--" End Sub Sub ExpressionDereference() 'DESCRIPTION: Insert a pointer dereference expression. ActiveDocument.Selection.Text = "*" & ActiveDocument.Selection.Text End Sub Sub ExpressionAddressof() 'DESCRIPTION: Insert an addressof expression. ActiveDocument.Selection.Text = "&" & ActiveDocument.Selection.Text End Sub Sub ExpressionNot() 'DESCRIPTION: Insert a logical not expression. ActiveDocument.Selection.Text = "!" & ActiveDocument.Selection.Text End Sub Sub ExpressionBitNot() 'DESCRIPTION: Insert a bitwise not expression. ActiveDocument.Selection.Text = "~" & ActiveDocument.Selection.Text End Sub Sub ExpressionNegative() 'DESCRIPTION: Insert a negative expression. ActiveDocument.Selection.Text = "-" & ActiveDocument.Selection.Text End Sub Sub ExpressionNew() 'DESCRIPTION: Insert a new expression. ActiveDocument.Selection.Text = "new " & ActiveDocument.Selection.Text End Sub Sub ExpressionNewInitialize() 'DESCRIPTION: Insert a new expression which initializes. Dim Sel Sel = ActiveDocument.Selection.Text ActiveDocument.Selection.Text = "new " & Sel & "()" If Sel = "" Then ActiveDocument.Selection.CharLeft(False, 2) Else ActiveDocument.Selection.CharLeft(False, 1) End If End Sub Sub ExpressionNewArray() 'DESCRIPTION: Insert a new array expression. ActiveDocument.Selection.Text = "new " & ActiveDocument.Selection.Text & "[]" End Sub Sub ExpressionTypeof() 'DESCRIPTION: Insert a typeof expression. InsertUnaryExpressionParen("typeof") End Sub Sub ExpressionSizeof() 'DESCRIPTION: Insert a sizeof expression. InsertUnaryExpressionParen("sizeof") End Sub Sub InsertUnaryExpressionParen(ByVal Operator) 'DESCRIPTION: Insert a unary expression with parentheses. Dim Sel Sel = ActiveDocument.Selection.Text ActiveDocument.Selection.Text = Operator & "(" & Sel & ")" If Sel = "" Then ActiveDocument.Selection.CharLeft(False, 1) End If End Sub Sub LiteralTrue() Dim ts As TextSelection = ActiveDocument.Selection ts.Insert("true") End Sub Sub LiteralFalse() Dim ts As TextSelection = ActiveDocument.Selection ts.Insert("false") End Sub Sub LiteralNull() Dim ts As TextSelection = ActiveDocument.Selection ts.Insert("null") End Sub Sub LiteralString() Dim ts As TextSelection = ActiveDocument.Selection ts.Insert("""""") End Sub Sub LiteralThis() Dim ts As TextSelection = ActiveDocument.Selection ts.Insert("this") End Sub Sub TypeVoid() Dim ts As TextSelection = ActiveDocument.Selection ts.Insert("void") End Sub Sub TypeObject() Dim ts As TextSelection = ActiveDocument.Selection ts.Insert("object") End Sub Sub TypeString() Dim ts As TextSelection = ActiveDocument.Selection ts.Insert("string") End Sub Sub TypeInt() Dim ts As TextSelection = ActiveDocument.Selection ts.Insert("int") End Sub Sub TypeBool() Dim ts As TextSelection = ActiveDocument.Selection ts.Insert("bool") End Sub Sub TypeFloat() Dim ts As TextSelection = ActiveDocument.Selection ts.Insert("float") End Sub Sub TypeDouble() Dim ts As TextSelection = ActiveDocument.Selection ts.Insert("double") End Sub Function SimplifyWhitespaceNewlines(ByVal Text) 'DESCRIPTION: convert all tabs and newlines to spaces and eliminate redundant spaces Dim NewText, SpacePos NewText = "" Text = Trim(Replace(Replace(Text, vbTab, " "), vbCrLf, " ")) SpacePos = InStr(Text, " ") Do While SpacePos <> 0 NewText = NewText & Left(Text, SpacePos) Text = LTrim(Mid(Text, (SpacePos + 1))) SpacePos = InStr(Text, " ") Loop SimplifyWhitespaceNewlines = NewText & Text End Function Function ClassNameFromFileBase(ByVal FileBase) 'DESCRIPTION: compute the name of the class associated with a file name Dim ClassName, UBPos ClassName = "" UBPos = InStr(FileBase, "_") Do While UBPos <> 0 ClassName = ClassName & CapitalizeFirstLetter(Left(FileBase, (UBPos - 1))) FileBase = LTrim(Mid(FileBase, (UBPos + 1))) UBPos = InStr(FileBase, "_") Loop ClassNameFromFileBase = ClassName & CapitalizeFirstLetter(FileBase) End Function Function CapitalizeFirstLetter(ByVal Text) If Len(Text) <> 0 Then CapitalizeFirstLetter = UCase(Left(Text, 1)) & Mid(Text, 2) Else CapitalizeFirstLetter = "" End If End Function ' Collapse or expand the next get or set function found Sub FormatCollapseExpandGetSet() Dim ts As TextSelection = DTE.ActiveDocument.Selection Dim saveTs As EditPoint = ts.ActivePoint.CreateEditPoint() Dim contextWasOpen As Boolean = DTE.UndoContext.IsOpen() If Not contextWasOpen Then ' Open the UndoContext object to put all operations in one transaction. DTE.UndoContext.Open("Collapse/Expand Get/Set") End If Try ' First look on same line ts.StartOfLine(vsStartOfLineOptions.vsStartOfLineOptionsFirstText) Dim found As Boolean = ts.FindText("(get|set)", _ vsFindOptions.vsFindOptionsMatchCase + vsFindOptions.vsFindOptionsMatchWholeWord + _ vsFindOptions.vsFindOptionsRegularExpression) If Not found Then ts.MoveToPoint(saveTs) Return End If ts.CharRight() Dim endOfKeyword As EditPoint = ts.ActivePoint.CreateEditPoint() ' determine if we are collapsing or expanding Dim expand As Boolean = False If ts.FindText("}") Then If ts.ActivePoint.Line = endOfKeyword.Line Then expand = True End If End If ts.MoveToPoint(endOfKeyword) ' select to opening brace 'ts.WordRight(True) If Not ts.FindText("{") Then Return End If ts.MoveToPoint(endOfKeyword, True) collapseExpand(expand) ' select to first statement If expand Then ts.StartOfLine(vsStartOfLineOptions.vsStartOfLineOptionsFirstText) End If ts.CharRight() Dim beginBlock As EditPoint = ts.ActivePoint.CreateEditPoint() ' find first non-whitespace (note this is not the same as a .net reg expr) If Not ts.FindText("[^:Wh]", vsFindOptions.vsFindOptionsRegularExpression) Then Return End If ts.MoveToPoint(beginBlock, True) collapseExpand(expand) ' move to end of last statement If Not ts.FindText("}") Then Return End If Dim endBlock As EditPoint = ts.ActivePoint.CreateEditPoint() ts.CharLeft() Dim beforeEndBlock As EditPoint = ts.ActivePoint.CreateEditPoint() If Not ts.FindText(";", vsFindOptions.vsFindOptionsBackwards) Then Return End If ts.CharRight() ' select to closing brace ts.MoveToPoint(beforeEndBlock, True) collapseExpand(expand) endOfKeyword.SmartFormat(endBlock) Finally ts.MoveToPoint(saveTs) If Not contextWasOpen Then ' Close the UndoContext object to commit the changes. DTE.UndoContext.Close() End If End Try End Sub Private Sub collapseExpand(ByVal expand As Boolean) Dim ts As TextSelection = DTE.ActiveDocument.Selection If expand Then ts.NewLine() Else ts.Text = " " End If End Sub End Module