예제 #1
0
        public async Task <FolderViewModel> AddChild(string name)
        {
            var child = new FolderViewModel(name, _visualTree);
            var a     = await this.AddChild(child);

            return(child);
        }
예제 #2
0
        public async Task <bool> AddChild(FolderViewModel Child)
        {
            if (Child.Parent == this)
            {
                return(true);                      // do nothing
            }
            {
                var hasParent = false;
                if (Child.Parent != null)
                {
                    hasParent = !(await Child.Parent.RemoveChild(Child));
                }
                if (!hasParent)
                {
                    hasParent = await Child.SetParent(this);

                    if (!hasParent)
                    {
                        return(false);
                    }
                    this._children.Add(Child);
                    OnPropertyChanged("Children");
                    return(true);
                }
            }
            return(false);
        }
예제 #3
0
        public static async Task GetRootItems(FolderTreeViewModel folderTree)
        {
            Debug.Assert(folderTree != null);
            var db          = Database.DbConnection;
            var rootFolders = await db.Table <Folders>().Where(f => f.Parent == 0).ToListAsync();

            //  Skip single rootfolders, unless it does not have children
            while (rootFolders.Count == 1)
            {
                var rootId   = rootFolders.First().Id;
                var children = await db.Table <Folders>().Where(f => f.Parent == rootId).ToListAsync();

                if (children.Count == 0)
                {
                    break;
                }
                rootFolders = children;
            }
            var root = new ObservableCollection <FolderViewModel>();

            foreach (Folders folder in rootFolders)
            {
                var folderViewModel = new FolderViewModel(folder, null, folderTree);
                await folderViewModel.ReadChildrenFromDb();

                root.Add(folderViewModel);
            }
            folderTree.Children = root;
        }
예제 #4
0
        //private async Task<List<int>> GetIdTree()
        //{
        // }
        #endregion
        #region ReadChildren
        private async Task ReadChildrenFromDb()
        {
            var db       = Database.DbConnection;
            var children = await db.Table <Folders>().Where(f => f.Parent == this._folder.Id).ToListAsync();

            foreach (Folders childfolder in children)
            {
                var child = new FolderViewModel(childfolder, this, _visualTree);
                _children.Add(child);
                await child.ReadChildrenFromDb();
            }
        }
예제 #5
0
        public async Task <bool> RemoveChild(FolderViewModel Child)
        {
            Child._parent = null;
            await Child.Save();

            if (this._children.Remove(Child))
            {
                this.OnPropertyChanged("Children");
                return(true);
            }
            else
            {
                return(false);
            }
        }
        private async Task AddAllFolders(string rootName)
        {
            var rootFolder = new FolderViewModel(rootName, _folderTree);
            await rootFolder.Save();

            var infolder = await rootFolder.AddChild("In");

            this._emailProvider.InFolderId = infolder.Id;
            var outFolder = await rootFolder.AddChild("Out");

            this._emailProvider.OutFolderId = outFolder.Id;
            var sentFolder = await rootFolder.AddChild("Sent");

            this._emailProvider.SentFolderId = sentFolder.Id;
            var conceptsFolder = await rootFolder.AddChild("Concepts");

            this._emailProvider.ConceptsFolderId = conceptsFolder.Id;
        }
예제 #7
0
        public async Task <bool> SetParent(FolderViewModel parent)
        {
            if (_parent == parent)
            {
                return(true);
            }
            if (_parent != null)
            {
                await _parent.RemoveChild(this);
            }
            _parent = parent;
            if (parent == null)
            {
                if (_visualTree?.Children?[0] == null)
                {
                    _folder.Parent = 0;
                }
                else
                {
                    _folder.Parent = _visualTree.Children[0]._parent.Id;
                }
                _parent = null;
                await Save(new List <int>());
            }
            else
            {
                if (parent.Id == 0)
                {
                    await parent.Save();
                }
                _folder.Parent = parent.Id;
                var saved = await Save(new List <int>());

                if (!saved)
                {
                    _folder.Parent = 0;
                    _parent        = null;
                    return(false);
                }
                _parent?.OnPropertyChanged("Children");
            }
            OnPropertyChanged("Path");
            return(true);
        }
예제 #8
0
        private async Task <bool> Save(List <int> children)
        {
            var i = 0; //number of records inserted or updated.

            if (_folder == null)
            {
                return(false);
            }
            var checkedOk = CheckParent(children);

            if (!checkedOk)
            {
                return(false);
            }

            var db = Database.DbConnection;

            if ((_parent != null) && (_parent.Id == 0))
            {
                children.Add(this.Id);
                if (await this.Parent.Save(children))
                {
                    _folder.Parent = Parent.Id;
                }
                else
                {
                    _parent = null;
                }
            }
            if (_folder.Id == 0)
            {
                i = await db.InsertAsync(_folder);
            }
            else
            {
                i = await db.UpdateAsync(_folder);
            }
            if (_parent == null)
            {
                _visualTree?.Children?.Add(this);
            }
            return(i == 1);
        }
예제 #9
0
        internal async Task <bool> SelectItem(FolderViewModel element, bool refreshOnFail = false)
        {
            var ancestors = new List <FolderViewModel>();
            var current   = element;

            while (current.Parent != null)
            {
                ancestors.Add(current.Parent);
                current = current.Parent;
            }
            for (int i = ancestors.Count - 1; i <= 0; i--)
            {
                if (!ancestors[i].IsExpanded)
                {
                    ancestors[i].IsExpanded = true;
                }
            }
            element.IsSelected = true;
            return(true);
        }
예제 #10
0
        internal async Task Refresh()
        {
            //if (this.SelectedItem != null)
            //{
            //    await this.SelectedItem.Refresh();
            //}
            //else
            //if (this.RootElements.Count == 1 &&
            //    this.RootElements[0] is DependencyObjectViewModel &&
            //    ((DependencyObjectViewModel)this.RootElements[0]).Model == Window.Current.Content)
            //{
            //    await this.RootElements[0].RefreshAsync();
            //}
            //else
            //{
            this.Children.Clear();
            await FolderViewModel.GetRootItems(this);

            //}
        }
예제 #11
0
 internal FolderViewModel(Folders myFolder, FolderViewModel myParent, FolderTreeViewModel visualTree)
 {
     this._folder = myFolder;
     _visualTree  = visualTree;
     _parent      = myParent;
 }