Ejemplo n.º 1
0
            /// <summary>
            /// We allow grouping of the similar actions during the restricted time interval.
            /// </summary>
            /// <param name="otherAction"></param>
            /// <returns>True if groupped successfully.</returns>
            public bool TryGroupWith(EditorAction otherAction)
            {
                if (this.Title != otherAction.Title)
                {
                    return(false);
                }

                var timeDelta = otherAction.TimestampSeconds - this.TimestampSeconds;

                if (timeDelta < 0 ||
                    timeDelta > ActionsGroupingMaxTimeIntervalSeconds)
                {
                    return(false);
                }

                if (this.isDone)
                {
                    otherAction.Do();
                }

                this.listDo.AddRange(otherAction.listDo);
                this.listUndo.AddRange(otherAction.listUndo);
                otherAction.listDo.Clear();
                otherAction.listUndo.Clear();

                return(true);
            }
Ejemplo n.º 2
0
        public static void DoAction(string title, Action onDo, Action onUndo, bool canGroupWithPreviousAction = true)
        {
            Api.ValidateIsClient();

            var editorAction = new EditorAction(title, onDo, onUndo);

            // remove all non-done editor actions
            Actions.RemoveAll(a => !a.IsDone);
            var lastAction = Actions.LastOrDefault();

            if (lastAction is not null &&
                canGroupWithPreviousAction &&
                lastAction.TryGroupWith(editorAction))
            {
                // actions are grouped together. No need to call editorAction.Do().
                return;
            }

            Actions.Add(editorAction);
            editorAction.Do();
        }