May 8, 2011

FxCop Integrator 1.4.0 Planned Feature Set

After I released FxCop Integrator 1.3.0 on Apr 24 2011, I received some bug reports. The cause of them is the "Code Analysis on Build" feature that is implemented in 1.3.0. I don't know why, but event handlers of Visual Studio build events, are used by this feature, don't work in VS2010 SP1. So I immediately released 1.3.0p1 that is disabled this feature.

In 1.4.0, I'll enable the "Code Analysis on Build" feature again. I plan to implement it with a different way, thus it should be able to be used on VS2010 SP1.


I also plan to implement following features,

Enable customization of data grid of code analysis result window. I'll enable data grid of code analysis result window to sort, show/hide columns and persistent column settings.

More useful error report window. I'll add the error report window that makes it easy to send feedback.


I'll release FxCop Integrator 1.4.0 in May 22 2011.

May 5, 2011

FxCop Integrator 1.3.0p1 Released

I've released FxCop Integrator 1.3.0p1.

In this release, I temporarily disabled the "Code Analysis on Build" feature that is implemented in ver1.3.0, because I realized that events of EnvDTE.BuildEventsClass don't raised on VS2010 SP1(*). "Code Analysis on Build" depends to their events, so I had no choice but to disable it. I'll enable this feature in the future release if I can find out a workaround.
This version is also improved performance and fixed some bugs.


* I sent a feedback about this problem to Microsoft Connect.

May 4, 2011

How to store/restore UI state of Visual Studio tool window pane


A tool window pane of Visual Studio is a class that inherits from Microsoft.VisualStudio.Shell.ToolWindowPane. We can create a sub classes of this to add custom a tool window pane to our VSPackage.

ToolWindowPane class has overridable SaveUIState and LoadUIState methods. It seems that we can use them to store/restore UI state of tool window pane, but thier methods are never called. According to this thread, it looks like their methods are only called on document windows not tool window panes.

Instead of SaveUIState and LoadUIState, we can use OnCreate and OnClose methods. Just like the name implies, OnCreate is called when a tool window pane is created, and OnClose is called when a tool window pane is closed. So if we override them, we can implement the feature to store/restore UI state.

For example, we can store UI state to xml file and restore UI state from xml file like this.

public CustomToolWindowPane : ToolWindowPane
{
    private string path;

    public CustomToolWindowPane()
    {
        ...
        var directory = Path.GetDirectoryName(typeof(CustomToolWindowPane).Assembly.Location);
        path = Path.Combine(directory, "uistate.xml");
    }

    protected override void OnCreate()
    {
        using (var stream = File.Open(path, FileMode.Open))
        {
            var serializer = new XmlSerializer(typeof(UIState));
            var state = (UIState)serializer.Deserialize(stream);
            ApplyUIState(state);
        }
    }

    private void ApplyUIState(UIState state)
    {
        ...
    }

    protected override void OnClose()
    {
        var state = BuildUpUIState();
        using (var stream = File.Open(path, FileMode.Create))
        {
            var serializer = new XmlSerializer(typeof(UIState));
            serializer.Serialize(stream, state);
        }
    }

    private UIState BuildUpUIState()
    {
        ...
    }


    public class UIState
    {
        ...
    }
}