Beispiel #1
0
        private void DrawingArea_KeyPressEvent(object o, KeyPressEventArgs args)
        {
            var @event = args.Event;

            // Check that control is the only modifier pressed.
            if ((@event.State ^ ModifierType.ControlMask) == 0)
            {
                if (@event.Key == Gdk.Key.z)
                {
                    // This is ctrl-z, i.e. undo
                    if (Transactions.TryUndo(out var transaction))
                    {
                        switch (transaction)
                        {
                        case WireTransaction wt:
                            Wires.RevertTransaction(wt);
                            break;

                        case GateTransaction gt:
                            Gates.RevertGateTransaction(gt);
                            break;

                        default:
                            throw new Exception($"Unknown transaction type! {transaction.GetType()}");
                        }
                        Console.WriteLine($"Undid transaction: {transaction}");
                        DrawingArea.QueueDraw();
                    }
                }
                else if (@event.Key == Gdk.Key.y)
                {
                    // This is ctrl-y, i.e. redo
                    if (Transactions.TryRedo(out var transaction))
                    {
                        switch (transaction)
                        {
                        case WireTransaction wt:
                            Wires.ApplyTransaction(wt);
                            break;

                        case GateTransaction gt:
                            Gates.ApplyTransaction(gt);
                            break;

                        default:
                            throw new Exception($"Unknown transaction type! {transaction.GetType()}");
                        }
                        Console.WriteLine($"Redid transaction: {transaction}");
                        DrawingArea.QueueDraw();
                    }
                }
            }

            if ((@event.State ^ (ModifierType.ControlMask | ModifierType.ShiftMask)) == 0)
            {
                if (@event.Key == Gdk.Key.Z)
                {
                    // This is ctrl-shift-z, i.e. redo
                    if (Transactions.TryRedo(out var transaction))
                    {
                        switch (transaction)
                        {
                        case WireTransaction wt:
                            Wires.ApplyTransaction(wt);
                            break;

                        case GateTransaction gt:
                            Gates.ApplyTransaction(gt);
                            break;

                        default:
                            throw new Exception($"Unknown transaction type! {transaction.GetType()}");
                        }
                        Console.WriteLine($"Redid transaction: {transaction}");
                        DrawingArea.QueueDraw();
                    }
                }
            }
        }