소스 검색

Add explicit 'verify' event for constraints/actions.

Bentley James Oakes 7 년 전
부모
커밋
0a180528c5
3개의 변경된 파일60개의 추가작업 그리고 42개의 파일을 삭제
  1. 3 2
      doc/new_language.rst
  2. 56 39
      mmmk.js
  3. 1 1
      types.js

+ 3 - 2
doc/new_language.rst

@@ -235,8 +235,9 @@ The events that can trigger are:
 * **post-disconnect**, which triggers just after a link between two instances is deleted
 * **post-delete**, which triggers just after an instance is deleted
 * **post-edit**, which triggers just after an instance is edited
+* **verify**, which triggers when the user presses the *verify* button on the *MainMenu* toolbar
 
-.. note:: A constraint without a trigger is evaluated when the user presses the *verify* button on the *MainMenu* toolbar.
+.. note:: A constraint/action with no defined triggers will execute on the *verify* event. These constraints/actions should be updated to select the event explicitly.
 
 .. _action-library:
 
@@ -365,4 +366,4 @@ To compile your concrete syntax, make sure the current active model is the concr
 
 .. image:: img/compile_cs.png
 
-Each time you make a change to your abstract or concrete syntax, recompile them before using them.
+Each time you make a change to your abstract or concrete syntax, recompile them before using them.

+ 56 - 39
mmmk.js

@@ -813,41 +813,55 @@ module.exports = {
 				types2ids[type].push(id);
 			}
 
-			for( var i in allHandlers )
-			{
-				var handler = allHandlers[i];
-				if( _utils.contains(events,handler['event']) )
-				{
-					if( handler['targetType'] == '*' )
-					{
-						for( var j in ids )
-							if( (res = this.__runDesignerCode(
-														handler['code'],
-														handler['event']+' '+handler['name'],
-														handlerType,
-														ids[j])) )
-								return res;
-
-						if( ids.length == 0 )
-							if( (res = this.__runDesignerCode(
-														handler['code'],
-														handler['event']+' '+handler['name'],
-														handlerType)) )
-								return res;
-					}
-					else
-						for( var j in types2ids[handler['targetType']] )
-						{
-							var id = types2ids[handler['targetType']][j];
-							if( (res = this.__runDesignerCode(
-														handler['code'],
-														handler['event']+' '+handler['name'],
-														handlerType,
-														id)) )
-								return res;
-						}
-				}
-			}
+            for (let i in allHandlers) {
+                let handler = allHandlers[i];
+
+                let handled = _utils.contains(events, handler['event']) ||
+                    (_utils.contains(events, "validate") && handler['event'] == ""); //handle legacy events
+
+                if (!handled) {
+                    continue;
+                }
+                if (handler['targetType'] == '*') {
+                    let result = null;
+                    for (let j in ids) {
+                        result = this.__runDesignerCode(
+                            handler['code'],
+                            handler['event'] + ' ' + handler['name'],
+                            handlerType,
+                            ids[j]);
+                        if (result) {
+                            return result;
+                        }
+                    }
+
+                    if (ids.length == 0) {
+                        result = this.__runDesignerCode(
+                            handler['code'],
+                            handler['event'] + ' ' + handler['name'],
+                            handlerType);
+
+                        if (result) {
+                            return result;
+                        }
+                    }
+                }
+                else {
+                    for (let j in types2ids[handler['targetType']]) {
+                        let id = types2ids[handler['targetType']][j];
+                        let result = this.__runDesignerCode(
+                            handler['code'],
+                            handler['event'] + ' ' + handler['name'],
+                            handlerType,
+                            id);
+
+                        if (result) {
+                            return result;
+                        }
+                    }
+                }
+
+            }
 		},
 
 
@@ -954,10 +968,13 @@ module.exports = {
                     checked_for_loops= checked_for_loops.concat(visited);
                 }
 			}
-			
-			for( var metamodel in this.metamodels )
-				if( (err=this.__runEventHandlers(this.metamodels[metamodel]['constraints'], [''], [], 'constraint')) )
-					return err;
+
+            for (let metamodel in this.metamodels) {
+
+                let err = this.__runEventHandlers(this.metamodels[metamodel]['constraints'], ['validate'], [], 'constraint');
+                if (err)
+                    return err;
+            }
 		},
 
 

+ 1 - 1
types.js

@@ -8,7 +8,7 @@ __specialTypes = {
 
 	'$CARDINALITY':'map<[dir,type,min,max],[string,string,string,string]>',
 
-	'$EVENT':'ENUM(pre-connect,pre-create,pre-disconnect,pre-delete,pre-edit,post-connect,post-create,post-disconnect,post-delete,post-edit)',
+	'$EVENT':'ENUM(pre-connect,pre-create,pre-disconnect,pre-delete,pre-edit,post-connect,post-create,post-disconnect,post-delete,post-edit,validate)',
 
 	'$EVENT_HANDLER':'map<[name,event,code],[string,$EVENT,code]>',