예제 #1
0
        protected override void CreateChildItems(Telerik.WinControls.RadElement parent)
        {
            base.CreateChildItems(parent);

            this.spellChecker        = new RadSpellChecker();
            this.controlSpellChecker = this.spellChecker.GetControlSpellChecker(typeof(RadRichTextBox));
            this.controlSpellChecker.CurrentControl = this;
        }
        private static void RegisterSpellChecker(IControlSpellChecker controlSpellChecker)
        {
            DocumentSpellChecker documentSpellChecker = controlSpellChecker.SpellChecker as DocumentSpellChecker;
            if (documentSpellChecker != null)
            {
                documentSpellChecker.AddDictionary(new RadEn_USDictionary(), CultureInfo.InvariantCulture);
            }

            ControlSpellCheckersManager.RegisterControlSpellChecker(controlSpellChecker);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="SpellCheckWordByWordWindow"/> class.
        /// </summary>
        /// <param name="word">
        /// The initial error word.
        /// </param>
        /// <param name="spellCheckingManager">
        /// The spell checking manager.
        /// </param>
        public SpellCheckWordByWordWindow(string word, IControlSpellChecker spellCheckingManager)
        {
            if (string.IsNullOrEmpty(word))
                throw new ArgumentException(@"The word cannot be null or empty.", "word");

            if (spellCheckingManager == null)
                throw new ArgumentNullException("spellCheckingManager");

            InitializeComponent();
            DataContext = this;
            IsAddToDictionaryButtonVisible = RadSpellChecker.WindowSettings.IsAddToDictionaryButtonVisible;
            IsIgnoreAllButtonVisible = RadSpellChecker.WindowSettings.IsIgnoreAllButtonVisible;
            IsEditCustomDictionaryButtonVisible = RadSpellChecker.WindowSettings.IsEditCustomDictionaryButtonVisible;
            WindowWidth = RadSpellChecker.WindowSettings.SpellCheckingWindowsWidth;
            WindowHeight = RadSpellChecker.WindowSettings.SpellCheckingWindowsHeight;
            _spellCheckingManager = spellCheckingManager;
            _initialErrorWord = word;
            NotInDictionaryTextBox.Text = InitialErrorWord;
            if (StyleManager.IsEnabled && RadSpellChecker.WindowSettings.SpellCheckingWindowsStyle != null)
                Style = RadSpellChecker.WindowSettings.SpellCheckingWindowsStyle;
            Owner = FindOwner(SpellCheckingManager.CurrentControl);

            if (StyleManager.IsEnabled)
            {
                IsTopmost = true;
            }

            Loaded += OnLoaded;
        }
        /// <summary>
        /// Shows the spell checking dialog.
        /// </summary>
        /// <param name="controlSpellChecker">
        /// The control spell checker.
        /// </param>
        /// <returns>
        /// A task that completes when the window is closed.
        /// </returns>
        /// <exception cref="ArgumentNullException">
        /// The <paramref name="controlSpellChecker"/> parameter is null.
        /// </exception>
        public Task<SpellCheckingResult> ShowDialog(IControlSpellChecker controlSpellChecker)
        {
            if (controlSpellChecker == null)
                throw new ArgumentNullException("controlSpellChecker");

            _tcs = new TaskCompletionSource<SpellCheckingResult>();
            _controlSpellChecker = controlSpellChecker;
            _spellCheckingManager.SpellChecker = _controlSpellChecker.SpellChecker;
            _spellCheckingManager.IgnoredWords = _controlSpellChecker.IgnoredWords;
            var document = _controlSpellChecker.GetContentAsDocument();

            RtbSpellCheckingContext.Document = document;
            RtbSpellCheckingContext.Document.CaretPosition.MoveToFirstPositionInDocument();
            _originalDocumentLayoutMode = document.LayoutMode;
            document.LayoutMode = DocumentLayoutMode.Flow;
            
            HasErrors = TryLoadIncorrectSentence(true);
            
            if (HasErrors)
            {
                Dispatcher.BeginInvoke(ShowDialog);
                UpdateAvailableCulturesAsync();
                UpdateSpellingSuggestionsAsync(_currentIncorrectWord);
            }
            else
            {
                _tcs.TrySetResult(new SpellCheckingResult(false));
            }

            return _tcs.Task;
        }