示例#1
0
	   public static DeleteFileCommand[] ConvertDelete(DeleteStartItemCommand uiCommand) {

		  List<DeleteFileCommand> result = new List<DeleteFileCommand>();
		  foreach (string root in Utility.GetAllRoots()) {
			 string source = Path.Combine(root, uiCommand.StartItem.RealName);
			 string target = "";
			 // All local item are in local trash, everything else is in user trash
			 if(root == Utility.LOCAL_START_ROOT){
				target = Path.Combine(Utility.LOCAL_TRASH_ROOT, GetRandomString());
			 }else{
				target = Path.Combine(Utility.USER_TRASH_ROOT, GetRandomString());
			 }

			 if (uiCommand.StartItem.Exists(source)) {
				result.Add(new DeleteFileCommand(source, target, uiCommand.StartItem, uiCommand.StartItem.Name, ""));
			 }
		  }
		  return result.ToArray();
	   }
示例#2
0
        private void deleteToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if ((_itemList.SelectedItems != null) && (_itemList.SelectedItems.Count > 0))
            {
                CommandGroup group = new CommandGroup(string.Format(Language.DeleteItemsFormat, _itemList.SelectedItems.Count));
                foreach (ListViewItem listItem in _itemList.SelectedItems)
                {
                    StartItem item = (StartItem)listItem.Tag;
                    DeleteStartItemCommand cmd = new DeleteStartItemCommand(item, this.startManager);
                    group.Commands.Add(cmd);
                    _itemList.Items.Remove(listItem);
                }

                group.Execute();


                if (group.Commands.Count == 1)
                {
                    this.AddUndoCommand(group.Commands[0]);
                }
                else if (group.Commands.Count > 1)
                {
                    this.AddUndoCommand(group);
                }
            }
        }
示例#3
0
        private void _categoryTree_DragDrop(object sender, DragEventArgs e)
        {
            if (e.Data.GetDataPresent(dragDataType))
            {
                ListView.SelectedListViewItemCollection draggedItems = e.Data.GetData(dragDataType) as ListView.SelectedListViewItemCollection;

                if (draggedItems != null)
                {
                    Point pt = _categoryTree.PointToClient(new Point(e.X, e.Y));
                    TreeNode target = _categoryTree.GetNodeAt(pt);

                    if (target != null)
                    {
                        target.BackColor = SystemColors.Window;
                        CommandGroup group = new CommandGroup(string.Format(Language.MoveItemsFormat, draggedItems.Count));

                        foreach (ListViewItem listItem in draggedItems)
                        {
                            StartItem item = (StartItem)listItem.Tag;
                            // TODO: Check if target exists. 
                            //   Give options: 'Overwrite' or 'Don't Move'
                            // Overwrite:
                            //	 Delete Target, Move File
                            var existingItems = startManager.GetByCategory(target.Name);
                            if (target.Name != item.Category)
                            {
                                MoveStartItemCommand cmd = new MoveStartItemCommand(item, target.Name);
                                DeleteStartItemCommand cmdDelete = null;
                                bool cancel = false;

                                foreach (StartItem existing in existingItems)
                                {
                                    if ((existing.Name == cmd.NewName) && (existing.Type == item.Type))
                                    {
                                        if (MessageBox.Show("An item named '" + existing.Name + "' already exists. Do still want to move?", Application.ProductName, MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation) == DialogResult.No)
                                        {
                                            cancel = true;
                                        }
                                        else
                                        {
                                            cmdDelete = new DeleteStartItemCommand(existing, startManager);
                                        }
                                        break;
                                    }
                                }
                                if (cancel) { continue; } // go to next one
                                if (cmdDelete != null) group.Commands.Add(cmdDelete);
                                group.Commands.Add(cmd);
                                _itemList.Items.Remove(listItem);
                            }
                        }

                        group.Execute();


                        if (group.Commands.Count == 1)
                        {
                            this.AddUndoCommand(group.Commands[0]);
                        }
                        else if (group.Commands.Count > 1)
                        {
                            this.AddUndoCommand(group);
                        }
                    }
                }
            }
        }