private void delete_Menu(object sender, RoutedEventArgs e) { ExplorerObject row = (ExplorerObject)files_dataGrid.SelectedItem; if (row != null) { string path = Path.Combine(dir_textBox.Text, row.Name); MessageBoxResult result = MessageBox.Show("Вы действительно хотите удалить объект?", "Подтверждение", MessageBoxButton.YesNo, MessageBoxImage.Question); if (result == MessageBoxResult.Yes) { try { RecyclingBin.MoveHere(path); MessageBox.Show("Перемещено в корзину!"); string dir_str = dir_textBox.Text; getFoldersAndFiles(dir_str); } catch (IOException ee) { MessageBox.Show(ee.Message); return; } } } }
private void rename_Menu(object sender, RoutedEventArgs e) { ExplorerObject row = (ExplorerObject)files_dataGrid.SelectedItem; if (row != null) { renameObject a = new renameObject(); a.newname_TextBox.SelectionStart = 0; a.newname_TextBox.SelectionLength = a.newname_TextBox.Text.Length; a.newname_TextBox.SelectAll(); a.newname_TextBox.Text = row.Name; a.btn.Click += (s, ee) => { try { if (row.Type != "Папка") { File.Move(Path.Combine(dir_textBox.Text, row.Name), Path.Combine(dir_textBox.Text, a.newname_TextBox.Text)); } else { Directory.Move(Path.Combine(dir_textBox.Text, row.Name), Path.Combine(dir_textBox.Text, a.newname_TextBox.Text)); } a.Close(); } catch (Exception ex) { MessageBox.Show(ex.Message); } getFoldersAndFiles(dir_textBox.Text); }; a.Show(); } }
private void files_dataGrid_KeyDown(object sender, System.Windows.Input.KeyEventArgs e) { ExplorerObject row = (ExplorerObject)files_dataGrid.SelectedItem; if (e.Key == System.Windows.Input.Key.Space && row.Type == "Папка") { forward_stack.Clear(); back_btn.IsEnabled = true; back_stack.Push(dir_textBox.Text); getFoldersAndFiles(Path.Combine(dir_textBox.Text, row.Name)); dir_textBox.Text = Path.Combine(dir_textBox.Text, row.Name); //if (back_stack.Count == 0) //{ // back_btn.IsEnabled = false; //} } if (e.Key == System.Windows.Input.Key.Back && back_stack.Count != 0) { forward_btn.IsEnabled = true; forward_stack.Push(dir_textBox.Text); string path = back_stack.Pop(); getFoldersAndFiles(path); dir_textBox.Text = path; if (back_stack.Count == 0) { back_btn.IsEnabled = false; } } if (e.Key == System.Windows.Input.Key.F5) { getFoldersAndFiles(dir_textBox.Text); } }
private void files_dataGrid_MouseDoubleClick(object sender, System.Windows.Input.MouseButtonEventArgs e) { ExplorerObject row = (ExplorerObject)files_dataGrid.SelectedItem; string path = Path.Combine(dir_textBox.Text, row.Name); if (row.Type == "Папка") { back_stack.Push(dir_textBox.Text); dir_textBox.Text = path; getFoldersAndFiles(path); } }
private void copy_Menu(object sender, RoutedEventArgs e) { ExplorerObject row = (ExplorerObject)files_dataGrid.SelectedItem; if (row != null) { string path = Path.Combine(dir_textBox.Text, row.Name); StringCollection paths = new StringCollection(); paths.Add(path); Clipboard.SetFileDropList(paths); paste_Item.IsEnabled = true; } }
private void getFoldersAndFiles(string path) { files_dataGrid.Items.Clear(); if (path == "") { return; } else { DirectoryInfo dir = new DirectoryInfo(path); FileInfo[] files = null; DirectoryInfo[] dirs = null; //попытка получить список подпапок try { dirs = dir.GetDirectories(); } catch (Exception ex) { MessageBox.Show(ex.Message); return; } //добавляем в datagrid foreach (DirectoryInfo subDir in dirs) { var data = new ExplorerObject { Name = subDir.Name, Date = subDir.LastWriteTime.ToString(), Type = "Папка", Size = "" }; files_dataGrid.Items.Add(data); } //попытка получить файлы try { files = dir.GetFiles(); } catch { } foreach (FileInfo file in files) { var data = new ExplorerObject { Name = file.Name, Date = file.LastWriteTime.ToString(), Type = file.Extension, Size = SizeSuffix(file.Length) }; files_dataGrid.Items.Add(data); } files_dataGrid.SelectedIndex = 0; files_dataGrid.Focus(); } }
private void files_treeView_SelectedItemChanged(object sender, RoutedPropertyChangedEventArgs <object> e) { files_dataGrid.Items.Clear(); DirectoryInfo dir; TreeViewItem tvi = (TreeViewItem)((TreeView)sender).SelectedItem; e.Handled = true; if (tvi.Tag is DriveInfo || tvi.Tag is DirectoryInfo) { if (tvi.Tag is DriveInfo) { DriveInfo drive = (DriveInfo)tvi.Tag; dir = drive.RootDirectory; } else { dir = (DirectoryInfo)tvi.Tag; } back_stack.Push(dir_textBox.Text); forward_stack.Clear(); forward_btn.IsEnabled = false; dir_textBox.Text = dir.FullName; back_btn.IsEnabled = true; DirectoryInfo[] dirs = null; //попытка получить список подпапок try { dirs = dir.GetDirectories(); } catch (Exception ex) { MessageBox.Show(ex.Message); return; } //добавляем в datagrid foreach (DirectoryInfo subDir in dirs) { var data = new ExplorerObject { Name = subDir.Name, Date = subDir.LastWriteTime.ToString(), Type = "Папка", Size = "" }; files_dataGrid.Items.Add(data); } FileInfo[] files = null; //попытка получить файлы try { files = dir.GetFiles(); } catch (Exception ex) { MessageBox.Show(ex.Message); return; } //добавляем в datagrid foreach (FileInfo file in files) { var data = new ExplorerObject { Name = file.Name, Date = file.LastWriteTime.ToString(), Type = file.Extension, Size = SizeSuffix(file.Length) }; files_dataGrid.Items.Add(data); } } else { FileInfo file = (FileInfo)tvi.Tag; var data = new ExplorerObject { Name = file.Name, Date = file.LastWriteTime.ToString(), Type = file.Extension, Size = SizeSuffix(file.Length) }; files_dataGrid.Items.Add(data); } //files_dataGrid.Focus(); }