?? spellcheck.aspx
字號:
<%@ 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;
}
//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)
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -