internal FileManager() { DataXML xml = new DataXML(); xml.GetDataFromXML(); _consoleWidth = xml.XMLConsoleWidth; ConsoleHeight = xml.XMLConsoleHeight; _startDirectoryLeft = xml.XMLStartDirectoryLeft; _startDirectoryRight = xml.XMLStartDirectoryRight; _newCommandText = ""; bool leftIsActive = xml.LeftIsActive; Console.SetWindowSize(_consoleWidth, ConsoleHeight); //Console.SetBufferSize(Console.LargestWindowWidth, Console.LargestWindowHeight); Borders border = new Borders(); FilePanel filePanelLeft = new FilePanel(_startDirectoryLeft, 1, _consoleWidth / 2 - 1); filePanelLeft.CurrentItem = xml.XMLLeftActiveItem; FilePanel filePanelRight = new FilePanel(_startDirectoryRight, _consoleWidth / 2, _consoleWidth - 1); filePanelRight.CurrentItem = xml.XMLRightActiveItem; if (leftIsActive) { filePanelLeft.IsActive = true; _active = filePanelLeft; filePanelRight.IsActive = false; _passive = filePanelRight; } else { filePanelLeft.IsActive = false; _active = filePanelRight; filePanelRight.IsActive = true; _passive = filePanelLeft; } _currentItemLeft = filePanelLeft.CurrentItem; _currentItemRight = filePanelRight.CurrentItem; _leftIsActive = filePanelLeft.IsActive; PrintFileManager(filePanelLeft, filePanelRight, border); GetUserCommands(filePanelLeft, filePanelRight, border);// Don't add any command after call this method - because endless while! }
private void PrintFileManager(FilePanel filePanelLeft, FilePanel filePanelRight, Borders border) { border.BorderWidth = _consoleWidth; border.BorderHeight = ConsoleHeight; border.PrintBorders(); filePanelLeft.PanelHeight = ConsoleHeight; filePanelLeft.UntilX = _consoleWidth / 2 - 1; filePanelLeft.ShowDirectoryContent(); filePanelRight.PanelHeight = ConsoleHeight; filePanelRight.FromX = _consoleWidth / 2; filePanelRight.UntilX = _consoleWidth - 1; filePanelRight.ShowDirectoryContent(); PrintSingleKeyCommands(); // like F1 F2 etc. PrintUserCommand(); }
/// <summary> /// avaiting key input and react on keys, react on change panels size /// </summary> /// <param name="filePanelLeft"></param> /// <param name="filePanelRight"></param> /// <param name="border"></param> private void GetUserCommands(FilePanel filePanelLeft, FilePanel filePanelRight, Borders border) { bool exit = false; while (!exit) { bool xmlBeSaved = false; if (Console.WindowWidth != _consoleWidth || Console.WindowHeight != ConsoleHeight) { if (Console.WindowWidth != _consoleWidth) { xmlBeSaved = true; } if (Console.WindowHeight != ConsoleHeight) { xmlBeSaved = true; } Console.Clear(); _consoleWidth = Console.WindowWidth; ConsoleHeight = Console.WindowHeight; PrintFileManager(filePanelLeft, filePanelRight, border); } //else values to xml check for changes if (filePanelLeft.StartDirectory != _startDirectoryLeft) { xmlBeSaved = true; } if (filePanelRight.StartDirectory != _startDirectoryRight) { xmlBeSaved = true; } if (filePanelLeft.CurrentItem != _currentItemLeft) { xmlBeSaved = true; } if (filePanelRight.CurrentItem != _currentItemRight) { xmlBeSaved = true; } if (filePanelLeft.IsActive != _leftIsActive) { xmlBeSaved = true; _leftIsActive = filePanelLeft.IsActive; } if (xmlBeSaved) { string pathConfigXML = "Resources/Config.xml"; XmlDocument xmlConfig = new XmlDocument(); xmlConfig.Load(pathConfigXML); XmlNode nodeWidth = xmlConfig.SelectSingleNode("//Width"); nodeWidth.InnerText = Console.WindowWidth.ToString(); XmlNode nodeHeight = xmlConfig.SelectSingleNode("//Height"); nodeHeight.InnerText = Console.WindowHeight.ToString(); XmlNode nodeLastDirL = xmlConfig.SelectSingleNode("//LeftStartDir"); nodeLastDirL.InnerText = filePanelLeft.StartDirectory; XmlNode nodeLastDirR = xmlConfig.SelectSingleNode("//RightStartDir"); nodeLastDirR.InnerText = filePanelRight.StartDirectory; XmlNode nodeLeftActive = xmlConfig.SelectSingleNode("//LeftActiveItem"); nodeLeftActive.InnerText = filePanelLeft.CurrentItem.ToString(); XmlNode nodeRightActive = xmlConfig.SelectSingleNode("//RightActiveItem"); nodeRightActive.InnerText = filePanelRight.CurrentItem.ToString(); XmlNode nodeActive = xmlConfig.SelectSingleNode("//LeftIsActive"); nodeActive.InnerText = filePanelLeft.IsActive.ToString(); try { xmlConfig.Save(pathConfigXML); } catch (Exception s) { ClassLibrary.Do.ShowAlert($"Save to configuration XML file {pathConfigXML} Error - " + s.Message, _consoleWidth / 2); } } Actions newActon = new Actions(_active, _passive, _consoleWidth); if (Console.KeyAvailable) { ConsoleKeyInfo userKey = Console.ReadKey(true); //show commands history if ((ConsoleModifiers.Control & userKey.Modifiers) != 0 && userKey.Key == ConsoleKey.E) { _newCommandText = newActon.GetCommandsHystory(); PrintFileManager(filePanelLeft, filePanelRight, border); } // search something with mask like *.* else if ((ConsoleModifiers.Control & userKey.Modifiers) != 0 && userKey.Key == ConsoleKey.S)// S - because Ctrl+F already reserved with windows search { string newSearch = newActon.GetNameForMaskedSearh(); if (newSearch.Length > 0) { ClassLibrary.Do.WriteCommandToFile($"find " + newSearch); PrintFileManager(filePanelLeft, filePanelRight, border); newActon.ShowFindedItems(newSearch); } PrintFileManager(filePanelLeft, filePanelRight, border); } if (Char.IsControl(userKey.KeyChar)) { bool isConfirmed = false; switch (userKey.Key) { case ConsoleKey.Tab: FilePanel temp = _active; _active = _passive; _passive = temp; _active.IsActive = true; _passive.IsActive = false; filePanelLeft.ShowDirectoryContent(); filePanelRight.ShowDirectoryContent(); ClassLibrary.Do.WriteCommandToFile($"cd {_active.StartDirectory}"); break; case ConsoleKey.DownArrow: newActon.ChangeCurrentItem(1); break; case ConsoleKey.UpArrow: newActon.ChangeCurrentItem(-1); break; case ConsoleKey.PageDown: newActon.ChangeCurrentItem(100); break; case ConsoleKey.PageUp: newActon.ChangeCurrentItem(-100); break; case ConsoleKey.Home: newActon.ChangeCurrentItem(-1000); break; case ConsoleKey.End: newActon.ChangeCurrentItem(1000); break; case ConsoleKey.F1: newActon.ShowHelp(); PrintFileManager(filePanelLeft, filePanelRight, border); break; case ConsoleKey.F3: newActon.ShowInfo(); PrintFileManager(filePanelLeft, filePanelRight, border); break; case ConsoleKey.F5: isConfirmed = newActon.UserConfirmAction("Copy", _passive.StartDirectory); if (isConfirmed) { newActon.CopyFromPanel(); } PrintFileManager(filePanelLeft, filePanelRight, border); break; case ConsoleKey.F6: isConfirmed = newActon.UserConfirmAction("Move", _passive.StartDirectory); if (isConfirmed) { newActon.MoveItemTo(_passive.StartDirectory); } PrintFileManager(filePanelLeft, filePanelRight, border); break; case ConsoleKey.F7: newActon.CreateNewDir("Create New Directory"); PrintFileManager(filePanelLeft, filePanelRight, border); break; case ConsoleKey.F8: isConfirmed = newActon.UserConfirmAction("Delete", _active.CurrentItemName); if (isConfirmed && _active.CurrentItem != 0) { newActon.DeleteItem(Path.Combine(_active.StartDirectory, _active.CurrentItemName)); } PrintFileManager(filePanelLeft, filePanelRight, border); break; case ConsoleKey.F9: newActon.RenameItem("Rename"); PrintFileManager(filePanelLeft, filePanelRight, border); break; case ConsoleKey.Enter: if ((userKey.Modifiers & ConsoleModifiers.Control) != 0) { _newCommandText = _newCommandText + _active.CurrentItemName; } else { if (_newCommandText.Length > 0) { newActon.AnalizeCommand(_newCommandText, true); ClassLibrary.Do.WriteCommandToFile(_newCommandText); _newCommandText = ""; } else { newActon.ExecuteCurrent(); } PrintFileManager(filePanelLeft, filePanelRight, border); } break; case ConsoleKey.Backspace: if (_newCommandText.Length > 0) { _newCommandText = _newCommandText.Substring(0, _newCommandText.Length - 1); } break; default: break; } } else { if ((userKey.Modifiers & ConsoleModifiers.Shift) != 0) { _newCommandText = _newCommandText + userKey.KeyChar; } else { _newCommandText = _newCommandText + userKey.KeyChar.ToString().ToLower(); } } PrintUserCommand(); } } }