void VSFormatFileOpenedDocumentsEventHandler(object sender, EventArgs e)
        {
            if (_package.Dte != null &&
                _package.Dte.ActiveWindow != null &&
                _package.Dte.ActiveWindow.Type == EnvDTE.vsWindowType.vsWindowTypeDocument &&
                _package.Dte.Documents != null
                )
            {
                var list = _package.Dte.Documents.OfType <EnvDTE.Document>().ToList();

                foreach (var doc in list)
                {
                    if (doc.ActiveWindow == null ||
                        doc.ActiveWindow.Type != EnvDTE.vsWindowType.vsWindowTypeDocument ||
                        doc.ActiveWindow.Visible == false
                        )
                    {
                        continue;
                    }

                    if (_package.Dte.ItemOperations.IsFileOpen(doc.FullName, EnvDTE.Constants.vsViewKindTextView) ||
                        _package.Dte.ItemOperations.IsFileOpen(doc.FullName, EnvDTE.Constants.vsViewKindCode)
                        )
                    {
                        _package.Format(doc);
                    }
                }
            }
        }
コード例 #2
0
        public int OnBeforeSave(uint docCookie)
        {
            _package.Format(docCookie);

            return(VSConstants.S_OK);
        }