public GIIMacroCommand(string name) { _subCommands = new Queue <IGIICommand>(); _currentCommand = null; _name = name; _needsClosure = false; }
void processCommand(IGIICommand cmd) { // 立即执行,并且结束 !!(所以对于 MacroCommand,如果有一个操作需要等待,则整个操作都不立即执行) cmd.ExecuteInCommandCenter(this); if (!cmd.IsFinished()) { _pendingCommands.Push(cmd); } // 处理由该Command产生的消息 sendPendingEvents(_inProcessingCommands + 1); }
public void AddSubCommand(IGIICommand command) { if (_currentCommand == null) { _currentCommand = command; } else { _subCommands.Enqueue(command); } if (!_needsClosure && command.NeedsClosure()) { // 只要有一个子指令需要等待,则该操作需要等待 _needsClosure = true; } }
public virtual bool ExecuteInCommandCenter(IGIICommandCenter commandCenter) { if (_currentCommand == null) { // 出现这种情况的时候表示当前指令已经执行完 // Debug.Assert(false, "!! Current Command is finished already !!"); return(true); } _currentCommand.ExecuteInCommandCenter(commandCenter); while (_currentCommand.IsFinished() && _subCommands.Count > 0) { _currentCommand = _subCommands.Dequeue(); _currentCommand.ExecuteInCommandCenter(commandCenter); } if (_currentCommand.IsFinished()) { _currentCommand = null; return(true); } return(_currentCommand.IsFinished()); // always false }
// public virtual bool IsClosureEvent(string eventName) // { // if(_currentCommand == null) // { // // 出现这种情况的时候表示当前指令已经执行完 // Debug.Assert(false, "!! Current Command is finished already !!"); // return true; // } // // return _currentCommand.IsClosureEvent (eventName); // } // 执行结束事件 // 返回:当前指令是否结束 public virtual bool OnClosureEvent(string eventName, IGIICommandCenter commandCenter) { if (_currentCommand == null) { // 出现这种情况的时候表示当前指令已经执行完 Debug.Assert(false, "!! Current Command is finished already !!"); return(true); } if (_currentCommand.OnClosureEvent(eventName, commandCenter)) { // 是当前指令期待的结束符 _currentCommand = null; if (_subCommands.Count > 0) { // 下一个指令 _currentCommand = _subCommands.Dequeue(); ExecuteInCommandCenter(commandCenter); } } return(IsFinished()); }