diff --git a/butterflow-ui/ButterflowWrapper.cs b/butterflow-ui/ButterflowWrapper.cs index c9d3564..1fe2b20 100644 --- a/butterflow-ui/ButterflowWrapper.cs +++ b/butterflow-ui/ButterflowWrapper.cs @@ -24,6 +24,8 @@ namespace butterflow_ui private Lazy executablePath = new Lazy(() => Path.Combine(Directory.GetCurrentDirectory(), "ThirdPartyCompiled", "butterflow.exe")); /// The console output from butterflow. private string consoleOutput = string.Empty; + /// True if butterflow is running, false if not. + private bool isRunning; /// Event queue for all listeners interested in ParsedConsoleOutputRecieved events. public event EventHandler ParsedConsoleOutputRecieved; @@ -46,6 +48,21 @@ namespace butterflow_ui } } + /// Gets or sets a value indicating whether butterflow is currently running. + /// True if butterflow is running, false if not. + public bool IsRunning + { + get + { + return this.isRunning; + } + set + { + this.isRunning = value; + OnPropertyChanged(); + } + } + #endregion #region Methods @@ -71,20 +88,34 @@ namespace butterflow_ui /// Options for controlling the operation. private void Run(string arguments) { - var process = new Process(); - process.StartInfo = new ProcessStartInfo(executablePath.Value, arguments); + if (!this.IsRunning) + { + var process = new Process(); + process.StartInfo = new ProcessStartInfo(executablePath.Value, arguments); - process.StartInfo.CreateNoWindow = true; - process.StartInfo.UseShellExecute = false; - process.StartInfo.RedirectStandardOutput = true; - process.StartInfo.RedirectStandardError = true; - process.EnableRaisingEvents = true; - process.OutputDataReceived += Process_OutputDataReceived; - process.ErrorDataReceived += Process_OutputDataReceived; + process.StartInfo.CreateNoWindow = true; + process.StartInfo.UseShellExecute = false; + process.StartInfo.RedirectStandardOutput = true; + process.StartInfo.RedirectStandardError = true; + process.EnableRaisingEvents = true; + process.OutputDataReceived += Process_OutputDataReceived; + process.ErrorDataReceived += Process_OutputDataReceived; + process.Exited += Process_Exited; - process.Start(); - process.BeginOutputReadLine(); - process.BeginErrorReadLine(); + process.Start(); + process.BeginOutputReadLine(); + process.BeginErrorReadLine(); + + this.IsRunning = true; + } + } + + /// Event handler. Called by Process for exited events. + /// Source of the event. + /// Event information. + private void Process_Exited(object sender, EventArgs e) + { + this.IsRunning = false; } /// diff --git a/butterflow-ui/InverseBoolConverter.cs b/butterflow-ui/InverseBoolConverter.cs new file mode 100644 index 0000000..989e776 --- /dev/null +++ b/butterflow-ui/InverseBoolConverter.cs @@ -0,0 +1,57 @@ +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Data; + +namespace butterflow_ui +{ + /// An inverse boolean converter. + [ValueConversion(typeof(bool), typeof(bool))] + public class InverseBoolConverter : IValueConverter + { + /// Converts a boolean to its inverse. + /// Thrown when an object cannot be cast to a required + /// type. + /// The value produced by the binding source. + /// The type of the binding target property. + /// The converter parameter to use. + /// The culture to use in the converter. + /// + /// A converted value. If the method returns , the valid null value is + /// used. + /// + public object Convert(object value, Type targetType, object parameter, CultureInfo culture) + { + if(targetType == typeof(bool)) + { + return !(bool)value; + } + + throw new InvalidCastException(string.Format("Cannot convert type {0} to boolean.", targetType.Name)); + } + + /// Converts an inverse boolean back to its original state. + /// Thrown when an object cannot be cast to a required + /// type. + /// The value that is produced by the binding target. + /// The type to convert to. + /// The converter parameter to use. + /// The culture to use in the converter. + /// + /// A converted value. If the method returns , the valid null value is + /// used. + /// + public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) + { + if (targetType == typeof(bool)) + { + return !(bool)value; + } + + throw new InvalidCastException(string.Format("Cannot convert type {0} to boolean.", targetType.Name)); + } + } +} diff --git a/butterflow-ui/MainWindow.xaml b/butterflow-ui/MainWindow.xaml index 8978095..fbf169a 100644 --- a/butterflow-ui/MainWindow.xaml +++ b/butterflow-ui/MainWindow.xaml @@ -23,6 +23,7 @@ + @@ -102,7 +103,7 @@ -