Exemplo n.º 1
0
 /// <summary>
 /// Verification is handled by this form rather than the expression editor, as the expression editor is just for the
 /// expression rather than the equation object as a whole.
 /// </summary>
 private void inputWindow_Verify(object sender, ExpressionVerificationEventArgs e)
 {
     try
     {
         e.Equation.Parse();
     }
     catch (ParseException ex)
     {
         MessageBox.Show(ex.Message, "Equation Parse Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
         if (ex.Cause != null)
         {
             e.Cursor.Expression = ex.Cause.Parent;
             e.Cursor.Index      = ex.Cause.IndexInParent();
         }
         e.Failure = true;
     }
 }
Exemplo n.º 2
0
        /// <summary>
        /// Verifies that the entered expression is valid by iterating through all of the event
        /// handlers for the <see cref="Graphmatic.ExpressionEditor.Verify"/> event and checking that
        /// the <see cref="Graphmatic.ExpressionVerificationEventArgs.Failure"/> property is not
        /// set to true. If the property remains false, then this method returns true; this method
        /// returns false otherwise.
        /// </summary>
        /// <returns>Returns whether the expression verification was successful.</returns>
        private bool VerifyExpression()
        {
            EventHandler <ExpressionVerificationEventArgs> eventHandler = Verify;

            if (eventHandler != null)
            {
                var multicastHandlers = eventHandler.GetInvocationList();
                var eventArgs         = new ExpressionVerificationEventArgs()
                {
                    Cursor   = expressionDisplay.ExpressionCursor,
                    Failure  = false,
                    Equation = Equation
                };
                foreach (EventHandler <ExpressionVerificationEventArgs> multicastHandler in multicastHandlers)
                {
                    multicastHandler(this, eventArgs);
                    if (eventArgs.Failure)
                    {
                        return(false);
                    }
                }
            }
            return(true);
        }