/// <summary> /// Creates a new <see cref="T:TemplateField"/>. /// </summary> /// <param name="id">The id from the database, 0 if not attaced.</param> /// <param name="name">The name of the field.</param> /// <param name="type">The <see cref="T:Type">type</see> of the field.</param> /// <param name="category"></param> public TemplateField(int id, string name, FieldType type, Category category, string minRange, string maxRange, short order) : base(id, name) { this.Category = category; this.Type = type; this.minRange = minRange; this.minRange = maxRange; this.order = order; }
protected virtual void OnSelectedCategoryChanged(object sender, Category oldCategory, Category newCategory) { }
private static void SelectItem(ItemsControl itemsControl, Category category) { ItemContainerGenerator gen = itemsControl.ItemContainerGenerator; if (gen.Status != System.Windows.Controls.Primitives.GeneratorStatus.ContainersGenerated) { EventHandler eh = null; eh = new EventHandler(delegate { if (gen.Status == System.Windows.Controls.Primitives.GeneratorStatus.ContainersGenerated) { gen.StatusChanged -= eh; SelectItem(itemsControl, category); } }); gen.StatusChanged += eh; } else { TreeViewItem root = gen.ContainerFromItem(category) as TreeViewItem; if (root != null) { root.IsSelected = true; return; } Category original = category; while (category != null) { foreach (var item in itemsControl.Items) { TreeViewItem container = gen.ContainerFromItem(item) as TreeViewItem; if (item == original) { if (container != null) { container.IsSelected = true; } return; } else { if (item == category) { if (container != null) { container.IsExpanded = true; SelectItem(container, original); } } } } category = category.Parent; } } }
public static void Select(this TreeView treeView, Category category) { SelectItem(treeView, category); }
public Category(int id, string name, short order, Category parent) : base(id, name) { this.parent = parent; this.order = order; }
/// <summary> /// Occurs when the list of passwords has changed. /// </summary> protected void OnPasswordsChanged(object sender, NotifyEventArgs<Password> e) { OnPropertyChanged("Passwords"); Category parent = Parent; while (parent != null) { parent.OnPropertyChanged("NestedPasswords"); parent = parent.Parent; } }
private bool IsNestedTemplateModified(Category category) { if (category.IsModified) return true; return category.Categories.Any(c => IsNestedTemplateModified(c)); }
/// <summary> /// Adds a new child Category. /// </summary> /// <param name="name">The name of the new child Category.</param> /// <returns>The new Category.</returns> public Category AddCategory(string name) { Category category = new Category(0, name, (short)Categories.Count, this); Categories.Add(category); category.Save(); foreach (TemplateField field in Fields) { TemplateField copy = new TemplateField(0, field.Name, field.Type, category, field.MinRange, field.MaxRange, (short)Fields.Count); copy.IsModified = true; category.Fields.Add(copy); } category.SaveTemplate(); return category; }
public void NewPassword(Category category) { Password password = category.CreatePassword(); if (password != null) { password.Name = "New Password"; SelectedCategory = password.Category; this.SelectedPassword = password; this.PasswordGrid.FocusPassword(); } }
protected virtual void OnSelectedCategoryChanged(object sender, Category oldCategory, Category newCategory) { if (newCategory != null) { newCategory.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(SelectedCategoryPropertyChanged); } if (oldCategory != null) { oldCategory.PropertyChanged -= SelectedCategoryPropertyChanged; } if (newCategory != null) this.foldersTreeView.Deselect(); this.PasswordGrid.DataContext = newCategory; templateCategoryTree.Select(newCategory); categoriesTree.Select(newCategory); SelectedNode = newCategory; SelectedTemplateField = null; IsTemplateModified = newCategory != null ? newCategory.IsModified : false; }
/// <summary> /// Creates a new instance. /// </summary> public Password(int categoryId, int id, string name) : base(id, name) { this.category = Context.GetCategory(categoryId); }
/// <summary> /// Creates a new instance. /// </summary> public Password(Category category, int id, string name) : base(id, name) { this.category = category; }
private void SetCategoryByPath(string value) { if (!string.IsNullOrEmpty(value)) { // first get the root: Category category = Category; while (category.Parent is Category) category = category.Parent; string[] names = value.Split('\\'); foreach (string name in names) { category = GetCategoryByName(category, name); if (category == null) break; } if (category != null) { Category = category; } } }
private Category GetCategoryByName(Category category, string name) { return category.Categories.Where(c => c.Name.Equals(name, StringComparison.InvariantCultureIgnoreCase)).FirstOrDefault(); }
/// <summary> /// Creates a new instance. /// </summary> public Password(Category category) : base() { this.category = category; }