diff --git a/MPF.Library/Data/DumpEnvironment.cs b/MPF.Library/Data/DumpEnvironment.cs index 58522f3b..ee4f735e 100644 --- a/MPF.Library/Data/DumpEnvironment.cs +++ b/MPF.Library/Data/DumpEnvironment.cs @@ -246,7 +246,6 @@ namespace MPF.Data // Cache if we had a directory separator or not bool endedWithDirectorySeparator = directory.EndsWith(Path.DirectorySeparatorChar.ToString()) || directory.EndsWith(Path.AltDirectorySeparatorChar.ToString()); - bool endedWithSpace = directory.EndsWith(" "); // Combine the path to make things separate easier string combinedPath = Path.Combine(directory, filename); @@ -271,10 +270,6 @@ namespace MPF.Data if (replacePeriods) filename = Path.GetFileNameWithoutExtension(filename).Replace('.', '_') + "." + Path.GetExtension(filename).TrimStart('.'); - // If we had a space at the end before, add it again - if (endedWithSpace) - directory += " "; - // If we had a directory separator at the end before, add it again if (endedWithDirectorySeparator) directory += Path.DirectorySeparatorChar; diff --git a/MPF/Windows/MainWindow.xaml.cs b/MPF/Windows/MainWindow.xaml.cs index 256cfd71..54df0445 100644 --- a/MPF/Windows/MainWindow.xaml.cs +++ b/MPF/Windows/MainWindow.xaml.cs @@ -208,10 +208,9 @@ namespace MPF.Windows { SystemTypeComboBox.SelectionChanged += SystemTypeComboBoxSelectionChanged; MediaTypeComboBox.SelectionChanged += MediaTypeComboBoxSelectionChanged; - OutputFilenameTextBox.TextChanged += OutputFilenameTextBoxTextChanged; - OutputDirectoryTextBox.TextChanged += OutputDirectoryTextBoxTextChanged; DriveLetterComboBox.SelectionChanged += DriveLetterComboBoxSelectionChanged; DriveSpeedComboBox.SelectionChanged += DriveSpeedComboBoxSelectionChanged; + AddPathEventHandlers(); } /// @@ -221,10 +220,27 @@ namespace MPF.Windows { SystemTypeComboBox.SelectionChanged -= SystemTypeComboBoxSelectionChanged; MediaTypeComboBox.SelectionChanged -= MediaTypeComboBoxSelectionChanged; - OutputFilenameTextBox.TextChanged -= OutputFilenameTextBoxTextChanged; - OutputDirectoryTextBox.TextChanged -= OutputDirectoryTextBoxTextChanged; DriveLetterComboBox.SelectionChanged -= DriveLetterComboBoxSelectionChanged; DriveSpeedComboBox.SelectionChanged -= DriveSpeedComboBoxSelectionChanged; + RemovePathEventHandlers(); + } + + /// + /// Add path textbox event handlers + /// + private void AddPathEventHandlers() + { + OutputFilenameTextBox.TextChanged += OutputFilenameTextBoxTextChanged; + OutputDirectoryTextBox.TextChanged += OutputDirectoryTextBoxTextChanged; + } + + /// + /// Remove path textbox event handlers + /// + private void RemovePathEventHandlers() + { + OutputFilenameTextBox.TextChanged -= OutputFilenameTextBoxTextChanged; + OutputDirectoryTextBox.TextChanged -= OutputDirectoryTextBoxTextChanged; } /// @@ -352,14 +368,17 @@ namespace MPF.Windows ParametersTextBox.Text); // Disable automatic reprocessing of the textboxes until we're done - OutputDirectoryTextBox.TextChanged -= OutputDirectoryTextBoxTextChanged; - OutputFilenameTextBox.TextChanged -= OutputFilenameTextBoxTextChanged; + RemovePathEventHandlers(); OutputDirectoryTextBox.Text = env.OutputDirectory; - OutputFilenameTextBox.Text = env.OutputFilename; + OutputDirectoryTextBox.SelectionStart = OutputDirectoryTextBox.Text.Length; + OutputDirectoryTextBox.SelectionLength = 0; - OutputDirectoryTextBox.TextChanged += OutputDirectoryTextBoxTextChanged; - OutputFilenameTextBox.TextChanged += OutputFilenameTextBoxTextChanged; + OutputFilenameTextBox.Text = env.OutputFilename; + OutputFilenameTextBox.SelectionStart = OutputFilenameTextBox.Text.Length; + OutputFilenameTextBox.SelectionLength = 0; + + AddPathEventHandlers(); return env; } @@ -426,6 +445,9 @@ namespace MPF.Windows // Get the extension for the file for the next two statements string extension = Env.Parameters?.GetDefaultExtension(mediaType); + // Disable automatic reprocessing of the textboxes until we're done + RemovePathEventHandlers(); + // Set the output filename, if we changed drives or it's not already if (driveChanged || string.IsNullOrEmpty(OutputFilenameTextBox.Text)) OutputFilenameTextBox.Text = (drive?.VolumeLabel ?? systemType.LongName()) + (extension ?? ".bin"); @@ -437,6 +459,14 @@ namespace MPF.Windows // Set the output directory, if we changed drives or it's not already if (driveChanged || string.IsNullOrEmpty(OutputDirectoryTextBox.Text)) OutputDirectoryTextBox.Text = Path.Combine(Options.DefaultOutputPath, Path.GetFileNameWithoutExtension(OutputFilenameTextBox.Text) ?? string.Empty); + + OutputDirectoryTextBox.SelectionStart = OutputDirectoryTextBox.Text.Length; + OutputDirectoryTextBox.SelectionLength = 0; + + OutputFilenameTextBox.SelectionStart = OutputFilenameTextBox.Text.Length; + OutputFilenameTextBox.SelectionLength = 0; + + AddPathEventHandlers(); } /// @@ -476,6 +506,9 @@ namespace MPF.Windows else Env.Parameters.Speed = DriveSpeedComboBox.SelectedValue as int?; + // Disable automatic reprocessing of the textboxes until we're done + RemovePathEventHandlers(); + string trimmedPath = Env.Parameters.OutputPath?.Trim('"') ?? string.Empty; string outputDirectory = Path.GetDirectoryName(trimmedPath); string outputFilename = Path.GetFileName(trimmedPath); @@ -489,6 +522,14 @@ namespace MPF.Windows else outputFilename = OutputFilenameTextBox.Text; + OutputDirectoryTextBox.SelectionStart = OutputDirectoryTextBox.Text.Length; + OutputDirectoryTextBox.SelectionLength = 0; + + OutputFilenameTextBox.SelectionStart = OutputFilenameTextBox.Text.Length; + OutputFilenameTextBox.SelectionLength = 0; + + AddPathEventHandlers(); + MediaType? mediaType = Env.Parameters.GetMediaType(); int mediaTypeIndex = MediaTypes.FindIndex(m => m == mediaType); if (mediaTypeIndex > -1)