Пример #1
0
        public MacToolbox(ToolboxService toolboxService, IPadWindow container)
        {
            WantsLayer = true;

            keyViewLoopDelegate = new KeyViewLoopDelegate();

            verticalStackView = new UnfocusableStackView()
            {
                Orientation          = NSUserInterfaceLayoutOrientation.Vertical,
                Alignment            = NSLayoutAttribute.Leading,
                Spacing              = 0,
                Distribution         = NSStackViewDistribution.Fill,
                AccessibilityElement = false,
                WantsLayer           = true
            };
            AddSubview(verticalStackView);

            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);
            verticalStackView.AddArrangedSubview(horizontalStackView);

            horizontalStackView.LeftAnchor.ConstraintEqualToAnchor(verticalStackView.LeftAnchor, 0).Active   = true;
            horizontalStackView.RightAnchor.ConstraintEqualToAnchor(verticalStackView.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()
            {
                AccessibilityTitle = GettextCatalog.GetString("Toolbox Toolbar"),
            };

            var scrollView = new UnfocusableScrollview()
            {
                HasVerticalScroller   = true,
                HasHorizontalScroller = false,
                DocumentView          = toolboxWidget
            };
            verticalStackView.AddArrangedSubview(scrollView);

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

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

            toolboxWidget.KeyDownPressed += ToolboxWidget_KeyDownPressed;

            //set initial state
            toolboxWidget.ShowCategories   = catToggleButton.Active = true;
            compactModeToggleButton.Active = MonoDevelop.Core.PropertyService.Get("ToolboxIsInCompactMode", false);
            toolboxWidget.IsListMode       = !compactModeToggleButton.Active;

            //custom message
            var cell = new VerticalAlignmentTextCell(NSTextBlockVerticalAlignment.Middle)
            {
                Font            = NativeViewHelper.GetSystemFont(false, (int)NSFont.SmallSystemFontSize),
                LineBreakMode   = NSLineBreakMode.ByWordWrapping,
                Alignment       = NSTextAlignment.Center,
                Editable        = false,
                Bordered        = false,
                Bezeled         = false,
                DrawsBackground = false,
                Selectable      = false
            };

            messageTextField = new NSTextField {
                Cell       = cell,
                WantsLayer = true,
                Hidden     = true
            };
            AddSubview(messageTextField);

            keyViewLoopDelegate.AddViews(filterEntry, catToggleButton, compactModeToggleButton, toolboxAddButton, toolboxWidget);
            keyViewLoopDelegate.RecalculeNextResponderChain();
        }
Пример #2
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;
            filterEntry.Focused           += FilterEntry_Focused;

            horizontalStackView.AddArrangedSubview(filterEntry);
            AddWidgetToFocusChain(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;
            catToggleButton.Focused           += CatToggleButton_Focused;

            horizontalStackView.AddArrangedSubview(catToggleButton);
            AddWidgetToFocusChain(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;
            compactModeToggleButton.Focused           += CompactModeToggleButton_Focused;

            horizontalStackView.AddArrangedSubview(compactModeToggleButton);
            AddWidgetToFocusChain(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;
            toolboxAddButton.Focused           += ToolboxAddButton_Focused;

            horizontalStackView.AddArrangedSubview(toolboxAddButton);
            AddWidgetToFocusChain(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"),
            };
            AddWidgetToFocusChain(toolboxWidget);

            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.MouseDownActivated   += ToolboxWidget_MouseDownActivated;
            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;
        }