Ejemplo n.º 1
0
        private UserDirectoryClass ShowExplorerLevel(List <UserDirectoryClass> Items, List <UserDirectoryClass> Root, int cLevel)
        {
            UserDirectoryClass result = null;

            for (int i = 0; i < Items.Count; i++)
            {
                if (IsCursorThere(Root, Items[i]))
                {
                    result = Items[i];
                    HighLightRow();
                }
                else
                {
                    DontHighLightRow();
                }

                Console.Write(new string(' ', cLevel * 2));
                Console.WriteLine(Items[i]);
                if (Items[i].IsActive)
                {
                    UserDirectoryClass tmp = ShowExplorerLevel(Items[i].Children, Root, cLevel + 1);
                    if (tmp != null)
                    {
                        result = tmp;
                    }
                }
            }
            return(result);
        }
Ejemplo n.º 2
0
        public void ShowExplorerForImplementation(List <UserDirectoryClass> Items, IExecuteble action, string message)
        {
            UserDirectoryClass selectedItem = null;
            int cLevel = 0;

            do
            {
                Console.WriteLine(message);
                selectedItem = ShowExplorerLevel(Items, Items, cLevel);
                DisplayImplementationFunctionKey();
                var key = Console.ReadKey();
                if (key.Key == ConsoleKey.DownArrow)
                {
                    AddCursorPosition(Items, cLevel);
                }
                else if (key.Key == ConsoleKey.UpArrow)
                {
                    DecCursorPosition(Items, cLevel);
                }
                else if (key.Key == ConsoleKey.Enter)
                {
                    DoActionForImplement(selectedItem, action);
                    break;
                }
                else if (key.Key == ConsoleKey.F10)
                {
                    break;
                }
                Console.Clear();
            } while (true);
        }
Ejemplo n.º 3
0
        private bool MoveFile(UserDirectoryClass source, UserDirectoryClass baseDestination)
        {
            if (!File.Exists(source.FullName))
            {
                return(false);
            }

            if (File.Exists(Path.Combine(baseDestination.FullName, source.Name)))
            {
                return(false);
            }

            new FileInfo(source.FullName).MoveTo(Path.Combine(baseDestination.FullName, source.Name));
            UserDirectoryClass destination = new UserDirectoryClass();

            destination.Name     = source.Name;
            destination.Children = null;
            destination.FullName = Path.Combine(baseDestination.FullName, source.Name);
            baseDestination.Children.Add(destination);

            int numSelected;

            if ((numSelected = ItemsWithSelected.FindIndex(x => x.FullName == selected.FullName)) >= 0)
            {
                ItemsWithSelected.RemoveAt(numSelected);
            }

            return(true);
        }
Ejemplo n.º 4
0
 public UIMover(UIExplorer _explorer, List <UserDirectoryClass> items, UserDirectoryClass _selected, List <UserDirectoryClass> _ItemsWithSelected)
 {
     explorer          = _explorer;
     Items             = items;
     selected          = _selected;
     ItemsWithSelected = _ItemsWithSelected;
 }
Ejemplo n.º 5
0
        public override void ShowExplorer(List <UserDirectoryClass> Items)
        {
            currItem.Add(0);
            UserDirectoryClass selectedItem = null;
            int cLevel = 0;

            do
            {
                selectedItem = ShowExplorerLevel(Items, Items, cLevel);
                DisplayFunctionKey();
                var key = Console.ReadKey();
                if (key.Key == ConsoleKey.DownArrow)
                {
                    AddCursorPosition(Items, cLevel);
                }
                else if (key.Key == ConsoleKey.UpArrow)
                {
                    DecCursorPosition(Items, cLevel);
                }
                else if (key.Key == ConsoleKey.Enter)
                {
                    DoActionForSelect(Items);
                }
                else if (key.Key == ConsoleKey.F3)
                {
                    if (selectedItem != null)
                    {
                        new UIFileViewer(selectedItem).View();
                    }
                }
                else if (key.Key == ConsoleKey.F5)
                {
                    if (selectedItem != null)
                    {
                        new UICopier(this, Items, selectedItem).Copy();
                    }
                }
                else if (key.Key == ConsoleKey.F6)
                {
                    if (selectedItem != null)
                    {
                        int clevel;
                        new UIMover(this, Items, selectedItem, getCurrParentItems(Items, out clevel)).Move();
                    }
                }
                else if (key.Key == ConsoleKey.F7)
                {
                    if (selectedItem != null)
                    {
                        new UIDirectoryCreator(selectedItem, currItem).CreateDirectory();
                    }
                }
                else if (key.Key == ConsoleKey.F10)
                {
                    break;
                }
                Console.Clear();
            } while (true);
        }
Ejemplo n.º 6
0
        private bool IsCursorThere(List <UserDirectoryClass> Root, UserDirectoryClass cItem)
        {
            List <UserDirectoryClass> userItems;
            int clevel;

            userItems = getCurrParentItems(Root, out clevel);
            if (userItems[currItem[clevel]].Equals(cItem))
            {
                return(true);
            }
            return(false);
        }
Ejemplo n.º 7
0
        public void Execute(UserDirectoryClass destination)
        {
            if (Directory.Exists(destination.FullName))
            {
                if (File.Exists(selected.FullName))
                {
                    CopyFile(selected, destination);
                }

                if (Directory.Exists(selected.FullName))
                {
                    CopyDirectory(selected, destination);
                }
            }
        }
Ejemplo n.º 8
0
        private void CopyFile(UserDirectoryClass source, UserDirectoryClass baseDestination)
        {
            if (!File.Exists(source.FullName))
            {
                return;
            }

            if (!File.Exists(Path.Combine(baseDestination.FullName, source.Name)))
            {
                new FileInfo(source.FullName).CopyTo(Path.Combine(baseDestination.FullName, source.Name));
                UserDirectoryClass destination = new UserDirectoryClass();
                destination.Name     = source.Name;
                destination.Children = null;
                destination.FullName = Path.Combine(baseDestination.FullName, source.Name);
                baseDestination.Children.Add(destination);
            }
        }
Ejemplo n.º 9
0
        private void MoveItemDirectory(UserDirectoryClass source, UserDirectoryClass baseDestination)
        {
            UserDirectoryClass destination = new UserDirectoryClass();
            int index = -1;

            if ((index = baseDestination.Children.FindIndex(x => x.FullName == Path.Combine(baseDestination.FullName, source.Name))) < 0)
            {
                destination.Name     = source.Name;
                destination.FullName = Path.Combine(baseDestination.FullName, source.Name);
                baseDestination.Children.Add(destination);
            }
            else
            {
                destination = baseDestination.Children[index];
            }
            foreach (UserDirectoryClass items in source.Children)
            {
                MoveItemDirectory(items, destination);
            }
        }
Ejemplo n.º 10
0
        public void CreateDirectory()
        {
            Console.Clear();
            FileAttributes attr = File.GetAttributes(creatDir.FullName);

            if ((attr & FileAttributes.Directory) != FileAttributes.Directory)
            {
                Console.WriteLine("The file \"{0}\" counld not accept us a base dirrectory.", creatDir.Name);
                Console.WriteLine("Press any key to continue ...\n\n");
                Console.ReadLine();
                return;
            }

            string nDir = null;

            Console.WriteLine("You are about to create a new directory.\nto the pass {0}\n Please, enter tha name of the new directory\n", creatDir.FullName);
            nDir = Console.ReadLine();

            if (nDir != null)
            {
                DirectoryInfo dir = new DirectoryInfo(creatDir.FullName);
                dir.CreateSubdirectory(nDir);

                if (creatDir.Children == null)
                {
                    creatDir.Children = new List <UserDirectoryClass>();
                }

                creatDir.IsActive = true;

                UserDirectoryClass userDir = new UserDirectoryClass();
                userDir.Name     = nDir.ToUpper();
                userDir.FullName = creatDir.FullName + @"\" + nDir;
                userDir.IsActive = true;
                currItemExplorer.Add(creatDir.Children.Count);
                userDir.Children = new List <UserDirectoryClass>();

                creatDir.Children.Add(userDir);
            }
        }
Ejemplo n.º 11
0
        private void CopyDirectory(UserDirectoryClass source, UserDirectoryClass baseDestination)
        {
            if (!Directory.Exists(source.FullName))
            {
                return;
            }

            if (!Directory.Exists(Path.Combine(baseDestination.FullName, source.Name)))
            {
                Directory.CreateDirectory(Path.Combine(baseDestination.FullName, source.Name));
            }

            UserDirectoryClass destination = new UserDirectoryClass();
            int index = -1;

            if ((index = baseDestination.Children.FindIndex(x => x.FullName == Path.Combine(baseDestination.FullName, source.Name))) < 0)
            {
                destination.Name     = source.Name;
                destination.FullName = Path.Combine(baseDestination.FullName, source.Name);
                baseDestination.Children.Add(destination);
            }
            else
            {
                destination = baseDestination.Children[index];
            }

            foreach (UserDirectoryClass item in source.Children)
            {
                if (Directory.Exists(item.FullName))
                {
                    CopyDirectory(item, destination);
                }

                if (File.Exists(item.FullName))
                {
                    CopyFile(item, destination);
                }
            }
        }
Ejemplo n.º 12
0
        private bool MoveDirectory(UserDirectoryClass source, UserDirectoryClass baseDestination)
        {
            if (!Directory.Exists(source.FullName))
            {
                return(false);
            }


            if (Directory.Exists(Path.Combine(baseDestination.FullName, source.Name)))
            {
                return(false);
            }

            new DirectoryInfo(source.FullName).MoveTo(Path.Combine(baseDestination.FullName, source.Name));
            MoveItemDirectory(source, baseDestination);

            int numSelected;

            if ((numSelected = ItemsWithSelected.FindIndex(x => x.FullName == selected.FullName)) >= 0)
            {
                ItemsWithSelected.RemoveAt(numSelected);
            }
            return(true);
        }
Ejemplo n.º 13
0
 public UIDirectoryCreator(UserDirectoryClass item, List <int> currItemExpl)
 {
     creatDir         = item;
     currItemExplorer = currItemExpl;
 }
Ejemplo n.º 14
0
 public UICopier(UIExplorer _explorer, List <UserDirectoryClass> items, UserDirectoryClass _selected)
 {
     explorer = _explorer;
     Items    = items;
     selected = _selected;
 }
Ejemplo n.º 15
0
 private void DoActionForImplement(UserDirectoryClass selected, IExecuteble action)
 {
     action.Execute(selected);
 }
Ejemplo n.º 16
0
 public UIFileViewer(UserDirectoryClass File)
 {
     FileToView = File;
 }