diff --git a/PROMS/Volian.Controls.Library/VlnSpellCheck.cs b/PROMS/Volian.Controls.Library/VlnSpellCheck.cs new file mode 100644 index 00000000..6af5dd81 --- /dev/null +++ b/PROMS/Volian.Controls.Library/VlnSpellCheck.cs @@ -0,0 +1,38 @@ +using System; +using System.Collections.Generic; +using System.Text; +using VEPROMS.CSLA.Library; + +namespace Volian.Controls.Library +{ + public class VlnSpellCheck + { + private StepItem _MyStepItem; + public StepItem MyStepItem + { + get { return _MyStepItem; } + set + { + _MyStepItem = value; + } + } + + + public VlnSpellCheck() + { + } + + public void DoSpellCheck() + { + while (MyStepItem.MyStepRTB.SpellCheckNext()) + { + ItemInfo next = MyStepItem.MyItemInfo.SearchNext; + if (next.IsSection) + return; // spell check only current section + MyStepItem.MyStepPanel.MyStepTabPanel.MyDisplayTabControl.OpenItem(next); + } + MyStepItem.MyStepRTB.Focus(); + } + + } +} diff --git a/PROMS/Volian.Controls.Library/VlnSpellCheckDlg.Designer.cs b/PROMS/Volian.Controls.Library/VlnSpellCheckDlg.Designer.cs new file mode 100644 index 00000000..cb4c4fa5 --- /dev/null +++ b/PROMS/Volian.Controls.Library/VlnSpellCheckDlg.Designer.cs @@ -0,0 +1,211 @@ +namespace Volian.Controls.Library +{ + partial class VlnSpellCheckDlg + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.lblNotInDictionary = new DevComponents.DotNetBar.LabelX(); + this.txbBadWord = new DevComponents.DotNetBar.Controls.TextBoxX(); + this.lbSuggestList = new System.Windows.Forms.ListBox(); + this.btnIgnore = new DevComponents.DotNetBar.ButtonX(); + this.btnIgnoreAll = new DevComponents.DotNetBar.ButtonX(); + this.btnChange = new DevComponents.DotNetBar.ButtonX(); + this.btnChangeAll = new DevComponents.DotNetBar.ButtonX(); + this.btnAddToDictionary = new DevComponents.DotNetBar.ButtonX(); + this.btnCancel = new DevComponents.DotNetBar.ButtonX(); + this.btnRemove = new DevComponents.DotNetBar.ButtonX(); + this.SuspendLayout(); + // + // lblNotInDictionary + // + // + // + // + this.lblNotInDictionary.BackgroundStyle.Class = ""; + this.lblNotInDictionary.Location = new System.Drawing.Point(12, 1); + this.lblNotInDictionary.Name = "lblNotInDictionary"; + this.lblNotInDictionary.Size = new System.Drawing.Size(108, 23); + this.lblNotInDictionary.TabIndex = 0; + this.lblNotInDictionary.Text = "Not In Dictionary:"; + // + // txbBadWord + // + this.txbBadWord.AcceptsReturn = true; + this.txbBadWord.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + // + // + // + this.txbBadWord.Border.Class = "TextBoxBorder"; + this.txbBadWord.Location = new System.Drawing.Point(12, 30); + this.txbBadWord.Name = "txbBadWord"; + this.txbBadWord.Size = new System.Drawing.Size(185, 22); + this.txbBadWord.TabIndex = 1; + this.txbBadWord.TextChanged += new System.EventHandler(this.txbBadWord_TextChanged); + // + // lbSuggestList + // + this.lbSuggestList.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.lbSuggestList.FormattingEnabled = true; + this.lbSuggestList.ItemHeight = 16; + this.lbSuggestList.Location = new System.Drawing.Point(12, 58); + this.lbSuggestList.Name = "lbSuggestList"; + this.lbSuggestList.Size = new System.Drawing.Size(185, 148); + this.lbSuggestList.TabIndex = 2; + this.lbSuggestList.SelectedIndexChanged += new System.EventHandler(this.lbSuggestList_SelectedIndexChanged); + this.lbSuggestList.DoubleClick += new System.EventHandler(this.lbSuggestList_DoubleClick); + // + // btnIgnore + // + this.btnIgnore.AccessibleRole = System.Windows.Forms.AccessibleRole.PushButton; + this.btnIgnore.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.btnIgnore.ColorTable = DevComponents.DotNetBar.eButtonColor.OrangeWithBackground; + this.btnIgnore.Location = new System.Drawing.Point(208, 29); + this.btnIgnore.Name = "btnIgnore"; + this.btnIgnore.Size = new System.Drawing.Size(75, 23); + this.btnIgnore.Style = DevComponents.DotNetBar.eDotNetBarStyle.StyleManagerControlled; + this.btnIgnore.TabIndex = 3; + this.btnIgnore.Text = "Ignore"; + this.btnIgnore.Click += new System.EventHandler(this.btnIgnore_Click); + // + // btnIgnoreAll + // + this.btnIgnoreAll.AccessibleRole = System.Windows.Forms.AccessibleRole.PushButton; + this.btnIgnoreAll.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.btnIgnoreAll.ColorTable = DevComponents.DotNetBar.eButtonColor.OrangeWithBackground; + this.btnIgnoreAll.Location = new System.Drawing.Point(289, 29); + this.btnIgnoreAll.Name = "btnIgnoreAll"; + this.btnIgnoreAll.Size = new System.Drawing.Size(75, 23); + this.btnIgnoreAll.Style = DevComponents.DotNetBar.eDotNetBarStyle.StyleManagerControlled; + this.btnIgnoreAll.TabIndex = 4; + this.btnIgnoreAll.Text = "Ignore All"; + this.btnIgnoreAll.Click += new System.EventHandler(this.btnIgnoreAll_Click); + // + // btnChange + // + this.btnChange.AccessibleRole = System.Windows.Forms.AccessibleRole.PushButton; + this.btnChange.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.btnChange.ColorTable = DevComponents.DotNetBar.eButtonColor.OrangeWithBackground; + this.btnChange.Location = new System.Drawing.Point(208, 58); + this.btnChange.Name = "btnChange"; + this.btnChange.Size = new System.Drawing.Size(75, 23); + this.btnChange.Style = DevComponents.DotNetBar.eDotNetBarStyle.StyleManagerControlled; + this.btnChange.TabIndex = 5; + this.btnChange.Text = "Change"; + this.btnChange.Click += new System.EventHandler(this.btnChange_Click); + // + // btnChangeAll + // + this.btnChangeAll.AccessibleRole = System.Windows.Forms.AccessibleRole.PushButton; + this.btnChangeAll.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.btnChangeAll.ColorTable = DevComponents.DotNetBar.eButtonColor.OrangeWithBackground; + this.btnChangeAll.Location = new System.Drawing.Point(289, 58); + this.btnChangeAll.Name = "btnChangeAll"; + this.btnChangeAll.Size = new System.Drawing.Size(75, 23); + this.btnChangeAll.Style = DevComponents.DotNetBar.eDotNetBarStyle.StyleManagerControlled; + this.btnChangeAll.TabIndex = 6; + this.btnChangeAll.Text = "Change All"; + this.btnChangeAll.Click += new System.EventHandler(this.btnChangeAll_Click); + // + // btnAddToDictionary + // + this.btnAddToDictionary.AccessibleRole = System.Windows.Forms.AccessibleRole.PushButton; + this.btnAddToDictionary.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.btnAddToDictionary.ColorTable = DevComponents.DotNetBar.eButtonColor.OrangeWithBackground; + this.btnAddToDictionary.Location = new System.Drawing.Point(208, 1); + this.btnAddToDictionary.Name = "btnAddToDictionary"; + this.btnAddToDictionary.Size = new System.Drawing.Size(156, 23); + this.btnAddToDictionary.Style = DevComponents.DotNetBar.eDotNetBarStyle.StyleManagerControlled; + this.btnAddToDictionary.TabIndex = 7; + this.btnAddToDictionary.Text = "Add To Dictionary"; + this.btnAddToDictionary.Click += new System.EventHandler(this.btnAddToDictionary_Click); + // + // btnCancel + // + this.btnCancel.AccessibleRole = System.Windows.Forms.AccessibleRole.PushButton; + this.btnCancel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.btnCancel.ColorTable = DevComponents.DotNetBar.eButtonColor.OrangeWithBackground; + this.btnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel; + this.btnCancel.Location = new System.Drawing.Point(287, 188); + this.btnCancel.Name = "btnCancel"; + this.btnCancel.Size = new System.Drawing.Size(75, 23); + this.btnCancel.Style = DevComponents.DotNetBar.eDotNetBarStyle.StyleManagerControlled; + this.btnCancel.TabIndex = 8; + this.btnCancel.Text = "Cancel"; + // + // btnRemove + // + this.btnRemove.AccessibleRole = System.Windows.Forms.AccessibleRole.PushButton; + this.btnRemove.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.btnRemove.ColorTable = DevComponents.DotNetBar.eButtonColor.OrangeWithBackground; + this.btnRemove.Location = new System.Drawing.Point(208, 87); + this.btnRemove.Name = "btnRemove"; + this.btnRemove.Size = new System.Drawing.Size(75, 23); + this.btnRemove.Style = DevComponents.DotNetBar.eDotNetBarStyle.StyleManagerControlled; + this.btnRemove.TabIndex = 9; + this.btnRemove.Text = "Remove"; + this.btnRemove.Click += new System.EventHandler(this.btnRemove_Click); + // + // VlnSpellCheckDlg + // + this.CancelButton = this.btnCancel; + this.ClientSize = new System.Drawing.Size(374, 223); + this.Controls.Add(this.btnRemove); + this.Controls.Add(this.btnCancel); + this.Controls.Add(this.btnAddToDictionary); + this.Controls.Add(this.btnChangeAll); + this.Controls.Add(this.btnChange); + this.Controls.Add(this.btnIgnoreAll); + this.Controls.Add(this.btnIgnore); + this.Controls.Add(this.lbSuggestList); + this.Controls.Add(this.txbBadWord); + this.Controls.Add(this.lblNotInDictionary); + this.MaximizeBox = false; + this.MinimizeBox = false; + this.MinimumSize = new System.Drawing.Size(392, 266); + this.Name = "VlnSpellCheckDlg"; + this.Text = "Spell Check"; + this.ResumeLayout(false); + + } + + #endregion + + private DevComponents.DotNetBar.LabelX lblNotInDictionary; + private DevComponents.DotNetBar.Controls.TextBoxX txbBadWord; + private System.Windows.Forms.ListBox lbSuggestList; + private DevComponents.DotNetBar.ButtonX btnIgnore; + private DevComponents.DotNetBar.ButtonX btnIgnoreAll; + private DevComponents.DotNetBar.ButtonX btnChange; + private DevComponents.DotNetBar.ButtonX btnChangeAll; + private DevComponents.DotNetBar.ButtonX btnAddToDictionary; + private DevComponents.DotNetBar.ButtonX btnCancel; + private DevComponents.DotNetBar.ButtonX btnRemove; + } +} \ No newline at end of file diff --git a/PROMS/Volian.Controls.Library/VlnSpellCheckDlg.cs b/PROMS/Volian.Controls.Library/VlnSpellCheckDlg.cs new file mode 100644 index 00000000..1b0176c2 --- /dev/null +++ b/PROMS/Volian.Controls.Library/VlnSpellCheckDlg.cs @@ -0,0 +1,292 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Text; +using System.Windows.Forms; +using DevComponents.DotNetBar; +using C1.Win.C1SpellChecker; + +namespace Volian.Controls.Library +{ + // Our custom Spell Checker dialog + public partial class VlnSpellCheckDlg : DevComponents.DotNetBar.Office2007Form, ISpellDialog + { + private C1SpellChecker _Spell; + private ISpellCheckableEditor _Editor; + private CharRangeList _Errors; + private int _ErrorCount; + private int _ErrorIndex = -1; // current error index + private bool _AutoSuggest = true; + private string _NoSuggestionsText = "(no suggestions)"; + + Dictionary _changeAll = new Dictionary(); + + /// + /// Gets the object that represents the error currently + /// displayed in the dialog. + /// + public CharRange CurrentError + { + get { return _Errors[_ErrorIndex]; } + } + + public VlnSpellCheckDlg() + { + InitializeComponent(); + } + /// + /// Initializes the dialog to use the given parameters. + /// + /// to use for spelling. + /// that contains the text to spell-check. + /// that contains the initial error list. + public void Initialize(C1SpellChecker spell, ISpellCheckableEditor editor, CharRangeList errors) + { + _Spell = spell; + _Editor = editor; + _Errors = errors; + if (_Errors == null) + { + _Errors = _Spell.CheckText(_Editor.Text); + } + _ErrorCount += _Errors.Count; + btnAddToDictionary.Visible = _Spell.UserDictionary.Enabled; + } + /// + /// Gets the total number of errors detected in the control. + /// + public int ErrorCount + { + get { return _ErrorCount; } + } + + /// + /// Gets or sets the index of the current error into the list. + /// + public int ErrorIndex + { + get { return _ErrorIndex; } + set + { + _ErrorIndex = value; + UpdateCurrentError(); + } + } + + private void UpdateEditor(string replacement) + { + // save starting point to continue checking from here + int start = CurrentError.Start; + + if (replacement.Length == 0) + { + // if replacement is empty, expand over spaces and commas + CharRange delete = CharRange.ExpandOverWhitespace(_Editor.Text, CurrentError); + _Editor.Select(delete.Start, delete.Text.Length); + } + + // replace word in text and re-check + _Editor.SelectedText = replacement; + _Errors = _Spell.CheckText(_Editor.Text, start); + + // update index + ErrorIndex = ErrorIndex; // originally 0; + } + + /// + /// Raises the event. + /// + /// that contains the event data. + protected override void OnLoad(EventArgs e) + { + // fire load event + base.OnLoad(e); + + // show first error (after firing load event) + ErrorIndex = 0; + } + + private bool _Initializing = false; + private string _OrgWord; + + // update dialog to show current error + private void UpdateCurrentError() + { + // design time + if (DesignMode || _Errors == null) + { + return; + } + // finished with this batch of errors + if (ErrorIndex >= _Errors.Count) + { + // check whether the editor has more text to check + while (_Editor.HasMoreText()) + { + _Errors = _Spell.CheckText(_Editor.Text); + if (_Errors.Count > 0) + { + _ErrorCount += _Errors.Count; + ErrorIndex = 0; + return; + } + } + + // editor has no more text... + DialogResult = DialogResult.OK; + return; + } + + // update current error + CharRange err = CurrentError; + + // select word in editor + _Editor.Select(err.Start, err.Text.Length); + + // honor 'change all' list + if (_changeAll.ContainsKey(err.Text)) + { + txbBadWord.Text = _changeAll[err.Text]; + btnChange_Click(this, EventArgs.Empty); + return; + } + + _Initializing = true; + // show bad word, new text + txbBadWord.Text = _OrgWord = err.Text; + + // repeated word? + if (err.Duplicate) + { + // adjust dialog + lblNotInDictionary.Text = "Duplicate Word"; + btnIgnoreAll.Enabled = false; + btnAddToDictionary.Enabled = false; + btnRemove.Enabled = true; + + // no suggestions + lbSuggestList.Items.Clear(); + } + else + { + // adjust dialog + lblNotInDictionary.Text = "Not In Dictionary"; + btnIgnoreAll.Enabled = true; + btnAddToDictionary.Enabled = true; + btnRemove.Enabled = false; + + SetupSuggestions(err.Text); + } + + // focus to new word + _AutoSuggest = false; + txbBadWord.SelectAll(); + txbBadWord.Focus(); + _AutoSuggest = true; + AcceptButton = btnIgnore; + + // show 'Add' button only if user dictionary is enabled + btnAddToDictionary.Visible = _Spell.UserDictionary.Enabled; + + // all ready, fire ErrorDisplayed event + //OnErrorDisplayed(EventArgs.Empty); + } + + private void SetupSuggestions(string badWord) + { + // show suggestions + _Initializing = true; + string[] suggestions = _Spell.GetSuggestions(badWord); + lbSuggestList.Items.Clear(); + if (suggestions.Length > 0) + { + lbSuggestList.Items.AddRange(suggestions); + lbSuggestList.SelectedIndex = -1; + lbSuggestList.Enabled = true; + } + else + { + lbSuggestList.Items.Add(_NoSuggestionsText); + lbSuggestList.SelectedIndex = -1; + lbSuggestList.Enabled = false; + } + _Initializing = false; + } + + private void txbBadWord_TextChanged(object sender, EventArgs e) + { + btnChange.Enabled = (_OrgWord != txbBadWord.Text); + btnChangeAll.Enabled = btnChange.Enabled && lblNotInDictionary.Text == "Not In Dictionary"; + btnAddToDictionary.Enabled = _Spell.UserDictionary.Enabled && !InDictionary(txbBadWord.Text); + if (_AutoSuggest && !_Initializing) + { + SetupSuggestions(txbBadWord.Text); + } + } + + private bool InDictionary(string word) + { + if (_Spell.MainDictionary.Contains(word)) + return true; + if (_Spell.CustomDictionary != null && _Spell.CustomDictionary.Contains(word)) + return true; + if (_Spell.UserDictionary != null && _Spell.UserDictionary.Contains(word)) + return true; + return false; + } + + private void btnChange_Click(object sender, EventArgs e) + { + UpdateEditor(txbBadWord.Text); + } + + private void btnChangeAll_Click(object sender, EventArgs e) + { + _changeAll[CurrentError.Text] = txbBadWord.Text; + UpdateEditor(txbBadWord.Text); + } + + private void btnIgnore_Click(object sender, EventArgs e) + { + ErrorIndex++; + } + + private void btnIgnoreAll_Click(object sender, EventArgs e) + { + _Spell.IgnoreList.Add(CurrentError.Text); + _Errors = _Spell.CheckText(_Editor.Text, CurrentError.Start); + UpdateCurrentError(); + } + + private void btnAddToDictionary_Click(object sender, EventArgs e) + { + _Spell.UserDictionary.AddWord(CurrentError.Text); + _Errors = _Spell.CheckText(_Editor.Text, CurrentError.Start); + ErrorIndex = 0; + } + + private void lbSuggestList_SelectedIndexChanged(object sender, EventArgs e) + { + _AutoSuggest = false; + if (!_Initializing && lbSuggestList.Text != _NoSuggestionsText) + txbBadWord.Text = lbSuggestList.Text; + _AutoSuggest = true; + } + + // double-click selects word for suggestion list and changes mis-spelled word + private void lbSuggestList_DoubleClick(object sender, EventArgs e) + { + if (txbBadWord.Text == lbSuggestList.Text) + { + UpdateEditor(txbBadWord.Text); + } + } + + private void btnRemove_Click(object sender, EventArgs e) + { + UpdateEditor(""); + } + } +} \ No newline at end of file diff --git a/PROMS/Volian.Controls.Library/VlnSpellCheckDlg.resx b/PROMS/Volian.Controls.Library/VlnSpellCheckDlg.resx new file mode 100644 index 00000000..19dc0dd8 --- /dev/null +++ b/PROMS/Volian.Controls.Library/VlnSpellCheckDlg.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file