1

Topic: vs2008: Macro Document.Selection failed with ViemuVS 2.5.4 installed

the following code is written by me to save cursor state on close and restore it on open
it used to work with ViEmuVS-2.2.9 but now when 2.5.4 installed it's broken
when i debug it in Macro IDE, i found that with in function OnDocumentClosing, selection == Nothing, broken by Viemu 2.5.4, why?
no such problem with viemu uninstalled or with 2.2.9

Option Strict Off
Option Explicit Off
Imports System
Imports EnvDTE
Imports EnvDTE80
Imports EnvDTE90
Imports System.Diagnostics

Public Class IniFile
    ' API functions
    Private Declare Ansi Function GetPrivateProfileString _
    Lib "kernel32.dll" Alias "GetPrivateProfileStringA" _
    (ByVal lpApplicationName As String, _
    ByVal lpKeyName As String, ByVal lpDefault As String, _
    ByVal lpReturnedString As System.Text.StringBuilder, _
    ByVal nSize As Integer, ByVal lpFileName As String) _
    As Integer
    Private Declare Ansi Function WritePrivateProfileString _
    Lib "kernel32.dll" Alias "WritePrivateProfileStringA" _
    (ByVal lpApplicationName As String, _
    ByVal lpKeyName As String, ByVal lpString As String, _
    ByVal lpFileName As String) As Integer
    Private Declare Ansi Function GetPrivateProfileInt _
    Lib "kernel32.dll" Alias "GetPrivateProfileIntA" _
    (ByVal lpApplicationName As String, _
    ByVal lpKeyName As String, ByVal nDefault As Integer, _
    ByVal lpFileName As String) As Integer
    Private Declare Ansi Function FlushPrivateProfileString _
    Lib "kernel32.dll" Alias "WritePrivateProfileStringA" _
    (ByVal lpApplicationName As Integer, _
    ByVal lpKeyName As Integer, ByVal lpString As Integer, _
    ByVal lpFileName As String) As Integer
    Dim strFilename As String

    ' Constructor, accepting a filename
    Public Sub New(ByVal Filename As String)
        strFilename = Filename
    End Sub

    ' Read-only filename property
    ReadOnly Property FileName() As String
        Get
            Return strFilename
        End Get
    End Property

    Public Function GetString(ByVal Section As String, _
    ByVal Key As String, ByVal [Default] As String) As String
        ' Returns a string from your INI file
        Dim intCharCount As Integer
        Dim objResult As New System.Text.StringBuilder(256)
        intCharCount = GetPrivateProfileString(Section, Key, _
        [Default], objResult, objResult.Capacity, strFilename)
        If intCharCount > 0 Then GetString = _
        Left(objResult.ToString, intCharCount)
    End Function

    Public Function GetInteger(ByVal Section As String, _
    ByVal Key As String, ByVal [Default] As Integer) As Integer
        ' Returns an integer from your INI file
        Return GetPrivateProfileInt(Section, Key, _
        [Default], strFilename)
    End Function

    Public Function GetBoolean(ByVal Section As String, _
    ByVal Key As String, ByVal [Default] As Boolean) As Boolean
        ' Returns a boolean from your INI file
        Return (GetPrivateProfileInt(Section, Key, _
        CInt([Default]), strFilename) = 1)
    End Function

    Public Sub WriteString(ByVal Section As String, _
    ByVal Key As String, ByVal Value As String)
        ' Writes a string to your INI file
        WritePrivateProfileString(Section, Key, Value, strFilename)
        Flush()
    End Sub

    Public Sub WriteInteger(ByVal Section As String, _
    ByVal Key As String, ByVal Value As Integer)
        ' Writes an integer to your INI file
        WriteString(Section, Key, CStr(Value))
        Flush()
    End Sub

    Public Sub WriteBoolean(ByVal Section As String, _
    ByVal Key As String, ByVal Value As Boolean)
        ' Writes a boolean to your INI file
        WriteString(Section, Key, CStr(CInt(Value)))
        Flush()
    End Sub

    Private Sub Flush()
        ' Stores all the cached changes to your INI file
        FlushPrivateProfileString(0, 0, 0, strFilename)
    End Sub

End Class

Public Module EnvironmentEvents

#Region "Automatically generated code, do not modify"
    'Automatically generated code, do not modify
    'Event Sources Begin
    <System.ContextStaticAttribute()> Public WithEvents DTEEvents As EnvDTE.DTEEvents
    <System.ContextStaticAttribute()> Public WithEvents DocumentEvents As EnvDTE.DocumentEvents
    <System.ContextStaticAttribute()> Public WithEvents WindowEvents As EnvDTE.WindowEvents
    <System.ContextStaticAttribute()> Public WithEvents TaskListEvents As EnvDTE.TaskListEvents
    <System.ContextStaticAttribute()> Public WithEvents FindEvents As EnvDTE.FindEvents
    <System.ContextStaticAttribute()> Public WithEvents OutputWindowEvents As EnvDTE.OutputWindowEvents
    <System.ContextStaticAttribute()> Public WithEvents SelectionEvents As EnvDTE.SelectionEvents
    <System.ContextStaticAttribute()> Public WithEvents BuildEvents As EnvDTE.BuildEvents
    <System.ContextStaticAttribute()> Public WithEvents SolutionEvents As EnvDTE.SolutionEvents
    <System.ContextStaticAttribute()> Public WithEvents SolutionItemsEvents As EnvDTE.ProjectItemsEvents
    <System.ContextStaticAttribute()> Public WithEvents MiscFilesEvents As EnvDTE.ProjectItemsEvents
    <System.ContextStaticAttribute()> Public WithEvents DebuggerEvents As EnvDTE.DebuggerEvents
    <System.ContextStaticAttribute()> Public WithEvents ProjectsEvents As EnvDTE.ProjectsEvents
    <System.ContextStaticAttribute()> Public WithEvents TextDocumentKeyPressEvents As EnvDTE80.TextDocumentKeyPressEvents
    <System.ContextStaticAttribute()> Public WithEvents CodeModelEvents As EnvDTE80.CodeModelEvents
    <System.ContextStaticAttribute()> Public WithEvents DebuggerProcessEvents As EnvDTE80.DebuggerProcessEvents
    <System.ContextStaticAttribute()> Public WithEvents DebuggerExpressionEvaluationEvents As EnvDTE80.DebuggerExpressionEvaluationEvents
    'Event Sources End
    'End of automatically generated code
#End Region

    Public Sub DTEEvents_OnMacrosRuntimeReset() Handles DTEEvents.OnMacrosRuntimeReset
        DocumentEvents = DTE.Events.DocumentEvents
    End Sub

    Public ini As IniFile = New IniFile(Environ("APPDATA") & "\VisualStudioSavedCursor.ini")

    Public Sub OnDocumentOpened(ByVal Document As EnvDTE.Document) Handles DocumentEvents.DocumentOpened
        Dim name As String = Document.FullName
        Dim selection As TextSelection = Document.Selection
        Dim activePoint As EnvDTE.VirtualPoint = selection.ActivePoint
        If activePoint.Line <> 1 Or activePoint.LineCharOffset <> 1 Then
            Return
        End If

        selection.MoveToLineAndOffset(ini.GetInteger(name, "startPoint.Line", 1), ini.GetInteger(name, "startPoint.Offset", 1))
        selection.TextPane.TryToShow(selection.ActivePoint.CreateEditPoint, vsPaneShowHow.vsPaneShowTop)
        selection.MoveToLineAndOffset(ini.GetInteger(name, "anchorPoint.Line", 1), ini.GetInteger(name, "anchorPoint.Offset", 1))
        selection.MoveToLineAndOffset(ini.GetInteger(name, "activePoint.Line", 1), ini.GetInteger(name, "activePoint.Offset", 1), True)
    End Sub

    Public Sub OnDocumentClosing(ByVal Document As EnvDTE.Document) Handles DocumentEvents.DocumentClosing
        Dim name As String = Document.FullName
        Dim selection As TextSelection = Document.Selection
        ' selection = Nothing, broken by Viemu 2.5.4 ?

        Dim startPoint As EnvDTE.TextPoint = selection.TextPane.StartPoint
        Dim anchorPoint As EnvDTE.VirtualPoint = selection.AnchorPoint
        Dim activePoint As EnvDTE.VirtualPoint = selection.ActivePoint

        ini.WriteInteger(name, "startPoint.Line", startPoint.Line)
        ini.WriteInteger(name, "startPoint.Offset", startPoint.LineCharOffset)
        ini.WriteInteger(name, "anchorPoint.Line", anchorPoint.Line)
        ini.WriteInteger(name, "anchorPoint.Offset", anchorPoint.LineCharOffset)
        ini.WriteInteger(name, "activePoint.Line", activePoint.Line)
        ini.WriteInteger(name, "activePoint.Offset", activePoint.LineCharOffset)
    End Sub
End Module

Last edited by mOo (2011-02-24 07:58:39)

2

Re: vs2008: Macro Document.Selection failed with ViemuVS 2.5.4 installed

i just uninstalled vax 1842 and the problem is gone. no problem with either vimemu/vax installed but reproduced with both of them installed

it looks like viemu/vax conflict with each other and cause macro issue. much like the twice esc problem

i hope that vax/viemu developers team will cooperate better with each other