Esempio n. 1
0
        private void ProcessCommand(IStudioCommand command, IStudioCommandScope scope)
        {
            var handlers = TryGetHandlers(command);

            if (handlers == null)
            {
                return;
            }

            var scopeHandlers = handlers.TryGetValue(scope) ?? (command.CanRouteToGlobalScope ? handlers.TryGetValue(_globalScope) : null);

            if (scopeHandlers == null)
            {
                return;
            }

            var guiAsyncActions = new List <Tuple <CommandTuple, IStudioCommand> >();

            foreach (var tuple in scopeHandlers.CachedValues)
            {
                if (!tuple.Item3)
                {
                    ProcessCommand(tuple, command);
                }
                else
                {
                    guiAsyncActions.Add(Tuple.Create(tuple, command));
                }
            }

            if (!guiAsyncActions.IsEmpty())
            {
                GuiDispatcher.GlobalDispatcher.AddAction(() => guiAsyncActions.ForEach(t => ProcessCommand(t.Item1, t.Item2)));
            }
        }
Esempio n. 2
0
        private static void BindStrategyToScope(this StrategyContainer strategy, IStudioCommandScope control)
        {
            var cmdSvc = ConfigManager.GetService <IStudioCommandService>();

            strategy.StrategyRemoved  += cmdSvc.UnBind;
            strategy.StrategyAssigned += newStrategy => cmdSvc.Bind(newStrategy, control);

            if (strategy.Strategy != null)
            {
                cmdSvc.Bind(strategy.Strategy, control);
            }
        }
Esempio n. 3
0
        private void ReplaceHandlersScope(object sender, IStudioCommandScope oldScope, IStudioCommandScope newScope)
        {
            lock (_handlers.SyncRoot)
            {
                foreach (var handlers in _handlers)
                {
                    var scopeHandlers = handlers.Value.TryGetValue(oldScope);

                    if (scopeHandlers == null)
                    {
                        continue;
                    }

                    var handler = scopeHandlers.TryGetValue(sender);

                    if (handler != null)
                    {
                        scopeHandlers.Remove(sender);
                        handlers.Value.SafeAdd(newScope)[sender] = handler;
                    }
                }
            }
        }
Esempio n. 4
0
        void IStudioCommandService.Bind(object sender, IStudioCommandScope scope)
        {
            if (sender == null)
            {
                throw new ArgumentNullException(nameof(sender));
            }

            if (scope == null)
            {
                throw new ArgumentNullException(nameof(scope));
            }

            _binds.Add(sender, scope);

            var s = _scopes.TryGetValue(sender);

            if (s != null)
            {
                ReplaceHandlersScope(sender, s, scope);
            }

            _scopes[sender] = scope;
        }
Esempio n. 5
0
 public void Bind(object sender, IStudioCommandScope scope)
 {
 }