public static MoveFileCommand[] ConvertMove(MoveStartItemCommand uiCommand) { List<MoveFileCommand> result = new List<MoveFileCommand>(); foreach (string root in Utility.GetAllRoots()) { string source = Path.Combine(root, uiCommand.OldName); string target = Path.Combine(Path.Combine(root, uiCommand.NewCategory), Path.GetFileName(uiCommand.NewName)); if(uiCommand.StartItem.Exists(source)){ result.Add(new MoveFileCommand(source, target, uiCommand.StartItem, uiCommand.OldName, uiCommand.NewName, uiCommand.StartItem.Exists(target))); } } return result.ToArray(); }
private void Paste() { if (Clipboard.ContainsData(clipboardDataType.Name)) { StartItem[] data; IDataObject dataObj = Clipboard.GetDataObject(); if (dataObj.GetDataPresent(clipboardDataType.Name)) { data = dataObj.GetData(clipboardDataType.Name) as StartItem[]; List<Command> commands = new List<Command>(); foreach (StartItem item in data) { if (item.Category != _categoryTree.SelectedNode.Name) { MoveStartItemCommand cmd = new MoveStartItemCommand(item, _categoryTree.SelectedNode.Name); commands.Add(cmd); } _itemList.Items.Add(StartItemToListItem(item, true)); startManager.AddItem(item); } if (commands.Count > 0) { CommandGroup group = new CommandGroup(string.Format(Language.MoveItemsFormat, commands.Count), commands); group.Execute(); if (group.Commands.Count == 1) { this.AddUndoCommand(group.Commands[0]); } else if (group.Commands.Count > 1) { this.AddUndoCommand(group); } } } } }
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); } } } } }
void ApplyTemplate(MoveStartItemCommand[] commands, string name) { if ((commands == null) || (commands.Length <= 0)) { MessageBox.Show(Language.NothingToDoMessage, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information); return; } using (ReviewChanges review = new ReviewChanges(true)) { foreach (MoveStartItemCommand cmd in commands) { foreach (string str in AddCategoryToTree(cmd.NewCategory)) { // Ensure that the target category is visible to user AddToManager(str); } review.Add("Move", "'" + cmd.OldName + "' to '" + cmd.NewName + "'"); } if (review.ShowDialog(this) == DialogResult.OK) { CommandGroup group = new CommandGroup(Language.ApplyTemplate, commands); AddUndoCommand(group, true); UpdateItemList(); } } }