Exemple #1
0
 private void Balance(ref TreeNote <T> current)
 {
     if (current.lengthleft > current.lengthright + 1)
     {
         //либо левый-левый, либо левый-правый
         TreeNote <T> downleft = current.left;
         if (downleft.lengthleft > downleft.lengthright)
         {
             //левый-левый
             RightRotate(ref current);
         }
         //левый-правый
         else
         {
             LeftRightRotate(ref current);
         }
     }
     else
     if (current.lengthright > current.lengthleft + 1)
     //либо правый-правый, либо правый-левый
     {
         TreeNote <T> downright = current.right;
         if (downright.lengthright > downright.lengthleft)
         {
             //правый-правый
             LeftRotate(ref current);
         }
         //правый-левый
         else
         {
             RightLeftRotate(ref current);
         }
     }
 }
Exemple #2
0
 private void RightLeftRotate(ref TreeNote <T> current)
 {
     RightRotate(ref current.right);
     //PrintTree();
     LeftRotate(ref current);
     //PrintTree();
 }
Exemple #3
0
    void LoadNote(string path, bool isActive)
    {
        AddRecentOpenedFiles(path);

        foreach (TreeNote existTree in MainTabGroup.TreeNotes)
        {
            if (existTree.File != null && existTree.File.FullName.Replace('\\', '/') == path.Replace('\\', '/'))
            {
                if (existTree.IsActive == false)
                {
                    existTree.IsActive = true;
                }
                return;
            }
        }

        TabButton tab      = Instantiate(TabButtonPrefab.gameObject, TabParent.transform).GetComponent <TabButton>();
        TreeNote  treeNote = Instantiate(TreeNotePrefab.gameObject, NoteParent.transform).GetComponent <TreeNote>();
        LogNote   logNote  = Instantiate(LogNotePrefab.gameObject, LogNoteParent.transform).GetComponent <LogNote>();

        MainTabGroup.OnTabCreated(tab);

        treeNote.LoadNote(path, tab, logNote);
        treeNote.IsActive = isActive;
    }
Exemple #4
0
        private void LeftRightRotate(ref TreeNote <T> current)
        {
            LeftRotate(ref current.left);
            //PrintTree();

            RightRotate(ref current);
            //PrintTree();
        }
Exemple #5
0
 private void DeleteBalance(ref TreeNote <T> current)
 {
     Balance(ref current);
     if (current != _root)
     {
         DeleteBalance(ref current.up);
     }
 }
Exemple #6
0
        public void Add(T item)
        {
            TreeNote <T> temp = null;

            if (_root == null)
            {
                temp = new TreeNote <T>();
            }
            Add(ref _root, item, temp);
        }
Exemple #7
0
    void NewNote(string path)
    {
        TabButton tab      = Instantiate(TabButtonPrefab.gameObject, TabParent.transform).GetComponent <TabButton>();
        TreeNote  treeNote = Instantiate(TreeNotePrefab.gameObject, NoteParent.transform).GetComponent <TreeNote>();
        LogNote   logNote  = Instantiate(LogNotePrefab.gameObject, LogNoteParent.transform).GetComponent <LogNote>();

        MainTabGroup.OnTabCreated(tab);

        treeNote.NewNote(path, tab, logNote);
        treeNote.IsActive = true;
    }
Exemple #8
0
 private TreeNote <T> SearchMin(TreeNote <T> root)
 {
     if (root.left != null)
     {
         return(SearchMin(root.left));
     }
     else
     {
         return(root);
     }
 }
Exemple #9
0
 private void Print(TreeNote <T> current)
 {
     if (current.left != null)
     {
         Print(current.left);
     }
     Console.Write(current.data + " ");
     if (current.right != null)
     {
         Print(current.right);
     }
 }
Exemple #10
0
        private void PrintTree(TreeNote <T> current, int left = 30, int top = 0)
        {
            Console.SetCursorPosition(left, top);
            Console.Write("{0}({4},{1},{2}) u{3}", current.data, current.lengthleft, current.lengthright, current.up.data, current.length);
            // Console.Write("{0}", current.data);

            if (current.left != null)
            {
                PrintTree(current.left, left - 5, top + 1);
            }

            if (current.right != null)
            {
                PrintTree(current.right, left + 5, top + 1);
            }
            Console.WriteLine();
        }
Exemple #11
0
    public void UpdateVerticalLayout()
    {
        float    logNoteRatio = 0;
        float    height       = MainTabGroup.NoteAreaTransform.rect.height;
        TreeNote treeNote     = MainTabGroup.ActiveTreeNote;
        LogNote  logNote      = null;

        if (treeNote != null)
        {
            logNote = treeNote.LogNote;
            LogTabButton.transform.parent.gameObject.SetActive(logNote.IsOpended && logNote.IsFullArea == false);

            logNoteRatio = logNote.IsOpended ? logNote.OpenRatio : 0.0f;

            if (logNote.IsFullArea)
            {
                OpenLogNoteButton.SetActive(false);
                CloseLogNoteButton.SetActive(true);
            }
            else if (logNote.IsOpended == false)
            {
                OpenLogNoteButton.SetActive(true);
                CloseLogNoteButton.SetActive(false);
            }
            treeNote.Tab.UpdateTitleText();
            treeNote.Tab.UpdateColor();
        }
        else
        {
            OpenLogNoteButton.SetActive(false);
            CloseLogNoteButton.SetActive(false);
            LogTabButton.transform.parent.gameObject.SetActive(false);
        }

        TreeNoteTransform.sizeDelta       = new Vector2(TreeNoteTransform.sizeDelta.x, height * (1.0f - logNoteRatio) - (logNoteRatio > 0.0f ? GameContext.Config.LogNoteHeaderMargin : 0.0f));
        LogNoteTransform.sizeDelta        = new Vector2(LogNoteTransform.sizeDelta.x, height * logNoteRatio);
        LogNoteTransform.anchoredPosition = new Vector2(LogNoteTransform.anchoredPosition.x, -height + LogNoteTransform.sizeDelta.y);

        if (treeNote != null)
        {
            treeNote.CheckScrollbarEnabled();
            logNote.CheckScrollbarEnabled();
        }
    }
Exemple #12
0
 private TreeNote <T> Search(TreeNote <T> root, T data)
 {
     if (_comparer.Compare(data, root.data) == 0)
     {
         return(root);
     }
     if (_comparer.Compare(data, root.data) < 0)
     {
         //ищем слева от корня
         return((root.left != null) ? Search(root.left, data) : null);
     }
     else
     if (_comparer.Compare(data, root.data) > 0)
     {
         //ищем справа
         return((root.right != null) ? Search(root.right, data) : null);
     }
     else
     {
         return(root);
     }
 }
Exemple #13
0
 private void Add(ref TreeNote <T> current, T item, TreeNote <T> up)
 {
     if (current == null)
     {
         current      = new TreeNote <T>();
         current.data = item;
         if (up != null)
         {
             current.up = up;
         }
         return;
     }
     if (_comparer.Compare(item, current.data) <= 0)
     {//item <= curent.data
         Add(ref current.left, item, current);
     }
     else
     {//item > curent.data
         Add(ref current.right, item, current);
     }
     //PrintTree();
     current.GetLength();
     Balance(ref current);
 }
Exemple #14
0
        //удаление первого вхождения
        private bool DeleteData(T data)
        {
            TreeNote <T> root = Search(_root, data);

            if (root != null)
            {
                //удаляем элемент
                if (root.right != null)
                {
                    TreeNote <T> minright = SearchMin(root.right);
                    root.data        = minright.data;
                    minright.up.left = null;
                    //DecLeftLength(ref minright);
                    DeleteBalance(ref minright.up);
                    return(true);
                }
                else
                {
                    if (root.up.left == root)
                    {
                        root.up.left = root.left;//заменяем удаляемое значение на левое от удаляемого
                        DeleteBalance(ref root.up);
                    }
                    else
                    {
                        root.up.right = root.right;//заменяем удаляемое значение на левое от удаляемого
                        DeleteBalance(ref root.up);
                    }
                    return(true);
                }
            }
            else
            {
                return(false);
            }
        }
Exemple #15
0
    public void Initialize(TreeNote treeNote)
    {
        treeNote_ = treeNote;

        string directoryName = ToDirectoryName(treeNote_);

        if (Directory.Exists(directoryName) == false)
        {
            Directory.CreateDirectory(directoryName);
        }
        string header = treeNote_.File.Name.Replace(".dtml", "");

        foreach (string path in Directory.GetFiles(directoryName))
        {
            // path would be like "dones-2017-01-01.dtml"
            if (Path.GetExtension(path) == ".dtml")
            {
                // splitPath would be like "[dones][2017][01][01]"
                string[] splitPath = Path.GetFileNameWithoutExtension(path).Split('-');
                int      year, month, day;
                if (splitPath.Length == 4 && splitPath[0] == header && int.TryParse(splitPath[1], out year) && int.TryParse(splitPath[2], out month) && int.TryParse(splitPath[3], out day))
                {
                    DateTime date = new DateTime(year, month, day);
                    logFileList_.Add(date, path);
                }
            }
        }

        today_     = DateTime.Now.Date;
        endDate_   = today_;
        todayTree_ = LoadLogTree(today_, ToFileName(treeNote_, today_));
        if (logFileList_.ContainsKey(today_.Date))
        {
            logFileList_.Remove(today_.Date);
        }
    }
Exemple #16
0
 public void UpdateColor()
 {
     if (BindedNote is TreeNote)
     {
         TreeNote treeNote = BindedNote as TreeNote;
         Background = isOn_ ? (treeNote.LogNote.IsFullArea ? GameContext.Config.DoneColor : GameContext.Config.ThemeColor) : Color.white;
         if (isOn_)
         {
             OwnerTabGroup.SplitBar.SetColor(treeNote.LogNote.IsFullArea ? GameContext.Config.DoneColor : GameContext.Config.ThemeColor);
         }
     }
     if (BindedNote is DiaryNote)
     {
         Background = isOn_ ? GameContext.Config.DiaryColor : Color.white;
         if (isOn_)
         {
             OwnerTabGroup.SplitBar.SetColor(GameContext.Config.DiaryColor);
         }
     }
     if (textComponent_ != null)
     {
         textComponent_.color = isOn_ ? Color.white : GameContext.Config.TextColor;
     }
 }
Exemple #17
0
 public static string ToFileName(TreeNote treeNote, DateTime date)
 {
     return(String.Format("{0}/{1}.dones/{1}{2}.dtml", treeNote.File.DirectoryName, treeNote.File.Name.Replace(".dtml", ""), date.ToString("-yyyy-MM-dd")));
 }
Exemple #18
0
 public static string ToDirectoryName(TreeNote treeNote)
 {
     return(String.Format("{0}/{1}.dones/", treeNote.File.DirectoryName, treeNote.File.Name.Replace(".dtml", "")));
 }
Exemple #19
0
        private void Change(ref TreeNote <T> current, ref TreeNote <T> down)
        {
            TreeNote <T> tmp_cur = current;
            TreeNote <T> tmp     = null;

            if (current.right == down)
            {
                tmp = down.left;
            }
            else
            {
                tmp = down.right;
            }
            TreeNote <T> tmp_down = down;

            down.up = current.up;

            if (current.up.right == current)
            {
                current.up.right = down;
            }
            else if (current.up.left == current)
            {
                current.up.left = down;
            }
            else if (_root == current)
            {
                _root = down;
            }
            else
            {
                throw (new Exception("???"));
            }

            if (tmp_cur.right == down)
            {
                tmp_cur.right = down.left;
                tmp_down.left = tmp_cur;
                if (tmp_cur.right != null)
                {
                    tmp_cur.right.up = tmp_cur;
                }
            }
            else
            {
                tmp_cur.left   = down.right;
                tmp_down.right = tmp_cur;
                if (tmp_cur.left != null)
                {
                    tmp_cur.left.up = tmp_cur;
                }
            }


            tmp_cur.up = tmp_down;

            if (tmp != null)
            {
                tmp.up = tmp_cur;
            }


            tmp_cur.up = current;

            //PrintTree();

            tmp_cur.GetLength();
            current.GetLength();
        }
Exemple #20
0
 private void RightRotate(ref TreeNote <T> current)
 {
     this.Change(ref current, ref current.left);
     //PrintTree();
 }