⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 spellcheck.aspx

📁 在线网页编辑器.net 2.0版!不错的在线网页编辑器
💻 ASPX
📖 第 1 页 / 共 2 页
字号:
<%@ Page Language="C#" ClassName="PopUpSpell" ValidateRequest="False" %>
<%@ import Namespace="System.IO" %>
<%@ import Namespace="NetSpell.SpellChecker" %>
<%@ import Namespace="NetSpell.SpellChecker.Dictionary" %>
<script runat="server">

    NetSpell.SpellChecker.Spelling SpellChecker;
    NetSpell.SpellChecker.Dictionary.WordDictionary WordDictionary;
    
    string culture = "en-US";
   
    void Page_Load(object sender, EventArgs e)
    {
         // if modal frame, quit
         if (this.ModalFrame.Visible)
             return;

         // add client side events
         this.Suggestions.Attributes.Add("onChange", "javascript: changeWord(this);");
         this.SpellingBody.Attributes.Add("onLoad", "javascript: initialize();");

         // load spell checker settings
         this.LoadValues();
         switch (this.SpellMode.Value)
         {
             case "start" :
                 this.EnableButtons();
                 this.SpellChecker.SpellCheck();
                 break;

             case "suggest" :
                 this.EnableButtons();
                 break;

             case "load" :
             case "end" :
             default :
                 this.DisableButtons();
                 break;
         }
         
    }

    void Page_Init(object sender, EventArgs e)
    {
         // show iframe for modal support
         if (Request.Params["Modal"] != null)
         {
             this.ModalFrame.Visible = true;
             this.SuggestionForm.Visible = false;
             return;
         }         
         
         if (Request.Params["Culture"] != null)
		 {
			culture = Request.Params["Culture"];
		 }

         // get dictionary from cache
         this.WordDictionary = (WordDictionary)HttpContext.Current.Cache["WordDictionary-" + culture];
         if (this.WordDictionary == null)
         {
             // if not in cache, create new
             this.WordDictionary = new NetSpell.SpellChecker.Dictionary.WordDictionary();
             this.WordDictionary.EnableUserFile = false;

             //getting folder for dictionaries
             string folderName="";
             
             if(ConfigurationSettings.AppSettings["DictionaryFolder"]== null)
				folderName = this.MapPath("~/bin");
			 else
			 {
				folderName = ConfigurationSettings.AppSettings["DictionaryFolder"];
				folderName = this.MapPath(Path.Combine(Request.ApplicationPath, folderName));
			 }
             
             this.WordDictionary.DictionaryFolder = folderName;
             
             // check if a dictionary exists for the culture, if so load it
             string cultureDictionary = String.Concat (culture, ".dic");
			 if (File.Exists (folderName +"\\"+ cultureDictionary))
			 {    
				this.WordDictionary.DictionaryFile = cultureDictionary;
			 }
			 else
			 {
			 	this.WordDictionary.DictionaryFile = "en-US.dic";
			 }
				
             //load and initialize the dictionary
             this.WordDictionary.Initialize();
             
             // Store the Dictionary in cache
             HttpContext.Current.Cache.Insert("WordDictionary-" + culture, this.WordDictionary, new CacheDependency(Path.Combine(folderName, this.WordDictionary.DictionaryFile)));
         }

         // create spell checker
         this.SpellChecker = new NetSpell.SpellChecker.Spelling();
         this.SpellChecker.ShowDialog = false;
         this.SpellChecker.Dictionary = this.WordDictionary;

         // adding events
         this.SpellChecker.MisspelledWord += new NetSpell.SpellChecker.Spelling.MisspelledWordEventHandler(this.SpellChecker_MisspelledWord);
         this.SpellChecker.EndOfText += new NetSpell.SpellChecker.Spelling.EndOfTextEventHandler(this.SpellChecker_EndOfText);
         this.SpellChecker.DoubledWord += new NetSpell.SpellChecker.Spelling.DoubledWordEventHandler(this.SpellChecker_DoubledWord);
    }

    void SpellChecker_DoubledWord(object sender, NetSpell.SpellChecker.SpellingEventArgs e)
    {
         this.SaveValues();
         this.CurrentWord.Text = this.SpellChecker.CurrentWord;
         this.Suggestions.Items.Clear();
         this.ReplacementWord.Text = string.Empty;
         this.SpellMode.Value = "suggest";
         this.StatusText.Text = string.Format("Word: {0} of {1}", this.SpellChecker.WordIndex + 1, this.SpellChecker.WordCount);
    }

    void SpellChecker_EndOfText(object sender, System.EventArgs e)
    {
         this.SaveValues();
         this.SpellMode.Value = "end";
         this.DisableButtons();
         this.StatusText.Text = string.Format("Word: {0} of {1}", this.SpellChecker.WordIndex + 1, this.SpellChecker.WordCount);
    }

    void SpellChecker_MisspelledWord(object sender, NetSpell.SpellChecker.SpellingEventArgs e)
    {
         this.SaveValues();
         this.CurrentWord.Text = this.SpellChecker.CurrentWord;
         this.SpellChecker.Suggest();
         this.Suggestions.DataSource = this.SpellChecker.Suggestions;
         this.Suggestions.DataBind();
         this.ReplacementWord.Text = string.Empty;
         this.SpellMode.Value = "suggest";
         this.StatusText.Text = string.Format("Word: {0} of {1}", this.SpellChecker.WordIndex + 1, this.SpellChecker.WordCount);
    }

    void EnableButtons()
    {
         this.IgnoreButton.Enabled = true;
         this.IgnoreAllButton.Enabled = true;
         this.AddButton.Enabled = true;
         this.ReplaceButton.Enabled = true;
         this.ReplaceAllButton.Enabled = true;
         this.ReplacementWord.Enabled = true;
         this.Suggestions.Enabled = true;
    }

    void DisableButtons()
    {
         this.IgnoreButton.Enabled = false;
         this.IgnoreAllButton.Enabled = false;
         this.AddButton.Enabled = false;
         this.ReplaceButton.Enabled = false;
         this.ReplaceAllButton.Enabled = false;
         this.ReplacementWord.Enabled = false;
         this.Suggestions.Enabled = false;
    }

    void SaveValues()
    {
         this.CurrentText.Value = this.SpellChecker.Text;
         this.WordIndex.Value = this.SpellChecker.WordIndex.ToString();

         // save ignore words
         string[] ignore = (string[])this.SpellChecker.IgnoreList.ToArray(typeof(string));

         this.IgnoreList.Value = String.Join("|", ignore);

         // save replace words
         ArrayList tempArray = new ArrayList(this.SpellChecker.ReplaceList.Keys);
         string[] replaceKey = (string[])tempArray.ToArray(typeof(string));

         this.ReplaceKeyList.Value = String.Join("|", replaceKey);
         tempArray = new ArrayList(this.SpellChecker.ReplaceList.Values);

         string[] replaceValue = (string[])tempArray.ToArray(typeof(string));

         this.ReplaceValueList.Value = String.Join("|", replaceValue);

         // saving user words
         tempArray = new ArrayList(this.SpellChecker.Dictionary.UserWords.Keys);

         string[] userWords = (string[])tempArray.ToArray(typeof(string));

         Response.Cookies["UserWords"].Value = String.Join("|", userWords);;
         Response.Cookies["UserWords"].Path = "/";
         Response.Cookies["UserWords"].Expires = DateTime.Now.AddMonths(1);
    }

    void LoadValues()
    {
         if (this.CurrentText.Value.Length > 0)
             this.SpellChecker.Text = this.CurrentText.Value;

         if (this.WordIndex.Value.Length > 0)
             this.SpellChecker.WordIndex = int.Parse(this.WordIndex.Value);

         // restore ignore list
         if (this.IgnoreList.Value.Length > 0)
         {
             this.SpellChecker.IgnoreList.Clear();
             this.SpellChecker.IgnoreList.AddRange(this.IgnoreList.Value.Split('|'));
         }

         // restore replace list
         if (this.ReplaceKeyList.Value.Length > 0 && this.ReplaceValueList.Value.Length > 0)
         {
             string[] replaceKeys = this.ReplaceKeyList.Value.Split('|');
             string[] replaceValues = this.ReplaceValueList.Value.Split('|');

             this.SpellChecker.ReplaceList.Clear();
             if (replaceKeys.Length == replaceValues.Length)
             {
                 for (int i = 0; i < replaceKeys.Length; i++)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -