예제 #1
0
        private IDisposable RegisterHotkeys(IEnumerable <Key> hotkeys, ITimelineStepViewModel action)
        {
            List <IDisposable> registrations = new List <IDisposable>();

            foreach (var hotkey in hotkeys)
            {
                string name = $"timeline_{hotkey.ToString()}";

                try
                {
                    NHotkey.Wpf.HotkeyManager.Current.AddOrReplace(name, hotkey, System.Windows.Input.ModifierKeys.None, (_, __) => Complete(action));

                    registrations.Add(Disposable.Create(() =>
                    {
                        NHotkey.Wpf.HotkeyManager.Current.Remove(name);
                    }));
                }
                catch (NHotkey.HotkeyAlreadyRegisteredException ex)
                {
                    // TODO LOG ! or show error !!!
                }
            }

            return(registrations.Any()
                 ? new CompositeDisposable(registrations)
                 : Disposable.Empty);
        }
예제 #2
0
        public void Proceed(SessionStepExecution execution)
        {
            ClearCallbacks();
            _hotkeysDisposable.Disposable = Disposable.Empty;

            _execution = execution;

            // wait for action executor completed
            // -> event Completed
            ITimelineStepViewModel action = ResolveStepActionViewModel(execution.Step.Action);

            // start timer
            // step.Completion.Duration
            // -> event Completed
            if (execution.Step.Completion.Duration.HasValue)
            {
                _timerDisposable.Disposable = new Timer(CompleteActionDurationTimer, action, execution.Step.Completion.Duration.Value, TimeSpan.FromMilliseconds(-1));
            }

            // set key shortcut
            // -> command
            // -> event Completed
            var hotkeys = ResolveHotkeys(execution.Step.Completion.Hotkeys);

            if (hotkeys.Any())
            {
                _hotkeysDisposable.Disposable = RegisterHotkeys(hotkeys, action);
            }

            Action = action;

            action.Execute(_recording);

            _recording.IsTimelineActive = action.IsContent;
        }
예제 #3
0
        private ITimelineStepViewModel ResolveStepActionViewModel(SessionStepActionSettings action)
        {
            ITimelineStepViewModel stepViewModel = null;

            if (_resolver.CanCreate(action))
            {
                stepViewModel = (ITimelineStepViewModel)_resolver.Create(action);
            }

            return(stepViewModel);
        }
예제 #4
0
        private bool Complete(ITimelineStepViewModel action)
        {
            ClearCallbacks();

            if (action != null && Action == action)
            {
                action.Completed -= Action_Completed;

                _execution.Result = action.Complete();      // Complete may be called twice

                StepCompleted?.Invoke(this, _execution);

                return(true);
            }

            return(false);
        }