internal void Delete(RegexRepositoryItem item)
        {
            if (this.items.Contains(item))
            {
                this.items.Remove(item);
            }

            SaveItems();
        }
        internal void Save(RegexRepositoryItem item)
        {
            if (!this.items.Contains(item))
            {
                this.items.Add(item);
            }

            SaveItems();
        }
        /// <summary>
        /// Clones an instance of <see cref="RegexRepositoryItem"/>
        /// </summary>
        /// <returns></returns>
        public object Clone()
        {
            RegexRepositoryItem item = new RegexRepositoryItem();

            item.Author      = this.Author;
            item.Category    = this.Category;
            item.Description = this.Description;
            item.Matches     = this.Matches;
            item.Title       = this.Title;
            item.Regex       = this.Regex;

            return(item);
        }
示例#4
0
        private void MenuItemDuplicateRepositoryItem_Click(object sender, RoutedEventArgs e)
        {
            if (this.regexRepositoryItemsDataGrid.SelectedItems != null)
            {
                foreach (RegexRepositoryItem selectedItem in this.regexRepositoryItemsDataGrid.SelectedItems.Cast <RegexRepositoryItem>().ToList())
                {
                    RegexRepositoryItem item = selectedItem.Clone() as RegexRepositoryItem;
                    this.context.RegexRepositoryService.GenerateUniqueTitle(item);

                    this.context.RegexRepositoryService.Save(item);
                    this.regexRepositoryItemsDataGrid.SelectedItem = item;
                }
            }
        }
示例#5
0
        internal static bool?ShowDialog(string regex, IWpfTextViewHost regexEditor, out string result)
        {
            RegexEditorDialog   editorDialog           = new RegexEditorDialog(regexEditor);
            RegexRepositoryItem selectedRepositoryItem = editorDialog.context.RegexRepositoryService.Items.FirstOrDefault(item => string.Compare(item.Regex, regex, true) == 0);

            if (selectedRepositoryItem != null)
            {
                editorDialog.context.SelectedItem = selectedRepositoryItem;
                editorDialog.regexRepositoryItemsDataGrid.SelectedItem = selectedRepositoryItem;
            }
            else
            {
                editorDialog.context.SelectedItem.Regex = regex;
            }

            bool?dialogResult = editorDialog.ShowDialog();

            result = editorDialog.GetExpressionText();

            return(dialogResult);
        }
 internal void GenerateUniqueTitle(RegexRepositoryItem item)
 {
     item.Title = GenerateUniqueName(title => this.items.Where(i => string.Compare(i.Title, title, true) == 0).Count() == 0, item.Title, 1);
 }