コード例 #1
0
        public void ChangeSelectedFileName()
        {
            audioPlaybackService.Stop();
            audioPlaybackService.KillAudio();

            CustomMessageBox tempDialog = new CustomMessageBox(
                caption: "Rename the selected file",
                icon: CustomMessageBoxIcon.Question,
                buttons: CustomMessageBoxButtons.OkAndCancel,
                messageRows: new List <string>(),
                prompt: Path.GetFileNameWithoutExtension(selectedFileService.SelectedFile.Name),
                controlFocus: CustomMessageBoxFocus.Prompt,
                promptValidationMode: CustomMessageBoxPromptValidation.EraseIllegalPathCharacters);

            tempDialog.TrySetViewablePositionFromOwner(OwnerControl);

            if (tempDialog.ShowDialog().HasValue&& tempDialog.Ok)
            {
                if (!selectedFileService.RenameSelectedFileWithoutExtension(tempDialog.PromptContent))
                {
                    _notificationManager.ShowAsync(
                        content: new NotificationContent()
                    {
                        Title   = "Something went wrong",
                        Message = "An unknown error occurred trying to rename the selected file",
                        Type    = NotificationType.Error
                    },
                        expirationTime: TimeSpan.FromSeconds(10));
                }
            }
        }
コード例 #2
0
        public void ExportSelectedFile()
        {
            audioPlaybackService.Stop();
            audioPlaybackService.KillAudio();

            string preferredFileName = string.Empty;

            if (appSettingService.PromptForExportFileName)
            {
                CustomMessageBox tempDialog = new CustomMessageBox(
                    caption: "Select a filename for the exported file",
                    icon: CustomMessageBoxIcon.Question,
                    buttons: CustomMessageBoxButtons.OkAndCancel,
                    messageRows: new List <string>(),
                    prompt: Path.GetFileNameWithoutExtension(selectedFileService.SelectedFile.Name),
                    controlFocus: CustomMessageBoxFocus.Prompt,
                    promptValidationMode: CustomMessageBoxPromptValidation.EraseIllegalPathCharacters);

                tempDialog.TrySetViewablePositionFromOwner(OwnerControl);

                if (!tempDialog.ShowDialog().HasValue || !tempDialog.Ok)
                {
                    return;
                }

                preferredFileName = tempDialog.PromptContent;
            }

            var exportedFileName = selectedFileService.ExportFile(preferredFileName);

            if (string.IsNullOrEmpty(exportedFileName))
            {
                _notificationManager.ShowAsync(
                    content: new NotificationContent()
                {
                    Title   = "Something went wrong",
                    Message = "An unknown error occurred trying to export the selected file",
                    Type    = NotificationType.Error
                },
                    expirationTime: TimeSpan.FromSeconds(10));
                return;
            }


            _notificationManager.ShowAsync(
                content: new NotificationContent()
            {
                Type    = NotificationType.Success,
                Title   = $"{selectedFileService.SelectedFile.Name} exported to MP3!",
                Message = $"Export was successful, file has been exported to {exportedFileName}."
            },
                onClick: () =>
            {
                string argument = "/select, \"" + exportedFileName + "\"";
                System.Diagnostics.Process.Start("explorer.exe", argument);
            });
        }