Ejemplo n.º 1
0
partial         void btnCreateCar(Foundation.NSObject sender)
        {
            NSWindow w = tableView.Window;

            // try to end any editing that is taking place
            bool editingEnded = w.MakeFirstResponder(w);
            if (!editingEnded) {
                Console.WriteLine("Unable to end editing");
                return;
            }

            NSUndoManager undo = this.UndoManager;

            // Has an edit occurred already in this event?
            if (undo.GroupingLevel > 0) {
                // Close the last group
                undo.EndUndoGrouping();
                // Open a new group
                undo.BeginUndoGrouping();
            }

            // Create the object
            // Should be able to do arrayController.NewObject, but it returns an NSObjectController
            // not an NSObject and also causes an InvalidCastException
            // BUG: https://bugzilla.xamarin.com/show_bug.cgi?id=25620
            //			var c = arrayController.NewObject;
            // Workaround - not available in Unified API... due to protection level.
            //			Car c = (Car)Runtime.GetNSObject(Messaging.IntPtr_objc_msgSend(arrayController.Handle, Selector.GetHandle ("newObject")));
            // Plus I can't figure out how to get the Car object from NSObjectController. Ah, this is due to above bug.
            // Creating my own Person object instead
            Car c = new Car();

            // Add it to the content array of arrayController
            arrayController.AddObject(c);

            // Re-sort (in case the user has sorted a column)
            arrayController.RearrangeObjects();

            // Get the sorted array
            NSArray a = NSArray.FromNSObjects(arrayController.ArrangedObjects());

            // Find the object just added
            nint row = -1;
            for (nuint i = 0; i < a.Count; i++) {
                if (c == a.GetItem<Car>(i)) {
                    row = (nint)i;
                    break;
                }
            }
            Console.WriteLine("Starting edit of {0} in row {1}", c, row);

            // Begin the edit of the first column
            tableView.EditColumn(0, row, null, true);
        }
Ejemplo n.º 2
0
 public void StartObservingCar(Car car)
 {
     car.AddObserver(this, new NSString("makeModel"), NSKeyValueObservingOptions.Old, this.Handle);
     car.AddObserver(this, new NSString("datePurchased"), NSKeyValueObservingOptions.Old, this.Handle);
     car.AddObserver(this, new NSString("condition"), NSKeyValueObservingOptions.Old, this.Handle);
     car.AddObserver(this, new NSString("onSpecial"), NSKeyValueObservingOptions.Old, this.Handle);
     car.AddObserver(this, new NSString("price"), NSKeyValueObservingOptions.Old, this.Handle);
     car.AddObserver(this, new NSString("photo"), NSKeyValueObservingOptions.Old, this.Handle);
 }
Ejemplo n.º 3
0
 public void StopObservingCar(Car car)
 {
     car.RemoveObserver(this, new NSString("makeModel"));
     car.RemoveObserver(this, new NSString("datePurchased"));
     car.RemoveObserver(this, new NSString("condition"));
     car.RemoveObserver(this, new NSString("onSpecial"));
     car.RemoveObserver(this, new NSString("price"));
     car.RemoveObserver(this, new NSString("photo"));
 }
Ejemplo n.º 4
0
 public void InsertObjectInCarsAtIndex(Car c, int index)
 {
     NSUndoManager undo = this.UndoManager;
     Console.WriteLine("Adding {0} to {1}", c, Cars);
     // Add the inverse of this operation to the undo stack
     NSArray args = NSArray.FromObjects(new object[]{c, new NSNumber(index)});
     undo.RegisterUndoWithTarget(this, new Selector("undoAdd:"), args);
     if (!undo.IsUndoing) {
         undo.SetActionname("Add Car");
     }
     // Add the car to the array
     this.StartObservingCar(c);
     Cars.Insert(c, index);
 }