Пример #1
0
        static void Main(string[] args)
        {
            NSApplication.Init();
            NSApplication.SharedApplication.ActivationPolicy = NSApplicationActivationPolicy.Regular;

            var xPos       = NSScreen.MainScreen.Frame.Width / 2;  // NSWidth([[window screen] frame])/ 2 - NSWidth([window frame])/ 2;
            var yPos       = NSScreen.MainScreen.Frame.Height / 2; // NSHeight([[window screen] frame])/ 2 - NSHeight([window frame])/ 2;
            var mainWindow = new MacAccInspectorWindow(new CGRect(xPos, yPos, 300, 368), NSWindowStyle.Titled | NSWindowStyle.Resizable | NSWindowStyle.Closable, NSBackingStore.Buffered, false);

            var stackView = new NSStackView()
            {
                Orientation = NSUserInterfaceLayoutOrientation.Vertical
            };

            mainWindow.ContentView = stackView;
            stackView.AddArrangedSubview(new NSTextField {
                StringValue = "123"
            });

            stackView.AddArrangedSubview(new NSTextField {
                StringValue = "45"
            });
            stackView.AddArrangedSubview(new NSTextField {
                StringValue = "345"
            });
            var button = new NSButton {
                Title = "Press to show a message"
            };

            stackView.AddArrangedSubview(button);

            var hotizontalView = new NSStackView()
            {
                Orientation = NSUserInterfaceLayoutOrientation.Horizontal
            };

            hotizontalView.AddArrangedSubview(new NSTextField()
            {
                StringValue = "test"
            });

            stackView.AddArrangedSubview(hotizontalView);

            button.Activated += (sender, e) => {
                var alert = new NSAlert();
                alert.MessageText     = "You clicked the button!!!";
                alert.InformativeText = "Are you sure!?";
                alert.AddButton("OK!");
                alert.RunModal();
            };

            var button2 = new NSButton {
                Title = "Opens Localized text"
            };

            button2.Activated += (sender, e) => {
                var window = new NSWindow()
                {
                    StyleMask = NSWindowStyle.Titled | NSWindowStyle.Resizable | NSWindowStyle.Closable
                };
                var stack = NativeViewHelper.CreateHorizontalStackView();
                var label = NativeViewHelper.CreateLabel(Strings.HelloText);
                stack.AddArrangedSubview(label);
                window.ContentView = stack;
                window.WillClose  += (sender1, e1) =>
                {
                    window.Dispose();
                };
                window.MakeKeyAndOrderFront(mainWindow);
            };
            stackView.AddArrangedSubview(button2);
            button2.HeightAnchor.ConstraintEqualToConstant(100).Active = true;;

            mainWindow.Title = "Example Debug Xamarin.Mac";

            //mainWindow.MakeKeyWindow();
            mainWindow.MakeKeyAndOrderFront(null);
            NSApplication.SharedApplication.ActivateIgnoringOtherApps(true);
            NSApplication.SharedApplication.Run();
            //mainWindow.Dispose();
        }
Пример #2
0
        public MacToolbarWindow(IInspectDelegate inspectDelegate, CGRect frame) : base(frame, NSWindowStyle.Titled | NSWindowStyle.FullSizeContentView, NSBackingStore.Buffered, false)
        {
            this.inspectDelegate = inspectDelegate;
            //BackgroundColor = NSColor.Clear;
            IsOpaque = false;
            TitlebarAppearsTransparent = true;
            TitleVisibility            = NSWindowTitleVisibility.Hidden;
            ShowsToolbarButton         = false;
            MovableByWindowBackground  = false;

            NSStackView verticalStackView;

            ContentView = verticalStackView = NativeViewHelper.CreateVerticalStackView(MenuItemSeparation);

            stackView = NativeViewHelper.CreateHorizontalStackView(MenuItemSeparation);
            verticalStackView.AddArrangedSubview(stackView);

            stackView.LeftAnchor.ConstraintEqualToAnchor(verticalStackView.LeftAnchor, 10).Active   = true;
            stackView.RightAnchor.ConstraintEqualToAnchor(verticalStackView.RightAnchor, 10).Active = true;

            secondStackView = NativeViewHelper.CreateHorizontalStackView(MenuItemSeparation);
            verticalStackView.AddArrangedSubview(secondStackView);

            secondStackView.LeftAnchor.ConstraintEqualToAnchor(verticalStackView.LeftAnchor, 10).Active   = true;
            secondStackView.RightAnchor.ConstraintEqualToAnchor(verticalStackView.RightAnchor, 10).Active = true;

            //Visual issues view
            var actualImage       = (NSImage)inspectDelegate.GetImageResource("overlay-actual.png").NativeObject;
            var keyViewLoopButton = new ToggleButton()
            {
                Image = actualImage
            };

            keyViewLoopButton.ToolTip = "Shows current focused item";
            AddButton(keyViewLoopButton);
            keyViewLoopButton.Activated += (s, e) => {
                KeyViewLoop?.Invoke(this, keyViewLoopButton.IsToggled);
            };

            var previousImage         = (NSImage)inspectDelegate.GetImageResource("overlay-previous.png").NativeObject;
            var prevKeyViewLoopButton = new ToggleButton()
            {
                Image = previousImage
            };

            prevKeyViewLoopButton.ToolTip = "Shows previous view item";
            AddButton(prevKeyViewLoopButton);
            prevKeyViewLoopButton.Activated += (s, e) => {
                PreviousKeyViewLoop?.Invoke(this, prevKeyViewLoopButton.IsToggled);
            };

            var nextImage             = (NSImage)inspectDelegate.GetImageResource("overlay-next.png").NativeObject;
            var nextKeyViewLoopButton = new ToggleButton()
            {
                Image = nextImage
            };

            nextKeyViewLoopButton.ToolTip = "Shows next view item";
            AddButton(nextKeyViewLoopButton);
            nextKeyViewLoopButton.Activated += (s, e) => {
                NextKeyViewLoop?.Invoke(this, nextKeyViewLoopButton.IsToggled);
            };

            AddSeparator();

            var rescanImage = (NSImage)inspectDelegate.GetImageResource("rescan-16.png").NativeObject;

            toolkitButton = new ToggleButton {
                Image = rescanImage
            };
            toolkitButton.ToolTip = "Change beetween Toolkits";
            AddButton(toolkitButton);
            toolkitButton.Activated += ToolkitButton_Activated;;

            rescanSeparator = AddSeparator();

            var themeImage  = (NSImage)inspectDelegate.GetImageResource("style-16.png").NativeObject;
            var themeButton = new ToggleButton {
                Image = themeImage
            };

            themeButton.ToolTip = "Change Style Theme";
            AddButton(themeButton);
            themeButton.Activated += ThemeButton_Activated;

            AddSeparator();

            var deleteImage = (NSImage)inspectDelegate.GetImageResource("delete-16.png").NativeObject;

            deleteButton         = new ImageButton();
            deleteButton.Image   = deleteImage;
            deleteButton.ToolTip = "Delete selected item";
            AddButton(deleteButton);
            deleteButton.Activated += (s, e) =>
            {
                ItemDeleted?.Invoke(this, EventArgs.Empty);
            };

            var changeImg = (NSImage)inspectDelegate.GetImageResource("image-16.png").NativeObject;

            changeImage         = new ImageButton();
            changeImage.Image   = changeImg;
            changeImage.ToolTip = "Change image from selected item";
            AddButton(changeImage);

            changeImage.Activated += (s, e) =>
            {
                ItemImageChanged?.Invoke(this, EventArgs.Empty);
            };

            AddSeparator();

            languagesComboBox = new NSComboBox()
            {
                TranslatesAutoresizingMaskIntoConstraints = false
            };
            languagesComboBox.ToolTip = "Change font from selected item";

            cultureInfos = CultureInfo.GetCultures(CultureTypes.AllCultures);
            var culturesStr = new NSString[cultureInfos.Length];

            NSString selected = null;

            for (int i = 0; i < cultureInfos.Length; i++)
            {
                culturesStr[i] = new NSString(cultureInfos[i].DisplayName);
                if (i == 0 || cultureInfos[i] == Thread.CurrentThread.CurrentUICulture)
                {
                    selected = culturesStr[i];
                }
            }

            languagesComboBox.Add(culturesStr);
            stackView.AddArrangedSubview(languagesComboBox);

            languagesComboBox.Select(selected);

            languagesComboBox.Activated        += LanguagesComboBox_SelectionChanged;
            languagesComboBox.SelectionChanged += LanguagesComboBox_SelectionChanged;
            languagesComboBox.WidthAnchor.ConstraintLessThanOrEqualToConstant(220).Active = true;

            //FONTS

            fontsCombobox = new NSComboBox()
            {
                TranslatesAutoresizingMaskIntoConstraints = false
            };
            fontsCombobox.ToolTip = "Change font from selected item";
            fonts = NSFontManager.SharedFontManager.AvailableFonts
                    .Select(s => new NSString(s))
                    .ToArray();

            fontsCombobox.Add(fonts);
            fontsCombobox.WidthAnchor.ConstraintGreaterThanOrEqualToConstant(220).Active = true;

            fontSizeTextView = new NSTextField()
            {
                TranslatesAutoresizingMaskIntoConstraints = false
            };
            fontSizeTextView.ToolTip = "Change font size from selected item";
            fontSizeTextView.WidthAnchor.ConstraintEqualToConstant(40).Active = true;

            fontsCombobox.SelectionChanged += (s, e) => {
                OnFontChanged();
            };

            fontSizeTextView.Activated += (s, e) => {
                OnFontChanged();
            };

            endSpace = new NSView()
            {
                TranslatesAutoresizingMaskIntoConstraints = false
            };

            //stackView.AddArrangedSubview(new NSView() { TranslatesAutoresizingMaskIntoConstraints = false });
        }
Пример #3
0
        public MacToolbox(ToolboxService toolboxService, IPadWindow container)
        {
            Orientation          = NSUserInterfaceLayoutOrientation.Vertical;
            Alignment            = NSLayoutAttribute.Leading;
            Spacing              = 0;
            Distribution         = NSStackViewDistribution.Fill;
            AccessibilityElement = false;
            this.toolboxService  = toolboxService;
            this.container       = container;

            #region Toolbar

            groupByCategoryImage = ImageService.GetIcon(Stock.GroupByCategory, Gtk.IconSize.Menu);
            var compactImage = ImageService.GetIcon(Stock.CompactDisplay, Gtk.IconSize.Menu);
            var addImage     = ImageService.GetIcon(Stock.Add, Gtk.IconSize.Menu);

            horizontalStackView = NativeViewHelper.CreateHorizontalStackView(IconsSpacing);
            AddArrangedSubview(horizontalStackView);

            horizontalStackView.LeftAnchor.ConstraintEqualToAnchor(LeftAnchor, 0).Active   = true;
            horizontalStackView.RightAnchor.ConstraintEqualToAnchor(RightAnchor, 0).Active = true;

            horizontalStackView.EdgeInsets = new NSEdgeInsets(7, 7, 7, 7);

            //Horizontal container
            filterEntry = new NativeViews.SearchTextField();
            filterEntry.AccessibilityTitle = GettextCatalog.GetString("Search Toolbox");
            filterEntry.AccessibilityHelp  = GettextCatalog.GetString("Enter a term to search for it in the toolbox");
            filterEntry.Activated         += FilterTextChanged;

            horizontalStackView.AddArrangedSubview(filterEntry);

            filterEntry.SetContentCompressionResistancePriority((int)NSLayoutPriority.DefaultLow, NSLayoutConstraintOrientation.Horizontal);
            filterEntry.SetContentHuggingPriorityForOrientation((int)NSLayoutPriority.DefaultLow, NSLayoutConstraintOrientation.Horizontal);

            catToggleButton       = new NativeViews.ToggleButton();
            catToggleButton.Image = groupByCategoryImage.ToNSImage();
            catToggleButton.AccessibilityTitle = GettextCatalog.GetString("Show categories");
            catToggleButton.ToolTip            = GettextCatalog.GetString("Show categories");
            catToggleButton.AccessibilityHelp  = GettextCatalog.GetString("Toggle to show categories");
            catToggleButton.Activated         += ToggleCategorisation;

            horizontalStackView.AddArrangedSubview(catToggleButton);

            catToggleButton.SetContentCompressionResistancePriority((int)NSLayoutPriority.DefaultHigh, NSLayoutConstraintOrientation.Horizontal);
            catToggleButton.SetContentHuggingPriorityForOrientation((int)NSLayoutPriority.DefaultHigh, NSLayoutConstraintOrientation.Horizontal);

            compactModeToggleButton                    = new NativeViews.ToggleButton();
            compactModeToggleButton.Image              = compactImage.ToNSImage();
            compactModeToggleButton.ToolTip            = GettextCatalog.GetString("Use compact display");
            compactModeToggleButton.AccessibilityTitle = GettextCatalog.GetString("Compact Layout");
            compactModeToggleButton.AccessibilityHelp  = GettextCatalog.GetString("Toggle for toolbox to use compact layout");
            compactModeToggleButton.Activated         += ToggleCompactMode;

            horizontalStackView.AddArrangedSubview(compactModeToggleButton);

            compactModeToggleButton.SetContentCompressionResistancePriority((int)NSLayoutPriority.DefaultHigh, NSLayoutConstraintOrientation.Horizontal);
            compactModeToggleButton.SetContentHuggingPriorityForOrientation((int)NSLayoutPriority.DefaultHigh, NSLayoutConstraintOrientation.Horizontal);

            toolboxAddButton       = new NativeViews.ClickedButton();
            toolboxAddButton.Image = addImage.ToNSImage();
            toolboxAddButton.AccessibilityTitle = GettextCatalog.GetString("Add toolbox items");
            toolboxAddButton.AccessibilityHelp  = GettextCatalog.GetString("Add toolbox items");
            toolboxAddButton.ToolTip            = GettextCatalog.GetString("Add toolbox items");
            toolboxAddButton.Activated         += ToolboxAddButton_Clicked;

            horizontalStackView.AddArrangedSubview(toolboxAddButton);

            toolboxAddButton.SetContentCompressionResistancePriority((int)NSLayoutPriority.DefaultHigh, NSLayoutConstraintOrientation.Horizontal);
            toolboxAddButton.SetContentHuggingPriorityForOrientation((int)NSLayoutPriority.DefaultHigh, NSLayoutConstraintOrientation.Horizontal);

            #endregion

            toolboxWidget = new MacToolboxWidget(container)
            {
                AccessibilityTitle = GettextCatalog.GetString("Toolbox Toolbar"),
            };

            var scrollView = new NSScrollView()
            {
                HasVerticalScroller   = true,
                HasHorizontalScroller = false,
                TranslatesAutoresizingMaskIntoConstraints = false
            };
            scrollView.WantsLayer   = true;
            scrollView.DocumentView = toolboxWidget;
            AddArrangedSubview(scrollView);

            //update view when toolbox service updated
            toolboxService.ToolboxContentsChanged += ToolboxService_ToolboxContentsChanged;
            toolboxService.ToolboxConsumerChanged += ToolboxService_ToolboxConsumerChanged;

            filterEntry.Changed += FilterEntry_Changed;

            toolboxWidget.DragBegin            += ToolboxWidget_DragBegin;
            toolboxWidget.ActivateSelectedItem += ToolboxWidget_ActivateSelectedItem;
            toolboxWidget.MenuOpened           += ToolboxWidget_MenuOpened;
            toolboxWidget.RegionCollapsed      += FilterTextChanged;

            //set initial state
            toolboxWidget.ShowCategories   = catToggleButton.Active = true;
            compactModeToggleButton.Active = MonoDevelop.Core.PropertyService.Get("ToolboxIsInCompactMode", false);
            toolboxWidget.IsListMode       = !compactModeToggleButton.Active;
        }
Пример #4
0
        public PreviewPane(
            NSImage severityIcon,
            string id,
            string title,
            string description,
            Uri helpLink,
            string helpLinkToolTipText,
            IReadOnlyList <object> previewContent,
            bool logIdVerbatimInTelemetry,
            Guid?optionPageGuid = null
            )
        {
            _differenceViewerPreview = (DifferenceViewerPreview)previewContent[0];
            var view = ((ICocoaDifferenceViewer)_differenceViewerPreview.Viewer).VisualElement;

            var originalSize = view.Frame.Size;

            this.TranslatesAutoresizingMaskIntoConstraints = false;

            // === Title ===
            // Title is in a stack view to help with padding
            var titlePlaceholder = new NSStackView()
            {
                Orientation = NSUserInterfaceLayoutOrientation.Vertical,
                EdgeInsets  = new NSEdgeInsets(5, 0, 5, 0),
                Alignment   = NSLayoutAttribute.Leading,
                TranslatesAutoresizingMaskIntoConstraints = false
            };

            // TODO: missing icon
            this.titleField = new NSTextField()
            {
                Editable        = false,
                Bordered        = false,
                BackgroundColor = NSColor.ControlBackground,
                DrawsBackground = false,
            };

            titlePlaceholder.AddArrangedSubview(titleField);
            AddSubview(titlePlaceholder);

            // === Preview View ===
            // This is the actual view, that shows the diff
            view.TranslatesAutoresizingMaskIntoConstraints = false;
            NSLayoutConstraint.Create(
                view,
                NSLayoutAttribute.Width,
                NSLayoutRelation.GreaterThanOrEqual,
                1,
                originalSize.Width
                ).Active = true;
            NSLayoutConstraint.Create(
                view,
                NSLayoutAttribute.Height,
                NSLayoutRelation.GreaterThanOrEqual,
                1,
                originalSize.Height
                ).Active = true;
            view.Subviews[0].TranslatesAutoresizingMaskIntoConstraints = false;
            view.WantsLayer = true;

            AddSubview(view);

            // === Constraints ===
            var constraints = new NSLayoutConstraint[]
            {
                // Title
                NSLayoutConstraint.Create(
                    titlePlaceholder,
                    NSLayoutAttribute.Top,
                    NSLayoutRelation.Equal,
                    this,
                    NSLayoutAttribute.Top,
                    1,
                    0
                    ),
                NSLayoutConstraint.Create(
                    titlePlaceholder,
                    NSLayoutAttribute.Leading,
                    NSLayoutRelation.Equal,
                    this,
                    NSLayoutAttribute.Leading,
                    1,
                    0
                    ),
                NSLayoutConstraint.Create(
                    titlePlaceholder,
                    NSLayoutAttribute.Trailing,
                    NSLayoutRelation.Equal,
                    this,
                    NSLayoutAttribute.Trailing,
                    1,
                    0
                    ),
                // Preview View
                NSLayoutConstraint.Create(
                    view,
                    NSLayoutAttribute.Bottom,
                    NSLayoutRelation.Equal,
                    this,
                    NSLayoutAttribute.Bottom,
                    1,
                    0
                    ),
                NSLayoutConstraint.Create(
                    view,
                    NSLayoutAttribute.Leading,
                    NSLayoutRelation.Equal,
                    this,
                    NSLayoutAttribute.Leading,
                    1,
                    0
                    ),
                NSLayoutConstraint.Create(
                    view,
                    NSLayoutAttribute.Trailing,
                    NSLayoutRelation.Equal,
                    this,
                    NSLayoutAttribute.Trailing,
                    1,
                    0
                    ),
                // subviews
                NSLayoutConstraint.Create(
                    view.Subviews[0],
                    NSLayoutAttribute.Top,
                    NSLayoutRelation.Equal,
                    view,
                    NSLayoutAttribute.Top,
                    1,
                    0
                    ),
                NSLayoutConstraint.Create(
                    view.Subviews[0],
                    NSLayoutAttribute.Bottom,
                    NSLayoutRelation.Equal,
                    view,
                    NSLayoutAttribute.Bottom,
                    1,
                    0
                    ),
                NSLayoutConstraint.Create(
                    view.Subviews[0],
                    NSLayoutAttribute.Left,
                    NSLayoutRelation.Equal,
                    view,
                    NSLayoutAttribute.Left,
                    1,
                    0
                    ),
                NSLayoutConstraint.Create(
                    view.Subviews[0],
                    NSLayoutAttribute.Right,
                    NSLayoutRelation.Equal,
                    view,
                    NSLayoutAttribute.Right,
                    1,
                    0
                    ),
            };

            if (
                GenerateAttributeString(id, title, helpLink, helpLinkToolTipText)
                is NSAttributedString attributedStringTitle
                )
            {
                this.titleField.AttributedStringValue = attributedStringTitle;
                // We do this separately, because the title sometimes isn't there (i.e. no diagnostics ID)
                // and we want the preview to stretch to the top
                NSLayoutConstraint.Create(
                    view,
                    NSLayoutAttribute.Top,
                    NSLayoutRelation.Equal,
                    titlePlaceholder,
                    NSLayoutAttribute.Bottom,
                    1,
                    0
                    ).Active = true;
            }
            else
            {
                NSLayoutConstraint.Create(
                    view,
                    NSLayoutAttribute.Top,
                    NSLayoutRelation.Equal,
                    this,
                    NSLayoutAttribute.Top,
                    1,
                    0
                    ).Active = true;
            }

            NSLayoutConstraint.ActivateConstraints(constraints);

            _differenceViewerPreview.Viewer.InlineView.TryMoveCaretToAndEnsureVisible(
                new Microsoft.VisualStudio.Text.SnapshotPoint(
                    _differenceViewerPreview.Viewer.InlineView.TextSnapshot,
                    0
                    )
                );
        }