Exemplo n.º 1
0
        public override bool Execute(UICommandContext ctx)
        {
            var dlg = new OpenFileDialog();

            dlg.Filter = "IGES Files(*.iges;*.igs)|*.iges;*.igs";
            if (dlg.ShowDialog() == DialogResult.OK)
            {
                var shape = IgesIO.Open(dlg.FileName);
                if (shape != null)
                {
                    var transaction = new UndoTransaction(ctx.Document);
                    transaction.Start(this.Name);

                    var shapeElement = new ShapeElement();
                    shapeElement.SetName(ImportStepCommand.ExtractName(dlg.SafeFileName));
                    ctx.Document.AddElement(shapeElement);
                    shapeElement.SetMaterialId(ctx.DefaultMaterialId);
                    shapeElement.SetShape(shape);
                    ctx.ShowElement(shapeElement);
                    transaction.Commit();

                    ctx.RequestUpdate();
                }
            }
            return(true);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Ends the transaction under which all undo/redo operations take place
        /// </summary>
        /// <param name="transaction">the transaction to be ended</param>
        public void EndTransaction(UndoTransaction transaction)
        {
            if (this.currentTransaction == transaction)
            {
                this.currentTransaction = null;

                // now we might have had no items added to undo and redo stack as a part of this transaction. Check empty transaction at top and remove them
                if (this.undoStack.Count > 0)
                {
                    UndoTransaction t = this.undoStack[0] as UndoTransaction;
                    if (t != null && t.OperationsCount == 0)
                    {
                        this.undoStack.Pop();
                    }
                }

                if (this.redoStack.Count > 0)
                {
                    UndoTransaction t = this.redoStack[0] as UndoTransaction;
                    if (t != null && t.OperationsCount == 0)
                    {
                        this.redoStack.Pop();
                    }
                }
            }
        }
Exemplo n.º 3
0
        public void UndoTransaction(int id)
        {
            var          toUndo      = _history.GetHistory()[id];
            ITransaction transaction = new UndoTransaction(toUndo);

            transaction.Execute();
            _history.GetHistory().Remove(toUndo);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Starts a transaction under which all undo redo operations take place
        /// </summary>
        /// <param name="undoTransaction">the undo transaction</param>
        public void StartTransaction(UndoTransaction undoTransaction)
        {
            if (this.currentTransaction == null)
            {
                this.currentTransaction = undoTransaction;

                // push an empty undo operation
                this.undoStack.Push(new UndoTransaction(undoTransaction.Name));
                this.redoStack.Push(new UndoTransaction(undoTransaction.Name));
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Opens a new change group used to batch several changes.
        /// ChangeGroups work as transactions and are used to support the Undo/Redo system.
        /// </summary>
        public override ChangeGroup OpenGroup(string changeGroupTitle, ICollection <DesignItem> affectedItems)
        {
            if (affectedItems == null)
            {
                throw new ArgumentNullException("affectedItems");
            }

            UndoService     undoService = this.Services.GetRequiredService <UndoService>();
            UndoTransaction g           = undoService.StartTransaction(affectedItems);

            g.Title = changeGroupTitle;
            return(g);
        }
Exemplo n.º 6
0
        public virtual void Complete(VMState state)
        {
            Action action = GetCompleteAction(state);

            if (action == null)
            {
                return;
            }
            using (UndoTransaction tx = new UndoTransaction(UndoManager, true))
            {
                action();
            }
        }
Exemplo n.º 7
0
 public void RemoveQuestion()
 {
     using (UndoTransaction tx = new UndoTransaction(UndoManager))
     {
         StudyUnit.OnRemoveQuestion(SelectedQuestion);
         SelectedQuestions.Remove(SelectedQuestion);
         SelectedQuestionItem = null;
         ConceptVM concept = SelectedConcept;
         UpdateModel(false);
         SelectedConcept = concept;
         tx.Commit();
     }
 }
Exemplo n.º 8
0
 public void Create(bool haveRealTransaction = true)
 {
     _factory = new MockRepository(MockBehavior.Strict);
     if (haveRealTransaction)
     {
         _realTransaction = _factory.Create <ITextUndoTransaction>();
         _transactionRaw  = new UndoTransaction("Undo", FSharpOption.Create(_realTransaction.Object));
     }
     else
     {
         _transactionRaw = new UndoTransaction("Undo", FSharpOption <ITextUndoTransaction> .None);
     }
     _transaction = _transactionRaw;
 }
Exemplo n.º 9
0
 public void Create(bool haveRealTransaction = true)
 {
     _factory = new MockRepository(MockBehavior.Strict);
     if (haveRealTransaction)
     {
         _realTransaction = _factory.Create<ITextUndoTransaction>();
         _transactionRaw = new UndoTransaction(FSharpOption.Create(_realTransaction.Object));
     }
     else
     {
         _transactionRaw = new UndoTransaction(FSharpOption<ITextUndoTransaction>.None);
     }
     _transaction = _transactionRaw;
 }
Exemplo n.º 10
0
        public BookVM AddBookExternal(BookRelation relation)
        {
            BookVM newBook = AddOrEditBook(null, relation);

            if (newBook != null)
            {
                using (UndoTransaction tx = new UndoTransaction(UndoManager))
                {
                    books.Add(newBook);
                    StudyUnit.OnRemoveBooks();
                    tx.Commit();
                }
            }
            return(newBook);
        }
Exemplo n.º 11
0
 public void RemoveCodeScheme()
 {
     if (SelectedCodeScheme == null)
     {
         return;
     }
     using (UndoTransaction tx = new UndoTransaction(UndoManager))
     {
         StudyUnit.RemoveCodeSchemeFromResponse(SelectedCodeScheme);
         SelectedCodeScheme.Codes.Clear();
         codeSchemes.Remove(SelectedCodeScheme);
         tx.Commit();
     }
     SelectedCodeScheme = null;
 }
Exemplo n.º 12
0
        public override bool Execute(UICommandContext ctx)
        {
            var transaction = new UndoTransaction(ctx.Document);

            transaction.Start(this.Name);

            var element = SphereElementSchema.Create(ctx.Document);

            ctx.ShowElement(element);

            transaction.Commit();

            ctx.RequestUpdate();

            return(true);
        }
Exemplo n.º 13
0
 protected override void SaveCore(Stream stream)
 {
     if (this.textBuffer != null)
     {
         using (StreamWriter streamWriter = new StreamWriter(stream, this.encoding))
             streamWriter.Write(this.TextBuffer.CurrentSnapshot.GetText(0, this.TextBuffer.CurrentSnapshot.Length));
         using (UndoTransaction transaction = this.undoManager.TextBufferUndoHistory.CreateTransaction("EmptyTransaction", false))
             transaction.Complete();
         this.undoManager.TextBufferUndoHistory.ReplaceMarkerOnTop(this.topMarker, (object)null);
         this.OnIsDirtyChanged(EventArgs.Empty);
     }
     else
     {
         using (StreamWriter streamWriter = new StreamWriter(stream, this.encoding))
             streamWriter.Write(this.contents);
     }
 }
Exemplo n.º 14
0
 public void RemoveBookExternal(BookVM targetBook)
 {
     if (targetBook == null)
     {
         return;
     }
     using (UndoTransaction tx = new UndoTransaction(UndoManager))
     {
         books.Remove(targetBook);
         StudyUnit.OnRemoveBooks();
         tx.Commit();
     }
     if (SelectedBook == targetBook)
     {
         SelectedBookItem = null;
     }
 }
Exemplo n.º 15
0
        public static void Run()
        {
            // Goto equi
            CurrentElement.Element = Example.Instance.mEqui;

            // set a a mark and then change a database value
            UndoTransaction trans = UndoTransaction.GetUndoTransaction();

            trans.StartTransaction("My Transaction");
            String s1 = Example.Instance.mEqui.GetString(DbAttributeInstance.DESC);
            String s2 = String.Concat(s1, "x");

            Example.Instance.mEqui.SetAttribute(DbAttributeInstance.DESC, s2);
            trans.EndTransaction();
            // now restore old value
            UndoTransaction.PerformUndo();

            String s3 = Example.Instance.mEqui.GetString(DbAttributeInstance.DESC);

            // restore new values
            UndoTransaction.PerformRedo();
            String s4 = Example.Instance.mEqui.GetString(DbAttributeInstance.DESC);

            // Add in a subscriber
            ExampleUndoSubscriber subscriber = new ExampleUndoSubscriber();

            UndoCaretaker.RegisterUndoSubscriber(subscriber);

            // set an initial value
            s1 = "Initial setting";
            s2 = "New setting";
            ExampleUndoSubscriber.val = s1;

            // Now do a transaction
            trans.StartTransaction("My Transaction");
            ExampleUndoSubscriber.val = s2;
            trans.EndTransaction();

            // restore old value
            UndoTransaction.PerformUndo();

            // restore new value
            UndoTransaction.PerformRedo();
            UndoCaretaker.RemoveUndoSubscriber(subscriber);
        }
Exemplo n.º 16
0
        public void ChangeQuestionNumbers()
        {
            ChangeMultipleQuestionNumberWindowVM vm     = new ChangeMultipleQuestionNumberWindowVM(this);
            ChangeMultipleQuestionNumberWindow   window = new ChangeMultipleQuestionNumberWindow(vm);

            window.Owner = Application.Current.MainWindow;
            if (window.ShowDialog() == true)
            {
                using (UndoTransaction tx = new UndoTransaction(UndoManager))
                {
                    if (SequenceUtils.RenumberQuestionNumbers(this, vm.QuestionNumbers))
                    {
                        UpdateModel(false);
                        tx.Commit();
                    }
                }
            }
        }
Exemplo n.º 17
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            UndoTransaction undo = new UndoTransaction(mElement);

            undo.Start("Transform");
            var cs = new GAx3();

            cs.SetLocation(mLocation);
            mElement.SetCoordinateSystem(cs);
            undo.Commit();

            LocationModified = false;

            if (UpdateViewEvent != null)
            {
                UpdateViewEvent();
            }
        }
Exemplo n.º 18
0
        public void EditConstruct()
        {
            ConstructVM construct = SelectedConstruct;

            if (construct is StatementVM)
            {
                StatementVM            statement = (StatementVM)construct;
                CreateSentenceWindowVM vm        = new CreateSentenceWindowVM(this, (Statement)statement.Model);
                CreateSentenceWindow   window    = new CreateSentenceWindow(vm);
                window.Owner = Application.Current.MainWindow;
                if (window.ShowDialog() == true && vm.Statement != null)
                {
                    StatementVM newStatement = new StatementVM(vm.Statement);
                    InitConstruct(newStatement);
                    int index = constructs.IndexOf(construct);
                    constructs.RemoveAt(index);
                    constructs.Insert(index, newStatement);
                    UpdateModel(true);
                    SelectedConstructItem = newStatement;
                }
            }
            else if (construct is IfThenElseVM)
            {
                EditBranchExternal((IfThenElseVM)construct, Application.Current.MainWindow);
            }
            else if (construct is QuestionConstructVM)
            {
                ChangeSingleQuestionNumberWindowVM vm     = new ChangeSingleQuestionNumberWindowVM((QuestionConstructVM)construct);
                ChangeSingleQuestionNumberWindow   window = new ChangeSingleQuestionNumberWindow(vm);
                window.Owner = Application.Current.MainWindow;
                if (window.ShowDialog() == true)
                {
                    using (UndoTransaction tx = new UndoTransaction(UndoManager))
                    {
                        if (SequenceUtils.RenumberQuestionNumber(this, vm.QuestionNumber))
                        {
                            UpdateModel(false);
                            tx.Commit();
                        }
                    }
                }
            }
        }
Exemplo n.º 19
0
        public BookVM EditBookExternal(BookVM targetBook)
        {
            if (targetBook == null)
            {
                return(null);
            }
            BookVM newBook = AddOrEditBook(targetBook.Book, null);

            if (newBook != null)
            {
                using (UndoTransaction tx = new UndoTransaction(UndoManager))
                {
                    int index = books.IndexOf(targetBook);
                    books.RemoveAt(index);
                    books.Insert(index, newBook);
                    StudyUnit.OnRemoveBooks();
                    tx.Commit();
                }
            }
            return(newBook);
        }
Exemplo n.º 20
0
        public BookVM SelectBookExternal(BookRelation relation)
        {
            SelectObjectWindowVM <BookVM> vm     = new SelectObjectWindowVM <BookVM>(books);
            SelectObjectWindow            window = new SelectObjectWindow(vm);
            BookVM book = SelectObjectWindow.Select(Resources.SelectBook, vm) as BookVM; //Select

            if (book != null)
            {
                using (UndoTransaction tx = new UndoTransaction(UndoManager))
                {
                    if (book.Book.FindRelation(relation) == null)
                    {
                        //Need not be generated here since ViewModel Since is re-generated every time EditBookWindow is displayed.
                        book.Book.BookRelations.Add(relation);
                    }
                    StudyUnit.OnRemoveBooks();
                    tx.Commit();
                }
            }
            return(book);
        }
Exemplo n.º 21
0
 private void MoveConstruct(int fromIndex, int toIndex)
 {
     using (UndoTransaction tx = new UndoTransaction(UndoManager))
     {
         ConstructVM fromConstruct = Constructs[fromIndex];
         ConstructVM toConstruct   = Constructs[toIndex];
         if (RenumberQuestionNo && fromConstruct is QuestionConstructVM && toConstruct is QuestionConstructVM)
         {
             QuestionNumberVM fromQuestionNumber = new QuestionNumberVM((QuestionConstructVM)fromConstruct);
             fromQuestionNumber.AfterValue = toConstruct.No;
             QuestionNumberVM toQuestionNumber = new QuestionNumberVM((QuestionConstructVM)toConstruct);
             toQuestionNumber.AfterValue = fromConstruct.No;
             List <QuestionNumberVM> questionNumbers = new List <QuestionNumberVM>();
             questionNumbers.Add(fromQuestionNumber);
             questionNumbers.Add(toQuestionNumber);
             SequenceUtils.RenumberQuestionNumbers(this, questionNumbers);
         }
         Constructs.Move(fromIndex, toIndex);
         UpdateModel(false);
         tx.Commit();
     }
     FocusCell();
 }
Exemplo n.º 22
0
        public override bool Execute(UICommandContext ctx)
        {
            //创建事务
            var transaction = new UndoTransaction(ctx.Document);

            transaction.Start(this.Name);

            var text = new MyTextElement();

            text.Text     = "这是一个好引擎!";
            text.Position = new Vector3(100, 100, 100);

            text.AddElement(ctx.Document);

            text.Show(ctx.RenderView.GetScene());


            //提交事务
            transaction.Commit();

            ctx.RequestUpdate();

            return(true);
        }
Exemplo n.º 23
0
 public void CompleteTransactionMerge(UndoTransaction newerTransaction, UndoTransaction olderTransaction, UndoTransaction mergedTransaction)
 {
 }
Exemplo n.º 24
0
 public bool CanMerge(UndoTransaction newerTransaction, UndoTransaction olderTransaction)
 {
     return(false);
 }
Exemplo n.º 25
0
 public TextUndoTransaction(UndoTransaction undoTransaction)
 {
     this.undoTransaction = undoTransaction;
 }