/// <summary>
        /// Event raised when key is pressed on a datagrid.
        /// Checks if a cell was deleted.
        /// If it was deleted then update the database.
        /// TODO: This should be converted to be done by pure binding instead using this event.
        /// TODO: USE: xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity" for binding!
        /// TODO: USE: xmlns:ei="http://schemas.microsoft.com/expression/2010/interactions" for binding!
        /// </summary>
        private void KeywordsDataGrid_PreviewKeyDown(object sender, KeyEventArgs e)
        {
            if (Key.Delete == e.Key)
            {
                foreach (var row in ((DataGrid)sender).SelectedItems)
                {
                    if (!row.ToString().Equals("{NewItemPlaceholder}"))
                    {
                        using (var businessContext = new BusinessContext())
                        {
                            Keyword keyword = (Keyword)row;

                            businessContext.DeleteKeyword(keyword);
                        }
                    }
                }
            }
        }
Example #2
0
        public MainWindowViewModel(MainWindow mainWindow)
        {
            this.mainWindow = mainWindow;

            RichTextBoxControl = mainWindow.RichTextBoxControl;

            Languages = new ObservableCollection<Language>();

            SelectedLanguages = new List<Language>();

            IsRichTextBoxTextAvailable = true;

            using (var businessContext = new BusinessContext())
            {
                var queryAllLanguages =
                    from languages in businessContext.DataContext.Languages
                    select languages;

                foreach (var language in queryAllLanguages)
                {
                    Languages.Add(language);
                }
            }
        }
        /// <summary>
        /// Event raised when a cell has finished editing.
        /// The edited cell is either updated or added to the database.
        /// TODO: This should be converted to be done by pure binding instead using this event.
        /// TODO: USE: xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity" for binding!
        /// TODO: USE: xmlns:ei="http://schemas.microsoft.com/expression/2010/interactions" for binding!
        /// </summary>
        private void DataGrid_CellEditEnding(object sender, DataGridCellEditEndingEventArgs e)
        {
            using (var businessContext = new BusinessContext())
            {
                Keyword keyword = (Keyword) e.Row.Item;
                keyword = businessContext.DataContext.Keywords.Find(keyword.Id);

                if (keyword != null)
                {
                    keyword.Name = ((TextBox)e.EditingElement).Text;
                    businessContext.UpdateKeyword(keyword);
                }
                else
                {
                    keyword = new Keyword
                    {
                        Name = ((TextBox)e.EditingElement).Text,
                        LanguageId = ((Language)LanguageTabControl.SelectedValue).Id
                    };

                    businessContext.AddNewKeyword(keyword);
                }
            }
        }
Example #4
0
        /// <summary>
        /// Uses the language.
        /// </summary>
        private void UseLanguage()
        {
            IsRichTextBoxTextAvailable = false;

            var searchInTextRange = new TextRange(RichTextBoxControl.Document.ContentStart, RichTextBoxControl.Document.ContentEnd);

            searchInTextRange.ApplyPropertyValue(TextElement.ForegroundProperty, new SolidColorBrush(Colors.Black));

            using (var businessContext = new BusinessContext())
            {
                foreach (var selectedLanguage in businessContext.DataContext.Languages)
                {
                    var language = SelectedLanguages.Find(l => l.Id == selectedLanguage.Id);
                    if (language != null)
                    {
                        foreach (var keyword in selectedLanguage.Keywords)
                        {
                            TextRange foundInTextRange = FindTextFromTextPointerPosition(RichTextBoxControl.Document.ContentStart, keyword.Name);

                            while (foundInTextRange != null)
                            {
                                foundInTextRange.ApplyPropertyValue(TextElement.ForegroundProperty, new SolidColorBrush(Colors.Blue));
                                RichTextBoxControl.Selection.ApplyPropertyValue(TextElement.ForegroundProperty, new SolidColorBrush(Colors.Black));
                                foundInTextRange = FindTextFromTextPointerPosition(foundInTextRange.End, keyword.Name);
                            }
                        }
                    }
                }
            }

            IsRichTextBoxTextAvailable = true;
        }