public void Register(IMacroHandler handler) { if (handler == null) { throw new ArgumentNullException(nameof(handler)); } var id = handler.ID; if (string.IsNullOrWhiteSpace(id)) { throw new ArgumentException("Handler ID is not set"); } if (_handlers.Any(h => h.ID == id)) { return; } _handlers.Add(handler); }
///////////////////////////////////////////////////////////////////////////// public IMacro AddBuiltinMacro( string macroName, IMacroHandler mh, object handlerData ) { using( new NMP.NmpMakeCurrent(nmp) ) { return nmp.MacroProcessor.AddBuiltinMacro( macroName, mh, handlerData ); } }
///////////////////////////////////////////////////////////////////////////// public static Macro NewTextMacro( IMacroProcessor mp, string name, IMacroHandler mh, string macroText, IList<string> argNames ) { // ****** Macro macro = new Macro( name, MacroType.Text, mh, null, macroText, argNames, mp ); // ****** return macro; }
///////////////////////////////////////////////////////////////////////////// public static Macro NewBuiltinMacro( IMacroProcessor mp, string name, IMacroHandler mh, object handlerData ) { // ****** Macro macro = new Macro( name, MacroType.Builtin, mh, null, null, null, mp ); macro.MacroHandlerData = handlerData; // ****** return macro; }
///////////////////////////////////////////////////////////////////////////// public static Macro NewBuiltinMacro( IMacroProcessor mp, string name, IMacroHandler mh, MacroCall method ) { // ****** Macro macro = new Macro( name, MacroType.Builtin, mh, null, null, null, mp ); macro.MacroHandlerData = method; // ****** return macro; }
///////////////////////////////////////////////////////////////////////////// public static Macro NewBuiltinMacro( IMacroProcessor mp, string name, IMacroHandler mh ) { return new Macro( name, MacroType.Builtin, mh, null, null, null, mp ); }
///////////////////////////////////////////////////////////////////////////// public static Macro NewObjectMacro( IMacroProcessor mp, string name, IMacroHandler mh, object netObj ) { return new Macro( name, MacroType.Object, mh, netObj, null, null, mp ); }
/////////////////////////////////////////////////////////////////////////////// // //public Macro( string name, MacroType macroType, CreateHandlerInstance createHandler, object netObj, string text, NmpStringList argNames ) // : this( name ) //{ // MacroType = macroType; // // //MacroHandler // CreateHandler = createHandler; // // MacroObject = netObj; // MacroText = string.IsNullOrEmpty(text) ? string.Empty : text; // ArgumentNames = null == argNames ? new NmpStringList() : argNames; //} // ///////////////////////////////////////////////////////////////////////////// public Macro( string name, MacroType macroType, IMacroHandler mh, object netObj, string text, IList<string> argNames, IMacroProcessor mp ) : this( name ) { // ****** MacroType = macroType; MacroHandler = mh; // ****** if( null != MacroHandler ) { IsBlockMacro = MacroHandler.HandlesBlocks; } // ****** MacroObject = netObj; MacroText = string.IsNullOrEmpty(text) ? string.Empty : text; // ****** ArgumentNames = null == argNames ? new NmpStringList() : argNames; for( int i = 0; i < ArgumentNames.Count; i++ ) { ArgumentNames[ i ] = ArgumentNames[ i ].Trim(); } // ****** MacroProcessor = mp; // ****** // // only do this if MacroProcessor is initialized - if it's not // we may be generating a macro for tooling, not when an actual // instance of NMP is running // if( null != MacroProcessor ) { //if( ThreadContext.PushbackResult ) { if( mp.GrandCentral.PushbackResult ) { Flags = MacroFlags.Pushback; } if( MacroType.Text == macroType ) { if( mp.GrandCentral.ExpandAndScan ) { Flags |= MacroFlags.FwdExpand; } } } // ****** PrivateData = null; }