code_junkie

Display solution/file path in Visual Studio IDE

Nov 10th, 2011
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.94 KB | None | 0 0
  1. 01 Private timer As System.Threading.Timer
  2. 02 Declare Auto Function SetWindowText Lib "user32" (ByVal hWnd As System.IntPtr, ByVal lpstring As String) As Boolean
  3. 03
  4. 04 Private _branchName As String = String.Empty
  5. 05 Private Sub SolutionEvents_Opened() Handles SolutionEvents.Opened
  6. 06 Try
  7. 07 If timer Is Nothing Then
  8. 08 ' Create timer which refreshes the caption because
  9. 09 ' IDE resets the caption very often
  10. 10 Dim autoEvent As New System.Threading.AutoResetEvent(False)
  11. 11 Dim timerDelegate As System.Threading.TimerCallback = _
  12. 12 AddressOf tick
  13. 13 timer = New System.Threading.Timer(timerDelegate, autoEvent, 0, 25)
  14. 14 End If
  15. 15 Dim sourceIndex As Integer = DTE.Solution.FullName.IndexOf("Source")
  16. 16 Dim shortTitle As String = DTE.Solution.FullName.Substring(0, sourceIndex)
  17. 17 Dim lastIndex As Integer = shortTitle.LastIndexOf("")
  18. 18 _branchName = shortTitle.Substring(lastIndex + 1)
  19. 19 showTitle(_branchName)
  20. 20 Catch ex As Exception
  21. 21
  22. 22 End Try
  23. 23 End Sub
  24. 24
  25. 25 Private Sub SolutionEvents_BeforeClosing() Handles SolutionEvents.BeforeClosing
  26. 26 If Not timer Is Nothing Then
  27. 27 timer.Dispose()
  28. 28 End If
  29. 29 End Sub
  30. 30
  31. 31
  32. 32 ''' <summary>Dispose the timer on IDE shutdown.</summary>
  33. 33 Public Sub DTEEvents_OnBeginShutdown() Handles DTEEvents.OnBeginShutdown
  34. 34 If Not timer Is Nothing Then
  35. 35 timer.Dispose()
  36. 36 End If
  37. 37 End Sub
  38. 38
  39. 39 '''<summary>Called by timer.</summary>
  40. 40 Public Sub tick(ByVal state As Object)
  41. 41 Try
  42. 42 showTitle(_branchName)
  43. 43 Catch ex As System.Exception
  44. 44 End Try
  45. 45 End Sub
  46. 46
  47. 47 '''<summary>Shows the title in main window.</summary>
  48. 48 Private Sub showTitle(ByVal title As String)
  49. 49 SetWindowText(New System.IntPtr(DTE.MainWindow.HWnd), title & " - " & DTE.Name)
  50. 50 End Sub
Add Comment
Please, Sign In to add comment