Example #1
0
	   public static RenameFileCommand[] ConvertRename(RenameStartItemCommand uiCommand) {

		  List<RenameFileCommand> result = new List<RenameFileCommand>();
		  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 RenameFileCommand(source, target, uiCommand.StartItem, uiCommand.OldName, uiCommand.NewName, uiCommand.StartItem.Exists(target)));
			 }
		  }
		  return result.ToArray();
	   }
Example #2
0
        private void _itemList_AfterLabelEdit(object sender, LabelEditEventArgs e)
        {
            StartItem startItem = (StartItem)_itemList.Items[e.Item].Tag;

            if (!string.IsNullOrEmpty(e.Label))
            {
                if (Utility.IsValidFileName(e.Label))
                {
                    string newName = e.Label;
                    if (startItem.Type == StartItemType.File) newName += Path.GetExtension(startItem.Name);

                    RenameStartItemCommand renameCmd = new RenameStartItemCommand(startItem, newName);
                    if (renameCmd.OldName != renameCmd.NewName)
                    {
                        StartItem[] matches = startManager.GetByName(renameCmd.NewName, startItem.Category);
                        if ((matches.Length > 0) && (matches[0].Type == startItem.Type))
                        {
                            e.CancelEdit = true;
                            _statusLabel.Text = "A folder by this name already exists";
                        }
                        else
                        {
                            renameCmd.Execute();
                            AddUndoCommand(renameCmd);
                        }
                    }
                }
                else
                {
                    e.CancelEdit = true;
                    _statusLabel.Text = Language.EnteredNameIsNotValid;
                }
            }
            else
            {
                e.CancelEdit = true;
                _statusLabel.Text = Language.EnteredNameIsNotValid;
            }
        }