private int OnBeforeDocumentSave(uint docCookie)
        {
            bool csFormatOnSave  = (bool)_props.Item("CsFormatOnSave").Value;;
            bool cppFormatOnSave = (bool)_props.Item("CppFormatOnSave").Value;

            if (!cppFormatOnSave && !csFormatOnSave)
            {
                return(VSConstants.S_OK);
            }

            var doc      = _dte.Documents.OfType <Document>().FirstOrDefault(x => x.FullName == _documentEventListener.GetDocumentName(docCookie));
            var language = GetLanguage(doc);

            if (language == Language.CSharp && csFormatOnSave)
            {
                FormatDocument(GetTextDocument(doc), Language.CSharp);
            }
            else if (language == Language.Cpp && cppFormatOnSave)
            {
                FormatDocument(GetTextDocument(doc), Language.Cpp);
            }

            return(VSConstants.S_OK);
        }
示例#2
0
        private int OnBeforeDocumentSave(uint docCookie)
        {
            if (!_dialog.CppFormatOnSave && !_dialog.CsFormatOnSave)
            {
                return(VSConstants.S_OK);
            }

            var doc      = _dte.Documents.OfType <Document>().FirstOrDefault(x => x.FullName == _documentEventListener.GetDocumentName(docCookie));
            var language = GetLanguage(doc);

            if (language == Language.CSharp && _dialog.CsFormatOnSave)
            {
                FormatDocument(GetTextDocument(doc), Language.CSharp);
            }
            else if (language == Language.Cpp && _dialog.CppFormatOnSave)
            {
                FormatDocument(GetTextDocument(doc), Language.Cpp);
            }

            return(VSConstants.S_OK);
        }
        private int OnBeforeDocumentSave(uint docCookie)
        {
            bool   csFormatOnSave       = (bool)_props.Item("CsFormatOnSave").Value;;
            bool   cppFormatOnSave      = (bool)_props.Item("CppFormatOnSave").Value;
            string cppIgnoredExtensions = (string)_props.Item("CppIgnoredFileExtensions").Value;

            if (!cppFormatOnSave && !csFormatOnSave)
            {
                return(VSConstants.S_OK);
            }

            var doc = _dte.Documents.OfType <Document>().FirstOrDefault(x => x.FullName == _documentEventListener.GetDocumentName(docCookie));

            //check ignored extensions
            if (!string.IsNullOrEmpty(cppIgnoredExtensions))
            {
                List <string> fileExtensionsList = new List <string>();
                fileExtensionsList.AddRange(cppIgnoredExtensions.Split(" ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries));
                string ext = System.IO.Path.GetExtension(doc.FullName);
                if (fileExtensionsList.Contains(ext))
                {
                    return(VSConstants.S_OK);
                }
            }
            var language = GetLanguage(doc);

            if (language == Language.CSharp && csFormatOnSave)
            {
                FormatDocument(GetTextDocument(doc), Language.CSharp);
            }
            else if (language == Language.Cpp && cppFormatOnSave)
            {
                FormatDocument(GetTextDocument(doc), Language.Cpp);
            }

            return(VSConstants.S_OK);
        }