Preface
The above makes the JS Code folding function usable. This article will continue to improve the Code for better use and practicality, and then introduce several plug-ins in Visual Studio JS.
Article
1. VS2003 folding code Micro
2. MSDN
3. Document Outline for Client Script in Visual Studio 2005
Body
1. Continue the above transformation, mainly to support comments and display comments after region
1.1. Here we will not deploy the steps. The detailed steps above are provided.
1.2 macro code. Modify the macro used above.
Option Strict Off
Option Explicit Off
Imports System
Imports EnvDTE
Imports EnvDTE80
Imports System. Diagnostics
Imports System. Collections
Public Module JsMacros
Sub OutlineRegions ()
Const REGION_START As String = "// region"
Const REGION_END As String = "// endregion"
Dim selection As EnvDTE. TextSelection = DTE. ActiveDocument. Selection
Dim startRegions As Stack = New Stack () 'Stack
Dim intCollapseStart As Integer = 0
Dim intCollapseNum As Integer = 0
Dim strLines () As String
Selection. StartOfDocument (True)
Selection. SelectAll ()
StrLines = selection. Text. Split (vbCrLf) 'Get all rows
For I = 0 To strLines. Length-1
If strLines (I). TrimStart. StartsWith (REGION_START) Then
StartRegions. Push (I + 1) 'Save the row number
End If
If strLines (I). TrimStart. StartsWith (REGION_END) Then
IntCollapseStart = startRegions. Pop () + 1' return row number
IntCollapseNum = (I + 1)-intCollapseStart + 1'
Selection. GotoLine (intCollapseStart)
Selection. LineDown (True, intCollapseNum)
Selection. SwapAnchor ()
Selection. OutlineSection ()
End If
Next
Selection. StartOfDocument ()
End Sub
End Module
1.3 Note
1.3.1. changed from "// # region", "// # endregion" to "// region" and "// endregion" in this article ".
1.3.2 If You Want To hide the line "// region", only "... ", you only need to set the macro code" intCollapseStart = startRegions. pop () + 1 "followed by" + 1. Unfortunately, the effect of C # folding fails.
1.3.3 if You Want To support the folding of keywords such as if for, we strongly recommend Article 1. This article is also modified on the basis of this article and corrected the bug that "// region" cannot be followed by annotations.
2. Support for JS Visual Studio plug-ins
2.1 ScriptOutline is not collapsed in the trial, but it shows the outline of the method without setting shortcuts. As a plug-in and VS integration, it can also quickly find a method. Refer to Article 3.
2.1.1 download plug-in: http://www.geocities.com/evgenypages/ScriptOutline.zip
2.1.2 copy ScriptOutline. AddIn and ScriptOutline. dll from the compressed file to the directory C: \ Documents and Settings \ <username> \ My Documents \ Visual Studio 2005 \ Addins
If the Addins directory does not exist, you can create one by yourself.
2.1.3 Tools> Add-in Manager (Tools). Check the ScriptOutline plug-in and click OK to display the Script Outline window.
2.1.4 write the test code and the effect
In this way, we can quickly switch between methods! Note that the Environment used here is Microsoft Visual Studio 2005.
2.2 SmartOutline
2.2.1 download http://submain.com/download/smartoutline/ enter email address point to download.
2.2.2 install the plug-in SmartOutline_v1.1.msi and click Next. SmallOutline appears in the toolbar, and you may need to restart.
2.2.3 write the test code by step:
2.2.3.1 if you select the function to be collapsed, the following prompt appears:
2.2.3.2 click the prompt or enter the shortcut keys Alt + S and Alt + C. The following dialog box is displayed. enter the name of the comment displayed after the JS Code is folded.
2.2.3.3 Final Results
2.2.4 Summary
In comparison, it is best to use the following advantages:
A). The source code is not contaminated, and the effect of # region written in C # is the same.
B). The folding effect is good, and the comments of the code block after the folding are displayed. You do not need to turn it off like a macro and then reactivate it.
C ). this plug-in supports both VS2005 and VS2008. In addition, it also supports C #, HTML, CSS, and so on, you can see other supported files in the list under SmallOutline-> General-> Enable SmallOutline for the following files.
2.3 For the JavaScript Function Outliner plug-in, please pay attention to and support this plug-in :)
End
Macro is a good plug-in. Although there is a ready-made plug-in, I still take this opportunity to learn it. I even have the idea of using macros to help ORM tools generate some code and have reference value for code generation :)
Ben Bo Visual Studio related articles
1. Visual Studio allows JS to also support code folding [Visual Studio | # region | # endregion]
2. Visual Studio template-custom WebForm Template
3. Use Visual Studio 2005/2008 to extract resources from the EXE file [Image | htm | cursor file]
4. Microsoft Visual Studio 2005 shortcut key prompt
5. Visual Studio runs the file system site in the root directory [Visual Studio | File System | WebDev. WebServer. EXE]