Exemplo n.º 1
0
        private void AddModificationToUndoRedoManager(IModification modification)
        {
            if ((UndoRedoManager != null) && (modification is IUndoableRedoable))
            {
                //To do: Dodanie nie ustawialnej listy nie wspieranych przez undoRedoManager typów modyfikacji
                if (modification is SubtitlesEditStateModification)
                {
                    return;
                }
                //else if ((modification is CompositeModification) && (UndoRedoManager.LastUndoableRedoable is CompositeModification))
                //{
                ////Co z sytuacją keidy mamy tylko SubtitlesContentModification, a nie composite?
                //var currentCompositeMod = (CompositeModification)modification;
                //var currentContentMods = from mod in currentCompositeMod where mod is SubtitlesContentModification select mod;

                //var lastCompositeMod = (CompositeModification)UndoRedoManager.LastUndoableRedoable;
                //var lastContentMods = from mod in lastCompositeMod where mod is SubtitlesContentModification select mod;

                //if (new HashSet<IModification>(currentContentMods).SetEquals(lastContentMods))
                //{
                //    UndoRedoManager.DeleteLastUndoableRedoeable();
                //}
                //}

                UndoRedoManager.AddUndoableRedoable(modification as IUndoableRedoable);
            }
        }
Exemplo n.º 2
0
 public static void DoModificationWithSelectionTracking(IModification mod, ComboBox animBox, ListBox frameBox, ListBox frameSpriteBox)
 {
     mod.SetPreChangeSelection(new SelectionState(animBox, frameBox, frameSpriteBox));
     mod.Do();
     mod.SetPostChangeSelection(new SelectionState(animBox, frameBox, frameSpriteBox));
     Console.WriteLine("Perform: " + mod);
 }
        /// <summary>
        /// Revert passed modification, if found in queue.
        /// </summary>
        /// <param name="modification">Modification to revert.</param>
        public void RevertModification(IModification modification)
        {
            // Find match.
            var match = _queue.FirstOrDefault(x => x == modification);

            // Can't revert a modification not in the queue.
            if (match == null)
            {
                throw new ArgumentException($"Modification [{modification}] not found, cannot revert.");
            }

            // Can't revert unless execution already took place.
            if (match.Status != Status.ExecuteSucceeded)
            {
                throw new ArgumentException($"Modification [{modification}] 'Status' must be Status.ExecuteSucceeded to revert.");
            }

            // Revert modification.
            match.Revert();

            // Update status and remove from queue.
            if (match.Status == Status.RevertSucceeded)
            {
                _queue.Remove(match);
            }
        }
 /// <summary>
 ///     Register a modification that can be brought with scraps in the modification menu
 /// </summary>
 /// <param name="modificationTarget">The type of something that can be modified (drone upgrade for example)</param>
 /// <param name="modification">An instance of the modification</param>
 public void RegisterModificationFor(Type modificationTarget, IModification modification)
 {
     if (!modificationsByType.ContainsKey(modificationTarget))
     {
         modificationsByType[modificationTarget] = new List <IModification>();
     }
     modificationsByType[modificationTarget].Add(modification);
 }
Exemplo n.º 5
0
        protected override void Initialize(object parameter)
        {
            _modification = parameter as IModification;
            if (_modification == null)
            {
                return;
            }

            this.NotifyPropertyChanged("Modification");
        }
Exemplo n.º 6
0
 public void Add(IModification change)
 {
     if (position < changes.Count - 1)
     {
         changes.RemoveRange(position + 1, changes.Count - 1 - position);
     }
     changes.Add(change);
     position = changes.Count - 1;
     OnHistoryUpdated();
 }
Exemplo n.º 7
0
    public bool Equals(IModification <MySolution> other_)
    {
        MyModification other = other_ as MyModification;

        if (other == null)
        {
            return(false);
        }

        return(true);
    }
Exemplo n.º 8
0
 private void AssignModificationTarget(IModification modification)
 {
     if (modification is IModificationSource <SubtitlesEditor> )
     {
         var mod = modification as IModificationSource <SubtitlesEditor>;
         if (mod.ModificationTarget == null)
         {
             mod.ModificationTarget = this;
         }
     }
 }
Exemplo n.º 9
0
        public static Account ApplyChanges(object parent, IModification <Account> mod, EntityContext context)
        {
            Account acct = context.ApplyChanges(parent, mod);

            if (mod.Type == ModificationType.Add)
            {
                acct.Password  = CryptoUtil.HashPassword(acct.Password);
                acct.DateAdded = DateTime.UtcNow;
            }
            acct.Status        = ACCOUNT_STATUS.ACTIVE;
            acct.LastLoginDate = DateTime.UtcNow;
            return(acct);
        }
Exemplo n.º 10
0
 internal void AddUndoOperation([NotNull] IModification m)
 {
     if (_RedoStack.Count > 0)
     {
         foreach (var md in _RedoStack)
         {
             md.Dispose();
         }
         _RedoStack.Clear();
     }
     _UndoStack.Push(m);
     Course.NotifyChanged();
 }
Exemplo n.º 11
0
        public void Redo()
        {
#if CHECKERS
            if (!CanRedo)
            {
                throw new InvalidOperationException();
            }
#endif
            IModification m = _RedoStack.Pop();
            m.Redo();
            _UndoStack.Push(m);
            Course.NotifyChanged();
        }
Exemplo n.º 12
0
        private SubtitlesEditState TryGetModifiedEditState()
        {
            //Jeśli modyfikacja należy do grupy modyfikacji
            //to sprawdzamy czy następna modyfikacja w grupie jest modyfikacją stanu edytowania.
            if ((Group != null) && (GroupIndex + 1 < Group.Count))
            {
                IModification mod = Group[GroupIndex + 1];
                if (mod is SubtitlesEditStateModification)
                {
                    return((mod as SubtitlesEditStateModification).ModifiedState);
                }
            }

            return(null);
        }
Exemplo n.º 13
0
        /// <summary>
        /// Wykonuje wskazana modyfikację.
        /// </summary>
        /// <param name="modification">Obiekt implementujący interfejs modyfikacji.</param>
        /// <remarks>
        /// </remarks>
        public void PerformModification(IModification modification)
        {
            if (modification is CompositeModification)
            {
                foreach (var mod in (modification as CompositeModification))
                {
                    AssignModificationTarget(mod);
                }
            }
            else
            {
                AssignModificationTarget(modification);
            }

            modification.Perform();

            AddModificationToUndoRedoManager(modification);
        }
        public void RevertModification(IModification modification)
        {
            var match = _queue.FirstOrDefault(x => x == modification);

            if (match == null)
            {
                throw new ArgumentException("Modification not found");
            }
            if (match.Status != Status.ExecuteSucceeded)
            {
                throw new ArgumentException("Modification must be be...");
            }
            match.Revert();

            if (match.Status == Status.RevertSucceeded)
            {
                _queue.Remove(match);
            }
        }
 public void AddModification(IModification modification)
 {
     _queue.Add(modification);
 }
 public void ApplyChange(IModification <T> newModification)
 {
     Commit(newModification);
 }
Exemplo n.º 17
0
 private async Task OnItemClickCommand(IModification arg)
 {
     NavigationServiceCustom.NavigateTo <ModificationPageVm>(arg);
 }
Exemplo n.º 18
0
        //protected void Inject_ClassCreationHook(ClassCreationHook classCreationHook)
        //{
        //    var meth = MethodBaseToMethodDefinition(classCreationHook.InterceptCreationInMethod);
        //    //var conType = Module.Import(classCreationHook.ClassToInterceptCreation);
        //    var ilgen = meth.Body.GetILProcessor();
        //    for (var i = 0; i < meth.Body.Instructions.Count; i++)
        //    {
        //        var ins = meth.Body.Instructions[i];
        //        if (ins.OpCode == OpCodes.Newobj)
        //        {
        //            var trgMeth = ins.Operand as MethodReference;
        //            if (Helper_TypeReference_to_Type(trgMeth.DeclaringType) == classCreationHook.ClassToInterceptCreation)
        //            //if ((trgMeth.DeclaringType == conType) && trgMeth.Name == ".ctor")
        //            {
        //                meth.Body.Instructions[i] = ilgen.Create(OpCodes.Call, Module.Import(classCreationHook.CustomCreationMethod));
        //            }
        //        }
        //    }
        //    //throw new NotImplementedException();
        //}
        internal void InjectModification(IModification modification)
        {
            if (modification == null)
            {
                throw new Exception("Modification is null.");
            }

            if (modification is MethodHook)
            {
                InjectHook(modification as MethodHook);
            }
            else if (modification is MethodAddVirtual)
            {
                Inject_Virtual(modification as MethodAddVirtual);
            }
            else if (modification is MethodRefHook)
            {
                Inject_RefHook(modification as MethodRefHook);
            }
            else if (modification is EnumAddElement)
            {
                Inject_AddEnumElement(modification as EnumAddElement);
            }
            else if (modification is ClassChangeBase)
            {
                Inject_ClassChangeBase(modification as ClassChangeBase);
            }
            //else if (modification is ClassCreationHook)
            //{
            //    Inject_ClassCreationHook(modification as ClassCreationHook);
            //}
            else if (modification is IModificationCollection)
            {
                foreach (var subModification in (modification as IModificationCollection))
                {
                    InjectModification(subModification);
                }
            }
            else
            {
                throw new Exception("Unknown change " + modification.GetType().FullName + "; failed to apply!");
            }
        }
Exemplo n.º 19
0
 public void Add(IModification modification)
 {
     modifications.Add(modification);
 }
Exemplo n.º 20
0
 private void DoModification(IModification mod)
 {
     ModHelper.DoModificationWithSelectionTracking(mod, animationBox, frameListBox, frameSpriteListBox);
     undoHistory.Add(mod);
 }
Exemplo n.º 21
0
 public static void RedoAndRestoreSelection(IModification mod, ComboBox animBox, ListBox frameBox, ListBox frameSpriteBox)
 {
     mod.Do();
     RestoreSelection(mod.GetPostChangeSelection(), animBox, frameBox, frameSpriteBox);
     Console.WriteLine("Redo: " + mod);
 }
Exemplo n.º 22
0
        void OnGUI()
        {
            if (implementations == null || implementations.Length == 0)
            {
                SearchConfigurationModifiers();
            }

            GUILayout.Label("Essentials Settings", EditorStyles.boldLabel);
            GUILayout.Label("");

            if (implementations != null && implementations.Length != 0)
            {
                GUILayout.Label("Recommended modifications:");

                EditorGUILayout.BeginHorizontal();

                EditorGUILayout.BeginVertical();
                foreach (var modificationType in implementations)
                {
                    IModification modification = (IModification)Activator.CreateInstance(modificationType);
                    if (!modification.showInSettingsWindow)
                    {
                        continue;
                    }
                    GUILayout.Label($" • {modification.title}");
                }
                EditorGUILayout.EndVertical();

                EditorGUILayout.BeginVertical();
                foreach (var modificationType in implementations)
                {
                    IModification modification = (IModification)Activator.CreateInstance(modificationType);
                    if (!modification.showInSettingsWindow)
                    {
                        continue;
                    }

                    EditorGUILayout.BeginHorizontal();

                    if (GUILayout.Button(new GUIContent(modification.infoButtonText, $"Open {modification.infoURL}")))
                    {
                        modification.OpenInfoURL();
                    }
                    GUILayout.Label(""); //Separation
                    GUILayout.Label(""); //Separation

                    if (GUILayout.Button(new GUIContent(modification.applyButtonText, modification.applyModificationShortEplanation)))
                    {
                        modification.Apply();
                    }
                    if (GUILayout.Button(new GUIContent(modification.revertButtonText, modification.revertModificationShortEplanation)))
                    {
                        modification.Revert();
                    }

                    EditorGUILayout.EndHorizontal();
                }
                EditorGUILayout.EndVertical();

                EditorGUILayout.EndHorizontal();

                GUILayout.Label("");


                EditorGUILayout.BeginHorizontal();
                if (GUILayout.Button("Apply all"))
                {
                    foreach (var modificationType in implementations)
                    {
                        IModification modification = (IModification)Activator.CreateInstance(modificationType);
                        modification.Apply();
                    }
                }

                if (GUILayout.Button("Revert all"))
                {
                    foreach (var modificationType in implementations)
                    {
                        IModification modification = (IModification)Activator.CreateInstance(modificationType);
                        modification.Revert();
                    }
                }
                EditorGUILayout.EndHorizontal();

                GUILayout.Label("");
            }

            GUILayout.Label("");

            #region Tooltip
            GUIStyle   style            = GUI.skin.label;  //get the current style of the GUI;
            TextAnchor defaultAlignment = style.alignment; // Expected: TextAnchor.MiddleLeft
            style.alignment = TextAnchor.MiddleRight;
            GUILayout.Label(GUI.tooltip, style);
            style.alignment = defaultAlignment;
            #endregion

            EditorGUILayout.BeginHorizontal();
            if (implementations != null)
            {
                EditorGUILayout.LabelField($"Found {implementations.Count()} modifications", EditorStyles.helpBox);
            }
            if (implementations == null)
            {
                EditorGUILayout.LabelField($"NO IMPLEMENTATIONS FOUND");
            }
            if (GUILayout.Button(new GUIContent("Search for modifications", "Search for any implementation of the abstract class 'Modification' to be displayed in this window.")) && implementations == null)
            {
                SearchConfigurationModifiers();
            }
            EditorGUILayout.EndHorizontal();
        }