Beispiel #1
0
//		protected override void Initialize()
//		{
//			base.Initialize();
//		}

        public override void AfterLabelEdit(string newName)
        {
            if (newName == null)
            {
                return;
            }
            if (!FileService.CheckDirectoryEntryName(newName))
            {
                return;
            }
            string oldFileName = FileName;

            if (oldFileName != null)
            {
                string newFileName = Path.Combine(Path.GetDirectoryName(oldFileName), newName);
                if (FileService.RenameFile(oldFileName, newFileName, false))
                {
                    Text          = newName;
                    this.fileName = newFileName;

                    string oldPrefix = Path.GetFileNameWithoutExtension(oldFileName) + ".";
                    string newPrefix = Path.GetFileNameWithoutExtension(newFileName) + ".";
                    foreach (TreeNode node in Nodes)
                    {
                        FileNode fileNode = node as FileNode;
                        if (fileNode != null)
                        {
                            FileProjectItem fileItem = fileNode.ProjectItem as FileProjectItem;
                            if (fileItem != null && string.Equals(fileItem.DependentUpon, Path.GetFileName(oldFileName), StringComparison.OrdinalIgnoreCase))
                            {
                                fileItem.DependentUpon = newName;
                            }
                            if (fileNode.Text.StartsWith(oldPrefix))
                            {
                                fileNode.AfterLabelEdit(newPrefix + fileNode.Text.Substring(oldPrefix.Length));
                            }
                        }
                        else
                        {
                            LoggingService.Warn("FileNode.AfterLabelEdit. Child is not a FileNode.");
                        }
                    }

                    Project.Save();
                }
            }
        }
Beispiel #2
0
        public override void AfterLabelEdit(string newName)
        {
            if (newName == null)
            {
                return;
            }
            if (!FileService.CheckDirectoryEntryName(newName))
            {
                return;
            }
            if (String.Compare(Text, newName, true) == 0)
            {
                return;
            }
            string oldText = Text;

            Text = newName;
            if (Directory != null)
            {
                string newPath = Path.Combine(Path.GetDirectoryName(Directory), newName);
                if (System.IO.Directory.Exists(newPath))
                {
                    if (System.IO.Directory.GetFileSystemEntries(newPath).Length == 0)
                    {
                        System.IO.Directory.Delete(newPath);
                    }
                    else
                    {
                        MessageService.ShowError("The folder already exists and contains files!");
                        Text = oldText;
                        return;
                    }
                }
                if (!FileService.RenameFile(Directory, newPath, true))
                {
                    Text = oldText;
                    return;
                }

                this.directory = newPath;
                Project.Save();
            }
        }