private void buttonRename_Click(object sender, EventArgs e) { FilesDataGridView focused = lastFocusedFileDataGridView; if (focused.SelectedRows.Count == 0) { MessageBox.Show("Выберите хотябы 1 элемент!", "", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } else if (focused.SelectedRows.Count > 1) { MessageBox.Show("Выберите только 1 элемент!", "", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } string fileName = focused.SelectedRows[0].Cells[0].Value.ToString(); new InputQuestion("Выберите новое название", fileName, (answer, newName) => { if (answer) { focused.RanameRow(focused.SelectedRows[0], newName); } focused.Focus(); }) { Owner = this, StartPosition = FormStartPosition.CenterParent }.ShowDialog(); }
public void Bind(FilesDataGridView filesDataGridView, ComboBox comboBox) { filesDataGridView.UpdateDrivesHandler += (driverInfoList) => { comboBox.Items.Clear(); List <DriveInfo> filteredDriveInfo = new List <DriveInfo>(); driverInfoList.ForEach(drive => { if (drive.IsReady) { filteredDriveInfo.Add(drive); } }); filteredDriveInfo.ForEach(info => comboBox.Items.Add(info.Name)); if (comboBox.SelectedIndex == -1) { for (int i = 0; i < comboBox.Items.Count; i++) { string value = comboBox.GetItemText(comboBox.Items[i]); if (value.Equals(filesDataGridView.CurrentDrive.Name)) { comboBox.SelectedIndex = i; } } } ; }; comboBox.SelectedIndexChanged += (sender, e) => { string drive = (string)comboBox.SelectedItem; filesDataGridView.SelectDriveByName(drive); }; }
private void buttonMove_Click(object sender, EventArgs e) { FilesDataGridView focused = lastFocusedFileDataGridView; if (focused.SelectedRows.Count == 0) { MessageBox.Show("Выберите хотябы 1 элемент!", "", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } new PathQuestions("Выберите каталог для перемещения, выбрано " + focused.SelectedRows.Count + " элементов:", (answer, newDirName) => { if (answer) { foreach (DataGridViewRow row in focused.SelectedRows) { focused.MoveRow(row, newDirName); } } focused.Focus(); }) { Owner = this, StartPosition = FormStartPosition.CenterParent }.ShowDialog(); }
public void BindFocus(FilesDataGridView dataGrid, Panel panel) { dataGrid.GotFocus += (source, e) => { panel.BackColor = SystemColors.ActiveCaption; }; dataGrid.LostFocus += (source, e) => { panel.BackColor = SystemColors.Control; }; }
public MainForm() { InitializeComponent(); BindCmdRuner(); settingsCache = new SettingsCacheIniImpl(); LoadSizeFromCache(); LoadPositionFromCache(); dataGridViewOne.Cache = GetSettingCacheOne(settingsCache); dataGridViewTwo.Cache = GetSettingCacheTwo(settingsCache); dataGridViewOne.GotFocus += (sender, e) => lastFocusedFileDataGridView = dataGridViewOne; dataGridViewTwo.GotFocus += (sender, e) => lastFocusedFileDataGridView = dataGridViewTwo; dataGridViewOne.UpdateView += (dataGrid) => labelOne.Text = dataGrid.GetCurrentPath(); dataGridViewTwo.UpdateView += (dataGrid) => labelTwo.Text = dataGrid.GetCurrentPath(); dataGridViewOne.GlobalErrorHandler += (ex) => MessageBox.Show(ex.Message, "Ошибка!", MessageBoxButtons.OK, MessageBoxIcon.Error); dataGridViewTwo.GlobalErrorHandler += (ex) => MessageBox.Show(ex.Message, "Ошибка!", MessageBoxButtons.OK, MessageBoxIcon.Error); Bind(dataGridViewOne, comboBoxOne); Bind(dataGridViewTwo, comboBoxTwo); BindFocus(dataGridViewOne, panelOneChoseDisk); BindFocus(dataGridViewTwo, panelTwoChoseDisk); dataGridViewOne.UpdateDrives(); dataGridViewTwo.UpdateDrives(); dataGridViewOne.Focus(); //TODO сделать систему коммитов, чтобы каждый пиксель не записывать this.SizeChanged += (sender, e) => { Console.WriteLine("SizeChange"); settingsCache.Width = this.Width; settingsCache.Height = this.Height; }; this.LocationChanged += (sender, e) => { settingsCache.XPosition = this.Location.X; settingsCache.YPosition = this.Location.Y; }; this.MouseMove += (sender, e) => { if (Clipboard.ContainsFileDropList()) { Console.WriteLine(Clipboard.GetFileDropList()); } }; }
private void buttonNewFolder_Click(object sender, EventArgs e) { FilesDataGridView focused = lastFocusedFileDataGridView; new InputQuestion("Введите название нового каталога:", null, (answer, newDirName) => { if (answer) { focused.CreateSubDirectory(newDirName); } focused.Focus(); }) { Owner = this, StartPosition = FormStartPosition.CenterParent }.ShowDialog(); }
private void buttonChangeFolderName_Click(object sender, EventArgs e) { FilesDataGridView focused = lastFocusedFileDataGridView; if (focused.SelectedRows.Count == 0) { MessageBox.Show("Выберите хотябы 1 элемент!", "", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (!focused.SelectedRows[0].Cells[1].Value.ToString().ToLower().Equals("файл")) { MessageBox.Show("Выберите хотябы 1 файл!", "", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } string fileName = focused.SelectedRows[0].Cells[0].Value.ToString(); string filePath = focused.GetCurrentPath() + fileName; FileInfo fileInfo = new FileInfo(filePath); if (!fileInfo.Extension.Equals(".txt")) { MessageBox.Show("Файл должен быть формата txt", "", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } string data = File.ReadAllText(filePath); new Editor(fileName, data, (answer, changedData) => { if (answer) { File.WriteAllText(filePath, changedData); } focused.Focus(); }) { Owner = this, StartPosition = FormStartPosition.CenterScreen }.Show(); }
private void buttonCopy_Click(object sender, EventArgs e) { FilesDataGridView focused = lastFocusedFileDataGridView; new PathQuestions("Выберите каталог для копирования, выбрано " + focused.SelectedRows.Count + " элементов:", (answer, newDirName) => { if (answer) { foreach (DataGridViewRow row in focused.SelectedRows) { focused.CopyRow(row, newDirName); } } focused.Focus(); }) { Owner = this, StartPosition = FormStartPosition.CenterParent }.ShowDialog(); }
private void buttonDelet_Click(object sender, EventArgs e) { FilesDataGridView focused = lastFocusedFileDataGridView; new Questions("Вы действительно хотите удалить все выделенные элементы ?", (answer) => { if (answer) { foreach (DataGridViewRow row in focused.SelectedRows) { focused.DeleteRow(row); } } focused.Focus(); }) { Owner = this, StartPosition = FormStartPosition.CenterParent }.ShowDialog(); }