Skip to content

Commit

Permalink
サマリータブから右クリックでキャンセル可能に。
Browse files Browse the repository at this point in the history
  • Loading branch information
rigaya committed Feb 15, 2023
1 parent 29e69bf commit 07db03c
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 0 deletions.
27 changes: 27 additions & 0 deletions AmatsukazeGUI/ViewModels/SummaryItemViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

using Amatsukaze.Models;
using System.Windows.Media;
using Amatsukaze.Server;
using System.Collections;

namespace Amatsukaze.ViewModels
{
Expand Down Expand Up @@ -138,5 +140,30 @@ public void ToggleSuspend()
}
#endregion

#region CancelCommand
private ListenerCommand<IEnumerable> _CancelCommand;

public ListenerCommand<IEnumerable> CancelCommand
{
get
{
if (_CancelCommand == null)
{
_CancelCommand = new ListenerCommand<IEnumerable>(Cancel);
}
return _CancelCommand;
}
}

public async void Cancel(IEnumerable selectedItems)
{
await Model.Server?.ChangeItem(new ChangeItemData()
{
ItemId = -1,
workerId = Data.Id - 1,
ChangeType = ChangeItemType.Cancel
});
}
#endregion
}
}
5 changes: 5 additions & 0 deletions AmatsukazeGUI/Views/SummaryItem.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@
GPU:<Run Text="{Binding Data.GPU, Mode=OneWay}"/>@<Run Text="{Binding Data.GpuIndex, Mode=OneWay}"/>
</TextBlock>
<TextBlock Text="{Binding Data.LastLine, Mode=OneWay}" Foreground="{Binding ForeColor, Mode=OneWay}" VerticalAlignment="Center"/>
<DockPanel.ContextMenu>
<ContextMenu x:Name="queueMenu">
<MenuItem Header="キャンセル" Command="{Binding CancelCommand}" />
</ContextMenu>
</DockPanel.ContextMenu>
</DockPanel>
</Button>
<Button Width="100" HorizontalAlignment="Right" Command="{Binding ToggleSuspendCommand}">
Expand Down
14 changes: 14 additions & 0 deletions AmatsukazeServer/Server/EncodeServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2773,8 +2773,22 @@ internal QueueItem[] GetQueueItems(string srcPath)
return queueManager.Queue.Where(s => s.SrcPath == srcPath).ToArray();
}

int getItemIdFromWorkerId(int workerId)
{
var workers = workerPool.Workers.ToArray();
return (0 <= workerId && workerId < workers.Length) ? ((TranscodeWorker)workers[workerId]).GetItemId() : -1;
}

public Task ChangeItem(ChangeItemData data)
{
if (data.ItemId < 0)
{
data.ItemId = getItemIdFromWorkerId(data.workerId);
if (data.ItemId < 0)
{
return Task.FromResult(0);
}
}
return queueManager.ChangeItem(data);
}
#endregion
Expand Down
2 changes: 2 additions & 0 deletions AmatsukazeServer/Server/EncodeServerData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -810,6 +810,8 @@ public class ChangeItemData
[DataMember]
public int ItemId { get; set; }
[DataMember]
public int workerId { get; set; }
[DataMember]
public ChangeItemType ChangeType { get; set; }
[DataMember]
public int Priority { get; set; }
Expand Down
5 changes: 5 additions & 0 deletions AmatsukazeServer/Server/TranscodeWorker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ internal class TranscodeWorker : ConsoleTextBase, IScheduleWorker

private List<Task> waitList;

public int GetItemId()
{
return (item != null) ? item.Id : -1;
}

public TranscodeWorker(int id, EncodeServer server)
{
this.Id = id;
Expand Down

0 comments on commit 07db03c

Please sign in to comment.