예제 #1
0
 protected override void Exit()
 {
     if (m_app != null)
     {
         // Set the flag
         m_app.Stop(m_app);
         // Post an event to trigger the exit
         m_app.PostEvent(NSEvent.OtherEvent(NSEventType.ApplicationDefined,
                                            new System.Drawing.PointF(0, 0),
                                            0, 0, 0, null, 0, 0, 0), true);
     }
 }
예제 #2
0
        public void RunLoop(CancellationToken cancellationToken)
        {
            NSApplication.SharedApplication.ActivateIgnoringOtherApps(true);
            var app = NSApplication.SharedApplication;

            cancellationToken.Register(() =>
            {
                app.PostEvent(NSEvent.OtherEvent(NSEventType.ApplicationDefined, default(CGPoint),
                                                 default(NSEventModifierMask), 0, 0, null, 0, 0, 0), true);
            });
            while (!cancellationToken.IsCancellationRequested)
            {
                var ev = app.NextEvent(NSEventMask.AnyEvent, NSDate.DistantFuture, NSRunLoop.NSDefaultRunLoopMode, true);
                if (ev != null)
                {
                    app.SendEvent(ev);
                    ev.Dispose();
                }
            }
        }
예제 #3
0
            public override void WillClose(NSNotification notification)
            {
                base.WillClose(notification);

                var application = NSApplication.SharedApplication;

                application.Stop(application);
                // NSApplication.Stop merely signals the run
                // loop to stop after the next processed event.
                // For an immediate stop, we send a do-nothing
                // event to ensure that there is at least one
                // event in the queue.
                application.PostEvent(NSEvent.OtherEvent(
                                          NSEventType.ApplicationDefined,
                                          PointF.Empty,
                                          (NSEventModifierMask)0,
                                          0, 0,
                                          // HACK: Graphics context should be
                                          //       null, but MonoMac throws.
                                          new NSGraphicsContext(),
                                          0, 0, 0), true);
            }
예제 #4
0
        partial void StartSearch(NSSearchField sender)
        {
            var    noteResults    = AppDelegate.NoteEngine.GetNotes(sender.StringValue, true);
            NSMenu noteSearchMenu = new NSMenu("Search Results");
            var    action         = new MonoMac.ObjCRuntime.Selector("searchResultSelected");

            foreach (var name in noteResults.Values.Select(n => n.Title))
            {
                noteSearchMenu.AddItem(name, action, string.Empty);
            }
            Logger.Debug(sender.Frame.ToString());
            Logger.Debug(sender.Superview.Frame.ToString());
            Logger.Debug(sender.Superview.Superview.Frame.ToString());
            NSEvent evt = NSEvent.OtherEvent(NSEventType.ApplicationDefined,
                                             new PointF(sender.Frame.Left, sender.Frame.Top),
                                             (NSEventModifierMask)0,
                                             0,
                                             sender.Window.WindowNumber,
                                             sender.Window.GraphicsContext,
                                             (short)NSEventType.ApplicationDefined,
                                             0, 0);

            NSMenu.PopUpContextMenu(noteSearchMenu, evt, searchField);
        }