Example #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);
        }
Example #2
0
        public bool StopEditing()
        {
            NSWindow w = DepartmentsTableView.Window;
            // try to end any editing that is taking place
            bool editingEnded = w.MakeFirstResponder(w);

            if (!editingEnded)
            {
                Console.WriteLine("Unable to end editing");
            }
            return(editingEnded);
        }
        public override void DidShow(NSNotification notification)
        {
            Debug.Assert(window == null);
            this.window = ((NSPopover)notification.Object).ContentViewController.View.Window;

            if (this.prevFirstResponder != null)
            {
                window.MakeFirstResponder(this.prevFirstResponder);
            }

            window.AddObserver(this, key, NSKeyValueObservingOptions.Initial | NSKeyValueObservingOptions.New, IntPtr.Zero);
        }
Example #4
0
        public void Dispose()
        {
            if (keyWindow != null)
            {
                if (keyWindow.CanBecomeKeyWindow)
                {
                    keyWindow.MakeKeyAndOrderFront(null);
                }

                if (firstResponder != null && firstResponder.AcceptsFirstResponder())
                {
                    keyWindow.MakeFirstResponder(firstResponder);
                }
            }
        }
 /// <summary>
 /// Window closes or loses focus, We clear first responder so that field being edited gets applied
 /// </summary>
 /// <param name="notification">Notification.</param>
 public override void DidResignKey(Foundation.NSNotification notification)
 {
     Window.MakeFirstResponder(null);
 }
Example #6
0
        private void DisplayViewController(NSViewController vc)
        {
            BeginInvokeOnMainThread(() => {
                NSWindow w = box.Window;

                bool ended = w.MakeFirstResponder(w);
                if (!ended)
                {
                    AppKitFramework.NSBeep();
                    return;
                }
                // get the new View
                NSView newView = vc.View;

                // Get the old View
                NSView oldView = (NSView)box.ContentView;

                if (oldView == newView)
                {
                    return;
                }

                // Compute the new window frame
                CGSize currentSize = oldView.Frame.Size;
                CGSize newSize     = newView.Frame.Size;

                nfloat deltaWidth    = newSize.Width - currentSize.Width;
                nfloat deltaHeight   = newSize.Height - currentSize.Height;
                CGRect windowframe   = w.Frame;
                windowframe.Size     = new CGSize(windowframe.Size.Width, windowframe.Size.Height + deltaHeight);
                windowframe.Location = new CGPoint(windowframe.Location.X, windowframe.Location.Y - deltaHeight);
                windowframe.Size     = new CGSize(windowframe.Size.Width + deltaWidth, windowframe.Size.Height);


                NSDictionary windowResize   = NSDictionary.FromObjectsAndKeys(new NSObject[] { w, NSValue.FromCGRect(windowframe) }, new NSObject[] { NSViewAnimation.TargetKey, NSViewAnimation.EndFrameKey });
                NSDictionary oldViewFadeOut = NSDictionary.FromObjectsAndKeys(new NSObject[] { oldView, NSViewAnimation.FadeOutEffect }, new NSObject[] { NSViewAnimation.TargetKey, NSViewAnimation.EffectKey });
                NSDictionary newViewFadeOut = NSDictionary.FromObjectsAndKeys(new NSObject[] { newView, NSViewAnimation.FadeOutEffect }, new NSObject[] { NSViewAnimation.TargetKey, NSViewAnimation.EffectKey });
                NSDictionary fadeIn         = NSDictionary.FromObjectsAndKeys(new NSObject[] { newView, NSViewAnimation.FadeInEffect }, new NSObject[] { NSViewAnimation.TargetKey, NSViewAnimation.EffectKey });

                NSViewAnimation animation       = new NSViewAnimation(new NSDictionary[] { oldViewFadeOut });
                animation.AnimationBlockingMode = NSAnimationBlockingMode.Blocking;
                animation.AnimationCurve        = NSAnimationCurve.Linear;
                animation.Duration = 0.1;
                animation.StartAnimation();

                NSViewAnimation animation2       = new NSViewAnimation(new NSDictionary[] { newViewFadeOut });
                animation2.AnimationBlockingMode = NSAnimationBlockingMode.Blocking;
                animation2.Duration = 0.0;
                animation2.StartAnimation();

                box.ContentView = newView;

                NSViewAnimation animation3       = new NSViewAnimation(new NSDictionary[] { windowResize });
                animation3.AnimationBlockingMode = NSAnimationBlockingMode.Blocking;
                animation3.AnimationCurve        = NSAnimationCurve.EaseInOut;
                animation3.Duration = 0.2;
                animation3.StartAnimation();


                NSViewAnimation animation4       = new NSViewAnimation(new NSDictionary[] { fadeIn });
                animation4.AnimationBlockingMode = NSAnimationBlockingMode.Blocking;
                animation4.AnimationCurve        = NSAnimationCurve.Linear;
                animation4.Duration = 0.1;
                animation4.StartAnimation();
            });
        }