Ejemplo n.º 1
0
        public BasicTextEditor(EventHandler callback, string data)
        {
            try {
                SpellChecker = new TypingSpellChecker(Globals.WorkspaceSave.AffFile, Globals.WorkspaceSave.DicFile);
            }
            catch (Exception exception)
            {
                MessageBox.Show(exception.Message + "\nCannot enable automatic spell check.");
            }

            InitializeComponent();
            CenterToScreen();
            //MessageBox.Show(data);

            EditCallback += new EventHandler(callback);

            data = data.Replace("\\\\'", "'");
            data = data.Replace("\\'", "'");

            data = data.Replace("\\\\\"", "'");
            data = data.Replace("\\\"", "'");

            data = data.Replace("\\n", "\n");

            this.richTextBox1.Text = data;

            //gotta give the text editor focus and set a cursor index in order for
            //the spellchecker to work cirrectly with first right click
            richTextBox1.Focus();
            richTextBox1.Select();


            this.labelCharacterSizesChart.Font = richTextBox1.Font;

            this.richTextBox1.Location = new Point(TextBorder, this.richTextBox1.Location.Y);
            this.richTextBox1.Width    = labelCharacterSizesChart.Width;
            this.richTextBox1.Select(richTextBox1.Text.Length, 0);
            this.Width = richTextBox1.Width + (2 * TextBorder);

            this.buttonOk.Location     = new Point(buttonOk.Location.X, richTextBox1.Location.Y + richTextBox1.Height + (2 * TextBorder));
            this.buttonCancel.Location = new Point(buttonCancel.Location.X, buttonOk.Location.Y);

            if (SpellChecker != null)
            {
                SpellCheckerThread = new Thread(new ThreadStart(UpdateSpellCheckThread));
                SpellCheckerThread.Start();
            }
        }
Ejemplo n.º 2
0
        protected override void OnClosing(CancelEventArgs e)
        {
            ThreadClosing = true;

            //NOTE: I've decided to remove this block since it shouldn't matter (I think!)
            //      and it's causing an annoying lag when closing the text editor window.
            //SpellCheckerThread.Join(WORKERTHREAD_END_TIMEOUT);
            //if(SpellCheckerThread.IsAlive)
            //    {
            //    SpellCheckerThread.Abort();
            //    }
            if (SpellChecker != null)
            {
                SpellChecker.Dispose();
            }
            SpellChecker = null;

            base.OnClosing(e);
        }
Ejemplo n.º 3
0
        private List <SpellCheckRange> HilightEditorText(Stellarmap.FlickerFreeRichEditTextBox control, TypingSpellChecker checker)
        {
            List <SpellCheckRange> ranges;

            //Hack Alert, this isn't entirely thread safe because I could dispose of the SpellChecker
            // but not yet make the referece invalid
            lock (control)
            {
                if (SpellChecker == null || SpellChecker.DataDisposed)
                {
                    return(null);
                }
                if (Control.MouseButtons == MouseButtons.Left || Control.MouseButtons == MouseButtons.Right)
                {
                    return(null);
                }

                bool hadFocus = control.Focused;
                int  selStart = control.SelectionStart;
                int  selLen   = control.SelectionLength;

                richTextBox1.EnablePainting = false;
                ranges = checker.ProofRead(control.Text);
                control.Select(0, control.Text.Length);
                control.SelectionFont  = new Font(control.Font, FontStyle.Regular);
                control.SelectionColor = System.Drawing.SystemColors.ControlText;


                foreach (SpellCheckRange r in ranges)
                {
                    control.Select(r.Start, r.End - r.Start);
                    control.SelectionFont  = new Font(control.Font, FontStyle.Underline);
                    control.SelectionColor = System.Drawing.Color.Red;
                }


                //richTextBox1.Enabled = true;
                if (hadFocus)
                {
                    control.Focus();
                    control.Select(selStart, selLen);
                }
                control.EnablePainting = true;
            }                    //end crit section

            return(ranges);
        }