示例#1
0
        public override bool KeyPressed(CircuitEditor editor, Gdk.EventKey eventKey)
        {
            var modifiers = eventKey.State & Accelerator.DefaultModMask;

            if (modifiers == Gdk.ModifierType.None)
            {
                // No modifiers pressed

                if (eventKey.Key == Gdk.Key.Delete)
                {
                    // Here we should create a delete transaction for the wires and the gates
                    // and apply them as a bundled transaction
                    if (SelectedWires.Count > 0 || SelectedGates.Count > 0)
                    {
                        // FIXME: Change namespace Transaction so we don't need to do this stuff...
                        List <Transaction.Transaction> transactions = new List <Transaction.Transaction>();

                        // FIXME: We might want to make bundled transactions easier...
                        // Right now you have to apply each transaction before creating the
                        // next one in order for the created transactions to be consistent.
                        // We might want to add a CreateRemoveWiresTransaction where we can
                        // remove multiple wires at the same time.
                        foreach (var wire in SelectedWires)
                        {
                            var t = editor.Wires.CreateRemoveWireTransaction(wire);
                            transactions.Add(t);
                            editor.DoTransactionNoPush(t);
                        }

                        BundledTransaction bundleTransaction = new BundledTransaction(transactions);
                        // Push the transaction onto the stack, we don't need to apply it because it's already applied.
                        editor.Transactions.PushTransaction(bundleTransaction);
                        ClearSelection(editor);
                        return(true);
                    }
                }

                if (eventKey.Key == Gdk.Key.Escape)
                {
                    ClearSelection(editor);
                    return(true);
                }
            }


            return(false);
        }