示例#1
0
        /// <summary>
        /// Initialization of the package; this method is called right after the package is sited, so this is the place
        /// where you can put all the initilaization code that rely on services provided by VisualStudio.
        /// </summary>
        protected override void Initialize()
        {
            base.Initialize();
            IVsDebugger debugger;

            // Get VS services
            if ((_dte = Package.GetGlobalService(typeof(DTE)) as DTE) == null)
            {
                throw new NotSupportedException(Resources.CanNotCreateWindow);
            }
            if ((debugger = Package.GetGlobalService(typeof(IVsDebugger)) as IVsDebugger) == null)
            {
                throw new NotSupportedException(Resources.DebuggerServiceNotFound);
            }

            // Listen for when we enter debug mode so we can hook to debug events
            _dte.Events.DTEEvents.ModeChanged += DTEEvents_ModeChanged;

            // Add our command handlers for menu (commands must exist in the .vsct file)
            OleMenuCommandService mcs = GetService(typeof(IMenuCommandService)) as OleMenuCommandService;

            if (null != mcs)
            {
                // Create the command for the menu item
                CommandID   menuCommandID = new CommandID(GuidList.guidDumpMemoryCmdSet, (int)PkgCmdIDList.cmdidDumpMemory);
                MenuCommand menuItem      = new MenuCommand(ShowToolWindow, menuCommandID);
                mcs.AddCommand(menuItem);
            }

            // Get the instance number 0 of this tool window. This window is single instance so this instance
            // is actually the only one.
            // The last flag is set to true so that if the tool window does not exists it will be created.
            _window = this.FindToolWindow(typeof(DumpMemoryToolWindow), 0, true);
            if ((null == _window) || (null == _window.Frame))
            {
                throw new NotSupportedException(Resources.CanNotCreateWindow);
            }

            // Find the view model for the window
            var control = _window.Content as DumpMemoryControl;

            if (control == null || (_dumpMemory = control.DataContext as DumpMemory) == null)
            {
                throw new NotSupportedException(Resources.CanNotCreateWindow);
            }

            // Pass a reference to the debugger for the view model
            _dumpMemory.VsDebugger = debugger;

            // Add event handler if we are already in debugger
            if (_dte.Debugger.CurrentMode == dbgDebugMode.dbgBreakMode)
            {
                DTEEvents_ModeChanged(vsIDEMode.vsIDEModeDesign);
            }
        }
示例#2
0
 public DumpMemoryControl()
 {
     InitializeComponent();
     DataContext = new DumpMemory();
 }