static void SafeExecute( this ICommand command, MouseState state, object parameter )
		{
			var args = new MouseCommandArgs { MouseState = state, Parameter = parameter };
			if ( command != null && command.CanExecute( args ) )
			{
				command.Execute( args );
			}
		}
Пример #2
1
		public static bool CanDebug (this ProjectOperations opers, IBuildTarget entry)
		{
			ExecutionContext context = new ExecutionContext (DebuggingService.GetExecutionHandler (), IdeApp.Workbench.ProgressMonitors, IdeApp.Workspace.ActiveExecutionTarget);
			return opers.CanExecute (entry, context);
		}
Пример #3
1
 public static bool CanExecute( this ICommand command )
 {
     Arg.NotNull( command, nameof( command ) );
     return command.CanExecute( null );
 }
Пример #4
0
    /// <summary>
    /// Returns an observable sequence that indicates when the <paramref name="command"/> can be executed, 
    /// starting with the current state of the <paramref name="command"/>.
    /// </summary>
    /// <remarks>
    /// The observable is a sequence of values returned by <see cref="ICommand.CanExecute"/> 
    /// whenever the <paramref name="command"/> raises its <see cref="ICommand.CanExecuteChanged"/> event.
    /// </remarks>
    /// <param name="command">The <see cref="ICommand"/> to be observed.</param>
    /// <param name="parameter">The object that is passed to the <see cref="ICommand.CanExecute"/> method.
    /// This value can be <see langword="null"/> if the <paramref name="command"/> supports it.</param>
    /// <returns>An observable sequence that indicates when the <paramref name="command"/> can be executed, 
    /// starting with the current state of the <paramref name="command"/>.</returns>
    public static IObservable<bool> CanExecuteObservable(
      this ICommand command,
      object parameter)
    {
      Contract.Requires(command != null);
      Contract.Ensures(Contract.Result<IObservable<bool>>() != null);

      return Observable.FromEventPattern(
        handler => command.CanExecuteChanged += handler,
        handler => command.CanExecuteChanged -= handler)
        .Select(_ => command.CanExecute(parameter))
        .Publish(command.CanExecute(parameter))
        .RefCount()
        .DistinctUntilChanged();
    }
Пример #5
0
 public static void VerifyAndExecute(this ICommand command, object parameter)
 {
     if (command != null && command.CanExecute(parameter))
     {
         command.Execute(parameter);
     }
 }
Пример #6
0
 /// <summary>
 /// Executes if the specified <see cref="ICommand"/> with the specified argument if it can be executed.
 /// </summary>
 /// <param name="command">The command to try to execute.</param>
 /// <param name="arg">The arg specified in the command.</param>
 public static void TryExecute(this ICommand command, object arg)
 {
     if (command.CanExecute(arg))
     {
         command.Execute(arg);
     }
 }
        public static void ExecuteIfCan(this IReactiveCommand @this, object o)
        {
            if (@this == null)
                return;

            if (@this.CanExecute(o))
                @this.Execute(o);
        }
        /// <summary>Executes a command if it is able.</summary>
        public static void ExecuteIfCan(this ICommand command, object parameter)
        {
            if (command == null)
                return;

            if (command.CanExecute(parameter))
                command.Execute(parameter);
        }
 public static bool TryExecute(this ICommand command, object parameter = null)
 {
     var canExecute = command.CanExecute(parameter);
     if (canExecute)
     {
         command.Execute(parameter);
     }
     return canExecute;
 }
Пример #10
0
        public static IDisposable BindToTarget(this ICommand This, UIControl control, UIControlEvent events)
        {
            var ev = new EventHandler((o,e) => {
                if (!This.CanExecute(null)) return;
                This.Execute(null);
            });

            control.AddTarget(ev, events);
            return Disposable.Create(() => control.RemoveTarget(ev, events));
        }
Пример #11
0
        public static bool TryExecute(this ICommand command, object parameter)
        {
            if (command.CanExecute(parameter))
            {
                command.Execute(parameter);
                return true;
            }

            return false;
        }
        public static IDisposable BindToTarget(this ICommand This, View control)
        {
            var ev = new EventHandler((o, e) => {
                if (!This.CanExecute(null)) return;
                This.Execute(null);
            });

            var cech = new EventHandler((o, e) => {
                var canExecute = This.CanExecute(null);
                control.Enabled = canExecute;
            });

            This.CanExecuteChanged += cech;
            control.Click += ev;

            control.Enabled = This.CanExecute(null);

            return Disposable.Create(() => {
                This.CanExecuteChanged -= cech;
                control.Click -= ev;
            });
        }
        public static IDisposable BindToTarget(this ICommand This, UIControl control, UIControlEvent events)
        {
            var ev = new EventHandler((o,e) => {
                if (!This.CanExecute(null)) return;
                This.Execute(null);
            });

            var cech = new EventHandler((o, e) => {
                var canExecute = This.CanExecute(null);
                control.Enabled = canExecute;
            });

            This.CanExecuteChanged += cech;
            control.AddTarget(ev, events);

            control.Enabled = This.CanExecute(null);

            return Disposable.Create(() => {
                control.RemoveTarget(ev, events);
                This.CanExecuteChanged -= cech;
            });
        }
 /// <summary>
 /// Will call the Execute method for a command, iff the command can execute.
 /// </summary>
 /// <param name="command">Command to execute.</param>
 public static void ExecuteIfCan(this ICommand command)
 {
     if (command.CanExecute())
         command.Execute();
 }
Пример #15
0
 public static void TryExecute(this ICommand command, object parameter)
 {
     if (command.CanExecute(parameter))
         command.Execute(parameter);
 }
 static void SafeExecute( this ICommand command, object parameter )
 {
     if ( command != null && command.CanExecute( null ) )
     {
         command.Execute( parameter );
     }
 }
		static void SafeExecute( this ICommand dragCommand, ClickDragInfo dragInfo, object parameter )
		{
			var args = new MouseDragCommandArgs { DragInfo = dragInfo, Parameter = parameter };
			if ( dragCommand != null && dragCommand.CanExecute( args ) )
			{
				dragCommand.Execute( args );
			}
		}
Пример #18
0
 public static void ExecuteAsync(this DefaultableCompositeCommand command, object arg)
 {
     if (command.CanExecute(arg))
     {
         command.Execute(arg);
     }
 }
Пример #19
0
		/// <summary>
		/// Raises an appropriate ScriptRuntimeException if the specified access is not supported.
		/// Checks are made for the MemberDescriptorAccess permissions AND for the access of instance
		/// members through static userdatas.
		/// </summary>
		/// <param name="desc">The desc.</param>
		/// <param name="access">The access.</param>
		/// <param name="obj">The object to be checked for access.</param>
		public static void CheckAccess(this IMemberDescriptor desc, MemberDescriptorAccess access, object obj)
		{
			if (!desc.IsStatic && obj == null)
				throw ScriptRuntimeException.AccessInstanceMemberOnStatics(desc);

			if (access.HasAllFlags(MemberDescriptorAccess.CanExecute) && !desc.CanExecute())
				throw new ScriptRuntimeException("userdata member {0} cannot be called.", desc.Name);

			if (access.HasAllFlags(MemberDescriptorAccess.CanWrite) && !desc.CanWrite())
				throw new ScriptRuntimeException("userdata member {0} cannot be assigned to.", desc.Name);

			if (access.HasAllFlags(MemberDescriptorAccess.CanRead) && !desc.CanRead())
				throw new ScriptRuntimeException("userdata member {0} cannot be read from.", desc.Name);
		}
Пример #20
0
 public static void ExecuteIfItCan(this ICommand cmd, object parameter = null)
 {
     if (cmd.CanExecute(parameter))
         cmd.Execute(parameter);
 }
Пример #21
0
 public static bool CanExecute(this ICommand command)
 {
     return command.CanExecute(null);
 }
 public static ICommand AllowWhenNoErrors(this ICommand command, IDataErrorInfo viewModel)
 {
     return new DelegateCommand(command.Execute, x => string.IsNullOrWhiteSpace(viewModel.Error) && command.CanExecute(x));
 }
 public static void ExecuteIfCan(this ICommand @this, object o)
 {
     if (@this.CanExecute(o))
         @this.Execute(o);
 }