예제 #1
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);
        }
예제 #2
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);
        }
예제 #3
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, AwesomeBar.ToolbarWidgetHeight),
						MaxSize = new CGSize (1024, 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;//MacSystemInformation.OsVersion >= MacSystemInformation.ElCapitan ? 24 : 22;
				var size = new CGSize (win.Frame.Width - abFrameInWindow.X - 4, awesomebarHeight);
				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);
		}
예제 #4
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);
        }