/// <summary> /// This is used to get the classifier for the given file /// </summary> /// <param name="filename">The file for which to get a classifier</param> /// <param name="spellCheckConfiguration">The spell checker configuration that the classifier can use to /// determine what elements to return for spell checking if needed.</param> /// <returns>The classifier to use or null if the file should not be processed</returns> public static TextClassifier GetClassifier(string filename, SpellCheckerConfiguration spellCheckConfiguration) { ClassifierDefinition definition; TextClassifier classifier = null; string id, extension = Path.GetExtension(filename); if (extensionMap == null) { LoadClassifierConfiguration(); } if (!String.IsNullOrWhiteSpace(extension)) { extension = extension.Substring(1); } if (!extensionMap.TryGetValue(extension, out id)) { id = FileIsXml(filename) ? "XML" : "PlainText"; } if (id != "None" && definitions.TryGetValue(id, out definition)) { switch (definition.ClassifierType) { case "PlainTextClassifier": classifier = new PlainTextClassifier(filename, spellCheckConfiguration); break; case "XmlClassifier": classifier = new XmlClassifier(filename, spellCheckConfiguration); break; case "ReportingServicesClassifier": classifier = new ReportingServicesClassifier(filename, spellCheckConfiguration); break; case "ResourceFileClassifier": classifier = new ResourceFileClassifier(filename, spellCheckConfiguration); break; case "HtmlClassifier": classifier = new HtmlClassifier(filename, spellCheckConfiguration); break; case "CodeClassifier": classifier = new CodeClassifier(filename, spellCheckConfiguration, definition.Configuration); break; case "RegexClassifier": classifier = new RegexClassifier(filename, spellCheckConfiguration, definition.Configuration); break; default: break; } } return(classifier); }
//===================================================================== /// <summary> /// Constructor /// </summary> /// <param name="filename">The filename to load</param> /// <param name="spellCheckConfiguration">The spell checker configuration for the file</param> protected TextClassifier(string filename, SpellCheckerConfiguration spellCheckConfiguration) { this.Filename = filename; this.SpellCheckConfiguration = spellCheckConfiguration; ignoredClassifications = new List <RangeClassification>(); // Get the ignored classifications based on the extension. If there are none, check for the // file type. string ext = Path.GetExtension(filename); if (!String.IsNullOrWhiteSpace(ext)) { ext = ext.Substring(1); } var exclusions = spellCheckConfiguration.IgnoredClassificationsFor(PropertyNames.Extension + ext); if (!exclusions.Any()) { exclusions = spellCheckConfiguration.IgnoredClassificationsFor(PropertyNames.FileType + ClassifierFactory.ClassifierIdFor(filename)); } RangeClassification rangeType; foreach (string exclusion in exclusions) { if (Enum.TryParse <RangeClassification>(exclusion, out rangeType)) { ignoredClassifications.Add(rangeType); } } if (!File.Exists(filename)) { this.SetText(String.Empty); } else { using (StreamReader sr = new StreamReader(filename, Encoding.Default, true)) { this.SetText(sr.ReadToEnd()); } } }
/// <summary> /// Creates a tag provider for the specified buffer /// </summary> /// <typeparam name="T">The tag type</typeparam> /// <param name="buffer">The text buffer</param> /// <returns>The tag provider for the specified buffer or null if the buffer is null or spell /// checking as you type is disabled.</returns> public ITagger <T> CreateTagger <T>(ITextBuffer buffer) where T : ITag { if (buffer == null || !SpellCheckerConfiguration.SpellCheckAsYouType || SpellCheckerConfiguration.IsExcludedByExtension(buffer.GetFilenameExtension())) { return(null); } // Due to an issue with the built-in C# classifier, we avoid using it. This also lets us provide // configuration options to exclude certain elements from being spell checked if not wanted. if (buffer.ContentType.IsOfType("csharp")) { // The C# options are passed to the tagger for local use since it tracks the state of the // lines in the buffer. Changing the global options will require that any open editors be // closed and reopened for the changes to take effect. return(new CSharpCommentTextTagger(buffer) { IgnoreXmlDocComments = SpellCheckerConfiguration.IgnoreXmlDocComments, IgnoreDelimitedComments = SpellCheckerConfiguration.IgnoreDelimitedComments, IgnoreStandardSingleLineComments = SpellCheckerConfiguration.IgnoreStandardSingleLineComments, IgnoreQuadrupleSlashComments = SpellCheckerConfiguration.IgnoreQuadrupleSlashComments, IgnoreNormalStrings = SpellCheckerConfiguration.IgnoreNormalStrings, IgnoreVerbatimStrings = SpellCheckerConfiguration.IgnoreVerbatimStrings } as ITagger <T>); } var tagger = new CommentTextTagger(buffer, ClassifierAggregatorService.GetClassifier(buffer)); // Add the XML elements in which to ignore content and the XML attributes that will have their // content spell checked. foreach (string element in SpellCheckerConfiguration.IgnoredXmlElements) { tagger.IgnoredElementNames.Add(element); } foreach (string attr in SpellCheckerConfiguration.SpellCheckedXmlAttributes) { tagger.SpellCheckAttributeNames.Add(attr); } return(tagger as ITagger <T>); }
/// <summary> /// Creates a tag provider for the specified view and buffer /// </summary> /// <typeparam name="T">The tag type</typeparam> /// <param name="textView">The text view</param> /// <param name="buffer">The text buffer</param> /// <returns>The tag provider for the specified view and buffer or null if the buffer is not editable /// or spell checking as you type is disabled.</returns> public ITagger <T> CreateTagger <T>(ITextView textView, ITextBuffer buffer) where T : ITag { // If this view isn't editable, then there isn't a good reason to be showing these if (!textView.Roles.Contains(PredefinedTextViewRoles.Editable) || (!textView.Roles.Contains(PredefinedTextViewRoles.PrimaryDocument) && !textView.Roles.Contains(Utility.EmbeddedPeekTextView))) { return(null); } // Make sure we are only tagging the top buffer and only if wanted if (buffer != textView.TextBuffer || !SpellCheckerConfiguration.SpellCheckAsYouType || SpellCheckerConfiguration.IsExcludedByExtension(buffer.GetFilenameExtension())) { return(null); } return(new SpellSmartTagger(buffer, DictionaryService.GetDictionary(buffer), TagAggregatorFactory.CreateTagAggregator <IMisspellingTag>(textView)) as ITagger <T>); }
//===================================================================== /// <summary> /// Validate the information and save the results if necessary when closing /// </summary> /// <param name="sender">The sender of the event</param> /// <param name="e">The event arguments</param> private void UserPreferencesDlg_FormClosing(object sender, FormClosingEventArgs e) { ContentFileEditorCollection currentEditors; if (this.DialogResult == DialogResult.Cancel) { return; } string filePath = txtMSHelpViewerPath.Text.Trim(); if (filePath.Length != 0) { txtMSHelpViewerPath.Text = filePath = Path.GetFullPath(filePath); if (!File.Exists(filePath)) { epErrors.SetError(btnSelectMSHCViewer, "The viewer application does not exist"); e.Cancel = true; } } if (!e.Cancel) { if (lblBuildExample.BackColor == lblBuildExample.ForeColor) { lblBuildExample.BackColor = SystemColors.Window; lblBuildExample.ForeColor = SystemColors.WindowText; } Settings.Default.MSHelpViewerPath = txtMSHelpViewerPath.Text; Settings.Default.ASPNETDevServerPort = (int)udcASPNetDevServerPort.Value; Settings.Default.PerUserProjectState = chkPerUserProjectState.Checked; Settings.Default.BeforeBuild = (BeforeBuildAction)cboBeforeBuildAction.SelectedIndex; Settings.Default.VerboseLogging = chkVerboseLogging.Checked; Settings.Default.OpenHelpAfterBuild = chkOpenHelp.Checked; Settings.Default.ShowLineNumbers = chkShowLineNumbers.Checked; Settings.Default.EnterMatching = chkEnterMatching.Checked; Settings.Default.BuildOutputBackground = lblBuildExample.BackColor; Settings.Default.BuildOutputForeground = lblBuildExample.ForeColor; Settings.Default.BuildOutputFont = lblBuildExample.Font; Settings.Default.TextEditorFont = lblEditorExample.Font; if (wasModified) { currentEditors = Settings.Default.ContentFileEditors; currentEditors.Clear(); for (int idx = 0; idx < lbContentEditors.Items.Count; idx++) { currentEditors.Add((ContentFileEditor)lbContentEditors.Items[idx]); } currentEditors.Sort(); ContentFileEditorCollection.GlobalEditors.Clear(); ContentFileEditorCollection.GlobalEditors.AddRange(currentEditors); } Settings.Default.Save(); SpellCheckerConfiguration.DefaultLanguage = (CultureInfo)cboDefaultLanguage.SelectedItem; SpellCheckerConfiguration.IgnoreWordsWithDigits = chkIgnoreWordsWithDigits.Checked; SpellCheckerConfiguration.IgnoreWordsInAllUppercase = chkIgnoreAllUppercase.Checked; SpellCheckerConfiguration.IgnoreFilenamesAndEMailAddresses = chkIgnoreFilenamesAndEMail.Checked; SpellCheckerConfiguration.IgnoreXmlElementsInText = chkIgnoreXmlInText.Checked; SpellCheckerConfiguration.TreatUnderscoreAsSeparator = chkTreatUnderscoresAsSeparators.Checked; SpellCheckerConfiguration.SetIgnoredXmlElements(lbIgnoredXmlElements.Items.OfType <string>()); SpellCheckerConfiguration.SetSpellCheckedXmlAttributes(lbSpellCheckedAttributes.Items.OfType <string>()); if (!SpellCheckerConfiguration.SaveConfiguration()) { MessageBox.Show("Unable to save spell checking configuration", Constants.AppName, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } } }
//===================================================================== /// <summary> /// Constructor /// </summary> /// <param name="filename">The filename to load</param> /// <param name="spellCheckConfiguration">The spell checker configuration for the file</param> public ResourceFileClassifier(string filename, SpellCheckerConfiguration spellCheckConfiguration) : base(filename, spellCheckConfiguration) { }
public CSpellApi(SpellCheckerConfiguration config, bool debugFlag = false) { Init(); }