예제 #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 initialization code that rely on services provided by VisualStudio.
        /// </summary>
        protected override void Initialize()
        {
            base.Initialize();

            dte = GetService(typeof (DTE)) as DTE;

            if (null == dte)
            {
                throw new ArgumentNullException(nameof(dte));
            }

            var pane = GetService(typeof(SVsGeneralOutputWindowPane)) as IVsOutputWindowPane;

            if (null == pane)
            {
                throw new ArgumentNullException(nameof(pane));
            }

            output = new VisualStudioOutputPaneProvider(pane);

            formatDocumentEvent = dte.Events.CommandEvents[VsStd2KCmdIdGuid, (int) VSConstants.VSStd2KCmdID.FORMATDOCUMENT];
            saveProjectItemEvent = dte.Events.CommandEvents[VsStd97CmdIdGuid, (int) VSConstants.VSStd97CmdID.SaveProjectItem];

            factory = new CommandFactory(dte, output);

            formatDocumentEvent.BeforeExecute += OnFormatDocumentBeforeExecute;
            saveProjectItemEvent.BeforeExecute += OnSaveProjectItemBeforeExecute;
        }
예제 #2
0
        protected override void Dispose(bool dispose)
        {
            try
            {
                if (dispose)
                {
                    saveProjectItemEvent.BeforeExecute -= OnSaveProjectItemBeforeExecute;
                    formatDocumentEvent.BeforeExecute -= OnFormatDocumentBeforeExecute;

                    dte = null;
                    factory = null;

                    GC.SuppressFinalize(this);
                }
            }
            finally
            {
                base.Dispose(dispose);
            }
        }