Пример #1
0
        private string FancyEntryWithFileFlag(CatalogEntry entry)
        {
            bool isFile = IsFile(entry.codePrefix, out string path, out bool isImage);

            //Color bg = isFile ? (isImage ? Color.DodgerBlue : Color.OrangeRed) : Color.FromArgb(12, 12, 12);
            return(entry.FancifyEntry(isFile, -3) +
                   (isFile ? PC.Format($"{{{(isImage ? 0 : -2)}}}", " <\u25A0>") : ""));
        }
Пример #2
0
        private void PromptSearch()
        {
            PC.WriteLine("Insert the phrase to search:");
            List <CatalogEntry> entries = catalog.Search(ReadAnswer());

            for (int x = 0; x < entries.Count; x++)
            {
                PC.FormatWrite("{-2}) ", x);
                Console.WriteLine(FancyEntryWithFileFlag(entries[x]));
            }

            if (entries.Count != 0)
            {
                PC.FormatWriteLine("Would you like to {3} {-3} {3} {-3} one of the entries? ", "0) open", "1) edit ", "2) view catalog from ", "3) back ");
                int          dec = int.Parse(ReadAnswer());
                CatalogEntry e   = null;
                if (dec <= 2 && dec >= 0)
                {
                    PC.WriteLine("Insert the number to view");
                    int num = int.Parse(ReadAnswer());
                    if (num < 0 || num >= entries.Count)
                    {
                        throw new CatalogError($"Cannot aceess number {num}");
                    }
                    e = entries[num];
                }

                switch (dec)
                {
                case 0:
                    if (IsFile(e.codePrefix, out string path))
                    {
                        OpenFileProcess(path);
                    }
                    else
                    {
                        OpenFileProcess(folder + storage + FolderFor(e.codePrefix));
                    }
                    break;

                case 1:
                    PromptAddUpdateRecord(e.codePrefix);
                    break;

                case 2:
                    PC.WriteLine("And to what depth (-1 for all)?");
                    if (!int.TryParse(ReadAnswer(), out int depth))
                    {
                        depth = -1;
                    }
                    Console.WriteLine(TreePrint(e, depth));
                    break;
                }
            }
        }
Пример #3
0
        public CatalogCode NewChild(CatalogCode code)
        {
            CatalogEntry ce = Get(code);

            if (ce == null || ce.children.Count == 0)
            {
                return(new CatalogCode(code + (code.Equals(CatalogCode.current) ? "" : ".") + "0"));
            }

            int max      = ce.children.Max(c => c.codePrefix.Youngest());
            int addition = 0;

            if (max + 1 == ce.children.Count)
            {
                addition = max + 1;
            }
            else
            {
                List <CatalogEntry> children = ce.children;
                if (children[0].codePrefix.Youngest() != 0)
                {
                    addition = 0;
                }
                else
                {
                    CatalogCode prev = children[0].codePrefix;
                    int         pos  = 1;
                    while (pos < children.Count)
                    {
                        CatalogCode comp = children[pos].codePrefix;
                        if (comp.Youngest() - prev.Youngest() != 1)
                        {
                            addition = prev.Youngest() + 1;
                            break;
                        }

                        prev = comp;
                        pos++;
                    }
                }
            }

            if (code.Equals(CatalogCode.current))
            {
                return(new CatalogCode(addition.ToString()));
            }
            return(new CatalogCode(code + $".{addition}"));
        }
Пример #4
0
        private IEnumerable <CatalogCode> CardsOf(CatalogEntry temp)
        {
            List <CatalogCode> output = new List <CatalogCode>();

            foreach (CatalogEntry child in temp.children)
            {
                IsFile(child.codePrefix, out string p, out bool isImage);
                if (isImage)
                {
                    output.Add(child.codePrefix);
                }
                output.AddRange(CardsOf(child));
            }

            return(output);
        }
Пример #5
0
        private string NonTreePrint(CatalogEntry entry, int depth = -1)
        {
            if (depth == 0)
            {
                return("");
            }
            bool   isFile     = IsFile(entry.codePrefix, out string path, out bool isImage);
            string thisString = new String('\t', entry.codePrefix.Depth) + entry.FileName +
                                (isFile ?  " <\u25A0>":"") + "\n";

            if (depth > 1 || depth == -1)
            {
                for (int i = 0; i < entry.children.Count; i++)
                {
                    CatalogEntry child = entry.children[i];
                    thisString += NonTreePrint(child, depth == -1 ? -1 : depth - 1);
                }
            }
            return(thisString);
        }
Пример #6
0
        private string TreePrint(CatalogEntry entry, int depth = -1, int spacing = 3, string head = "", string body = "") //TODO LIKE CONSOLE TREE
        {
            if (depth == 0)
            {
                return("");
            }
            string thisString = head + FancyEntryWithFileFlag(entry) + "\n";

            if (depth > 1 || depth == -1)
            {
                for (int i = 0; i < entry.children.Count; i++)
                {
                    CatalogEntry child       = entry.children[i];
                    string       childheader = (i == entry.children.Count - 1 ? "\u2514" : "\u251C") + new String('\u2500', spacing);
                    string       childbody   = (i == entry.children.Count - 1? " " :"\u2502") + new String(' ', spacing);
                    thisString += TreePrint(child, depth == -1 ? -1 : depth - 1, spacing, body + childheader, body + childbody);
                }
            }
            return(thisString);
        }
Пример #7
0
        private void Move(CatalogCode a, CatalogCode b)
        {
            if (!catalog.Contains(a))
            {
                return;
            }
            CatalogEntry entry = catalog.Get(a);
            string       title = entry.name;

            foreach (CatalogEntry child in entry.children)
            {
                Move(child.codePrefix, b + CatalogCode.Relative(a, child.codePrefix));
            }
            if (!Directory.Exists(folder + storage + FolderFor(b)))
            {
                Directory.CreateDirectory(folder + storage + FolderFor(b));
            }
            if (IsFile(a, out string oldPath, out bool x))
            {
                SetFileCode(oldPath, b, title);
            }
            catalog.Update(b, title);
        }
Пример #8
0
 public Catalog(Dictionary <string, string> dict)
 {
     root = new CatalogEntry();
     GenerateCatalog(dict);
 }
Пример #9
0
 public Catalog()
 {
     root = new CatalogEntry();
 }