public MainWindow() { InitializeComponent(); GenerateMenu(); _filesManagement = new FilesManagement(); }
private async void Structure_MouseDoubleClick(object sender, MouseButtonEventArgs e) { if (e.Source is TreeView) { FileItem file = ((TreeView)e.Source).SelectedItem as FileItem; if (file != null) { await ChangeStatusText($" Size: {file.GetFileSizeInMegabytes()} MB; Trying to open file \"{file.Title}\"... ", true); try { string fileContent = await FilesManagement.GetFileContent(file); FileContentTextBox.Text = fileContent; await ChangeStatusText("Opened!", true); } catch (Exception ex) { await ChangeStatusText(ex.Message); } } } }
private void MenuItemCreateNewClick(object sender, RoutedEventArgs e) { try { MenuItem clickedMenuItem = sender as MenuItem; StructureItem structureItem = clickedMenuItem.DataContext as StructureItem; // TODO: Delete mock and add window creator FilesManagement.CreateNewElement(structureItem, "TESTOWY", ElementType.DIRECTORY); FilesManagement.CreateNewElement(structureItem, "TESTOWY.txt", ElementType.FILE); (structureItem as DirectoryItem).IsChanged = true; } catch (Exception ex) { StatusText.Text = $"Problem while creating element. {ex.Message}"; } }
private void MenuItemDeleteClick(object sender, RoutedEventArgs e) { try { MenuItem clickedMenuItem = sender as MenuItem; StructureItem structureItem = clickedMenuItem.DataContext as StructureItem; DirectoryItem parentDirectory = structureItem.Parent; FilesManagement.RemoveElement(structureItem); if (parentDirectory != null) { parentDirectory.IsChanged = true; } } catch (Exception ex) { StatusText.Text = $"Problem while deleting. {ex.Message}"; } }
private void GenerateMenu() { string[] drives = FilesManagement.GetDrives(); foreach (string drive in drives) { MenuItem menuItem = new MenuItem() { Header = drive, IsCheckable = true }; menuItem.Click += MenuDriveSelectorClick; MenuItemCalledAsMenu.Items.Add(menuItem); } MenuItemCalledAsMenu.Items.Add(new Separator()); MenuItem exitMenuItem = new MenuItem() { Header = "Exit" }; exitMenuItem.Click += (sender, e) => App.Current.Shutdown(); MenuItemCalledAsMenu.Items.Add(exitMenuItem); if (drives.Length > 0) { StatusText.Text = "SELECT DRIVE FIRST"; } else { StatusText.Text = "NO DRIVE DETECTED!"; } }