Remove scoped blocks in ReplayBrowserLogic.

This commit is contained in:
Paul Chote
2019-06-07 22:05:18 +01:00
committed by abcdefg30
parent 208b5b9686
commit 9f15754926

View File

@@ -371,42 +371,40 @@ namespace OpenRA.Mods.Common.Widgets.Logic
void SetupManagement() void SetupManagement()
{ {
var renameButton = panel.Get<ButtonWidget>("MNG_RENSEL_BUTTON");
renameButton.IsDisabled = () => selectedReplay == null;
renameButton.OnClick = () =>
{ {
var button = panel.Get<ButtonWidget>("MNG_RENSEL_BUTTON"); var r = selectedReplay;
button.IsDisabled = () => selectedReplay == null; var initialName = Path.GetFileNameWithoutExtension(r.FilePath);
button.OnClick = () => var directoryName = Path.GetDirectoryName(r.FilePath);
{ var invalidChars = Path.GetInvalidFileNameChars();
var r = selectedReplay;
var initialName = Path.GetFileNameWithoutExtension(r.FilePath);
var directoryName = Path.GetDirectoryName(r.FilePath);
var invalidChars = Path.GetInvalidFileNameChars();
ConfirmationDialogs.TextInputPrompt( ConfirmationDialogs.TextInputPrompt(
"Rename Replay", "Rename Replay",
"Enter a new file name:", "Enter a new file name:",
initialName, initialName,
onAccept: newName => RenameReplay(r, newName), onAccept: newName => RenameReplay(r, newName),
onCancel: null, onCancel: null,
acceptText: "Rename", acceptText: "Rename",
cancelText: null, cancelText: null,
inputValidator: newName => inputValidator: newName =>
{ {
if (newName == initialName) if (newName == initialName)
return false; return false;
if (string.IsNullOrWhiteSpace(newName)) if (string.IsNullOrWhiteSpace(newName))
return false; return false;
if (newName.IndexOfAny(invalidChars) >= 0) if (newName.IndexOfAny(invalidChars) >= 0)
return false; return false;
if (File.Exists(Path.Combine(directoryName, newName))) if (File.Exists(Path.Combine(directoryName, newName)))
return false; return false;
return true; return true;
}); });
}; };
}
Action<ReplayMetadata, Action> onDeleteReplay = (r, after) => Action<ReplayMetadata, Action> onDeleteReplay = (r, after) =>
{ {
@@ -423,47 +421,43 @@ namespace OpenRA.Mods.Common.Widgets.Logic
onCancel: () => { }); onCancel: () => { });
}; };
var deleteButton = panel.Get<ButtonWidget>("MNG_DELSEL_BUTTON");
deleteButton.IsDisabled = () => selectedReplay == null;
deleteButton.OnClick = () =>
{ {
var button = panel.Get<ButtonWidget>("MNG_DELSEL_BUTTON"); onDeleteReplay(selectedReplay, () =>
button.IsDisabled = () => selectedReplay == null;
button.OnClick = () =>
{ {
onDeleteReplay(selectedReplay, () => if (selectedReplay == null)
SelectFirstVisibleReplay();
});
};
var deleteAllButton = panel.Get<ButtonWidget>("MNG_DELALL_BUTTON");
deleteAllButton.IsDisabled = () => replayState.Count(kvp => kvp.Value.Visible) == 0;
deleteAllButton.OnClick = () =>
{
var list = replayState.Where(kvp => kvp.Value.Visible).Select(kvp => kvp.Key).ToList();
if (list.Count == 0)
return;
if (list.Count == 1)
{
onDeleteReplay(list[0], () => { if (selectedReplay == null) SelectFirstVisibleReplay(); });
return;
}
ConfirmationDialogs.ButtonPrompt(
title: "Delete all selected replays?",
text: "Delete {0} replays?".F(list.Count),
onConfirm: () =>
{ {
list.ForEach(DeleteReplay);
if (selectedReplay == null) if (selectedReplay == null)
SelectFirstVisibleReplay(); SelectFirstVisibleReplay();
}); },
}; confirmText: "Delete All",
} onCancel: () => { });
};
{
var button = panel.Get<ButtonWidget>("MNG_DELALL_BUTTON");
button.IsDisabled = () => replayState.Count(kvp => kvp.Value.Visible) == 0;
button.OnClick = () =>
{
var list = replayState.Where(kvp => kvp.Value.Visible).Select(kvp => kvp.Key).ToList();
if (list.Count == 0)
return;
if (list.Count == 1)
{
onDeleteReplay(list[0], () => { if (selectedReplay == null) SelectFirstVisibleReplay(); });
return;
}
ConfirmationDialogs.ButtonPrompt(
title: "Delete all selected replays?",
text: "Delete {0} replays?".F(list.Count),
onConfirm: () =>
{
list.ForEach(DeleteReplay);
if (selectedReplay == null)
SelectFirstVisibleReplay();
},
confirmText: "Delete All",
onCancel: () => { });
};
}
} }
void RenameReplay(ReplayMetadata replay, string newFilenameWithoutExtension) void RenameReplay(ReplayMetadata replay, string newFilenameWithoutExtension)