Example #1
0
		/// <summary>
		/// Initializes a new instance of <see cref="UndoPopup"/>.
		/// </summary>
		/// <param name="undoManager">The undo manager used to populate the action list.</param>
		/// <param name="mode">The mode the popup shows actions for.</param>
		public UndoPopup(UndoManager undoManager, UndoPopupMode mode)
			: base(new Control())
		{
			// Set some defaults on the host control.
			Control.Margin = Padding.Empty;
			Control.Size = new Size(400, 300);
			Control.TabStop = false;

			// Add the listbox.
			_listBox = new ListBox
			{
				Dock = DockStyle.Fill,
				BorderStyle = BorderStyle.None,
				IntegralHeight = false,
				SelectionMode = SelectionMode.MultiSimple,
				HorizontalScrollbar = true
			};
			_listBox.MouseDown += ListBox_MouseDown;
			_listBox.MouseMove += ListBox_MouseMove;

			Control.Controls.Add(_listBox);

			// Create tooltip.
			_tooltip = new ToolTip();

			_mode = mode;
			UndoManager = undoManager;
		}
Example #2
0
        public void SetUp()
        {
            _comboBox = new ComboBox();
            _comboBox.SetValue(UndoManager.UndoScopeNameProperty, "ScopeName");
            _fakeVm = new FakeVm();
            var selected = new Binding("SelectedEnum")
            {
                Source = _fakeVm,
                UpdateSourceTrigger = UpdateSourceTrigger.Explicit,
                NotifyOnSourceUpdated = true,
                NotifyOnTargetUpdated = true,
                Mode = BindingMode.TwoWay
            };
            BindingOperations.SetBinding(_comboBox, Selector.SelectedItemProperty, selected);

            var itemsSource = new Binding("EnumValues")
            {
                Source = _fakeVm,
                UpdateSourceTrigger = UpdateSourceTrigger.Explicit,
                NotifyOnSourceUpdated = true,
                NotifyOnTargetUpdated = true,
                Mode = BindingMode.OneWay
            };
            BindingOperations.SetBinding(_comboBox, ItemsControl.ItemsSourceProperty, itemsSource);
            _comboBox.DataContext = _fakeVm;
            _undoManager = UndoManager.GetUndoManager(_comboBox);
        }
Example #3
0
    void Awake()
    {
        Instance = this;

        undoStack = new Stack<UndoableAction>();
        redoStack = new Stack<UndoableAction>();

        UpdateButtonsInteractability();
    }
 void Start()
 {
     playerSelectManager = GetComponent<PlayerSelectManager>();
     gameManager = GetComponent<GameManager>();
     undoManager = GetComponent<UndoManager>();
     mapGenerator = GetComponent<MapGenerator>();
     currentActionSelected = -1;
     tileColorManager = GetComponent<TileColorManager>();
 }
Example #5
0
 public UndoRedoAction(UndoManager undoManager, int position, string oldText, string newText,
     int insertMarkPosition, int selectionBoundPosition)
 {
     this.undoManager = undoManager;
     Position = position;
     OldText = oldText;
     NewText = newText;
     this.insertMarkPosition = insertMarkPosition;
     this.selectionBoundPosition = selectionBoundPosition;
 }
Example #6
0
 public UndoRedoButtons(UndoManager undoManager,
     ToolStripMenuItem undoMenuItem, ToolStripSplitButton undoButton,
     ToolStripMenuItem redoMenuItem, ToolStripSplitButton redoButton,
     Action<Action> runUIAction)
 {
     _undoManager = undoManager;
     _undoMenuItem = undoMenuItem;
     _undoButton = undoButton;
     _redoMenuItem = redoMenuItem;
     _redoButton = redoButton;
     _runUIAction = runUIAction;
 }
Example #7
0
        public UndoManagerVm(string name, UndoManager manager)
        {
            Name = name;
            Manager = manager;

            UndoStack = new CollectionView(Manager.History.UndoStack);
            RedoStack = new CollectionView(Manager.History.RedoStack);
            manager.History.PropertyChanged += (sender, args) =>
            {
                UndoStack.Refresh();
                RedoStack.Refresh();
            };
        }
Example #8
0
 public MainWindow()
     : base(Gtk.WindowType.Toplevel)
 {
     Build ();
     _undoManager = new UndoManager ();
     View = new StandardDrawingView (this);
     _scrolledwindow.Add ((Widget) View);
     Tool = new SelectionTool (this);
     UndoManager.StackChanged += delegate {
         UpdateUndoRedoSensitiveness ();
     };
     ShowAll ();
 }
Example #9
0
    void Start()
    {
        initializeEntityLists();
		turnsCompleted = 0;
        gameManager = this;
        currentPlayers = new LinkedList<Entity>();
        currentTurn = JANITOR;
        cameraManager = GetComponent<CameraManager>();
        undoManager = GetComponent<UndoManager>();
        uiManager = GameObject.FindObjectOfType<UIManager>();
        aiStateMachine = GameObject.FindObjectOfType<AIStateMachine>();
        turnsLeft = turnsPerPlayer;
        updateEntitiesPresent();
    }
Example #10
0
 public void ExecuteXDocumentVariation(XNode toReplace, XNode newValue)
 {
     XDocument xDoc = new XDocument(toReplace);
     XDocument xDocOriginal = new XDocument(xDoc);
     using (UndoManager undo = new UndoManager(xDoc))
     {
         undo.Group();
         using (EventsHelper docHelper = new EventsHelper(xDoc))
         {
             toReplace.ReplaceWith(newValue);
             docHelper.Verify(new XObjectChange[] { XObjectChange.Remove, XObjectChange.Add }, new XObject[] { toReplace, newValue });
         }
         undo.Undo();
         Assert.True(XNode.DeepEquals(xDoc, xDocOriginal), "Undo did not work!");
     }
 }
        /// <summary>
        /// Execution of the Action.  
        /// </summary>
        /// <returns>True:  Execution of the Action was successful</returns>
        public bool Execute(ActionCallingContext ctx)
        {
            using (UndoStep undo = new UndoManager().CreateUndoStep())
            {
                SelectionSet sel = new SelectionSet();

                //Make sure that terminals are ordered by designation
                var terminals = sel.Selection.OfType<Terminal>().OrderBy(t => t.Properties.FUNC_PINORTERMINALNUMBER.ToInt());
                if (terminals.Count() < 2)
                    throw new Exception("Must select at least 2 Terminals");

                //Create a list of terminals for each level. Those lists get added to a dictionnary
                //with the level as the key.
                Dictionary<int, List<Terminal>> levels = new Dictionary<int, List<Terminal>>();

                //Fill the dictionnary
                foreach (Terminal t in terminals)
                {
                    int level = t.Properties.FUNC_TERMINALLEVEL;

                    if (!levels.ContainsKey(level))
                        levels.Add(level, new List<Terminal>());

                    levels[level].Add(t);
                }

                var keys = levels.Keys.OrderBy(k => k);

                //Make sure that all levels have the same number of terminals
                int qty = levels.First().Value.Count;
                if (!levels.All(l => l.Value.Count == qty))
                    throw new Exception("There must be the same number of Terminals on each level");

                //Assign sort code by taking a terminal from each level in sequence
                int sortCode = 1;
                for (int i = 0; i < qty; i++)
                {
                    foreach (int j in keys)
                    {
                        levels[j][i].Properties.FUNC_TERMINALSORTCODE = sortCode++;
                    }
                }

            }

            return true;
        }
Example #12
0
 public void XProcessingInstructionPIVariation()
 {
     XProcessingInstruction toChange = new XProcessingInstruction("target", "data");
     XProcessingInstruction original = new XProcessingInstruction(toChange);
     using (UndoManager undo = new UndoManager(toChange))
     {
         undo.Group();
         using (EventsHelper eHelper = new EventsHelper(toChange))
         {
             toChange.Target = "newTarget";
             Assert.True(toChange.Target.Equals("newTarget"), "Name did not change");
             eHelper.Verify(XObjectChange.Name, toChange);
         }
         undo.Undo();
         Assert.True(XNode.DeepEquals(toChange, original), "Undo did not work");
     }
 }
Example #13
0
 public void ExecuteXDocumentVariation(XNode[] content, int index)
 {
     XDocument xDoc = new XDocument(content);
     XDocument xDocOriginal = new XDocument(xDoc);
     XNode toRemove = xDoc.Nodes().ElementAt(index);
     using (UndoManager undo = new UndoManager(xDoc))
     {
         undo.Group();
         using (EventsHelper docHelper = new EventsHelper(xDoc))
         {
             toRemove.Remove();
             docHelper.Verify(XObjectChange.Remove, toRemove);
         }
         undo.Undo();
         Assert.True(XNode.DeepEquals(xDoc, xDocOriginal), "Undo did not work!");
     }
 }
Example #14
0
 public void ExecuteXElementVariation(XElement toChange, XName newName)
 {
     XElement original = new XElement(toChange);
     using (UndoManager undo = new UndoManager(toChange))
     {
         undo.Group();
         using (EventsHelper eHelper = new EventsHelper(toChange))
         {
             toChange.Name = newName;
             Assert.True(newName.Namespace == toChange.Name.Namespace, "Namespace did not change");
             Assert.True(newName.LocalName == toChange.Name.LocalName, "LocalName did not change");
             eHelper.Verify(XObjectChange.Name, toChange);
         }
         undo.Undo();
         Assert.True(XNode.DeepEquals(toChange, original), "Undo did not work");
     }
 }
 public void SetUp()
 {
     _textBox = new TextBox();
     _textBox.SetValue(UndoManager.UndoScopeNameProperty, "ScopeName");
     _fakeVm = new FakeVm();
     var binding = new Binding("Value")
     {
         Source = _fakeVm,
         UpdateSourceTrigger = UpdateSourceTrigger.Explicit,
         NotifyOnSourceUpdated = true,
         NotifyOnTargetUpdated = true,
         Mode = BindingMode.TwoWay
     };
     BindingOperations.SetBinding(_textBox, TextBox.TextProperty, binding);
     _textBox.DataContext = _fakeVm;
     _undoManager = UndoManager.GetUndoManager(_textBox);
 }
Example #16
0
 public void ExecuteXElementVariation(XNode toReplace, XNode newValue)
 {
     XElement xElem = new XElement("root", toReplace);
     XElement xElemOriginal = new XElement(xElem);
     using (UndoManager undo = new UndoManager(xElem))
     {
         undo.Group();
         using (EventsHelper eHelper = new EventsHelper(xElem))
         {
             toReplace.ReplaceWith(newValue);
             xElem.Verify();
             eHelper.Verify(new XObjectChange[] { XObjectChange.Remove, XObjectChange.Add }, new XObject[] { toReplace, newValue });
         }
         undo.Undo();
         Assert.True(xElem.Nodes().SequenceEqual(xElemOriginal.Nodes(), XNode.EqualityComparer), "Undo did not work!");
         Assert.True(xElem.Attributes().EqualsAllAttributes(xElemOriginal.Attributes(), Helpers.MyAttributeComparer), "Undo did not work!");
     }
 }
Example #17
0
 public void ExecuteXElementVariation(XNode[] content, int index)
 {
     XElement xElem = new XElement("root", content);
     XNode toRemove = xElem.Nodes().ElementAt(index);
     XElement xElemOriginal = new XElement(xElem);
     using (UndoManager undo = new UndoManager(xElem))
     {
         undo.Group();
         using (EventsHelper elemHelper = new EventsHelper(xElem))
         {
             toRemove.Remove();
             xElem.Verify();
             elemHelper.Verify(XObjectChange.Remove, toRemove);
         }
         undo.Undo();
         Assert.True(xElem.Nodes().SequenceEqual(xElemOriginal.Nodes(), XNode.EqualityComparer), "Undo did not work!");
         Assert.True(xElem.Attributes().EqualsAllAttributes(xElemOriginal.Attributes(), Helpers.MyAttributeComparer), "Undo did not work!");
     }
 }
Example #18
0
 public void ExecuteXDocumentVariation(XNode toReplace)
 {
     XNode newValue = new XText(" ");
     XDocument xDoc = new XDocument(toReplace);
     XDocument xDocOriginal = new XDocument(xDoc);
     using (UndoManager undo = new UndoManager(xDoc))
     {
         undo.Group();
         using (EventsHelper docHelper = new EventsHelper(xDoc))
         {
             xDoc.ReplaceNodes(newValue);
             Assert.True(xDoc.Nodes().Count() == 1, "Not all content were removed");
             Assert.True(Object.ReferenceEquals(xDoc.FirstNode, newValue), "Did not replace correctly");
             docHelper.Verify(new XObjectChange[] { XObjectChange.Remove, XObjectChange.Add }, new XObject[] { toReplace, newValue });
         }
         undo.Undo();
         Assert.True(XNode.DeepEquals(xDoc, xDocOriginal), "Undo did not work!");
     }
 }
Example #19
0
        public void XElementWorkOnTextNodes1()
        {
            XElement elem = new XElement("A", "text2");
            XNode    n    = elem.FirstNode;

            using (UndoManager undo = new UndoManager(elem))
            {
                undo.Group();
                using (EventsHelper eHelper = new EventsHelper(elem))
                {
                    n.AddBeforeSelf("text0");
                    Assert.Equal("text0text2", elem.Value);
                    n.AddBeforeSelf("text1");
                    Assert.Equal("text0text1text2", elem.Value);
                    eHelper.Verify(new XObjectChange[] { XObjectChange.Add, XObjectChange.Value });
                }
                undo.Undo();
                Assert.Equal("text2", elem.Value);
            }
        }
Example #20
0
    private void OnDeleteActivated(object o, EventArgs args)
    {
        // Don't remove sector if it is the only one.
        if (level.Sectors.Count == 1)
        {
            application.PrintStatus("A level has to have at least one sector.");
            return;
        }

        application.PrintStatus("Sector '" + sector.Name + "' removed.");
        SectorRemoveCommand command = new SectorRemoveCommand(
            "Removed sector",
            sector,
            level);

        command.OnSectorAdd    += OnSectorAdd;
        command.OnSectorRemove += OnSectorRemove;
        command.Do();
        UndoManager.AddCommand(command);
    }
Example #21
0
        /// <summary>
        /// Ends all batch updates in progress.
        /// </summary>
        /// <param name="rollback"></param>
        /// <returns></returns>
        public int EndUpdateAll(bool rollback = false)
        {
            var actionCount = 0;

            while (UndoManager.BatchDepth > 0)
            {
                actionCount = UndoManager.EndBatch(rollback);
            }

            if (EoB_RequireRebuildDependencyTree)
            {
                EoB_PostponeOperations = false; FormulaFixup.BuildDependencyTree(); EoB_RequireRebuildDependencyTree = false;
            }

            while (Tree.UpdateLocks > 0)
            {
                Tree.EndUpdate();
            }
            return(actionCount);
        }
Example #22
0
 public void Add(IGameObject Object, string type, bool NoUndo)
 {
     if (!NoUndo)
     {
         ObjectAddCommand command = new ObjectAddCommand(
             "Created Object '" + type + "'",
             Object,
             this);
         UndoManager.AddCommand(command);
     }
     GameObjects.Add(Object);
     try {
         if (ObjectAdded != null)
         {
             ObjectAdded(this, Object);
         }
     } catch (Exception e) {
         ErrorDialog.Exception(e);
     }
 }
Example #23
0
 public void Remove(IGameObject Object, bool NoUndo)
 {
     if (!NoUndo)
     {
         ObjectRemoveCommand command = new ObjectRemoveCommand(
             "Delete Object " + Object,
             Object,
             this);
         UndoManager.AddCommand(command);
     }
     GameObjects.Remove(Object);
     try {
         if (ObjectRemoved != null)
         {
             ObjectRemoved(this, Object);
         }
     } catch (Exception e) {
         ErrorDialog.Exception(e);
     }
 }
Example #24
0
        public void TestThatUndoManagerUndoAndRedoWithCustomRootCorrectly()
        {
            PrepareUndoManagerForTest();
            UndoManager undoManager = new UndoManager(this);

            TestPropertyClass testProp = new TestPropertyClass();
            int newVal = 5;

            testProp.IntProperty = newVal;
            undoManager.AddUndoChange(new Change("IntProperty", 0, newVal, root: testProp));
            Assert.Equal(newVal, testProp.IntProperty);

            undoManager.Undo();

            Assert.Equal(0, testProp.IntProperty);

            undoManager.Redo();

            Assert.Equal(newVal, testProp.IntProperty);
        }
Example #25
0
        public SESpriteGridManager()
        {
            camera         = GameData.Camera;
            cursor         = GameData.Cursor;
            currentSprites = GameData.EditorLogic.CurrentSprites;

            messages = GuiData.messages;

            mSpriteGridBorder = new SpriteGridBorder(cursor,
                                                     camera);

            UndoManager.SetAfterUpdateDelegate(typeof(SpriteGrid), "XLeftBound", RepopulateSpriteGrid);
            UndoManager.SetAfterUpdateDelegate(typeof(SpriteGrid), "XRightBound", RepopulateSpriteGrid);
            UndoManager.SetAfterUpdateDelegate(typeof(SpriteGrid), "YTopBound", RepopulateSpriteGrid);
            UndoManager.SetAfterUpdateDelegate(typeof(SpriteGrid), "YBottomBound", RepopulateSpriteGrid);
            UndoManager.SetAfterUpdateDelegate(typeof(SpriteGrid), "ZCloseBound", RepopulateSpriteGrid);
            UndoManager.SetAfterUpdateDelegate(typeof(SpriteGrid), "ZFarBound", RepopulateSpriteGrid);

            tla = new List <TextureLocation <Texture2D> >();
        }
Example #26
0
        private void editor_ValueWasChanged(object sender, DesignerPropertyInfo property)
        {
            if (!_isParReady)
            {
                return;
            }

            UndoManager.PreSave();

            DesignerPropertyEditor editor = sender as DesignerPropertyEditor;
            int rowIndex = getRowIndex(null, null, null, editor, null);

            _rootNode.Pars[rowIndex].Variable = editor.GetVariable();

            _rootNode.OnPropertyValueChanged(true);

            UndoManager.Save((Nodes.Behavior)_rootNode);

            UndoManager.PostSave();
        }
Example #27
0
        public void ExecuteXAttributeVariation(XAttribute toChange, object newValue)
        {
            XElement xElem         = new XElement("root", toChange);
            XElement xElemOriginal = new XElement(xElem);

            using (UndoManager undo = new UndoManager(xElem))
            {
                undo.Group();
                using (EventsHelper eHelper = new EventsHelper(toChange))
                {
                    xElem.SetAttributeValue(toChange.Name, newValue);
                    Assert.True(newValue.Equals(toChange.Value), "Value did not change");
                    xElem.Verify();
                    eHelper.Verify(XObjectChange.Value, toChange);
                }
                undo.Undo();
                Assert.True(xElem.Nodes().SequenceEqual(xElemOriginal.Nodes(), XNode.EqualityComparer), "Undo did not work!");
                Assert.True(xElem.Attributes().EqualsAllAttributes(xElemOriginal.Attributes(), Helpers.MyAttributeComparer), "Undo did not work!");
            }
        }
Example #28
0
        public void ExecuteXElementVariation(XElement toChange, object newValue)
        {
            int      count         = toChange.Nodes().Count();
            XElement xElemOriginal = new XElement(toChange);

            using (UndoManager undo = new UndoManager(toChange))
            {
                undo.Group();
                using (EventsHelper eHelper = new EventsHelper(toChange))
                {
                    toChange.SetValue(newValue);
                    Assert.True(newValue.Equals(toChange.Value), "Value change was not correct");
                    toChange.Verify();
                    eHelper.Verify(count + 1);
                }
                undo.Undo();
                Assert.True(toChange.Nodes().SequenceEqual(xElemOriginal.Nodes(), XNode.EqualityComparer), "Undo did not work!");
                Assert.True(toChange.Attributes().EqualsAllAttributes(xElemOriginal.Attributes(), Helpers.MyAttributeComparer), "Undo did not work!");
            }
        }
Example #29
0
        public void ExecuteXAttributeVariation(XAttribute[] content, int index)
        {
            XElement   xElem         = new XElement("root", content);
            XAttribute toRemove      = xElem.Attributes().ElementAt(index);
            XElement   xElemOriginal = new XElement(xElem);

            using (UndoManager undo = new UndoManager(xElem))
            {
                undo.Group();
                using (EventsHelper elemHelper = new EventsHelper(xElem))
                {
                    toRemove.Remove();
                    xElem.Verify();
                    elemHelper.Verify(XObjectChange.Remove, toRemove);
                }
                undo.Undo();
                Assert.True(xElem.Nodes().SequenceEqual(xElemOriginal.Nodes(), XNode.EqualityComparer), "Undo did not work!");
                Assert.True(xElem.Attributes().EqualsAllAttributes(xElemOriginal.Attributes(), Helpers.MyAttributeComparer), "Undo did not work!");
            }
        }
Example #30
0
        public void ExecuteXAttributeVariation(XAttribute[] content)
        {
            XElement xElem         = new XElement("root", content);
            XElement xElemOriginal = new XElement(xElem);

            using (UndoManager undo = new UndoManager(xElem))
            {
                undo.Group();
                using (EventsHelper eHelper = new EventsHelper(xElem))
                {
                    xElem.ReplaceAttributes(new XAttribute("a", "aa"));
                    Assert.True(XObject.ReferenceEquals(xElem.FirstAttribute, xElem.LastAttribute), "Did not replace attributes correctly");
                    xElem.Verify();
                    eHelper.Verify(content.Length + 1);
                }
                undo.Undo();
                Assert.True(xElem.Nodes().SequenceEqual(xElemOriginal.Nodes(), XNode.EqualityComparer), "Undo did not work!");
                Assert.True(xElem.Attributes().EqualsAllAttributes(xElemOriginal.Attributes(), Helpers.MyAttributeComparer), "Undo did not work!");
            }
        }
Example #31
0
        public void ExecuteXDocumentVariation(XNode toReplace)
        {
            XNode     newValue     = new XText(" ");
            XDocument xDoc         = new XDocument(toReplace);
            XDocument xDocOriginal = new XDocument(xDoc);

            using (UndoManager undo = new UndoManager(xDoc))
            {
                undo.Group();
                using (EventsHelper docHelper = new EventsHelper(xDoc))
                {
                    xDoc.ReplaceNodes(newValue);
                    Assert.True(xDoc.Nodes().Count() == 1, "Not all content were removed");
                    Assert.True(Object.ReferenceEquals(xDoc.FirstNode, newValue), "Did not replace correctly");
                    docHelper.Verify(new XObjectChange[] { XObjectChange.Remove, XObjectChange.Add }, new XObject[] { toReplace, newValue });
                }
                undo.Undo();
                Assert.True(XNode.DeepEquals(xDoc, xDocOriginal), "Undo did not work!");
            }
        }
Example #32
0
        private NodeViewModel(IDocument document, UndoManager undoManager, ITreeNode treeNodeObject, INodeViewModel parent, NodeInfo info, bool isRootNode)
        {
            _document       = document;
            _undoManager    = undoManager;
            _treeNodeObject = treeNodeObject;

            IsRootNode = isRootNode;
            Parent     = parent;
            NodeInfo   = info;

            Children = new ObservableCollection <INodeViewModel>();

            this.PagePreviewCommand = new DelegateCommand <object>(PagePreviewExecute);
            this.EndPreviewCommand  = new DelegateCommand <object>(EndPreviewExecute);

            if (treeNodeObject != null)
            {
                SetNodeImage();
            }
        }
Example #33
0
    protected void OnOk(object o, EventArgs args)
    {
        try {
            uint newWidth  = UInt32.Parse(WidthEntry.Text);
            uint newHeight = UInt32.Parse(HeightEntry.Text);
            //application.TakeUndoSnapshot( "Sector resized to " + newWidth + "x" + newHeight);
            SectorSizeChangeCommand command = new SectorSizeChangeCommand(
                undoTitleBase + " resized to " + newWidth + "x" + newHeight,
                sector,
                tilemap,
                newWidth,
                newHeight);
            command.Do();
            UndoManager.AddCommand(command);
        } catch (Exception e) {
            ErrorDialog.Exception(e);
        }

        resizeDialog.Hide();
    }
Example #34
0
        private void Menu_System_Open(object sender, RoutedEventArgs e)
        {
            Microsoft.Win32.OpenFileDialog openFileDialog = new Microsoft.Win32.OpenFileDialog
            {
                Title       = StringTable.SharedStrings ["open_files"],
                Filter      = StringTable.SharedStrings ["all_files"],
                Multiselect = true
            };
            if (openFileDialog.ShowDialog() == false)
            {
                return;
            }

            UndoManager.SaveToUndoStack(FileInfo.Files);

            foreach (string s in from s in openFileDialog.FileNames orderby s select s)
            {
                AddItem(s);
            }
        }
Example #35
0
        public void Test_UndoManager()
        {
            using (UndoManager undoman = new UndoManager()) {
                Assert.IsNotNull(undoman);

                Assert.IsFalse(undoman.CanUndo());
                Assert.IsFalse(undoman.CanRedo());

                undoman.Clear();

                Assert.IsFalse(undoman.DoOperation(null));

                undoman.Undo();
                undoman.Redo();
                undoman.Commit();
                undoman.Rollback();

                Assert.IsFalse(undoman.DoOperation(new InvalidOperation(undoman)));
            }
        }
        private void SavePbit(string fileName)
        {
            if (SourceType != ModelSourceType.Pbit || pbit == null)
            {
                Status = "Save failed!";
                throw new InvalidOperationException("Tabular Editor cannot currently convert an Analysis Services Tabular model to a Power BI Template. Please choose a different save format.");
            }

            var dbcontent = Serializer.SerializeDB(SerializeOptions.PowerBi);

            // Save to .pbit file:
            pbit.SetModelJson(dbcontent);
            pbit.SaveAs(fileName);

            Status = "File saved.";
            if (!IsConnected)
            {
                UndoManager.SetCheckpoint();
            }
        }
 private void OnComboBoxChanged(object o, EventArgs args)
 {
     try {
         ComboBox comboBox = (ComboBox)o;
         string   newText  = comboBox.ActiveText;
         string   oldText  = (string)Field.GetValue(Object);
         if (newText != oldText)
         {
             PropertyChangeCommand command = new PropertyChangeCommand(
                 "Changed value of " + Field.Name,
                 Field,
                 Object,
                 newText);
             command.Do();
             UndoManager.AddCommand(command);
         }
     } catch (Exception e) {
         ErrorDialog.Exception(e);
     }
 }
Example #38
0
        /// <summary>
        /// Populates the list box with the list of undo/redo actions, and displays the form
        /// directly below the tool strip button.
        /// </summary>
        /// <param name="dropDownButton">Tool strip button under which this form should be displayed</param>
        /// <param name="undo">true if this is "undo", false for "redo"</param>
        /// <param name="undoManager">the UndoManager</param>
        public void ShowList(ToolStripDropDownItem dropDownButton, bool undo, UndoManager undoManager)
        {
            Point location =
                dropDownButton.Owner.PointToScreen(new Point(dropDownButton.Bounds.Left, dropDownButton.Bounds.Bottom));
            Left = location.X;
            Top = location.Y;
            _undo = undo;
            _undoManager = undoManager;
            listBox.Items.Clear();
            IEnumerable<String> descriptions = undo ? undoManager.UndoDescriptions : undoManager.RedoDescriptions;
            foreach (String description in descriptions)
            {
                listBox.Items.Add(description);
            }
            UpdateSelectedIndex(0);

            Height = listBox.ItemHeight * Math.Min(MAX_DISPLAY_ITEMS, listBox.Items.Count) + label.Height + TOTAL_BORDER_WIDTH;
            Show(dropDownButton.Owner);
            listBox.Focus();
        }
Example #39
0
        public void Test1()
        {
            Counter     counter = new Counter();
            UndoManager undoMgr = new UndoManager();

            counter.Increase();
            undoMgr.AddAction(new AddCountAction(counter));
            counter.Increase();
            undoMgr.AddAction(new AddCountAction(counter));
            counter.Increase();
            undoMgr.AddAction(new AddCountAction(counter));

            Assert.IsTrue(counter.Count == 3);
            Assert.IsTrue(undoMgr.UndoStackCount == counter.Count);

            undoMgr.Undo();
            Assert.IsTrue(counter.Count == 2);
            Assert.IsTrue(undoMgr.UndoStackCount == 2);
            Assert.IsTrue(undoMgr.RedoStackCount == 1);
            undoMgr.Undo();
            Assert.IsTrue(counter.Count == 1);
            Assert.IsTrue(undoMgr.UndoStackCount == 1);
            Assert.IsTrue(undoMgr.RedoStackCount == 2);
            undoMgr.Undo();
            Assert.IsTrue(counter.Count == 0);
            Assert.IsTrue(undoMgr.UndoStackCount == 0);
            Assert.IsTrue(undoMgr.RedoStackCount == 3);

            undoMgr.Redo();
            Assert.IsTrue(counter.Count == 1);
            Assert.IsTrue(undoMgr.UndoStackCount == 1);
            Assert.IsTrue(undoMgr.RedoStackCount == 2);
            undoMgr.Redo();
            Assert.IsTrue(counter.Count == 2);
            Assert.IsTrue(undoMgr.UndoStackCount == 2);
            Assert.IsTrue(undoMgr.RedoStackCount == 1);
            undoMgr.Redo();
            Assert.IsTrue(counter.Count == 3);
            Assert.IsTrue(undoMgr.UndoStackCount == 3);
            Assert.IsTrue(undoMgr.RedoStackCount == 0);
        }
Example #40
0
        // add an object to the level. this step of reference is needed for later deconstruction of the level and serialization
        public void DeleteObject(LevelObject levelObj)
        {
            if (LevelPlacer._instance != null)
            {
                switch (levelObj.objectType)
                {
                case LevelObject.ObjectType.turret:
                    turrets.Remove((Turret)levelObj);
                    break;

                case LevelObject.ObjectType.attractor:
                    attractors.Remove((Attractor)levelObj);
                    break;

                case LevelObject.ObjectType.portal:
                    portals.Remove((Portal)levelObj);
                    levelObj.GetComponent <Portal>().Unlink();
                    break;

                case LevelObject.ObjectType.speedStrip:
                    speedStrips.Remove((SpeedStrip)levelObj);
                    break;

                case LevelObject.ObjectType.bouncer:
                    bouncers.Remove((Bouncer)levelObj);
                    break;

                default:
                    //Debug.Log("Wasnt able to add the levelobject to the LevelDataMono of type " + lo.objectType);
                    break;
                }

                //ProgressManager.GetProgress().unlocks.inventory.Add(levelObj.objectType, 1);
                DestroyImmediate(levelObj.gameObject);
                UndoManager.AddUndoPoint();
            }
            else
            {
                Debug.LogError("LevelPlacer needed to add an object to the level.");
            }
        }
Example #41
0
    protected void Save(bool chooseName)
    {
        if (fileName == null)
        {
            chooseName = true;
        }

        if (level == null)
        {
            return;
        }

        if (chooseName)
        {
            fileChooser.Title  = "Select file to save Level";
            fileChooser.Action = Gtk.FileChooserAction.Save;
            fileChooser.SetCurrentFolder(Settings.Instance.LastDirectoryName);
            fileChooser.Filter = fileChooser.Filters[(level.isWorldmap)?2:1];
            int result = fileChooser.Run();
            fileChooser.Hide();
            if (result != (int)Gtk.ResponseType.Ok)
            {
                return;
            }
            Settings.Instance.LastDirectoryName = fileChooser.CurrentFolder;
            Settings.Instance.addToRecentDocuments(fileChooser.Filename);
            Settings.Instance.Save();
            UpdateRecentDocuments();
            fileName = fileChooser.Filename;
        }
        QACheck.ReplaceDeprecatedTiles(level);

        try {
            serializer.Write(fileName, level);
        } catch (Exception e) {
            ErrorDialog.Exception("Couldn't save level", e);
        }

        UndoManager.MarkAsSaved();
        UpdateTitlebar();
    }
        /// <summary>
        /// Initializes a new instance of the <see cref="UndoManagerSettingsForm"/> class.
        /// </summary>
        /// <param name="undoManager">The undo manager.</param>
        /// <param name="dataStorage">The data storage, where data are stored.</param>
        public UndoManagerSettingsForm(
            UndoManager undoManager,
            IDataStorage dataStorage)
        {
            InitializeComponent();

            _undoManager = undoManager;
            _dataStorage = dataStorage;

            undoLevelNumericUpDown.Value = _undoManager.UndoLevel;

            storageGroupBox.Enabled = false;

            Type   type        = this.GetType();
            string storagePath = Path.GetDirectoryName(type.Assembly.Location);

            storagePath = Path.Combine(storagePath, "Undo");
            if (!Directory.Exists(storagePath))
            {
                Directory.CreateDirectory(storagePath);
            }


            if (dataStorage is CompressedImageStorageInMemory)
            {
                compressedVintasoftImageInMemoryRadioButton.Checked = true;
            }
            else if (dataStorage is CompressedImageStorageOnDisk)
            {
                storageGroupBox.Enabled = true;
                compressedVintasoftImageOnDiskRadioButton.Checked = true;
                CompressedImageStorageOnDisk dataStorageOnDisk = (CompressedImageStorageOnDisk)dataStorage;
                storagePath = dataStorageOnDisk.StoragePath;
            }
            else
            {
                vintasoftImageInMemoryRadioButton.Checked = true;
            }

            storagePathTextBox.Text = storagePath;
        }
Example #43
0
        private void ListViewFiles_KeyUp(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.Delete)
            {
                UndoManager.SaveToUndoStack(FileInfo.Files);

                List <FileInfo> tempFileInfos = new List <FileInfo> ();
                foreach (FileInfo fileInfo in listViewFiles.SelectedItems)
                {
                    tempFileInfos.Add(fileInfo);
                }
                foreach (FileInfo fileInfo in tempFileInfos)
                {
                    FileInfo.Files.Remove(fileInfo);
                }
                if (FileInfo.Files.Count == 0)
                {
                    UndoManager.ClearAll();
                }
            }
        }
Example #44
0
        void OnKeyPressEvent(object o, KeyPressEventArgs args)
        {
            if ((args.Event.State & Gdk.ModifierType.ControlMask) != 0)
            {
                switch (args.Event.Key)
                {
                case Gdk.Key.z:
                    UndoManager.Undo();
                    args.RetVal = true;
                    break;

                case Gdk.Key.Z:
                case Gdk.Key.y:
                    UndoManager.Redo();
                    args.RetVal = true;
                    break;
                }
            }

            args.RetVal = false;
        }
Example #45
0
        public void ExecuteXDocumentVariation(XNode[] toAdd, XNode contextNode)
        {
            IEnumerable <XNode> allNodes, toAddList = toAdd.OfType <XNode>();
            XDocument           xDoc         = contextNode == null ? new XDocument() : new XDocument(contextNode);
            XDocument           xDocOriginal = new XDocument(xDoc);

            using (UndoManager undo = new UndoManager(xDoc))
            {
                undo.Group();
                using (EventsHelper docHelper = new EventsHelper(xDoc))
                {
                    xDoc.Add(toAdd);
                    allNodes = contextNode == null?xDoc.Nodes() : contextNode.NodesAfterSelf();

                    Assert.True(toAddList.SequenceEqual(allNodes, XNode.EqualityComparer), "Nodes not added correctly!");
                    docHelper.Verify(XObjectChange.Add, toAdd);
                }
                undo.Undo();
                Assert.True(XNode.DeepEquals(xDoc, xDocOriginal), "Undo did not work!");
            }
        }
Example #46
0
        public static IUndoManager GetUndoManager(Object key)
        {
            IUndoManager manager;

            if (key == null)
            {
                if (_undoManager == null)
                {
                    _undoManager = new UndoManager();
                }

                return(_undoManager);
            }

            if (!_undoManagerLookup.TryGetValue(key, out manager))
            {
                manager = new UndoManager();
                _undoManagerLookup[key] = manager;
            }
            return(manager);
        }
Example #47
0
    /// <summary>Create a new blank level</summary>
    protected void OnNew(object o, EventArgs args)
    {
        if (!ChangeConfirm("create a blank level"))
        {
            return;
        }

        try {
            UndoManager.Clear();
            Level level = LevelUtil.CreateLevel();
            CurrentLevel = level;
        } catch (Exception e) {
            ErrorDialog.Exception("Couldn't create new level", e);
        }
        fileName = null;
        UpdateUndoButtons();
        UpdateTitlebar();
        UndoManager.MarkAsSaved();
        ToolButtonCamera.Sensitive = true;
        EditProperties(CurrentLevel, "Level");
    }
Example #48
0
        public void ExecuteXElementVariation(XObject[] content)
        {
            XElement xElem         = new XElement("root", content);
            XElement xElemOriginal = new XElement(xElem);

            using (UndoManager undo = new UndoManager(xElem))
            {
                undo.Group();
                using (EventsHelper elemHelper = new EventsHelper(xElem))
                {
                    xElem.RemoveAll();
                    Assert.True(xElem.IsEmpty, "Not all content were removed");
                    Assert.True(!xElem.HasAttributes, "RemoveAll did not remove attributes");
                    xElem.Verify();
                    elemHelper.Verify(XObjectChange.Remove, content);
                }
                undo.Undo();
                Assert.True(xElem.Nodes().SequenceEqual(xElemOriginal.Nodes(), XNode.EqualityComparer), "Undo did not work!");
                Assert.True(xElem.Attributes().EqualsAllAttributes(xElemOriginal.Attributes(), Helpers.MyAttributeComparer), "Undo did not work!");
            }
        }
Example #49
0
 private void OnCheckButtonToggled(object o, EventArgs args)
 {
     try {
         Gtk.CheckButton checkButton = (Gtk.CheckButton)o;
         FieldOrProperty field       = fieldTable[widgetTable.IndexOf(checkButton)];
         bool            oldValue    = (bool)field.GetValue(Object);
         bool            newValue    = checkButton.Active;
         if (oldValue != newValue)                   //no change => no Undo action
         {
             PropertyChangeCommand command = new PropertyChangeCommand(
                 "Changed value of " + field.Name,
                 field,
                 Object,
                 newValue);
             command.Do();
             UndoManager.AddCommand(command);
         }
     } catch (Exception e) {
         ErrorDialog.Exception(e);
     }
 }
Example #50
0
        public UIEditor()
        {
            Space = new WindowSpace();

            UndoManager = new UndoManager();

            ViewModel = new MainViewModel(this);
            ViewModel.Resolution = new Size(1024, 768);
            ViewModel.OnPropertyChanged(ViewModel_SelectedGadget, "SelectedGadget");
            ViewModel.OnPropertyChanged(ViewModel_ChangeFile, "UIFile");

            InitializeComponent();

            ViewsContainer.SizeChanged += ViewsContainer_SizeChanged;
            ViewsContainer.MouseDown += ViewsContainer_MouseDown;

            IsVisibleChanged += (o, e) => {
                if (dirty) Load();
            };

            KeyDown += MainWindow_KeyDown;
        }
Example #51
0
 public void ExecuteXDocumentVariation(XNode[] toAdd, XNode contextNode)
 {
     IEnumerable<XNode> toAddList = toAdd.OfType<XNode>();
     XDocument xDoc = new XDocument(contextNode);
     XDocument xDocOriginal = new XDocument(xDoc);
     using (UndoManager undo = new UndoManager(xDoc))
     {
         undo.Group();
         using (EventsHelper docHelper = new EventsHelper(xDoc))
         {
             using (EventsHelper nodeHelper = new EventsHelper(contextNode))
             {
                 contextNode.AddBeforeSelf(toAdd);
                 Assert.True(toAddList.SequenceEqual(contextNode.NodesBeforeSelf(), XNode.EqualityComparer), "Nodes not added correctly!");
                 nodeHelper.Verify(0);
             }
             docHelper.Verify(XObjectChange.Add, toAdd);
         }
         undo.Undo();
         Assert.True(XNode.DeepEquals(xDoc, xDocOriginal), "Undo did not work!");
     }
 }
Example #52
0
 public void ExecuteXElementVariation(XNode[] toAdd, XNode contextNode)
 {
     IEnumerable<XNode> toAddList = toAdd.OfType<XNode>();
     XElement xElem = new XElement("root", contextNode);
     XElement xElemOriginal = new XElement(xElem);
     using (UndoManager undo = new UndoManager(xElem))
     {
         undo.Group();
         using (EventsHelper elemHelper = new EventsHelper(xElem))
         {
             using (EventsHelper nodeHelper = new EventsHelper(contextNode))
             {
                 contextNode.AddBeforeSelf(toAdd);
                 Assert.True(toAddList.SequenceEqual(contextNode.NodesBeforeSelf(), XNode.EqualityComparer), "Nodes not added correctly!");
                 nodeHelper.Verify(0);
             }
             elemHelper.Verify(XObjectChange.Add, toAdd);
         }
         undo.Undo();
         Assert.True(xElem.Nodes().SequenceEqual(xElemOriginal.Nodes(), XNode.EqualityComparer), "Undo did not work!");
         Assert.True(xElem.Attributes().EqualsAllAttributes(xElemOriginal.Attributes(), Helpers.MyAttributeComparer), "Undo did not work!");
     }
 }
Example #53
0
 public void XCommentChangeValue()
 {
     XComment toChange = new XComment("Original Value");
     String newValue = "New Value";
     XElement xElem = new XElement("root", toChange);
     XElement xElemOriginal = new XElement(xElem);
     using (UndoManager undo = new UndoManager(xElem))
     {
         undo.Group();
         using (EventsHelper eHelper = new EventsHelper(xElem))
         {
             using (EventsHelper comHelper = new EventsHelper(toChange))
             {
                 toChange.Value = newValue;
                 Assert.True(toChange.Value.Equals(newValue), "Value did not change");
                 xElem.Verify();
                 comHelper.Verify(XObjectChange.Value, toChange);
             }
             eHelper.Verify(XObjectChange.Value, toChange);
         }
         undo.Undo();
         Assert.True(XNode.DeepEquals(xElem, xElemOriginal), "Undo did not work!");
     }
 }
Example #54
0
 public void XProcessingInstructionChangeValue()
 {
     XProcessingInstruction toChange = new XProcessingInstruction("target", "Original Value");
     String newValue = "New Value";
     XElement xElem = new XElement("root", toChange);
     XElement xElemOriginal = new XElement(xElem);
     using (UndoManager undo = new UndoManager(xElem))
     {
         undo.Group();
         using (EventsHelper eHelper = new EventsHelper(xElem))
         {
             using (EventsHelper piHelper = new EventsHelper(toChange))
             {
                 toChange.Data = newValue;
                 Assert.True(toChange.Data.Equals(newValue), "Value did not change");
                 xElem.Verify();
                 piHelper.Verify(XObjectChange.Value, toChange);
             }
             eHelper.Verify(XObjectChange.Value, toChange);
         }
         undo.Undo();
         Assert.True(XNode.DeepEquals(xElem, xElemOriginal), "Undo did not work!");
     }
 }
Example #55
0
 public void ExecuteValueVariation(XElement content, object newValue)
 {
     int count = content.Nodes().Count();
     XElement xElem = new XElement("root", content);
     XElement xElemOriginal = new XElement(xElem);
     using (UndoManager undo = new UndoManager(xElem))
     {
         undo.Group();
         using (EventsHelper eHelper = new EventsHelper(xElem))
         {
             xElem.SetElementValue(content.Name, newValue);
             // First all contents are removed and then new element with the value is added.
             xElem.Verify();
             eHelper.Verify(count + 1);
         }
         undo.Undo();
         Assert.True(xElem.Nodes().SequenceEqual(xElemOriginal.Nodes(), XNode.EqualityComparer), "Undo did not work!");
         Assert.True(xElem.Attributes().EqualsAllAttributes(xElemOriginal.Attributes(), Helpers.MyAttributeComparer), "Undo did not work!");
     }
 }
Example #56
0
 public void ExecuteRemoveVariation(XElement content)
 {
     XElement xElem = new XElement("root", content);
     XElement xElemOriginal = new XElement(xElem);
     using (UndoManager undo = new UndoManager(xElem))
     {
         undo.Group();
         using (EventsHelper eHelper = new EventsHelper(xElem))
         {
             xElem.SetElementValue(content.Name, null);
             xElem.Verify();
             eHelper.Verify(XObjectChange.Remove, content);
         }
         undo.Undo();
         Assert.True(xElem.Nodes().SequenceEqual(xElemOriginal.Nodes(), XNode.EqualityComparer), "Undo did not work!");
         Assert.True(xElem.Attributes().EqualsAllAttributes(xElemOriginal.Attributes(), Helpers.MyAttributeComparer), "Undo did not work!");
     }
 }
Example #57
0
 public void ExecuteXAttributeVariation(XAttribute toChange, object newValue)
 {
     XElement xElem = new XElement("root", toChange);
     XElement xElemOriginal = new XElement(xElem);
     using (UndoManager undo = new UndoManager(xElem))
     {
         undo.Group();
         using (EventsHelper eHelper = new EventsHelper(toChange))
         {
             xElem.SetAttributeValue(toChange.Name, newValue);
             Assert.True(newValue.Equals(toChange.Value), "Value did not change");
             xElem.Verify();
             eHelper.Verify(XObjectChange.Value, toChange);
         }
         undo.Undo();
         Assert.True(xElem.Nodes().SequenceEqual(xElemOriginal.Nodes(), XNode.EqualityComparer), "Undo did not work!");
         Assert.True(xElem.Attributes().EqualsAllAttributes(xElemOriginal.Attributes(), Helpers.MyAttributeComparer), "Undo did not work!");
     }
 }
Example #58
0
 public void ExecuteXElementVariation(XElement toChange, object newValue)
 {
     int count = toChange.Nodes().Count();
     XElement xElemOriginal = new XElement(toChange);
     using (UndoManager undo = new UndoManager(toChange))
     {
         undo.Group();
         using (EventsHelper eHelper = new EventsHelper(toChange))
         {
             toChange.SetValue(newValue);
             Assert.True(newValue.Equals(toChange.Value), "Value change was not correct");
             toChange.Verify();
             eHelper.Verify(count + 1);
         }
         undo.Undo();
         Assert.True(toChange.Nodes().SequenceEqual(xElemOriginal.Nodes(), XNode.EqualityComparer), "Undo did not work!");
         Assert.True(toChange.Attributes().EqualsAllAttributes(xElemOriginal.Attributes(), Helpers.MyAttributeComparer), "Undo did not work!");
     }
 }
Example #59
0
        private void InitUndo()
        {
            _undoMgr = new UndoManager();
            _undoMgr.UndoItemsChanged += _undoMgr_UndoItemsChanged;
            _undoMgr.RedoItemsChanged += _undoMgr_RedoItemsChanged;

            undoButton.Enabled = false;
            undoButton.ItemChosen += undoButton_ItemChosen;

            redoButton.Enabled = false;
            redoButton.ItemChosen += redoButton_ItemChosen;
        }
Example #60
0
 public void LoadUndoManager(ToolStripSplitButton Undo, ToolStripSplitButton Redo)
 {
     UndoManager = new UndoManager(Undo, Redo, this);
 }