public void UpdateContent() { MainMenu.Content = CurrentDirectory.GetDirectories().ToList <FileSystemInfo>(); foreach (var file in CurrentDirectory.GetFiles()) { MainMenu.Content.Add(file.ToDirectoryInfo()); } }
private void listView1_MouseDoubleClick(object sender, MouseEventArgs e) { string path = Path.Combine(CurrentDirectory.ToString(), listView1.SelectedItems[0].Text); if (File.Exists(path)) { Process.Start(path); } else { ViewFileListPanel(path); } }
/// <summary> /// Обновляет список файлов в панели со списком файлов в текущей директории. /// </summary> private void UpdateCurrentDir() { if (CurrentDirectory == null) { return; } list.Add(new Button("..") .AsIKeyHandler() .Add(new KeySelector(ConsoleKey.Enter), () => ChangeDir(CurrentDirectory.Parent?.FullName))); var infos = CurrentDirectory.SafeFileSystemInfos(); if (infos.State == ResultState.Error) { ShowError(infos, "Не удалось получить список файлов", "Попробуйте перейти в директорию выше или нажмите «/», чтобы вернуться к списку дисков"); return; } foreach (var entry in infos.Value.OrderBy(i => i?.Name)) { var action = CreateAddToSelectedAction(entry); var button = new Button("", panelWidth); button.AsIKeyHandler() .Add(new KeySelector(ConsoleKey.Insert), action) .Add(new KeySelector(ConsoleKey.Spacebar), action); if (entry.Attributes.HasFlag(FileAttributes.Directory)) { button.AsIKeyHandler() .Add(new KeySelector(ConsoleKey.Enter), () => ChangeDir(entry.FullName)); button.Text = $"{entry.Name}/"; } else { button.AsIKeyHandler() .Add(new KeySelector(ConsoleKey.Enter), () => ShowInfo(entry.FullName)); button.Text = $"{entry.Name}"; } list.Add(button); } }
public void Search(string param) { if (param != String.Empty) { if (ContentState == State.Searched || ContentState == State.History) { MoveOut(); } MainMenu.Content = CurrentDirectory.Search(param); Sort(new DirFilesComparer()); SearchRes = new List <FileSystemInfo>(MainMenu.Content); ManagerLogger.Log("Search", CurrentDirectory.FullName); if (MainMenu.Content.Count == 0) { ManagerDialogWindows.ErrorMessage("No results :("); UpdateContent(); } else { ContentState = State.Searched; } MainMenu.NullPos(); } }
static void Main(string[] args) { IDirectory currentDirectory = new CurrentDirectory(); IMessageViewer messageViewer = new ConsoleMessageViewer(); FileManager consoleFileManager = new ConsoleFileManager(currentDirectory, messageViewer); while (true) { Console.WriteLine("Select the action:"); Console.WriteLine("1: Display the name of the current folder"); Console.WriteLine("2: Display the current directory"); Console.WriteLine("3: Display the contents of the current directory"); Console.WriteLine("4: Rise up one level higher"); Console.WriteLine("5: Go down to the specified folder"); Console.WriteLine("6: Add a new folder to the current directory"); Console.WriteLine("7: Add a new file to the current directory"); Console.WriteLine("8: Remove the specified folder from the current directory"); Console.WriteLine("Any other key: Exit from the program"); string command = Console.ReadLine(); string invitationToEnterAName; switch (command) { case "1": consoleFileManager.ShowTheNameOfTheCurrentFolder(); break; case "2": consoleFileManager.ShowThePathOfTheCurrentDirectory(); break; case "3": consoleFileManager.ShowTheContentsOfTheCurrentDirectory(); break; case "4": consoleFileManager.RiseToTheUpperLevel(); break; case "5": invitationToEnterAName = "Enter the name of the component you want to go to:"; string nameOfDesiredComponentForGoDown = getNameOfDesiredComponent(invitationToEnterAName); consoleFileManager.GoDownToTheLowerLevel(nameOfDesiredComponentForGoDown); break; case "6": invitationToEnterAName = "Enter the name of the new folder:"; string nameOfNewFolder = getNameOfDesiredComponent(invitationToEnterAName); consoleFileManager.AddNewFolderToTheCurrentDirectory(nameOfNewFolder); break; case "7": invitationToEnterAName = "Enter the name of the new file:"; string nameOfNewFile = getNameOfDesiredComponent(invitationToEnterAName); consoleFileManager.AddNewFileToTheCurrentDirectory(nameOfNewFile); break; case "8": invitationToEnterAName = "Enter the name of the removable component:"; string nameOfRemovableComponent = getNameOfDesiredComponent(invitationToEnterAName); consoleFileManager.RemoveAComponentFromTheCurrentDirectory(nameOfRemovableComponent); break; default: return; } } }