//\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
//
// UserWin satellite library | Author: Sergei Y.Kitáev
//
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
using System;

using System.Windows;
using System.Windows.Input;

using CommonHelpers;

namespace UserWin {

//**************************************************************************************************
/// <summary>
/// </summary>
public static partial class UXCommand {
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

public static void Suppress(UIElement element,ICommand command)
{
   element.CommandBindings.Add(
      new CommandBinding( command, null, SuppressCommand_Handler ));
}

//--------------------------------------------------------------------------------------------------

public static bool TryExecute(RoutedCommand command)
{
   return TryExecute(false,command);
}

public static bool TryExecute(RoutedCommand command,object paramater)
{
   return TryExecute(false,command,paramater);
}

public static bool TryExecute(RoutedCommand command,object paramater,IInputElement target)
{
   return TryExecute(false,command,paramater,target);
}

//--------------------------------------------------------------------------------------------------

public static bool TryExecute( bool soundSignalDisabled,
                               RoutedCommand command )
{
   return TryExecute(soundSignalDisabled,command,null);
}

public static bool TryExecute( bool soundSignalDisabled,
                               RoutedCommand command,
                               object paramater )
{
   return TryExecute(soundSignalDisabled,command,paramater,null);
}

public static bool TryExecute( bool soundSignalDisabled,
                               RoutedCommand command,
                               object paramater,
                               IInputElement target )
{
   if (command.CanExecute( paramater, target ))
   {
      command.Execute( paramater, target );
      return true;
   }
   if (soundSignalDisabled)
      HSound.PlayDisabled();
   return false;
}

//--------------------------------------------------------------------------------------------------

public static void SuppressCommand_Handler(object sender,CanExecuteRoutedEventArgs e)
{
   e.CanExecute=false; e.Handled=true;
}

//==================================================================================================

static UXCommand()
{
   UserWin_Library.Access();
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
} // UXCommand
//**************************************************************************************************

} // UserWin
