/// <summary> /// 返回到管理界面 /// </summary> private void btnReturn_Click(object sender, EventArgs e) { //前置列表 this.tabFileGroup.BringToFront(); //后置配置分组 this.gbConfigGroupName.SendToBack(); this.tabFileGroup.Visible = false; //刷新图标列表 this.initShortcutStyle(); this.tabFileGroup.Visible = true; //刷新托盘菜单 FrmTray.DoInitMenu(); }
/// <summary> /// 快捷ListView的右键菜单事件 /// </summary> private void loveToolStripItem_Click(object sender, EventArgs e) { ToolStripMenuItem menuItem = sender as ToolStripMenuItem; BoxFile selectBoxFileItem; if (menuItem.Name == MenuName_RemoveFileItemInLove) //移除选定项 { if (listViewLove.SelectedItems.Count > 0) { for (int i = 0; i < listViewLove.SelectedItems.Count; i++) { selectBoxFileItem = listViewLove.SelectedItems[i].Tag as BoxFile; BoxFileData.deleteLikeShortcut(selectBoxFileItem); } //刷新该分组下的图标 this.refreshLikeShortcut(); //刷新托盘菜单 FrmTray.DoInitMenu(); } } }
/// <summary> /// ListView的右键菜单事件 /// </summary> private void toolStripItem_Click(object sender, EventArgs e) { ToolStripMenuItem menuItem = sender as ToolStripMenuItem; if (menuItem.Name == MenuName_MoveToNewGroup) { return; } TabPage selectTabPage = this.tabFileGroup.SelectedTab; ListView selectListView = selectTabPage.Controls[0] as ListView; BoxFile selectBoxFileItem; string groupName = selectTabPage.Text; if (menuItem.Name == MenuName_LoveFileItem) //标记此项 { if (selectListView.SelectedItems.Count > 0) { for (int i = 0; i < selectListView.SelectedItems.Count; i++) { selectBoxFileItem = selectListView.SelectedItems[i].Tag as BoxFile; BoxFileData.addLikeShortcut(selectBoxFileItem); } // 刷新快捷位置的图标 this.refreshLikeShortcut(); //刷新托盘菜单 FrmTray.DoInitMenu(); } } else if (menuItem.Name == MenuName_RemoveFileItem) //移除选定项 { if (selectListView.SelectedItems.Count > 0) { for (int i = 0; i < selectListView.SelectedItems.Count; i++) { selectBoxFileItem = selectListView.SelectedItems[i].Tag as BoxFile; //删除文件 BoxFileData.deleteShortcut(selectBoxFileItem, groupName); } //刷新该分组下的图标 this.refreshShortcut(groupName, selectListView); //更新托盘窗体对应分组下面的图标 FrmTray.DoUpdateMenuByGroupName(groupName); } } else if (menuItem.Name == MenuName_ModifyFileItemName) //重命名 { if (selectListView.SelectedItems.Count > 0) { selectBoxFileItem = selectListView.SelectedItems[0].Tag as BoxFile; string value = selectBoxFileItem.Name; if (MessageUtil.ShowPrompt("重命名", "请输入文件名称:", ref value) == DialogResult.OK) { //修改文件名称 BoxFileData.updateShortcut(selectBoxFileItem.Key, value, groupName); //刷新该分组下的图标 this.refreshShortcut(groupName, selectListView); //更新托盘窗体对应分组下面的图标 FrmTray.DoUpdateMenuByGroupName(groupName); } } } else if (menuItem.Name == MenuName_ModifyFileItemIcon) //修改文件图标 { if (selectListView.SelectedItems.Count > 0) { for (int i = 0; i < selectListView.SelectedItems.Count; i++) { selectBoxFileItem = selectListView.SelectedItems[i].Tag as BoxFile; Bitmap fileLargeIcon = Utils.GetFileIcon(selectBoxFileItem.Path, false).ToBitmap(); Bitmap fileSmallIcon = Utils.GetFileIcon(selectBoxFileItem.Path, true).ToBitmap(); BoxFileData.updateShortcut(selectBoxFileItem.Key, fileLargeIcon, fileSmallIcon, selectTabPage.Text); } //刷新该分组下的图标 this.refreshShortcut(groupName, selectListView); //更新托盘窗体对应分组下面的图标 FrmTray.DoUpdateMenuByGroupName(groupName); } } else if (menuItem.Name == MenuName_OpenWorkingDirectory) //打开文件位置 { if (selectListView.SelectedItems.Count > 0) { selectBoxFileItem = selectListView.SelectedItems[0].Tag as BoxFile; //打开文件位置 Utils.OpenFolder(selectBoxFileItem.Path); } } else if (menuItem.Name == MenuName_SetGroup) //设置分组 { //设置分组 //前置配置分组 this.tabFileGroup.SendToBack(); //后置列表 this.gbConfigGroupName.BringToFront(); } else if (menuItem.Name.StartsWith("MoveToGroup_")) //移动分组 { if (selectListView.SelectedItems.Count > 0) { string newGroupName = menuItem.Name.Split('_')[1]; for (int i = 0; i < selectListView.SelectedItems.Count; i++) { selectBoxFileItem = selectListView.SelectedItems[i].Tag as BoxFile; BoxFileData.moveShortcut(selectBoxFileItem, groupName, newGroupName); } //刷新该分组下的图标 this.refreshShortcut(groupName, selectListView); //更新托盘窗体对应分组下面的图标 FrmTray.DoUpdateMenuByGroupName(groupName); //刷新新分组下的图标 this.refreshShortcut(newGroupName); //更新托盘窗体对应新分组下面的图标 FrmTray.DoUpdateMenuByGroupName(newGroupName); } } }
/// <summary> /// 拖拽文件到当前选中的TabPage中 /// </summary> private void listViewFiles_DragDrop(object sender, DragEventArgs e) { TabPage selectTabPage = this.tabFileGroup.SelectedTab; ListView selectListView = selectTabPage.Controls[0] as ListView; string groupName = selectTabPage.Text; //获取拖拽进来的文件数组 string[] files = e.Data.GetData(DataFormats.FileDrop) as string[]; if (files.Length > 0) { string fileName; string fileExtension; string filePath; Bitmap fileLargeIcon; Bitmap fileSmallIcon; BoxFile boxFileItem; foreach (string file in files) { if (File.Exists(file)) { //文件名称 fileName = Path.GetFileNameWithoutExtension(file); //文件格式 fileExtension = Path.GetExtension(file).ToLower(); //文件路径 if (fileExtension == ".lnk") { //如果是快捷方式,就取出真实路径 filePath = Utils.GetFileTargetPath(file);//根据快捷方式获取真实路径 } else { filePath = Path.GetFullPath(file); } //文件大图标 fileLargeIcon = Utils.GetFileLargeIcon(filePath).ToBitmap(); //文件小图标 fileSmallIcon = Utils.GetFileSmallIcon(filePath).ToBitmap(); //添加新文件 boxFileItem = new BoxFile() { Name = fileName, LargeIcon = fileLargeIcon, SmallIcon = fileSmallIcon, Path = filePath }; //添加新文件到组中 BoxFileData.addShortcut(boxFileItem, groupName); } } //刷新该分组下的图标 this.refreshShortcut(groupName, selectListView); //更新托盘窗体对应分组下面的图标 FrmTray.DoUpdateMenuByGroupName(groupName); } }