Exemplo n.º 1
0
        /// <summary>
        /// Handles IUICommandHandler.Execute function for supported events
        /// </summary>
        /// <param name="verb">the mode of execution</param>
        /// <param name="key">the property that has changed</param>
        /// <param name="currentValue">the new value of the property that has changed</param>
        /// <param name="commandExecutionProperties">additional data for this execution</param>
        /// <returns>Returns S_OK if successful, or an error value otherwise</returns>
        public override HRESULT Execute(ExecutionVerb verb, PropertyKeyRef key, PropVariantRef currentValue, IUISimplePropertySet commandExecutionProperties)
        {
            if (verb == ExecutionVerb.Execute)
            {
                if (ExecuteEvent != null)
                {
                    try
                    {
                        ExecuteEvent(_sender, new ExecuteEventArgs(key, currentValue, commandExecutionProperties));
                    }
                    catch (Exception ex)
                    {
                        BaseRibbonControl ctrl = _sender as BaseRibbonControl;
                        if (ctrl != null)
                        {
                            ThreadExceptionEventArgs e = new ThreadExceptionEventArgs(ex);
                            if (ctrl._ribbon.OnRibbonEventException(_sender, e))
                            {
                                return(HRESULT.E_FAIL);
                            }
                        }
                        Environment.FailFast(ex.StackTrace);
                        return(HRESULT.E_ABORT);
                    }
                }
            }

            return(HRESULT.S_OK);
        }
Exemplo n.º 2
0
 /// <summary>
 /// Called for each Command specified in the Windows Ribbon (Ribbon) framework markup to bind
 /// the Command to an IUICommandHandler.
 /// </summary>
 /// <param name="commandId">The ID for the Command, which is specified in the markup resource file.</param>
 /// <param name="typeID">The Command type that is associated with a specific control.</param>
 /// <param name="commandHandler">When this method returns, contains the address of a pointer to an
 /// IUICommandHandler object. This object is a host application Command handler that is bound to one or
 /// more Commands.</param>
 /// <returns>Returns S_OK if successful, or an error value otherwise.</returns>
 public HRESULT OnCreateUICommand(uint commandId, CommandType typeID, out IUICommandHandler commandHandler)
 {
     if (_ribbonControl.MapRibbonControls.ContainsKey(commandId))
     {
         BaseRibbonControl control = _ribbonControl.MapRibbonControls[commandId] as BaseRibbonControl;
         if (control != null)
         {
             control.CommandType = typeID;
         }
     }
     commandHandler = _ribbon;
     return(HRESULT.S_OK);
 }