Exemple #1
0
        private void UpdatePreview()
        {
            // File Name Preview and Save All Button
            if (inputFiles.Count > 0)
            {
                if (inputFiles.Count == 1)
                {
                    InputFileNameTextBlock.Text = Path.GetFileName(inputFilePaths[0]);
                    Save_All_Button.IsEnabled   = false;
                }
                else // Multiple Files
                {
                    Save_All_Button.IsEnabled = true;
                    Save_All_Button.ClearValue(Button.ToolTipProperty);
                    InputFileNameTextBlock.Text = Path.GetFileName(inputFilePaths[0]) + " ["
                                                  + inputFilePaths.Count.ToString() + "]";
                }

                InputClearButton.Visibility = System.Windows.Visibility.Visible;
                Save_Button.IsEnabled       = true;
                // Update input preview
                if (inputFilePreviewString != inputFiles[0])
                {
                    InputFilePreview.Text = inputFilePreviewString = inputFiles[0];
                }

                // Update output preview
                string temp = CalculateOutput(inputFiles[0]);
                if (temp != outputPreviewString)
                {
                    OutputFilePreview.Text = outputPreviewString = temp;
                }
            }
            else // No files left, or somehow negative files.
            {
                InputFilePreview.Text       = inputFilePreviewString = "";
                OutputFilePreview.Text      = outputPreviewString = "";
                InputFileNameTextBlock.Text = "";
                InputClearButton.Visibility = System.Windows.Visibility.Hidden;
                Save_All_Button.IsEnabled   = false;
                Save_Button.IsEnabled       = false;
            }
        }
Exemple #2
0
        private void InputFileSelectionButton_Click(object sender, RoutedEventArgs e)
        {
            OpenFileDialog fileDialog = new OpenFileDialog();

            fileDialog.Multiselect = true;
            fileDialog.Filter      = "All files (*.*)|*.*|Text Files (*.txt)|*.txt|Log Files (*.log)|*.log";
            fileDialog.DefaultExt  = "*.*";
            Nullable <bool> result = fileDialog.ShowDialog();

            if (result == true)
            {
                // Write to the debug console
                System.Diagnostics.Debug.WriteLine(fileDialog.FileName);
                System.Diagnostics.Debug.WriteLine(fileDialog.FileNames);
                inputOpenFileDialog = fileDialog;

                // Modify InputPreviewFileName TextBlock
                // Includes the first input file (previewed file)
                // and total number of files if applicable
                if (fileDialog.FileNames.Count <string>() > 1)
                {
                    Save_All_Button.IsEnabled = true;
                    Save_All_Button.ClearValue(Button.ToolTipProperty);
                    InputPreviewFileName.Text = fileDialog.SafeFileName
                                                + " ["
                                                + fileDialog.FileNames.Count <string>().ToString()
                                                + "]";
                    System.Diagnostics.Debug.WriteLine(InputPreviewFileName);
                }
                else
                {
                    InputPreviewFileName.Text = fileDialog.SafeFileName;
                    Save_All_Button.IsEnabled = false;
                }

                // Importing first file to string
                try
                {
                    inputPreviewString = File.ReadAllText(fileDialog.FileName);
                }
                catch
                {
                    MessageBox.Show("Could not read text from: " + fileDialog.SafeFileName);
                    inputPreviewString = "";
                }
                finally
                {
                    InputFilePreview.Text = inputPreviewString;
                }
            }

            // If Open File Dialog Failed (eg. Cancel Button)
            else
            {
                inputPreviewString = "";
            }

            string temp = UpdateOutput(inputPreviewString);

            if (temp != outputPreviewString)
            {
                OutputFilePreview.Text = temp;
                outputPreviewString    = temp;
            }
        }