Gilgame.SEWorkbench.ViewModels.ProjectItemViewModel.UpdatePath C# (CSharp) Method

UpdatePath() public method

public UpdatePath ( string source, string destination ) : void
source string
destination string
return void
        public void UpdatePath(string source, string destination)
        {
            Path = Path.Replace(source, destination);
            foreach(ProjectItemViewModel child in Children)
            {
                child.UpdatePath(source, destination);
            }
        }

Usage Example

コード例 #1
0
        public void PerformRename()
        {
            ProjectItemViewModel selected = SelectedItem;

            if (selected == null)
            {
                return;
            }
            if (selected.Type != ProjectItemType.Collection && selected.Type != ProjectItemType.Folder && selected.Type != ProjectItemType.File)
            {
                return;
            }

            Views.NewItemDialog view   = new Views.NewItemDialog();
            Nullable <bool>     result = view.ShowDialog();

            if (result != null && result.Value == true)
            {
                string source      = selected.Path;
                string destination = String.Empty;
                if (selected.Type == ProjectItemType.File)
                {
                    string filename = String.Format("{0}.csx", view.ItemName);
                    destination = Path.Combine(Path.GetDirectoryName(source), filename);
                    if (File.Exists(destination))
                    {
                        MessageBox.ShowMessage(String.Format("A file with the name \"{0}\" already exists.", destination));
                        return;
                    }
                    try
                    {
                        File.Move(source, destination);

                        selected.Name = view.ItemName;
                        selected.Path = destination;

                        SaveProject();
                    }
                    catch (Exception ex)
                    {
                        MessageBox.ShowError("Unable to rename file", ex);
                        return;
                    }
                }

                if (selected.Type == ProjectItemType.Collection || selected.Type == ProjectItemType.Folder)
                {
                    destination = Path.Combine(Directory.GetParent(source).FullName, view.ItemName);
                    if (Directory.Exists(destination))
                    {
                        MessageBox.ShowMessage(String.Format("A folder with the name \"{0}\" already exists.", destination));
                        return;
                    }
                    try
                    {
                        Directory.Move(source, destination);

                        selected.Name = view.ItemName;
                        selected.Path = destination;

                        selected.UpdatePath(source, destination);

                        SaveProject();
                    }
                    catch (Exception ex)
                    {
                        MessageBox.ShowError("Unable to rename directory", ex);
                        return;
                    }
                }
            }
        }