Exemplo n.º 1
0
    private void ExecuteRenameProject(PrintElement project)
    {
        string Validation(string newName)
        {
            if (string.Equals(project.Name, newName, StringComparison.OrdinalIgnoreCase))
            {
                return(null);
            }

            var path = Path.Combine(Path.GetDirectoryName(project.DirectoryLocation), newName);

            if (Directory.Exists(path))
            {
                return(string.Format(_translationManager.GetTranslation(nameof(StringTable.Msg_ProjectAlreadyExists)), newName));
            }

            return(null);
        }

        var dialog = new RenameDialog(
            _translationManager.GetTranslation(nameof(StringTable.Title_RenameProject)),
            string.Format(_translationManager.GetTranslation(nameof(StringTable.Desc_RenameProject)), project.Name),
            project.Name,
            Validation)
        {
            Owner = Application.Current.MainWindow,
        };

        if (dialog.ShowDialog() == true)
        {
            var newPath = Path.Combine(Path.GetDirectoryName(project.DirectoryLocation), dialog.NewName);

            SelectedElement = null;
            PrintElements.Remove(project);
            project.Dispose();

            Directory.Move(project.DirectoryLocation, newPath);

            var newProject = new PrintElement(newPath);
            PrintElements.Add(newProject);
            SelectedElement = newProject;
        }
    }
Exemplo n.º 2
0
    private async Task ExecuteDeleteProject(PrintElement project)
    {
        if (MessageBox.Show(string.Format(_translationManager.GetTranslation(nameof(StringTable.Msg_ConfirmProjectDeletion)), project.Name), "CuraManager", AlertButton.YesNo, AlertImage.Question) == AlertResult.No)
        {
            return;
        }

        await ExecuteLoadingAction(
            string.Format(_translationManager.GetTranslation(nameof(StringTable.Prog_DeleteProject)), project.Name),
            async() =>
        {
            project.Dispose();
            PrintElements.Remove(project);
            await Task.Run(() => Directory.Delete(project.DirectoryLocation, true));
            if (SelectedElement == project)
            {
                SelectedElement = null;
            }
        },
            string.Format(_translationManager.GetTranslation(nameof(StringTable.Suc_DeleteProject)), project.Name),
            string.Format(_translationManager.GetTranslation(nameof(StringTable.Fail_DeleteProject)), project.Name));
    }