public FigmaDesignerOutlinePad()
        {
            outlinePanel = new OutlinePanel();

            outlinePanel.RaiseFirstResponder += (s, e) =>
            {
                RaiseFirstResponder?.Invoke(s, e);
            };
            outlinePanel.RaiseDeleteItem += (s, e) =>
            {
                RaiseDeleteItem?.Invoke(s, e);
            };

            var widget = GtkMacInterop.NSViewToGtkWidget(outlinePanel.EnclosingScrollView);

            CanFocus  = widget.CanFocus = true;
            Sensitive = widget.Sensitive = true;

            widget.Focused += FigmaDesignerOutlinePad_Focused;

            PackStart(widget, true, true, 0);
            ShowAll();

            Focused += FigmaDesignerOutlinePad_Focused;
        }
Ejemplo n.º 2
0
 public static Widget CreateMacWebView(string url)
 {
     return(GtkMacInterop.NSViewToGtkWidget((object)new WebView()
     {
         PolicyDelegate = (WebPolicyDelegate) new MacWebView.DownLoadCallback(), UIDelegate = (WebUIDelegate) new MacWebView.MarkdownWebUIDelegate(), MainFrameUrl = url
     }));
 }
Ejemplo n.º 3
0
        static void ShowCustomModalDialog(Gtk.Window dialog, Window parent)
        {
            CenterWindow(dialog, parent);

            var nsdialog = GtkMacInterop.GetNSWindow(dialog);
            // Make the GTK window modal WRT the current modal NSWindow

            NSWindow nativeParent = null;

            try {
                nativeParent = parent;
                nativeParent.AddChildWindow(nsdialog, NSWindowOrderingMode.Above);
            } catch (Exception ex) {
                LoggingService.LogInternalError("Failed to get the native parent window", ex);
            }
            var s = NSApplication.SharedApplication.BeginModalSession(nsdialog);

            void unrealizer(object sender, EventArgs e)
            {
                if (nativeParent != null)
                {
                    nativeParent.RemoveChildWindow(nsdialog);
                }
                NSApplication.SharedApplication.EndModalSession(s);
                dialog.Unrealized -= unrealizer;
            }

            dialog.Unrealized += unrealizer;
        }
Ejemplo n.º 4
0
        public override void ViewDidMoveToWindow()
        {
            base.ViewDidMoveToWindow();

            // Needs to be grabbed after it's parented.
            gtkWidget = GtkMacInterop.NSViewToGtkWidget(this);
        }
Ejemplo n.º 5
0
        // Methods
        protected override void OnRealized()
        {
            WidgetFlags |= WidgetFlags.Realized;
            WindowAttr attributes = default(WindowAttr);

            attributes.X          = Allocation.X;
            attributes.Y          = Allocation.Y;
            attributes.Height     = Allocation.Height;
            attributes.Width      = Allocation.Width;
            attributes.WindowType = Gdk.WindowType.Child;
            attributes.Wclass     = WindowClass.InputOutput;
            attributes.Visual     = Visual;
            attributes.TypeHint   = (WindowTypeHint)100;
            attributes.Colormap   = Colormap;
            attributes.EventMask  = (int)(Events | EventMask.ExposureMask | EventMask.Button1MotionMask | EventMask.ButtonPressMask | EventMask.ButtonReleaseMask | EventMask.KeyPressMask | EventMask.KeyReleaseMask);
            WindowAttributesType attributes_mask = WindowAttributesType.X | WindowAttributesType.Y | WindowAttributesType.Colormap | WindowAttributesType.Visual;

            GdkWindow          = new Gdk.Window(ParentWindow, attributes, (int)attributes_mask);
            GdkWindow.UserData = Handle;
            Style = Style.Attach(GdkWindow);
            Style.SetBackground(GdkWindow, State);
            WidgetFlags &= ~WidgetFlags.NoWindow;
            NSView nSView = GtkMacInterop.GetNSView(this);

            nSView.RemoveFromSuperview();
            embedParent.AddSubview(nSView);
            nSView.Frame = new CGRect(0, 0, embedParent.Frame.Width, embedParent.Frame.Height);
        }
Ejemplo n.º 6
0
        protected override void Initialize(IPadWindow window)
        {
            base.Initialize(window);
#if MAC
            this.window             = window;
            toolbox                 = new Toolbox.MacToolbox(DesignerSupport.Service.ToolboxService, window);
            widget                  = GtkMacInterop.NSViewToGtkWidget(toolbox);
            widget.CanFocus         = true;
            widget.Sensitive        = true;
            widget.KeyPressEvent   += toolbox.OnKeyPressed;
            widget.KeyReleaseEvent += toolbox.KeyReleased;

            widget.DragBegin += Widget_DragBegin;
            widget.DragEnd   += Widget_DragEnd;
            widget.Focused   += Widget_Focused;

            this.window.PadContentShown  += Container_PadContentShown;
            this.window.PadContentHidden += Container_PadContentHidden;

            toolbox.ContentFocused += Toolbox_ContentFocused;
            toolbox.DragSourceSet  += Toolbox_DragSourceSet;
            toolbox.DragBegin      += Toolbox_DragBegin;

            widget.ShowAll();
#else
            widget = new Toolbox.Toolbox(DesignerSupport.Service.ToolboxService, window);
#endif
        }
Ejemplo n.º 7
0
        public override void Initialize()
        {
            base.Initialize();

            view   = new MonoMac.WebKit.WebView();
            Widget = GtkMacInterop.NSViewToGtkWidget(view);
            Widget.Show();
        }
Ejemplo n.º 8
0
        protected override void Initialize(IPadWindow container)
        {
            base.Initialize(container);
#if MAC
            toolbox                 = new Toolbox.MacToolbox(DesignerSupport.Service.ToolboxService, container);
            widget                  = GtkMacInterop.NSViewToGtkWidget(toolbox);
            widget.CanFocus         = true;
            widget.Sensitive        = true;
            widget.KeyPressEvent   += toolbox.OnKeyPressed;
            widget.KeyReleaseEvent += toolbox.KeyReleased;

            widget.DragBegin += (o, args) => {
                if (!isDragging)
                {
                    DesignerSupport.Service.ToolboxService.DragSelectedItem(widget, args.Context);
                    isDragging = true;
                }
            };

            widget.DragEnd += (o, args) => {
                isDragging = false;
            };

            widget.Focused += (s, e) => {
                toolbox.FocusSelectedView();
            };

            toolbox.ContentFocused += (s, e) => {
                if (!widget.HasFocus)
                {
                    widget.HasFocus = true;
                    toolbox.FocusSelectedView();
                }
            };
            toolbox.DragSourceSet += (s, e) => {
                targets = new Gtk.TargetList();
                targets.AddTable(e);
            };
            toolbox.DragBegin += (object sender, EventArgs e) => {
                if (!isDragging)
                {
                    Gtk.Drag.SourceUnset(widget);

                    // Gtk.Application.CurrentEvent and other copied gdk_events seem to have a problem
                    // when used as they use gdk_event_copy which seems to crash on de-allocating the private slice.
                    IntPtr currentEvent = GtkWorkarounds.GetCurrentEventHandle();
                    Gtk.Drag.Begin(widget, targets, Gdk.DragAction.Copy | Gdk.DragAction.Move, 1, new Gdk.Event(currentEvent));

                    // gtk_drag_begin does not store the event, so we're okay
                    GtkWorkarounds.FreeEvent(currentEvent);
                }
            };

            widget.ShowAll();
#else
            widget = new Toolbox.Toolbox(DesignerSupport.Service.ToolboxService, container);
#endif
        }
Ejemplo n.º 9
0
        public override void Initialize()
        {
            base.Initialize();

            view            = new WebKit.WebView();
            view.UIDelegate = new XwtWebUIDelegate(this);
            Widget          = GtkMacInterop.NSViewToGtkWidget(view);
            Widget.Show();
        }
Ejemplo n.º 10
0
        void RootWindow_Hidden(object sender, EventArgs e)
        {
            var parent = GtkMacInterop.GetNSWindow(IdeApp.Workbench.RootWindow);

            parent.RemoveChildWindow(window);

            OrderFront();
            Agent.Play("GoodBye");
            Agent.Sound = false;
        }
Ejemplo n.º 11
0
        void RootWindow_Shown(object sender, EventArgs e)
        {
            var parent = GtkMacInterop.GetNSWindow(IdeApp.Workbench.RootWindow);

            parent.AddChildWindow(window, NSWindowOrderingMode.Above);

            OrderFront();
            Agent.Play("Greeting");
            Agent.Sound = PropertySettings.AudioEnabled;
        }
Ejemplo n.º 12
0
        /// <summary>Centers a window relative to its parent.</summary>
        static void CenterWindow(Window childControl, Window parentControl)
        {
            var gtkChild  = childControl?.nativeWidget as Gtk.Window;
            var gtkParent = parentControl?.nativeWidget as Gtk.Window;

#if MAC
            var nsChild  = childControl?.nativeWidget as NSWindow;
            var nsParent = parentControl?.nativeWidget as NSWindow ?? parentControl;

            if (nsChild != null)
            {
                if (nsParent == null || !nsParent.IsVisible)
                {
                    nsChild.Center();
                }
                else
                {
                    int x = (int)Math.Max(0, nsParent.Frame.Left + (nsParent.Frame.Width - nsChild.Frame.Width) / 2);
                    int y = (int)Math.Max(0, nsParent.Frame.Top + (nsParent.Frame.Height - nsChild.Frame.Height) / 2);
                    nsChild.SetFrameOrigin(new CoreGraphics.CGPoint(x, y));
                }

                return;
            }
#endif
            if (gtkChild != null)
            {
                gtkChild.Show();
                int x, y;
                gtkChild.GetSize(out var w, out var h);
                if (gtkParent != null)
                {
                    gtkChild.TransientFor = gtkParent;
                    gtkParent.GetSize(out var winw, out var winh);
                    gtkParent.GetPosition(out var winx, out var winy);
                    x = Math.Max(0, (winw - w) / 2) + winx;
                    y = Math.Max(0, (winh - h) / 2) + winy;
                    gtkChild.Move(x, y);
#if MAC
                }
                else if (nsParent != null)
                {
                    nsChild = GtkMacInterop.GetNSWindow(gtkChild);
                    x       = (int)Math.Max(0, nsParent.Frame.Left + (nsParent.Frame.Width - w) / 2);
                    y       = (int)Math.Max(0, nsParent.Frame.Top + (nsParent.Frame.Height - h) / 2);
                    nsChild.SetFrameOrigin(new CoreGraphics.CGPoint(x, y));
#endif
                }
                else
                {
                    gtkChild.SetPosition(Gtk.WindowPosition.Center);
                }
            }
        }
Ejemplo n.º 13
0
        public GtkEmbed2(Gtk.Widget w)
        {
            if (!GtkMacInterop.SupportsGtkIntoNSViewEmbedding())
            {
                throw new NotSupportedException("GTK/NSView embedding is not supported by the installed GTK");
            }

            embeddedWidget = w;
            var s = w.SizeRequest();

            SetFrameSize(new CGSize(s.Width, s.Height));
            WatchForFocus(w);
        }
Ejemplo n.º 14
0
        protected override void OnRealized()
        {
            base.OnRealized();
            this.nsview             = GtkMacInterop.GetNSView(this);
            containers[this.nsview] = this;

            if (child != null)
            {
                child.AutoresizingMask = NSViewResizingMask.WidthSizable | NSViewResizingMask.HeightSizable;
                child.Frame            = nsview.Bounds;
                nsview.AddSubview(child);
            }
            this.ConnectSubviews(this.nsview);
        }
Ejemplo n.º 15
0
        static void ShowCustomModalDialog(Gtk.Window dialog, Window parent)
        {
            CenterWindow(dialog, parent);

            var nsdialog = GtkMacInterop.GetNSWindow(dialog);
            // Make the GTK window modal WRT the current modal NSWindow
            var s = NSApplication.SharedApplication.BeginModalSession(nsdialog);

            EventHandler unrealizer = null;

            unrealizer = delegate {
                NSApplication.SharedApplication.EndModalSession(s);
                dialog.Unrealized -= unrealizer;
            };
            dialog.Unrealized += unrealizer;
        }
Ejemplo n.º 16
0
        static void HandleShown(object sender, EventArgs e)
        {
            var dialog   = (Gtk.Window)sender;
            var nsdialog = GtkMacInterop.GetNSWindow(dialog);

            // Make the GTK window modal WRT the current modal NSWindow
            var s = NSApplication.SharedApplication.BeginModalSession(nsdialog);

            EventHandler unrealizer = null;

            unrealizer = delegate {
                NSApplication.SharedApplication.EndModalSession(s);
                dialog.Unrealized -= unrealizer;
            };
            dialog.Unrealized += unrealizer;
            dialog.Shown      -= HandleShown;
        }
Ejemplo n.º 17
0
		static object ConvertToType (Type t, object w)
		{
			if (t.IsInstanceOfType (w))
				return w;

#if MAC
			if (w is NSView && t == typeof (Gtk.Widget)) {
				var ww = GtkMacInterop.NSViewToGtkWidget ((NSView)w);
				ww.Show ();
				return ww;
			}
			if (w is Gtk.Widget && t == typeof (NSView)) {
				return new GtkEmbed ((Gtk.Widget)w);
			}
#endif
			throw new NotSupportedException ();
		}
Ejemplo n.º 18
0
        static object ConvertToType(Type t, object w)
        {
            if (t.IsInstanceOfType(w))
            {
                return(w);
            }

                        #if MAC
            if (w is MonoMac.AppKit.NSView && t == typeof(Gtk.Widget))
            {
                var ww = GtkMacInterop.NSViewToGtkWidget((MonoMac.AppKit.NSView)w);
                ww.Show();
                return(ww);
            }
                        #endif
            throw new NotSupportedException();
        }
Ejemplo n.º 19
0
        void WatchForFocus(Gtk.Widget widget)
        {
            widget.FocusInEvent += (o, args) =>
            {
                var view = GtkMacInterop.GetNSView(widget);
                if (view != null)
                {
                    view.Window.MakeFirstResponder(view);
                }
            };

            if (widget is Gtk.Container)
            {
                var c = (Gtk.Container)widget;
                foreach (var w in c.Children)
                {
                    WatchForFocus(w);
                }
            }
        }
Ejemplo n.º 20
0
        public FigmaViewContent(FilePath fileName)
        {
            FigmaEnvirontment.SetAccessToken(FigmaRuntime.Token);

            this.fileName = fileName;
            ContentName   = fileName;

            container                       = new NSStackView();
            container.Spacing               = 10;
            container.WantsLayer            = true;
            container.Layer.BackgroundColor = NSColor.DarkGray.CGColor;

            container.Distribution = NSStackViewDistribution.Fill;
            container.Orientation  = NSUserInterfaceLayoutOrientation.Vertical;

            _content           = GtkMacInterop.NSViewToGtkWidget(container);
            _content.CanFocus  = true;
            _content.Sensitive = true;

            var scrollView = new NSScrollView()
            {
                HasVerticalScroller   = true,
                HasHorizontalScroller = true,
            };

            scrollView.AutohidesScrollers = false;
            scrollView.BackgroundColor    = NSColor.DarkGray;
            scrollView.ScrollerStyle      = NSScrollerStyle.Legacy;

            renderer = new NSView();
            scrollView.DocumentView   = renderer;
            renderer.AutoresizingMask = NSViewResizingMask.WidthSizable | NSViewResizingMask.HeightSizable;

            container.AddArrangedSubview(scrollView);



            //IdeApp.Workbench.ActiveDocument.Editor.TextChanged += Editor_TextChanged;

            _content.ShowAll();
        }
Ejemplo n.º 21
0
        public FigmaFileDocumentController()
        {
            container = new NSStackView();

            container.Spacing               = 10;
            container.WantsLayer            = true;
            container.Layer.BackgroundColor = NSColor.DarkGray.CGColor;

            container.Distribution = NSStackViewDistribution.Fill;
            container.Orientation  = NSUserInterfaceLayoutOrientation.Vertical;

            _content           = GtkMacInterop.NSViewToGtkWidget(container);
            _content.CanFocus  = true;
            _content.Sensitive = true;

            var scrollView = new FNSScrollview()
            {
                HasVerticalScroller   = true,
                HasHorizontalScroller = true,
            };

            scrollView.AutohidesScrollers = false;
            scrollView.BackgroundColor    = NSColor.DarkGray;
            scrollView.ScrollerStyle      = NSScrollerStyle.Legacy;

            scrollViewWrapper = new ScrollView(scrollView);

            var contentView = new NSView();

            contentView.AutoresizingMask = NSViewResizingMask.WidthSizable | NSViewResizingMask.HeightSizable;
            scrollView.DocumentView      = contentView;

            container.AddArrangedSubview(scrollView);

            _content.ShowAll();

            grid          = PropertyPad.Instance.Control;
            grid.Changed += PropertyPad_Changed;
        }
Ejemplo n.º 22
0
        void UpdateAllocation()
        {
            if (container.GdkWindow == null || cw.GdkWindow == null)
            {
                return;
            }

            var gw = GtkMacInterop.GetNSView(cw);

            gw.Frame = new CGRect(0, 0, Frame.Width, Frame.Height);
            var rect = GetRelativeAllocation(GtkMacInterop.GetNSView(container), gw);

            var allocation = new Gdk.Rectangle
            {
                X      = (int)rect.Left,
                Y      = (int)rect.Top,
                Width  = (int)rect.Width,
                Height = (int)rect.Height
            };

            cw.SizeAllocate(allocation);
        }
Ejemplo n.º 23
0
        public MainToolbar(Gtk.Window window)
        {
            gtkWindow = window;
            widget    = new NSToolbar(MainToolbarId)
            {
                DisplayMode = NSToolbarDisplayMode.Icon,
            };

            awesomeBar = new AwesomeBar();
            awesomeBar.RunButton.Activated += (o, e) => {
                if (RunButtonClicked != null)
                {
                    RunButtonClicked(o, e);
                }
            };

            // Remove the focus from the Gtk system when Cocoa has focus
            // Fixes BXC #29601
            awesomeBar.SearchBar.GainedFocus += (o, e) => IdeApp.Workbench.RootWindow.Focus = null;

            AttachToolbarEvents(awesomeBar.SearchBar);

            selectorView.ConfigurationChanged += (sender, e) => {
                if (ConfigurationChanged != null)
                {
                    ConfigurationChanged(sender, e);
                }
            };

            selectorView.RuntimeChanged += (sender, ea) => {
                if (RuntimeChanged != null)
                {
                    RuntimeChanged(sender, ea);
                }
            };

            widget.WillInsertItem = (tool, id, send) => {
                switch (id)
                {
                case AwesomeBarId:
                    return(new NSToolbarItem(AwesomeBarId)
                    {
                        View = awesomeBar,
                        MinSize = new CGSize(1024, 25),
                        MaxSize = new CGSize(1024, 25)
                    });

                default:
                    throw new NotImplementedException();
                }
            };

            Action <NSNotification> resizeAction = notif => Runtime.RunInMainThread(() => {
                var win = awesomeBar.Window;
                if (win == null)
                {
                    return;
                }

                var item = widget.Items[0];

                var abFrameInWindow = awesomeBar.ConvertRectToView(awesomeBar.Frame, null);
                var size            = new CGSize(win.Frame.Width - abFrameInWindow.X - 4, 25);
                item.MinSize        = size;
                item.MaxSize        = size;
            });

            NSWindow nswin = GtkMacInterop.GetNSWindow(window);

            NSNotificationCenter.DefaultCenter.AddObserver(NSWindow.DidResizeNotification, resizeAction, nswin);
            NSNotificationCenter.DefaultCenter.AddObserver(NSWindow.DidEndLiveResizeNotification, resizeAction, nswin);
        }
Ejemplo n.º 24
0
        public MainToolbar(Gtk.Window window)
        {
            gtkWindow = window;
            widget    = new NSToolbar(MainToolbarId)
            {
                DisplayMode = NSToolbarDisplayMode.Icon,
            };

            awesomeBar = new AwesomeBar();
            awesomeBar.RunButton.Activated += (o, e) => {
                if (RunButtonClicked != null)
                {
                    RunButtonClicked(o, e);
                }
            };


            // Remove the focus from the Gtk system when Cocoa has focus
            // Fixes BXC #29601
            awesomeBar.SearchBar.GainedFocus += (o, e) => IdeApp.Workbench.RootWindow.Focus = null;

            AttachToolbarEvents(awesomeBar.SearchBar);

            selectorView.ConfigurationChanged += (sender, e) => {
                if (ConfigurationChanged != null)
                {
                    ConfigurationChanged(sender, e);
                }
            };

            selectorView.RunConfigurationChanged += (sender, e) => {
                if (RunConfigurationChanged != null)
                {
                    RunConfigurationChanged(sender, e);
                }
            };

            selectorView.RuntimeChanged += (sender, ea) => {
                if (RuntimeChanged != null)
                {
                    RuntimeChanged(sender, ea);
                }
            };

            widget.WillInsertItem = (tool, id, send) => {
                switch (id)
                {
                case AwesomeBarId:
                    return(new NSToolbarItem(AwesomeBarId)
                    {
                        View = awesomeBar,
                        MinSize = new CGSize(MacSystemInformation.OsVersion < MacSystemInformation.Mojave ? 1024: 600, AwesomeBar.ToolbarWidgetHeight),
                        MaxSize = new CGSize(float.PositiveInfinity, AwesomeBar.ToolbarWidgetHeight)
                    });

                default:
                    throw new NotImplementedException();
                }
            };

            // We can't use the events that Xamarin.Mac adds for delegate methods as they will overwrite
            // the delegate that Gtk has added
            NSWindow nswin = GtkMacInterop.GetNSWindow(window);

            // The way how sizing of the NSToolbar is implemented seems to have changen in Mojave.
            // Previously we had to track the window size and update our MinSize to prevent NSToolbar
            // from removing the item automatically. Now the same logic has the opposite effect on Mojave.
            // Additionally AwesomeBar has no active window, after being removed from the NSToolbar, making
            // the required size calculation much more complex. However letting NSToolbar do the magic
            // internally works on Mojave correctly.
            if (MacSystemInformation.OsVersion < MacSystemInformation.Mojave)
            {
                Action <NSNotification> resizeAction = notif => Runtime.RunInMainThread(() => {
                    var win = awesomeBar.Window;
                    if (win == null)
                    {
                        return;
                    }

                    var item = widget.Items [0];

                    var abFrameInWindow  = awesomeBar.ConvertRectToView(awesomeBar.Frame, null);
                    var awesomebarHeight = AwesomeBar.ToolbarWidgetHeight;
                    var size             = new CGSize(win.Frame.Width - abFrameInWindow.X - 4, awesomebarHeight);

                    if (item.MinSize != size)
                    {
                        item.MinSize = size;
                    }
                });
                NSNotificationCenter.DefaultCenter.AddObserver(NSWindow.DidResizeNotification, resizeAction, nswin);
                NSNotificationCenter.DefaultCenter.AddObserver(NSWindow.DidEndLiveResizeNotification, resizeAction, nswin);
            }

            NSNotificationCenter.DefaultCenter.AddObserver(NSWindow.WillEnterFullScreenNotification, (note) => IsFullscreen = true, nswin);
            NSNotificationCenter.DefaultCenter.AddObserver(NSWindow.WillExitFullScreenNotification, (note) => IsFullscreen  = false, nswin);
        }
Ejemplo n.º 25
0
        protected override void Initialize(IPadWindow window)
        {
            this.window = window;
            dragPad     = new FigmaDragAndDropContent();

            window.PadContentHidden += Container_PadHidden;
            window.PadContentShown  += Container_PadShown;

            widget           = GtkMacInterop.NSViewToGtkWidget(dragPad);
            widget.CanFocus  = true;
            widget.Sensitive = true;

            widget.DragBegin += (o, args) => {
                //if (!isDragging)
                //{
                //    var processedNode = dragPad.GetProcessedNode(dragPad.SelectedNode);
                //    selected = new TemplateToolboxNode(new Ide.CodeTemplates.CodeTemplate() { Code = processedNode.Code });
                //    CurrentConsumer.DragItem(selected, widget, args.Context);
                //    //DesignerSupport.Service.ToolboxService.DragSelectedItem(widget, args.Context);
                //    isDragging = true;
                //}
            };

            widget.DragEnd += (o, args) => {
                isDragging = false;
            };

            widget.Focused += (s, e) => {
                // toolbox
            };

            dragPad.SelectCode += (sender, e) =>
            {
                if (!string.IsNullOrEmpty(e))
                {
                    try
                    {
                        var editor   = IdeApp.Workbench.ActiveDocument.GetContent <ITextView>();
                        var position = editor.Caret.Position.BufferPosition.Position;
                        editor.TextBuffer.Insert(position, e);
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex);
                    }
                }
            };

            dragPad.DragSourceSet += (s, e) => {
                targets = new Gtk.TargetList();
                targets.AddTable(e);
            };
            dragPad.DragBegin += (object sender, EventArgs e) => {
                if (!isDragging)
                {
                    Gtk.Drag.SourceUnset(widget);

                    // Gtk.Application.CurrentEvent and other copied gdk_events seem to have a problem
                    // when used as they use gdk_event_copy which seems to crash on de-allocating the private slice.
                    IntPtr currentEvent = Components.GtkWorkarounds.GetCurrentEventHandle();
                    Gtk.Drag.Begin(widget, targets, Gdk.DragAction.Copy | Gdk.DragAction.Move, 1, new Gdk.Event(currentEvent));

                    // gtk_drag_begin does not store the event, so we're okay
                    //Components.GtkWorkarounds.FreeEvent(currentEvent);
                }
            };

            widget.ShowAll();


            if (IdeApp.Workbench != null)
            {
                //IdeApp.Workbench.ActiveDocumentChanged += Workbench_ActiveDocumentChanged;
                IdeApp.Workbench.ActiveDocumentChanged += onActiveDocChanged;  // += new EventHandler(onActiveDocChanged);
                onActiveDocChanged(null, null);
            }
        }
Ejemplo n.º 26
0
        public MainToolbar(Gtk.Window window)
        {
            gtkWindow = window;
            widget    = new NSToolbar(MainToolbarId)
            {
                DisplayMode = NSToolbarDisplayMode.Icon,
            };

            awesomeBar = new AwesomeBar();
            awesomeBar.RunButton.Activated += (o, e) => {
                if (RunButtonClicked != null)
                {
                    RunButtonClicked(o, e);
                }
            };

            // Remove the focus from the Gtk system when Cocoa has focus
            // Fixes BXC #29601
            awesomeBar.SearchBar.GainedFocus += (o, e) => IdeApp.Workbench.RootWindow.Focus = null;

            AttachToolbarEvents(awesomeBar.SearchBar);

            selectorView.ConfigurationChanged += (sender, e) => {
                if (ConfigurationChanged != null)
                {
                    ConfigurationChanged(sender, e);
                }
            };

            selectorView.RunConfigurationChanged += (sender, e) => {
                if (RunConfigurationChanged != null)
                {
                    RunConfigurationChanged(sender, e);
                }
            };

            selectorView.RuntimeChanged += (sender, ea) => {
                if (RuntimeChanged != null)
                {
                    RuntimeChanged(sender, ea);
                }
            };

            widget.WillInsertItem = (tool, id, send) => {
                switch (id)
                {
                case AwesomeBarId:
                    return(new NSToolbarItem(AwesomeBarId)
                    {
                        View = awesomeBar,
                        MinSize = new CGSize(1024, AwesomeBar.ToolbarWidgetHeight),
                        MaxSize = new CGSize(float.PositiveInfinity, AwesomeBar.ToolbarWidgetHeight)
                    });

                default:
                    throw new NotImplementedException();
                }
            };

            Action <NSNotification> resizeAction = notif => Runtime.RunInMainThread(() => {
                var win = awesomeBar.Window;
                if (win == null)
                {
                    return;
                }

                var item = widget.Items[0];

                var abFrameInWindow  = awesomeBar.ConvertRectToView(awesomeBar.Frame, null);
                var awesomebarHeight = AwesomeBar.ToolbarWidgetHeight;
                var size             = new CGSize(win.Frame.Width - abFrameInWindow.X - 4, awesomebarHeight);

                if (item.MinSize != size)
                {
                    item.MinSize = size;
                }
            });

            // We can't use the events that Xamarin.Mac adds for delegate methods as they will overwrite
            // the delegate that Gtk has added
            NSWindow nswin = GtkMacInterop.GetNSWindow(window);

            NSNotificationCenter.DefaultCenter.AddObserver(NSWindow.DidResizeNotification, resizeAction, nswin);
            NSNotificationCenter.DefaultCenter.AddObserver(NSWindow.DidEndLiveResizeNotification, resizeAction, nswin);

            NSNotificationCenter.DefaultCenter.AddObserver(NSWindow.WillEnterFullScreenNotification, (note) => IsFullscreen = true, nswin);
            NSNotificationCenter.DefaultCenter.AddObserver(NSWindow.WillExitFullScreenNotification, (note) => IsFullscreen  = false, nswin);
        }