Imports EnvDTE
Imports System.Diagnostics
Imports Microsoft.VisualBasic
Imports Microsoft.VisualBasic.ControlChars
Imports Microsoft.VisualBasic.Financial
'hello from paul! ' hello again!
Public Class frmCodelib
'hello from paul! ' hello again!
Inherits System.Windows.Forms.Form
Public applicationObject As EnvDTE.DTE
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub
'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents Button1 As System.Windows.Forms.Button
Friend WithEvents Button2 As System.Windows.Forms.Button
Friend WithEvents TabControl1 As System.Windows.Forms.TabControl
Friend WithEvents TabPage1 As System.Windows.Forms.TabPage
Friend WithEvents TabPage2 As System.Windows.Forms.TabPage
Friend WithEvents MainMenu1 As System.Windows.Forms.MainMenu
Friend WithEvents MenuItem1 As System.Windows.Forms.MenuItem
Friend WithEvents btnClose As System.Windows.Forms.Button
Friend WithEvents Label2 As System.Windows.Forms.Label
Friend WithEvents TabPage3 As System.Windows.Forms.TabPage
Friend WithEvents TabPage5 As System.Windows.Forms.TabPage
Friend WithEvents TabPage6 As System.Windows.Forms.TabPage
Friend WithEvents TreeView1 As System.Windows.Forms.TreeView
Friend WithEvents MenuItem2 As System.Windows.Forms.MenuItem
Friend WithEvents MenuItem3 As System.Windows.Forms.MenuItem
Friend WithEvents ImageList1 As System.Windows.Forms.ImageList
Friend WithEvents AxWebBrowser1 As AxSHDocVw.AxWebBrowser
Friend WithEvents TabPage7 As System.Windows.Forms.TabPage
Friend WithEvents Button3 As System.Windows.Forms.Button
Friend WithEvents Button4 As System.Windows.Forms.Button
Friend WithEvents TreeView2 As System.Windows.Forms.TreeView
Friend WithEvents Button5 As System.Windows.Forms.Button
Friend WithEvents Button6 As System.Windows.Forms.Button
Friend WithEvents Panel1 As System.Windows.Forms.Panel
Friend WithEvents Button7 As System.Windows.Forms.Button
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.components = New System.ComponentModel.Container
Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(frmCodelib))
Me.Button1 = New System.Windows.Forms.Button
Me.Button2 = New System.Windows.Forms.Button
Me.TabControl1 = New System.Windows.Forms.TabControl
Me.TabPage1 = New System.Windows.Forms.TabPage
Me.Panel1 = New System.Windows.Forms.Panel
Me.Button7 = New System.Windows.Forms.Button
Me.Button4 = New System.Windows.Forms.Button
Me.Button3 = New System.Windows.Forms.Button
Me.TreeView1 = New System.Windows.Forms.TreeView
Me.ImageList1 = New System.Windows.Forms.ImageList(Me.components)
Me.TabPage2 = New System.Windows.Forms.TabPage
Me.Label2 = New System.Windows.Forms.Label
Me.TabPage3 = New System.Windows.Forms.TabPage
Me.AxWebBrowser1 = New AxSHDocVw.AxWebBrowser
Me.TabPage6 = New System.Windows.Forms.TabPage
Me.TabPage7 = New System.Windows.Forms.TabPage
Me.TabPage5 = New System.Windows.Forms.TabPage
Me.Button6 = New System.Windows.Forms.Button
Me.Button5 = New System.Windows.Forms.Button
Me.TreeView2 = New System.Windows.Forms.TreeView
Me.MainMenu1 = New System.Windows.Forms.MainMenu
Me.MenuItem1 = New System.Windows.Forms.MenuItem
Me.MenuItem2 = New System.Windows.Forms.MenuItem
Me.MenuItem3 = New System.Windows.Forms.MenuItem
Me.btnClose = New System.Windows.Forms.Button
Me.TabControl1.SuspendLayout()
Me.TabPage1.SuspendLayout()
Me.Panel1.SuspendLayout()
Me.TabPage2.SuspendLayout()
Me.TabPage3.SuspendLayout()
CType(Me.AxWebBrowser1, System.ComponentModel.ISupportInitialize).BeginInit()
Me.TabPage5.SuspendLayout()
Me.SuspendLayout()
'
'Button1
'
Me.Button1.Location = New System.Drawing.Point(352, 0)
Me.Button1.Name = "Button1"
Me.Button1.Size = New System.Drawing.Size(96, 32)
Me.Button1.TabIndex = 0
Me.Button1.Text = "Close All Documents"
'
'Button2
'
Me.Button2.Location = New System.Drawing.Point(232, 8)
Me.Button2.Name = "Button2"
Me.Button2.Size = New System.Drawing.Size(104, 24)
Me.Button2.TabIndex = 1
Me.Button2.Text = "Add Comment"
'
'TabControl1
'
Me.TabControl1.Controls.Add(Me.TabPage1)
Me.TabControl1.Controls.Add(Me.TabPage2)
Me.TabControl1.Controls.Add(Me.TabPage3)
Me.TabControl1.Controls.Add(Me.TabPage6)
Me.TabControl1.Controls.Add(Me.TabPage7)
Me.TabControl1.Controls.Add(Me.TabPage5)
Me.TabControl1.Dock = System.Windows.Forms.DockStyle.Top
Me.TabControl1.Location = New System.Drawing.Point(0, 0)
Me.TabControl1.Name = "TabControl1"
Me.TabControl1.SelectedIndex = 0
Me.TabControl1.Size = New System.Drawing.Size(408, 352)
Me.TabControl1.TabIndex = 2
'
'TabPage1
'
Me.TabPage1.Controls.Add(Me.Panel1)
Me.TabPage1.Controls.Add(Me.TreeView1)
Me.TabPage1.Location = New System.Drawing.Point(4, 22)
Me.TabPage1.Name = "TabPage1"
Me.TabPage1.Size = New System.Drawing.Size(400, 326)
Me.TabPage1.TabIndex = 0
Me.TabPage1.Text = "Code Drop"
'
'Panel1
'
Me.Panel1.Controls.Add(Me.Button7)
Me.Panel1.Controls.Add(Me.Button2)
Me.Panel1.Controls.Add(Me.Button4)
Me.Panel1.Controls.Add(Me.Button3)
Me.Panel1.Controls.Add(Me.Button1)
Me.Panel1.Dock = System.Windows.Forms.DockStyle.Top
Me.Panel1.Location = New System.Drawing.Point(0, 280)
Me.Panel1.Name = "Panel1"
Me.Panel1.Size = New System.Drawing.Size(400, 40)
Me.Panel1.TabIndex = 7
'
'Button7
'
Me.Button7.FlatStyle = System.Windows.Forms.FlatStyle.Popup
Me.Button7.Location = New System.Drawing.Point(16, 8)
Me.Button7.Name = "Button7"
Me.Button7.Size = New System.Drawing.Size(24, 23)
Me.Button7.TabIndex = 0
Me.Button7.Text = "Button7"
'
'Button4
'
Me.Button4.FlatStyle = System.Windows.Forms.FlatStyle.Flat
Me.Button4.Location = New System.Drawing.Point(80, 8)
Me.Button4.Name = "Button4"
Me.Button4.Size = New System.Drawing.Size(24, 23)
Me.Button4.TabIndex = 6
Me.Button4.Text = "Paste"
'
'Button3
'
Me.Button3.FlatStyle = System.Windows.Forms.FlatStyle.Flat
Me.Button3.Image = CType(resources.GetObject("Button3.Image"), System.Drawing.Image)
Me.Button3.Location = New System.Drawing.Point(48, 8)
Me.Button3.Name = "Button3"
Me.Button3.Size = New System.Drawing.Size(24, 23)
Me.Button3.TabIndex = 5
Me.Button3.Text = "Copy"
'
'TreeView1
'
Me.TreeView1.Dock = System.Windows.Forms.DockStyle.Top
Me.TreeView1.HotTracking = True
Me.TreeView1.ImageList = Me.ImageList1
Me.TreeView1.Location = New System.Drawing.Point(0, 0)
Me.TreeView1.Name = "TreeView1"
Me.TreeView1.Nodes.AddRange(New System.Windows.Forms.TreeNode() {New System.Windows.Forms.TreeNode("Code Templates", New System.Windows.Forms.TreeNode() {New System.Windows.Forms.TreeNode("Property")}), New System.Windows.Forms.TreeNode("Comments", New System.Windows.Forms.TreeNode() {New System.Windows.Forms.TreeNode("Node4")}), New System.Windows.Forms.TreeNode("Node2")})
Me.TreeView1.Size = New System.Drawing.Size(400, 280)
Me.TreeView1.TabIndex = 4
'
'ImageList1
'
Me.ImageList1.ImageSize = New System.Drawing.Size(16, 16)
Me.ImageList1.ImageStream = CType(resources.GetObject("ImageList1.ImageStream"), System.Windows.Forms.ImageListStreamer)
Me.ImageList1.TransparentColor = System.Drawing.Color.Transparent
'
'TabPage2
'
Me.TabPage2.Controls.Add(Me.Label2)
Me.TabPage2.Location = New System.Drawing.Point(4, 22)
Me.TabPage2.Name = "TabPage2"
Me.TabPage2.Size = New System.Drawing.Size(464, 326)
Me.TabPage2.TabIndex = 1
Me.TabPage2.Text = "Macros"
'
'Label2
'
Me.Label2.Location = New System.Drawing.Point(112, 88)
Me.Label2.Name = "Label2"
Me.Label2.Size = New System.Drawing.Size(200, 96)
Me.Label2.TabIndex = 0
Me.Label2.Text = "IDE macros that we find useful"
'
'TabPage3
'
Me.TabPage3.Controls.Add(Me.AxWebBrowser1)
Me.TabPage3.Location = New System.Drawing.Point(4, 22)
Me.TabPage3.Name = "TabPage3"
Me.TabPage3.Size = New System.Drawing.Size(464, 326)
Me.TabPage3.TabIndex = 2
Me.TabPage3.Text = "Bugspray"
'
'AxWebBrowser1
'
Me.AxWebBrowser1.ContainingControl = Me
Me.AxWebBrowser1.Enabled = True
Me.AxWebBrowser1.Location = New System.Drawing.Point(8, 96)
Me.AxWebBrowser1.OcxState = CType(resources.GetObject("AxWebBrowser1.OcxState"), System.Windows.Forms.AxHost.State)
Me.AxWebBrowser1.Size = New System.Drawing.Size(392, 216)
Me.AxWebBrowser1.TabIndex = 0
'
'TabPage6
'
Me.TabPage6.Location = New System.Drawing.Point(4, 22)
Me.TabPage6.Name = "TabPage6"
Me.TabPage6.Size = New System.Drawing.Size(464, 326)
Me.TabPage6.TabIndex = 5
Me.TabPage6.Text = "Options"
'
'TabPage7
'
Me.TabPage7.Location = New System.Drawing.Point(4, 22)
Me.TabPage7.Name = "TabPage7"
Me.TabPage7.Size = New System.Drawing.Size(464, 326)
Me.TabPage7.TabIndex = 6
Me.TabPage7.Text = "Deploy"
'
'TabPage5
'
Me.TabPage5.Controls.Add(Me.Button6)
Me.TabPage5.Controls.Add(Me.Button5)
Me.TabPage5.Controls.Add(Me.TreeView2)
Me.TabPage5.Location = New System.Drawing.Point(4, 22)
Me.TabPage5.Name = "TabPage5"
Me.TabPage5.Size = New System.Drawing.Size(464, 326)
Me.TabPage5.TabIndex = 4
Me.TabPage5.Text = "Code library"
'
'Button6
'
Me.Button6.Location = New System.Drawing.Point(272, 96)
Me.Button6.Name = "Button6"
Me.Button6.Size = New System.Drawing.Size(104, 23)
Me.Button6.TabIndex = 7
Me.Button6.Text = "Property Creator"
'
'Button5
'
Me.Button5.Location = New System.Drawing.Point(264, 56)
Me.Button5.Name = "Button5"
Me.Button5.TabIndex = 6
Me.Button5.Text = "Create File"
'
'TreeView2
'
Me.TreeView2.HotTracking = True
Me.TreeView2.ImageList = Me.ImageList1
Me.TreeView2.Location = New System.Drawing.Point(104, 24)
Me.TreeView2.Name = "TreeView2"
Me.TreeView2.Nodes.AddRange(New System.Windows.Forms.TreeNode() {New System.Windows.Forms.TreeNode("Code Templates", New System.Windows.Forms.TreeNode() {New System.Windows.Forms.TreeNode("Property")}), New System.Windows.Forms.TreeNode("Comments", New System.Windows.Forms.TreeNode() {New System.Windows.Forms.TreeNode("Node4")}), New System.Windows.Forms.TreeNode("Node2")})
Me.TreeView2.Size = New System.Drawing.Size(136, 280)
Me.TreeView2.TabIndex = 5
'
'MainMenu1
'
Me.MainMenu1.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.MenuItem1, Me.MenuItem2})
'
'MenuItem1
'
Me.MenuItem1.Index = 0
Me.MenuItem1.Text = "File"
'
'MenuItem2
'
Me.MenuItem2.Index = 1
Me.MenuItem2.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.MenuItem3})
Me.MenuItem2.Text = "Tools"
'
'MenuItem3
'
Me.MenuItem3.Index = 0
Me.MenuItem3.Text = "Options"
'
'btnClose
'
Me.btnClose.Location = New System.Drawing.Point(8, 376)
Me.btnClose.Name = "btnClose"
Me.btnClose.TabIndex = 3
Me.btnClose.Text = "Close"
'
'frmCodelib
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(408, 414)
Me.Controls.Add(Me.btnClose)
Me.Controls.Add(Me.TabControl1)
Me.Menu = Me.MainMenu1
Me.Name = "frmCodelib"
Me.Text = "frmCodelib"
Me.TopMost = True
Me.TabControl1.ResumeLayout(False)
Me.TabPage1.ResumeLayout(False)
Me.Panel1.ResumeLayout(False)
Me.TabPage2.ResumeLayout(False)
Me.TabPage3.ResumeLayout(False)
CType(Me.AxWebBrowser1, System.ComponentModel.ISupportInitialize).EndInit()
Me.TabPage5.ResumeLayout(False)
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
CloseAllOpenDocuments()
End Sub
Sub CloseAllOpenDocuments()
'Description: Prints all open, active documents
Dim doc As Document
For Each doc In applicationObject.Documents()
doc.Close(vsSaveChanges.vsSaveChangesYes = vsSaveChanges.vsSaveChangesYes)
Next
End Sub
Sub NewCommentLine()
Dim ts As TextSelection = applicationObject.ActiveWindow.Selection
If Not ts Is Nothing Then
ts.NewLine()
ts.Insert("'hello from paul!", 1)
ts.Insert(" ' hello again!")
End If
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
NewCommentLine()
End Sub
Private Sub btnClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClose.Click
Close()
End Sub
Private Sub TreeView1_AfterSelect(ByVal sender As System.Object, ByVal e As System.Windows.Forms.TreeViewEventArgs) Handles TreeView1.AfterSelect
End Sub
Private Sub TreeView1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles TreeView1.Click
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
If Not TreeView1.SelectedNode Is Nothing Then
Dim ts As TextSelection = applicationObject.ActiveWindow.Selection
If Not ts Is Nothing Then
TreeView1.SelectedNode.Text = ts.Text
End If
End If
' TreeView1.Nodes(1).Text = ts.Text
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
pastetext()
End Sub
Private Sub pastetext()
If Not TreeView1.SelectedNode Is Nothing Then
Dim ts As TextSelection = applicationObject.ActiveWindow.Selection
If Not ts Is Nothing Then
ts.Text = TreeView1.SelectedNode.Text
End If
End If
End Sub
Sub CopyFile()
Dim Sel As TextSelection = applicationObject.ActiveDocument.Selection
Dim FileName As String = applicationObject.ActiveDocument.FullName + "copy.bak"
Dim Anchor As EditPoint = Sel.AnchorPoint.CreateEditPoint
Dim Active As EditPoint = Sel.ActivePoint.CreateEditPoint
Dim tw As TextWindow = applicationObject.ActiveWindow.Object
'im Pane As TextPane = tw.ActivePane
' Dim Corner As EditPoint = Panel.StartPoint.CreateEditPoint
Dim Text As String
Sel.SelectAll()
Text = Sel.Text
' Create the temp document, save, then close.
applicationObject.ItemOperations.NewFile("General\Text File")
applicationObject.ActiveDocument.Object("TextDocument").Selection.Insert(Text)
applicationObject.ActiveDocument.Save(FileName)
' applicationObject.ActiveDocument.Close(EnvDTE.vsSaveChanges.vsSaveChangesNo) 'Already saved with line above, don't need to save again
' Restore the selection.
'Sel.MoveToPoint(Anchor)
'Sel.MoveToPoint(Active, True)
'Pane.TryToShow(Corner, vsPaneShowHow.vsPaneShowTop)
End Sub
Sub SaveBackup()
Dim Sel As TextSelection = applicationObject.ActiveDocument.Selection
Dim FileName As String = applicationObject.ActiveDocument.FullName + ".bak"
Dim Anchor As EditPoint = Sel.AnchorPoint.CreateEditPoint
Dim Active As EditPoint = Sel.ActivePoint.CreateEditPoint
Dim tw As TextWindow = applicationObject.ActiveWindow.Object
Dim Pane As TextPane = tw.ActivePane
Dim Corner As EditPoint = Pane.StartPoint.CreateEditPoint
Dim Text As String
Sel.SelectAll()
Text = Sel.Text
' Create the temp document, save, then close.
applicationObject.ItemOperations.NewFile("General\Text File")
applicationObject.ActiveDocument.Object("TextDocument").Selection.Insert(Text)
applicationObject.ActiveDocument.Save(FileName)
applicationObject.ActiveDocument.Close(EnvDTE.vsSaveChanges.vsSaveChangesNo) 'Already saved with line above, don't need to save again
' Restore the selection.
Sel.MoveToPoint(Anchor)
Sel.MoveToPoint(Active, True)
Pane.TryToShow(Corner, vsPaneShowHow.vsPaneShowTop)
End Sub
Sub OutlineCode()
Dim i As Integer
Dim fileCM As FileCodeModel
fileCM = applicationObject.ActiveDocument().ProjectItem.FileCodeModel
Dim elts As CodeElements
elts = fileCM.CodeElements
Dim elt As CodeElement
For i = 1 To elts.Count
elt = elts.Item(i)
CollapseElt(elt, elts, i)
Next
End Sub
''' Helper to OutlineCode. Recursively outlines members of elt.
'''
Sub CollapseElt(ByVal elt As CodeElement, ByVal elts As CodeElements, ByVal loc As Integer)
Dim epStart As EditPoint
Dim epEnd As EditPoint
epStart = elt.GetStartPoint(vsCMPart.vsCMPartHeader).CreateEditPoint()
epEnd = elt.GetEndPoint(vsCMPart.vsCMPartWhole).CreateEditPoint() 'Copy it since we move it later.
epStart.EndOfLine()
If ((elt.IsCodeType()) And (elt.Kind <> EnvDTE.vsCMElement.vsCMElementDelegate)) Then
Dim i As Integer
Dim mems As CodeElements
mems = elt.Members
For i = 1 To mems.Count
CollapseElt(mems.Item(i), mems, i)
Next
ElseIf (elt.Kind = EnvDTE.vsCMElement.vsCMElementNamespace) Then
Dim i As Integer
Dim mems As CodeElements
mems = elt.Members
For i = 1 To mems.Count
CollapseElt(mems.Item(i), mems, i)
Next
End If
If (epStart.LessThan(epEnd)) Then
loc = loc + 1
If (loc <= elts.Count) Then
epEnd.MoveToPoint(elts.Item(loc).GetStartPoint(vsCMPart.vsCMPartHeader))
epEnd.LineUp()
epEnd.EndOfLine()
End If
epStart.OutlineSection(epEnd)
End If
End Sub
Private Sub TreeView1_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles TreeView1.DoubleClick
pastetext()
End Sub
Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
' CreateFile()
End Sub
Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
NewProperty()
End Sub
Private Sub NewProperty()
If Not applicationObject.ActiveWindow Is Nothing Then
'applicationObject.ItemOperations.AddNewItem(.LaunchW
Dim ts As TextSelection = applicationObject.ActiveWindow.Selection
If Not ts Is Nothing Then
Dim PropName As String
Dim PropType As String
PropName = InputBox("What is your property Name", "Property Wizard", "MyPropertyName")
PropType = InputBox("What is your property Type", "Property Wizard", "String")
ts.NewLine()
ts.Insert("'Autogenerated Property")
ts.NewLine()
ts.Insert("Private a" & PropName & " As " & PropType)
ts.NewLine()
ts.Insert("Property " & PropName & "() As " & PropType)
ts.NewLine()
ts.Insert("Get")
ts.NewLine()
ts.Insert("Return a" & PropName)
ts.NewLine()
ts.Insert("End Get")
ts.NewLine()
ts.Insert("Set(ByVal Value As String)")
ts.NewLine()
ts.Insert("a" & PropName & " = Value")
ts.NewLine()
ts.Insert("End Set")
ts.NewLine()
ts.Insert("End Property")
End If
End If
End Sub
Private aProperty As String
Property PropertyName() As String
Get
Return aProperty
End Get
Set(ByVal Value As String)
aProperty = Value
End Set
End Property
End Class