private void setupFilterIndex(uint filterIndex) { FilterIndex = filterIndex; filterComboBox.SelectedIndex = (int)filterIndex; _CurrentExts = IOComm.GetExts(_FilterArray[(int)filterIndex * 2]); loadDirectory(_CurrentPath); //刷新列表 }
private void tsmi_dgv_new_items_Click(object sender, EventArgs e) { string _path; ToolStripMenuItem tsmi = (ToolStripMenuItem)sender; if (IOComm.PathCreate(this, (PathType)tsmi.Tag, _CurrentPath, out _path)) { FileInfo _fi = new FileInfo(_path); if (_fi.Exists) { DataGridViewRow _row = dataGridView.Rows[dataGridView.Rows.Add()]; _row.Cells[nameColumn.Index].Value = _fi.Name; _row.Cells[typeColumn.Index].Value = _fi.Extension; _row.Cells[typeColumn.Index].Tag = PathType.File; _row.Cells[lengthColumn.Index].Value = string.Empty; _row.Cells[creattimeColumn.Index].Value = FileHelper.LengthFormat(_fi.Length); _row.Cells[icoColumn.Index].Value = IOComm.GetIcon(_fi.Extension); } else { DirectoryInfo _di = new DirectoryInfo(_path); DataGridViewRow _row = dataGridView.Rows[dataGridView.Rows.Add()]; _row.Cells[nameColumn.Index].Value = _di.Name; _row.Cells[typeColumn.Index].Value = "文件夹"; _row.Cells[typeColumn.Index].Tag = PathType.Floder; _row.Cells[lengthColumn.Index].Value = string.Empty; _row.Cells[creattimeColumn.Index].Value = _di.CreationTime; _row.Cells[icoColumn.Index].Value = IOComm.FloderIcon; } } }
protected virtual void this_Load(object sender, EventArgs e) { setToolStrip(); //如果么有父窗体(或未显示)则显示在屏幕中央 Comm.ApplyComm(this); // 初始化 navi IOComm.ResetNavi(naviTree, naviCms); }
private void this_Load(object sender, EventArgs e) { setToolStrip(); // 应用通用设置 Comm.ApplyComm(this); // 初始化 navi IOComm.ResetNavi(naviTree, naviCms); }
private void tsmi_item_rename_Click(object sender, EventArgs e) { string newName = IOComm.ShowRenameDialog(this, IOComm.PathCombin(_CurrentPath, _CurrentName)); if (string.IsNullOrWhiteSpace(newName)) { return; } _CurrentName = Path.GetFileName(newName); _CurrentRow.Cells[nameColumn.Index].Value = _CurrentName; }
private void tsmi_navi_open_Click(object sender, EventArgs e) { if (naviTree.SelectedNode.IsExpanded) { _CurrentNode.Collapse(); } else { IOComm.FillNode(_CurrentNode, naviCms); } }
protected override void OkButton_Click(object sender, EventArgs e) { string sp = null; #region 未输入保存文件名 if (string.IsNullOrWhiteSpace(SaveName)) { MessageBox.Show(this, "请输入保存文件名"); nameComboBox.Focus(); return; } #endregion #region 输入的文件名存在非法字符 else if (PathHelper.IsNameInvalidCharContained(SaveName)) { MessageBox.Show(this, "不合法的文件名, 请勿输入以下非法字符 < > / \\ | ? * \" : 等"); nameComboBox.Focus(); return; } #endregion else { #region 获取文件完整路径 // 获取文件拓展名 string sType = _CurrentExts[0] == ".*" ? string.Empty : _CurrentExts[0]; // 判断当前有没有选中一个文件夹 // 未选中文件或文件夹 if (string.IsNullOrWhiteSpace(_CurrentName)) { sp = IOComm.PathCombin(_CurrentPath, SaveName + sType); } else { sp = IOComm.PathCombin(_CurrentPath, Path.GetFileNameWithoutExtension(_CurrentName) + sType); } #endregion } #region 判断是否存在同名文件 if (PathHelper.IsExisted(sp)) { string inf = string.Format("存在同名文件或文件夹,是否继续?\r\npath = {0}", sp); DialogResult dr = MessageBox.Show(this, inf, "文件名冲突", MessageBoxButtons.YesNo); if (dr != DialogResult.Yes) { nameComboBox.Focus(); return; } } #endregion this.InputPath = sp; this.DialogResult = DialogResult.OK; this.Close(); }
private void tv_navi_NodeMouseDoubleClick(object sender, TreeNodeMouseClickEventArgs e) { if (e.Node.Level == 0 || e.Button == MouseButtons.Right) { return; } if (e.Node.Nodes.Count == 0) { IOComm.FillNode(e.Node, naviCms); } }
protected override void _Tsmi_item_Open_Click(object sender, EventArgs e) { if (_CurrentFf == PathType.File) { OkButton_Click(sender, e); } else if (_CurrentFf == PathType.Floder) { loadDirectory(IOComm.PathCombin(_CurrentPath, _CurrentName)); } }
protected override void OkButton_Click(object sender, EventArgs e) { if (string.IsNullOrWhiteSpace(nameComboBox.Text)) { MessageBox.Show(this, "您还未选择任何文件,请选择要打开的文件"); return; } string _path = string.Empty; List <string> _ps = new List <string>(); string[] _names = nameComboBox.Text.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries); foreach (string item in _names) { if (string.IsNullOrWhiteSpace(item)) { continue; } _path = IOComm.PathCombin(_CurrentPath, item); if (File.Exists(_path)) { _ps.Add(_path); } else { string inf = string.Format("系统找不到文件 < {0} >\r\npath = {1}", item, _path); MessageBox.Show(inf); return; } } if (_ps.Count == 0) { MessageBox.Show(this, "您选择的文件的个数为0,至少选择一个文件,请重新选择,退出请点击取消"); return; } else { this.InputPath = string.Empty; foreach (string item in _ps) { this.InputPath += item; this.InputPath += "|"; } this.InputPath = this.InputPath.Remove(this.InputPath.Length - 1, 1); this.InputPaths.Clear(); this.InputPaths.AddRange(_ps); this.DialogResult = DialogResult.OK; this.Close(); } }
protected override void _Tsmi_item_Open_Click(object sender, EventArgs e) { string tmp = IOComm.PathCombin(_CurrentPath, _CurrentName); if (File.Exists(tmp)) { System.Diagnostics.Process.Start(tmp); } else if (Directory.Exists(tmp)) { loadDirectory(tmp); } else { MessageBox.Show(this, "系统找不到以下路径:\r\nPath = " + tmp, null, MessageBoxButtons.OK); } }
private void tsmi_item_delete_Click(object sender, EventArgs e) { if (Forms.MessageBox.Show(this, string.Format("即将永久删除 <{0}> 个文件(夹),是否继续?", dataGridView.SelectedRows.Count), "删除提示", MessageBoxButtons.YesNo) == DialogResult.No) { return; } foreach (DataGridViewRow item in dataGridView.SelectedRows) { string delpath = IOComm.PathCombin(_CurrentPath, item.Cells[nameColumn.Index].Value.ToString()); try { PathHelper.Delete(delpath); dataGridView.Rows.Remove(item); } catch (Exception ex) { MessageBox.Show(this, string.Format("未删除 <{0}>,失败原因\r\n{1}", delpath, ex.Message), "删除失败", MessageBoxButtons.OK); } } }
private void tsmi_item_attribute_Click(object sender, EventArgs e) { Windows.Explore.ShowPropertiesDialog(IOComm.PathCombin(_CurrentPath, _CurrentName)); }
private void tsmi_navi_new_Click(object sender, EventArgs e) { IOComm.NodeCreate(_currentNode); }
private void tsmi_navi_del_Click(object sender, EventArgs e) { IOComm.NodeDelete(_currentNode); }
private void this_Shown(object sender, EventArgs e) { IOComm.LocateNode(rootNode, EnterPath, naviCms); }
private void nameComboBox_KeyPress(object sender, KeyPressEventArgs e) { IOComm.NameInputTest_Keypress(sender, e); }
//获取主列表 private void _loadDirectory() { Action _action; DirectoryInfo _di = null; DataGridViewRow _row; try { _di = new DirectoryInfo(_DirLoading); _CurrentDirs = _di.GetDirectories(); _CurrentFiles = _di.GetFiles(); } catch (Exception ex) { _action = delegate { MessageBox.Show(this, ex.Message, "读取错误", MessageBoxButtons.OK); }; Invoke(_action); return; } _CurrentPath = _DirLoading;//更新当前显示的路径 #region 导航栏更新 _action = delegate { dataGridView.Rows.Clear(); pathComboBox.Items.Clear(); pathComboBox.Items.Add(_CurrentPath); pathComboBox.Text = _CurrentPath; }; Invoke(_action); #endregion #region 加载文件夹 foreach (DirectoryInfo item in _CurrentDirs) { _action = delegate { _row = dataGridView.Rows[dataGridView.Rows.Add()]; _row.Cells[nameColumn.Index].Value = item.Name; _row.Cells[typeColumn.Index].Value = "文件夹"; _row.Cells[typeColumn.Index].Tag = PathType.Floder; _row.Cells[lengthColumn.Index].Value = string.Empty; _row.Cells[creattimeColumn.Index].Value = item.CreationTime; }; Invoke(_action); } #endregion #region 加载文件列表 IEnumerable <FileInfo> _query; if (_CurrentExts.Contains(".*")) { _query = _CurrentFiles; } else { _query = from FileInfo fi in _CurrentFiles where _CurrentExts.FindIndex(t => string.Compare(fi.Extension, t, true) == 0) != -1 select fi; } foreach (FileInfo item in _query) { _action = delegate { _row = dataGridView.Rows[dataGridView.Rows.Add()]; _row.Cells[nameColumn.Index].Value = item.Name; _row.Cells[typeColumn.Index].Value = item.Extension; _row.Cells[typeColumn.Index].Tag = PathType.File; _row.Cells[lengthColumn.Index].Value = FileHelper.LengthFormat(item.Length); _row.Cells[creattimeColumn.Index].Value = item.CreationTime; }; Invoke(_action); } //当前查看所有文件类型 #endregion #region 分组委托加载文件图标 PathType ff = PathType.Unknown; foreach (DataGridViewRow item in dataGridView.Rows) { _action = delegate { ff = (PathType)item.Cells[typeColumn.Index].Tag; if (ff == PathType.File) { item.Cells[icoColumn.Index].Value = IOComm.GetIcon(item.Cells[typeColumn.Index].Value?.ToString()); } else if (ff == PathType.Floder) { item.Cells[icoColumn.Index].Value = IOComm.FloderIcon; } else { item.Cells[icoColumn.Index].Value = IOComm.DefaultIcon; } }; Invoke(_action); } #endregion //刷新列表后清空选择的数据 _CurrentName = null; dataGridView.ClearSelection(); _CurrentFf = PathType.Floder; }