Skip to content

Commit

Permalink
add terminate button
Browse files Browse the repository at this point in the history
  • Loading branch information
HendrikMennen committed Nov 16, 2023
1 parent d0801b9 commit f09f363
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 18 deletions.
11 changes: 4 additions & 7 deletions src/OneWare.Core/Services/Active.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public Active(IWindowService windowService)
if (_activeStates.Count > 0)
{
//Check if active process is compiling
var withProcess = _activeStates.Where(x => x.Process != null || x.Terminate != null).ToArray();
var withProcess = _activeStates.Where(x => x.Terminate != null).ToArray();
ActiveProcess = (withProcess.Any() ? withProcess.Last() : _activeStates.Last());
}
else
Expand All @@ -46,7 +46,7 @@ public Active(IWindowService windowService)
/// <summary>
/// Use the key to remove the added state with RemoveState()
/// </summary>
public ApplicationProcess AddState(string status, AppState state, Process? process = null,
public ApplicationProcess AddState(string status, AppState state,
Action? terminate = null)
{
lock (_activeLock)
Expand All @@ -55,7 +55,6 @@ public ApplicationProcess AddState(string status, AppState state, Process? proce
{
StatusMessage = status,
State = state,
Process = process,
Terminate = terminate
};
_activeStates.Add(key);
Expand All @@ -72,7 +71,7 @@ public void RemoveState(ApplicationProcess key, string finishMessage = "Done")
}
}

public async Task TerminateActiveAsync()
public async Task TerminateActiveDialogAsync()
{
if(ActiveProcess.State == AppState.Idle) return;

Expand All @@ -81,9 +80,7 @@ public async Task TerminateActiveAsync()
if (result == MessageBoxStatus.Yes)
{
ActiveProcess.Terminated = true;

if (ActiveProcess.Terminate != null) ActiveProcess.Terminate.Invoke();
else if (ActiveProcess.Process is { } process && process.IsRunning()) process.Kill();
ActiveProcess.Terminate?.Invoke();
RemoveState(ActiveProcess);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/OneWare.Core/Services/ChildProcessService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ private static ProcessStartInfo GetProcessStartInfo(string path, string workingD

using var activeProcess = new Process();
activeProcess.StartInfo = startInfo;
var key = _active.AddState(status, state, activeProcess);
var key = _active.AddState(status, state, () => activeProcess?.Kill());

activeProcess.OutputDataReceived += (o, i) =>
{
Expand Down
7 changes: 7 additions & 0 deletions src/OneWare.Core/Styles/Icons.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -1000,6 +1000,13 @@
Geometry="F1M14,13L2,13 2,5 14,5z M1,14L15,14 15,2 1,2z" />
</DrawingGroup>
</DrawingImage>

<DrawingImage x:Key="VSImageLib2019.Stop_16x">
<DrawingGroup>
<GeometryDrawing Brush="#00FFFFFF" Geometry="F1M16,16L0,16 0,0 16,0z" />
<GeometryDrawing Brush="#FFA1260D" Geometry="F1M12,12L4,12 4,4 12,4z" />
</DrawingGroup>
</DrawingImage>

<DrawingImage x:Key="BoxIcons.RegularGitBranch">
<GeometryDrawing Brush="{StaticResource IconColor}"
Expand Down
7 changes: 6 additions & 1 deletion src/OneWare.Core/Views/Windows/MainView.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,19 @@
BorderBrush="{DynamicResource ThemeBorderLowBrush}">

<StackPanel Orientation="Horizontal">

<ItemsControl ItemsSource="{Binding RoundToolBarExtension}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</ItemsControl>
<StackPanel Orientation="Horizontal" IsVisible="{Binding Active.ActiveProcess.Terminate, Converter={x:Static ObjectConverters.IsNotNull}}">
<Separator Margin="0" Width="1" Background="{DynamicResource ThemeBorderLowBrush}" Height="24" />
<Button Command="{Binding Active.TerminateActiveDialogAsync}">
<Image Height="20" Source="{DynamicResource VSImageLib2019.Stop_16x}"></Image>
</Button>
</StackPanel>
</StackPanel>
</Border>
</StackPanel>
Expand Down
8 changes: 7 additions & 1 deletion src/OneWare.Core/Views/Windows/MainWindow.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,21 @@
BorderBrush="{DynamicResource ThemeBorderLowBrush}">

<StackPanel Orientation="Horizontal">

<ItemsControl ItemsSource="{Binding RoundToolBarExtension}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal"/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</ItemsControl>
<StackPanel Orientation="Horizontal" IsVisible="{Binding Active.ActiveProcess.Terminate, Converter={x:Static ObjectConverters.IsNotNull}}">
<Separator Margin="0" Width="1" Background="{DynamicResource ThemeBorderLowBrush}" Height="24" />
<Button Command="{Binding Active.TerminateActiveDialogAsync}">
<Image Height="20" Source="{DynamicResource VSImageLib2019.Stop_16x}"></Image>
</Button>
</StackPanel>
</StackPanel>

</Border>

<ItemsControl ItemsSource="{Binding LeftToolBarExtension}">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,9 @@ public async Task ShowSchemeAsync(IProjectFile jsonFile)
}

_output = string.Empty;

var state = _active.AddState("Rendering Scheme...", AppState.Loading);

var cancel = new CancellationTokenSource();
var state = _active.AddState("Rendering Scheme...", AppState.Loading, () => cancel.Cancel());

var theme = Application.Current!.ActualThemeVariant;
var skin = LoadSkin(theme);
Expand Down Expand Up @@ -145,7 +146,7 @@ await Task.Run(() =>
_output = _output.Replace("fill: white; stroke: none", $"fill: {backgroundHex}; stroke: none");
_output = _output.Replace("fill:#000", $"fill:#FFF");
}
});
}, cancel.Token);
}
catch (Exception e)
{
Expand Down
2 changes: 0 additions & 2 deletions src/OneWare.Shared/Models/ApplicationProcess.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ public string? FinishMessage
set => SetProperty(ref _finishMessage, value);
}

public Process? Process { get; init; }

public bool Terminated { get; set; }

public Action? Terminate { get; init; }
Expand Down
7 changes: 4 additions & 3 deletions src/OneWare.Shared/Services/IActive.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ namespace OneWare.Shared.Services;

public interface IActive
{
public ApplicationProcess AddState(string status, AppState state, Process? process = null,
Action? terminate = null);
public ApplicationProcess ActiveProcess { get; }

public ApplicationProcess AddState(string status, AppState state, Action? terminate = null);

public void RemoveState(ApplicationProcess key, string finishMessage = "Done");

public ApplicationProcess ActiveProcess { get; }
public Task TerminateActiveDialogAsync();
}

0 comments on commit f09f363

Please sign in to comment.