示例#1
0
        private void projectFiles_AfterLabelEdit(object sender, NodeLabelEditEventArgs e)
        {
            if (e.Label == null || e.Node == this.projectFiles.Nodes[0])
            {
                e.CancelEdit = true;
                return;
            }

            if (e.Label.Length > 0)
            {
                if (e.Label.IndexOfAny(new char[] { '@', ',', '!' }) == -1)
                {
                    string projectPath = Path.GetDirectoryName(this.GetSelectedNodeInternalPath());
                    string oldPath     = Path.Combine(Workspace.Project.BaseDirectory, projectPath, e.Node.Text);
                    string newPath     = Path.Combine(Workspace.Project.BaseDirectory, projectPath, e.Label);

                    if (oldPath != newPath)
                    {
                        if ((TreeNodeType)e.Node.Tag == TreeNodeType.Directory)
                        {
                            TreeNodeHelper.ChangeKeys(e.Node.Nodes, oldPath, newPath);

                            // Change directory's name.
                            Directory.Move(oldPath, newPath);
                        }
                        else
                        {
                            TreeNodeHelper.ChangeKey(e.Node, newPath);

                            // Change file's name.
                            File.Move(oldPath, newPath);
                        }

                        if (ItemRenamed != null)
                        {
                            ItemRenamed(this, new ItemRenamedEventArgs(oldPath, newPath));
                        }

                        // Change editor path.
                        foreach (Editor editor in Workspace.GetEditors().Values.ToList())
                        {
                            // Check if file path is greater or equal with modified path.
                            if (editor.FileName.Length >= oldPath.Length && editor.FileName.Substring(0, oldPath.Length) == oldPath)
                            {
                                string editorPath = editor.FileName;

                                // Remove and add the editor.
                                editor.Close();
                                Workspace.OpenFile(Path.Combine(newPath, editorPath.Remove(0, editorPath.Length <= oldPath.Length ? oldPath.Length : oldPath.Length + 1)));
                            }
                        }
                    }

                    e.Node.EndEdit(false);
                }
                else
                {
                    e.CancelEdit = true;
                    // TODO: Show message for invalid characters.
                    e.Node.BeginEdit();
                }
            }
            else
            {
                e.CancelEdit = true;
                // TODO: Show message for empty name.
                e.Node.BeginEdit();
            }
        }