/// <summary> /// Determine if an action should be enabled. /// </summary> /// <param name="actionName">The action name.</param> /// <returns>True if the action should be enabled. False if not or /// the action doesn't exist.</returns> public bool IsActionEnabled(string actionName) { /* * Return false if the action doesn't exist. * Cannot enable an action it can't do. */ if (!_actionStateHandlers.ContainsKey(actionName)) { return(false); } ActionStateHandler d = _actionStateHandlers[actionName]; if (d != null) { return(d()); } else { return(false); } }
/* * ActionState Handlers * * ActionState handlers allow a document to register callback * methods with the MainForm. Each callback responds to a * particular action available from a MainForm UI element * (menu and toolbar). When a document becomes active the * mainform calls each method registered for that document to * determine the state of each available UI element. * * If the callback returns false or no callback has been * registered the corresponding UI element will be disabled. */ /// <summary> /// Register an ActionState handler for the document. ActionState /// handlers allow a document to register callback methods with document /// management system. Each callback responds to a particular action /// available from a MainForm UI element (menu and toolbar). When a /// document becomes active the document manager calls each method /// registered for that document to determine the state of each available /// UI element. If the callback returns false or no callback has been /// registered the corresponding UI element will be disabled. /// </summary> /// <param name="action">The name of the action.</param> /// <param name="handler">The ActionState event handler.</param> public void RegisterActionStateHandler( string action, ActionStateHandler handler) { _actionStateHandlers[action] = handler; }