예제 #1
0
        public void Initialize(IList <string> args, bool isDocumentApp)
        {
            Console.CancelKeyPress += (sender, e) => Exit(0);

            NSApplication.Init();

            _dispatcher = _dispatcher ?? new Dispatcher(Thread.CurrentThread);
            Fusion.Application.MainThread = _dispatcher;

            Fusion.Application.PerFrame = Observable.Interval(
                TimeSpan.FromSeconds(1.0 / 60.0),
                new SynchronizationContextScheduler(SynchronizationContext.Current));

            var app = new AppDelegate(isDocumentApp);

            NSApplication.SharedApplication.Delegate = app;

            //TODO do we really need to retain this object?
                        #pragma warning disable 0219
            var documentController = new NSDocumentController();
                        #pragma warning restore 0219

            NSApplication.CheckForIllegalCrossThreadCalls = false;
            AppDelegate.ThrowOnTerminate = false;

            Desktop = new MacDialog <object>();

            EffectsImplementation.Initialize(_dispatcher);

            // Make so that the window popups with focus.
            NSApplication.SharedApplication.ActivateIgnoringOtherApps(true);

            MacEnvironment.Initialize(new MacEnvironmentImpl());
            DraggingImplementation.Initialize(_dispatcher);
            MenuBuilder.Initialize(_dispatcher);
            LayeringImplementation.Initialize(_dispatcher);
            LabelImplementation.Initialize(_dispatcher);
            SliderImplementation.Initialize(_dispatcher);
            LineImplementation.Initialize(_dispatcher);
            CircleImplementation.Initialize(_dispatcher);
            RectangleImplementation.Initialize(_dispatcher);
            TextBoxImplementation.Initialize(_dispatcher);
            CursorsImplementation.Initialize(_dispatcher);
            ToolTipImplementation.Initialize(_dispatcher);
            ContextMenuImplementation.Initialize(_dispatcher);
            DropDownImplementation.Initialize(_dispatcher);
            ButtonImplementation.Initialize(_dispatcher);
            ColorPickerImplementation.Initialize(_dispatcher);
            ScrollingImplementation.Initialize(_dispatcher);
            LogViewImplementation.Initialize(_dispatcher);
            Transformation.Initialize();
            ImageImplementation.Initialize(_dispatcher);
            OverlayImplementation.Initialize(_dispatcher);
            PointerImplementation.Initialize(_dispatcher);
            KeyboardImplementation.Initialize(_dispatcher);
            WebViewImplementation.Initialize(_dispatcher);
            LayoutTrackerImplementation.Initialize();
            FileDialogs.Initialize();

            // TODO: Fix this!!!
            Clipping.Initialize((control, clip) => control);

            // This notification occurs a _lot_, but is the most specific one I was able to find that would
            //  allow us to be notified when the first responder changes consistently
            NSNotificationCenter.DefaultCenter.AddObserver(new NSString("NSApplicationDidUpdateNotification"), _ => {
                var keyWindow = NSApplication.SharedApplication.KeyWindow;
                _firstResponder.OnNext(keyWindow != null ? keyWindow.FirstResponder : null);
            });

            app.Terminates.Subscribe(_ =>
            {
                if (Terminating != null)
                {
                    Terminating();
                }
            });

            EditMenu =

                /*CreateFirstResponderMenuItem(name: "Undo", hotkey: HotKey.Create(Fusion.ModifierKeys.Meta, Key.Z), selectorName: "undo:")
                 + CreateFirstResponderMenuItem(name: "Redo", hotkey: HotKey.Create(Fusion.ModifierKeys.Meta | Fusion.ModifierKeys.Shift, Key.Z), selectorName: "redo:")
                 + MenuItem.CreateSeparator()
                 + */CreateFirstResponderMenuItem(name: "Cut", hotkey: HotKey.Create(Fusion.ModifierKeys.Meta, Key.X), selectorName: "cut:")
                + CreateFirstResponderMenuItem(name: "Copy", hotkey: HotKey.Create(Fusion.ModifierKeys.Meta, Key.C), selectorName: "copy:")
                + CreateFirstResponderMenuItem(name: "Paste", hotkey: HotKey.Create(Fusion.ModifierKeys.Meta, Key.V), selectorName: "paste:")
                + CreateFirstResponderMenuItem(name: "Paste and Match Style", hotkey: HotKey.Create(Fusion.ModifierKeys.Meta | Fusion.ModifierKeys.Shift, Key.V), selectorName: "pasteAsPlainText:")
                + CreateFirstResponderMenuItem(name: "Delete", hotkey: HotKey.Create(Fusion.ModifierKeys.Meta, Key.Backspace), selectorName: "delete:")
                + CreateFirstResponderMenuItem(name: "Select All", hotkey: HotKey.Create(Fusion.ModifierKeys.Meta, Key.A), selectorName: "selectAll:");
        }
예제 #2
0
        public static void Initialize(Dispatcher dispatcher)
        {
            Layout.Implementation.LayerControls = (childFactory) =>
                                                  Control.Create(
                ctrl =>
            {
                var element = new Canvas();

                ctrl.BindNativeDefaults(element, dispatcher);

                childFactory(ctrl)
                // IMPORTANT: ConnectWhile has to be done first since else we'll lose all changes done to the children list while the ctrl is unrooted.
                // which breaks diffing, and we get dangling views (views that aren't removed).
                .ConnectWhile(ctrl.IsRooted)
                .DiffSequence()
                .ObserveOn(Fusion.Application.MainThread)
                .Subscribe(children =>
                {
                    foreach (var child in children.Removed)
                    {
                        var nativeChild = child.NativeHandle as FrameworkElement;
                        if (nativeChild != null)
                        {
                            element.Children.Remove(nativeChild);
                        }

                        child.Mount(MountLocation.Unmounted);
                    }

                    foreach (var child in children.Added)
                    {
                        child.Mount(new MountLocation.Mutable
                        {
                            IsRooted      = ctrl.IsRooted,
                            AvailableSize = ctrl.AvailableSize,
                            NativeFrame   = ObservableMath.RectangleWithSize(ctrl.NativeFrame.Size),
                        });

                        var nativeChild = child.NativeHandle as FrameworkElement;
                        if (nativeChild == null)
                        {
                            continue;
                        }

                        var parent = nativeChild.Parent as Canvas;
                        if (parent != null)
                        {
                            parent.Children.Remove(nativeChild);
                        }

                        element.Children.Add(nativeChild);
                    }
                });

                return(element);
            });

            Clipping.Initialize(
                (content, clipToBounds) =>
            {
                var container = Layout.Layer(content);

                Fusion.Application.MainThread.Schedule(() =>
                {
                    var elm          = (FrameworkElement)container.NativeHandle;
                    elm.ClipToBounds = clipToBounds;
                });

                return(container.WithSize(content.DesiredSize));
            });
        }