VSXtra-like implementation of the VS SDK's RDT Event Explorer sample

Package source code:

using System.Runtime.InteropServices;
using Microsoft.VisualStudio.Shell;
using VSXtra;

namespace DeepDiver.RdtEventsWindow
{
  [PackageRegistration(UseManagedResourcesOnly = true)]
  [DefaultRegistryRoot("Software\\Microsoft\\VisualStudio\\9.0")]
  [InstalledProductRegistration(false, "#110", "#112", "1.0", IconResourceID = 400)]
  [ProvideLoadKey("Standard", "1.0", "RdtEventsWindow", "DeepDiver", 1)]
  [ProvideMenuResource(1000, 1)]
  [XtraProvideOptionPage(typeof(RdtEventsOptionsPage), "RDT Event Explorer", "Explorer Options", 0, 0, true)]
  [ProvideProfile(typeof(RdtEventsOptionsPage), "RDT Event Explorer", "Explorer Options", 0, 0, true)]
  [XtraProvideToolWindow(typeof(RdtEventsWindowPane))]
  [Guid(GuidList.guidRdtEventsWindowPkgString)]
  public sealed class RdtEventsWindowPackage : PackageBase
  {
  }
}

RDT Events Explorer tool window pane:

using System.Runtime.InteropServices;
using VSXtra;
namespace DeepDiver.RdtEventsWindow
{
  [Guid("4CCE3BDE-60B2-4165-9FC9-8682A19BCB70")]
  [InitialCaption("RDT Event Explorer")]
  [Toolbar(typeof(RdtEventsCommandGroup.RdtEventExplorerToolbar))]
  public class RdtEventsWindowPane: ToolWindowPane<RdtEventsWindowPackage, RdtEventControl>
  {
    private RdtEventsOptionsPage _Options;
    public override void OnToolWindowCreated()
    {
      UIControl.SelectionTracker = SelectionTracker;
      RunningDocumentTable.OnAfterAttributeChange += OnAfterAttributeChange;
      RunningDocumentTable.OnAfterAttributeChangeEx += OnAfterAttributeChangeEx;
      RunningDocumentTable.OnAfterDocumentWindowHide += OnAfterDocumentWindowHide;
      RunningDocumentTable.OnAfterFirstDocumentLock += OnAfterFirstDocumentLock;
      RunningDocumentTable.OnAfterLastDocumentUnlock += OnAfterLastDocumentUnlock;
      RunningDocumentTable.OnAfterSave += OnAfterSave;
      RunningDocumentTable.OnAfterSaveAll += OnAfterSaveAll;
      RunningDocumentTable.OnBeforeDocumentWindowShow += OnBeforeDocumentWindowShow;
      RunningDocumentTable.OnBeforeFirstDocumentLock += OnBeforeFirstDocumentLock;
      RunningDocumentTable.OnBeforeLastDocumentUnlock += OnBeforeLastDocumentUnlock;
      RunningDocumentTable.OnBeforeSave += OnBeforeSave;
    }
    protected override void Dispose(bool disposing)
    {
      RunningDocumentTable.OnAfterAttributeChange -= OnAfterAttributeChange;
      RunningDocumentTable.OnAfterAttributeChangeEx -= OnAfterAttributeChangeEx;
      RunningDocumentTable.OnAfterDocumentWindowHide -= OnAfterDocumentWindowHide;
      RunningDocumentTable.OnAfterFirstDocumentLock -= OnAfterFirstDocumentLock;
      RunningDocumentTable.OnAfterLastDocumentUnlock -= OnAfterLastDocumentUnlock;
      RunningDocumentTable.OnAfterSave -= OnAfterSave;
      RunningDocumentTable.OnAfterSaveAll -= OnAfterSaveAll;
      RunningDocumentTable.OnBeforeDocumentWindowShow -= OnBeforeDocumentWindowShow;
      RunningDocumentTable.OnBeforeFirstDocumentLock -= OnBeforeFirstDocumentLock;
      RunningDocumentTable.OnBeforeLastDocumentUnlock -= OnBeforeLastDocumentUnlock;
      RunningDocumentTable.OnBeforeSave -= OnBeforeSave;
      base.Dispose(disposing);
    }
    private RdtEventsOptionsPage Options
    {
      get
      {
        if (_Options == null)
        {
          _Options = Package.GetDialogPage<RdtEventsOptionsPage>();
        }
        return _Options;
      }
    }
    void OnBeforeSave(object sender, RdtEventArgs e)
    {
      if (Options.OptBeforeSave) LogEvent(e);
    }

    void OnBeforeLastDocumentUnlock(object sender, RdtLockEventArgs e)
    {
      if (Options.OptBeforeLastDocumentUnlock) LogEvent(e);
    }

    void OnBeforeFirstDocumentLock(object sender, RdtFirstLockEventArgs e)
    {
      if (Options.OptBeforeFirstDocumentLock) LogEvent(e);
    }

    void OnBeforeDocumentWindowShow(object sender, RdtWindowShowEventArgs e)
    {
      if (Options.OptBeforeDocumentWindowShow) LogEvent(e);
    }

    void OnAfterSaveAll(object sender, RdtEventArgs e)
    {
      if (Options.OptAfterSaveAll) LogEvent(e);
    }

    void OnAfterSave(object sender, RdtEventArgs e)
    {
      if (Options.OptAfterSave) LogEvent(e);
    }

    void OnAfterLastDocumentUnlock(object sender, RdtLastUnlockEventArgs e)
    {
      if (Options.OptAfterLastDocumentUnlock) LogEvent(e);
    }

    void OnAfterFirstDocumentLock(object sender, RdtLockEventArgs e)
    {
      if (Options.OptAfterFirstDocumentLock) LogEvent(e);
    }

    void OnAfterDocumentWindowHide(object sender, RdtWindowEventArgs e)
    {
      if (Options.OptAfterDocumentWindowHide) LogEvent(e);
    }

    void OnAfterAttributeChangeEx(object sender, RdtDocumentChangedEventArgs e)
    {
      if (Options.OptAfterAttributeChangeEx) LogEvent(e);
    }

    void OnAfterAttributeChange(object sender, RdtDocumentChangedEventArgs e)
    {
      if (Options.OptAfterAttributeChange) LogEvent(e);
    }

    void LogEvent(RdtEventArgs e)
    {
      UIControl.AddEventToGrid(e);
    }

    [CommandExecMethod]
    [CommandId(CmdIDs.cmdidClearList)]
    private void ClearList()
    {
      UIControl.ClearGrid();
    }
  }
}

RDT Events Explorer UI code:

using System.Drawing;
using System.Windows.Forms;
using VSXtra;

namespace DeepDiver.RdtEventsWindow
{
  public partial class RdtEventControl : UserControl
  {
    public RdtEventControl()
    {
      InitializeComponent();
      eventGrid.AutoGenerateColumns = false;
      eventGrid.AllowUserToAddRows = false;
      eventGrid.SelectionMode = DataGridViewSelectionMode.FullRowSelect;

      eventGrid.Columns.Add("Event", Resources.EventHeader);
      eventGrid.Columns.Add("Moniker", Resources.MonikerHeader);
      eventGrid.Columns["Event"].ReadOnly = true;
      eventGrid.Columns["Moniker"].ReadOnly = true;
      eventGrid.AllowUserToResizeRows = false;
      eventGrid.AllowUserToResizeColumns = true;
      eventGrid.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;

      int x = Screen.PrimaryScreen.Bounds.Size.Width;
      int y = Screen.PrimaryScreen.Bounds.Size.Height;
      Size = new Size(x / 3, y / 3);
    }

    public SelectionTracker SelectionTracker { get; set; }

    protected override bool ProcessDialogChar(char charCode)
    {
      if (charCode != ' ' && ProcessMnemonic(charCode))
      {
        return true;
      }
      return base.ProcessDialogChar(charCode);
    }
    
    public void AddEventToGrid(RdtEventArgs ev)
    {
      if (ev == null) return;
      int n = eventGrid.Rows.Add();
      var row = eventGrid.Rows[n];
      row.Cells["Event"].Value = ev.EventType.ToString();
      row.Cells["Moniker"].Value = ev.Moniker;
      row.Tag = ev;
    }

    public void ClearGrid()
    {
      eventGrid.Rows.Clear();
      eventGrid.Refresh();
    }

    void eventGrid_CellClick(object sender, DataGridViewCellEventArgs e)
    {
      if (e.RowIndex < 0) return;
      var row = eventGrid.Rows[e.RowIndex];
      var ev = (RdtEventArgs)row.Tag;
      SelectionTracker.SelectObject(ev);
    }
  }
}
Screenshots:

RDTEventExplorer1.png

RDTEventExplorer2.png

Last edited Aug 8, 2008 at 6:16 PM by INovak, version 3

Comments

No comments yet.