mirror of
https://github.com/Tyrrrz/DiscordChatExporter.git
synced 2026-05-30 04:32:16 +00:00
Only execute commands from code if allowed
This commit is contained in:
@@ -0,0 +1,15 @@
|
|||||||
|
using System.Windows.Input;
|
||||||
|
|
||||||
|
namespace DiscordChatExporter.Gui.Utils.Extensions;
|
||||||
|
|
||||||
|
internal static class CommandExtensions
|
||||||
|
{
|
||||||
|
extension(ICommand command)
|
||||||
|
{
|
||||||
|
public void ExecuteIfCan(object? parameter = null)
|
||||||
|
{
|
||||||
|
if (command.CanExecute(parameter))
|
||||||
|
command.Execute(parameter);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -4,6 +4,7 @@ using Avalonia.Input;
|
|||||||
using Avalonia.Interactivity;
|
using Avalonia.Interactivity;
|
||||||
using DiscordChatExporter.Core.Discord.Data;
|
using DiscordChatExporter.Core.Discord.Data;
|
||||||
using DiscordChatExporter.Gui.Framework;
|
using DiscordChatExporter.Gui.Framework;
|
||||||
|
using DiscordChatExporter.Gui.Utils.Extensions;
|
||||||
using DiscordChatExporter.Gui.ViewModels.Components;
|
using DiscordChatExporter.Gui.ViewModels.Components;
|
||||||
|
|
||||||
namespace DiscordChatExporter.Gui.Views.Components;
|
namespace DiscordChatExporter.Gui.Views.Components;
|
||||||
@@ -18,7 +19,7 @@ public partial class DashboardView : UserControl<DashboardViewModel>
|
|||||||
private void AvailableGuildsListBox_OnSelectionChanged(
|
private void AvailableGuildsListBox_OnSelectionChanged(
|
||||||
object? sender,
|
object? sender,
|
||||||
SelectionChangedEventArgs args
|
SelectionChangedEventArgs args
|
||||||
) => DataContext.PullChannelsCommand.Execute(null);
|
) => DataContext.PullChannelsCommand.ExecuteIfCan(null);
|
||||||
|
|
||||||
private void AvailableChannelsTreeView_OnSelectionChanged(
|
private void AvailableChannelsTreeView_OnSelectionChanged(
|
||||||
object? sender,
|
object? sender,
|
||||||
@@ -40,6 +41,6 @@ public partial class DashboardView : UserControl<DashboardViewModel>
|
|||||||
if (DataContext.SelectedChannels.Count != 1)
|
if (DataContext.SelectedChannels.Count != 1)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
DataContext.ExportCommand.Execute(null);
|
DataContext.ExportCommand.ExecuteIfCan(null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -54,8 +54,7 @@ public partial class HyperLink : UserControl
|
|||||||
{
|
{
|
||||||
if (Command is not null)
|
if (Command is not null)
|
||||||
{
|
{
|
||||||
if (Command.CanExecute(CommandParameter))
|
Command.ExecuteIfCan(CommandParameter);
|
||||||
Command.Execute(CommandParameter);
|
|
||||||
}
|
}
|
||||||
else if (!string.IsNullOrWhiteSpace(Url))
|
else if (!string.IsNullOrWhiteSpace(Url))
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user