/// <summary> /// 文件列表编辑完成事件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void listView_File_EditSubItemCompleted(object sender, ListViewPlus.EditSubItemEventArgs e) { switch (e.UserSate) { case "rename": ((ListView)sender).Items[e.ItemRowIndex].Name = e.Label; //发送重命名请求 //oldFileName,newFileName //为了安全起见,这里使用绝对路径 _selectDirInTree = GetSelectedDirPathInDirTree(); string oldFileName = e.OldLabel; string newFileName = e.Label; string oldFileNameFullPath = Path.Combine(_selectDirInTree, oldFileName); string newFileNameFullPath = Path.Combine(_selectDirInTree, newFileName); _fileManager.RenameFileOrDir(oldFileNameFullPath, newFileNameFullPath); break; case "modifyTime": SelectedItemsStatus status = (SelectedItemsStatus)(((ListView)sender).Items[e.ItemRowIndex]).Tag; if (status == SelectedItemsStatus.IsDir) { string file = GetSelectedPathInListView(true); //修改时间 _fileManager.ModifyFileOrDirTime(file, e.Label); } else if (status == SelectedItemsStatus.IsFile) { string file = GetSelectedPathInListView(false); //修改时间 _fileManager.ModifyFileOrDirTime(file, e.Label); } break; case "createDir": ////打开设置界面 _selectDirInTree = GetSelectedDirPathInDirTree(); string dirName = e.Label; string dirFullPath = Path.Combine(_selectDirInTree, dirName); _fileManager.CreateDir(dirFullPath); break; default: break; } }
private void lv_header_AfterEditSubItem(object sender, ListViewPlus.EditSubItemEventArgs e) { if (e.Label == e.OldLabel) { e.IsCancelEdit = true; return; } if (e.Label == "") { e.IsCancelEdit = true; MessageBox.Show("不许为空"); return; } }
/// <summary> /// 文件列表编辑后事件 /// </summary> private void listView_File_AfterEditSubItem(object sender, ListViewPlus.EditSubItemEventArgs e) { //是否为空 if (string.IsNullOrEmpty(e.Label)) { e.IsCancelEdit = true; return; } //检查是否发生变化 if (e.OldLabel == e.Label) { e.IsCancelEdit = true; return; } switch (e.UserSate) { case "createDir": case "rename": //查找新文件名/文件夹名是否已经存在 if (((ListView)sender).Items.ContainsKey(e.Label)) { e.IsCancelEdit = true; MessageBox.Show("已经存在此名称,请重新命名"); return; } //MessageBox.Show("重命名发生变化"); break; case "modifyTime": break; default: break; } }