Exemplo n.º 1
0
 /// <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;
 }
Exemplo n.º 2
0
 protected virtual void OnSelectedCategoryChanged(object sender, Category oldCategory, Category newCategory)
 {
 }
Exemplo n.º 3
0
        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;
                }
            }
        }
Exemplo n.º 4
0
 public static void Select(this TreeView treeView, Category category)
 {
     SelectItem(treeView, category);
 }
Exemplo n.º 5
0
 public Category(int id, string name, short order, Category parent)
     : base(id, name)
 {
     this.parent = parent;
     this.order = order;
 }
Exemplo n.º 6
0
        /// <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;
            }
        }
Exemplo n.º 7
0
 private bool IsNestedTemplateModified(Category category)
 {
     if (category.IsModified) return true;
     return category.Categories.Any(c => IsNestedTemplateModified(c));
 }
Exemplo n.º 8
0
 /// <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;
 }
Exemplo n.º 9
0
        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();

            }
        }
Exemplo n.º 10
0
        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;
        }
Exemplo n.º 11
0
 /// <summary>
 /// Creates a new instance.
 /// </summary>
 public Password(int categoryId, int id, string name)
     : base(id, name)
 {
     this.category = Context.GetCategory(categoryId);
 }
Exemplo n.º 12
0
 /// <summary>
 /// Creates a new instance.
 /// </summary>
 public Password(Category category, int id, string name)
     : base(id, name)
 {
     this.category = category;
 }
Exemplo n.º 13
0
        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;
                }
            }
        }
Exemplo n.º 14
0
 private Category GetCategoryByName(Category category, string name)
 {
     return category.Categories.Where(c => c.Name.Equals(name, StringComparison.InvariantCultureIgnoreCase)).FirstOrDefault();
 }
Exemplo n.º 15
0
 /// <summary>
 /// Creates a new instance.
 /// </summary>
 public Password(Category category)
     : base()
 {
     this.category = category;
 }