Exemple #1
0
        private void OpenFolder_Click(object sender, EventArgs e)
        {
            var directoryNode = CurrentNode as DirectoryNode;

            if (directoryNode != null)
            {
                OsFeatures.OpenFolder(directoryNode.DirectoryInfo.FullName);
            }
        }
Exemple #2
0
        private void RenameDirectory(DirectoryInfo directory, NodeLabelEditEventArgs e)
        {
            if (directory.Parent == null)
            {
                e.CancelEdit = true;
                return;
            }
            foreach (var character in Path.GetInvalidPathChars().Union(Path.GetInvalidFileNameChars()))
            {
                if (e.Label.Contains(character))
                {
                    e.CancelEdit = true;
                    Program.Error(string.Format("Invalid character '{0}'", character));
                    return;
                }
            }

            var oldPath = directory.FullName.TrimEnd('\\', '/');
            var newPath = Path.Combine(directory.Parent.FullName, e.Label);

            if (Directory.Exists(newPath))
            {
                e.CancelEdit = true;
                Program.Error("Path already exists");
                return;
            }
            try
            {
                directory.MoveTo(newPath);
            }
            catch (Exception ex)
            {
                e.CancelEdit = true;
                Program.Error("Unable to rename directory:\n" + ex.Message);
                return;
            }
            _project.Pristine = false;
            for (var i = 0; i < _project.Directories.Count; i++)
            {
                var testDirectory = _project.Directories[i];
                if (testDirectory.FullName == oldPath)
                {
                    _project.Directories[i] = new DirectoryInfo(newPath);
                }
                else if (OsFeatures.IsInDirectory(testDirectory, oldPath))
                {
                    _project.Directories[i] = new DirectoryInfo(Path.Combine(newPath, _project.Directories[i].FullName.Substring(oldPath.Length + 1)));
                    var explorerDir = GetNode <DirectoryNode>(Nodes, d => d.DirectoryInfo == testDirectory);
                    if (explorerDir != null)
                    {
                        explorerDir.DirectoryInfo = _project.Directories[i];
                    }
                }
            }
            foreach (var file in _project.Files.Where(f => _project.IsInDirectory(f, oldPath)))
            {
                file.File = new FileInfo(Path.Combine(newPath, file.File.FullName.Substring(oldPath.Length + 1)));
            }

            RefreshTree();
        }