protected override void Dispose(bool disposing)
        {
            if (disposing && _action != null)
            {
                OnParentChanged(this.Parent, null);

                ToolStripBuilder.Clear(this.DropDownItems);

                // VERY IMPORTANT: instances of this class will be created and discarded frequently
                // throughout the lifetime of the application
                // therefore is it extremely important that the event handlers are disconnected
                // from the underlying _action events
                // otherwise, this object will hang around for the entire lifetime of the _action object,
                // even though this object is no longer needed
                _action.EnabledChanged   -= _actionEnabledChangedHandler;
                _action.CheckedChanged   -= _actionCheckedChangedHandler;
                _action.VisibleChanged   -= _actionVisibleChangedHandler;
                _action.AvailableChanged -= _actionAvailableChangedHandler;
                _action.LabelChanged     -= _actionLabelChangedHandler;
                _action.TooltipChanged   -= _actionTooltipChangedHandler;
                _action.IconSetChanged   -= _actionIconSetChangedHandler;

                _action = null;
            }

            base.Dispose(disposing);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Called to build menus and toolbars.  Override this method to customize menu and toolbar building.
        /// </summary>
        /// <remarks>
        /// The default implementation simply clears and re-creates the toolstrip using methods on the
        /// utility class <see cref="ToolStripBuilder"/>.
        /// </remarks>
        /// <param name="kind"></param>
        /// <param name="toolStrip"></param>
        /// <param name="actionModel"></param>
        protected virtual void BuildToolStrip(ToolStripBuilder.ToolStripKind kind, ToolStrip toolStrip, ActionModelNode actionModel)
        {
            // avoid flicker
            toolStrip.SuspendLayout();
            // very important to clean up the existing ones first
            ToolStripBuilder.Clear(toolStrip.Items);

            if (actionModel != null)
            {
                if (actionModel.ChildNodes.Count > 0)
                {
                    // Toolstrip should only be visible if there are items on it
                    if (kind == ToolStripBuilder.ToolStripKind.Toolbar)
                    {
                        ToolStripBuilder.BuildToolStrip(kind, toolStrip.Items, actionModel.ChildNodes, ToolStripBuilder.ToolStripBuilderStyle.GetDefault(), ToolStripSettings.Default.IconSize);
                    }
                    else
                    {
                        ToolStripBuilder.BuildToolStrip(kind, toolStrip.Items, actionModel.ChildNodes);
                    }
                }
            }

            toolStrip.ResumeLayout();
        }
Ejemplo n.º 3
0
        private void OnToolStripSettingsPropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            ToolStripSettings settings = ToolStripSettings.Default;

            if (e.PropertyName == "WrapLongToolstrips" || e.PropertyName == "ToolStripDock")
            {
                // handle both wrapping and docking together because both affect flow direction
                bool verticalOrientation = ReferenceEquals(_toolbar.Parent, _toolStripContainer.LeftToolStripPanel) ||
                                           ReferenceEquals(_toolbar.Parent, _toolStripContainer.RightToolStripPanel);

                _toolbar.SuspendLayout();
                _toolbar.LayoutStyle = settings.WrapLongToolstrips ? ToolStripLayoutStyle.Flow : ToolStripLayoutStyle.StackWithOverflow;
                if (settings.WrapLongToolstrips)
                {
                    ((FlowLayoutSettings)_toolbar.LayoutSettings).FlowDirection = verticalOrientation ? FlowDirection.TopDown : FlowDirection.LeftToRight;
                }
                _toolbar.ResumeLayout(true);

                ToolStripPanel targetParent = ConvertToToolStripPanel(_toolStripContainer, settings.ToolStripDock);
                if (targetParent != null && !ReferenceEquals(targetParent, _toolbar.Parent))
                {
                    _toolStripContainer.SuspendLayout();
                    targetParent.Join(_toolbar);

                    _toolStripContainer.ResumeLayout(true);
                }
            }
            else if (e.PropertyName == "IconSize")
            {
                ToolStripBuilder.ChangeIconSize(_toolbar, settings.IconSize);
            }
        }
 private void InitializeContextMenu()
 {
     ToolStripBuilder.Clear(_contextMenu.Items);
     if (_component != null && _component.MenuModel != null)
     {
         ToolStripBuilder.BuildMenu(_contextMenu.Items, _component.MenuModel.ChildNodes);
     }
 }
Ejemplo n.º 5
0
 private void InitializeMenu()
 {
     ToolStripBuilder.Clear(_contextMenu.Items);
     if (_menuModel != null)
     {
         ToolStripBuilder.BuildMenu(_contextMenu.Items, _menuModel.ChildNodes);
     }
 }
Ejemplo n.º 6
0
 private void InitializeToolStrip()
 {
     ToolStripBuilder.Clear(_toolStrip.Items);
     if (_toolbarModel != null)
     {
         ToolStripBuilder.BuildToolbar(_toolStrip.Items, _toolbarModel.ChildNodes);
     }
 }
        private void OnDropDownOpening(object sender, EventArgs e)
        {
            ToolStripBuilder.Clear(this.DropDownItems);

            ActionModelNode model = ((IDropDownAction)_action).DropDownMenuModel;

            if (model != null)
            {
                ToolStripBuilder.BuildMenu(this.DropDownItems, model.ChildNodes);
            }
        }
        private void InitializeToolStrip()
        {
            ToolStripBuilder.Clear(_toolStrip.Items);

            if (_component != null && _component.ToolbarModel != null)
            {
                ToolStripBuilder.BuildToolbar(_toolStrip.Items, _component.ToolbarModel.ChildNodes);
                if (_toolStrip.Items.Count > 0)
                {
                    _toolStrip.Visible = true;
                }
            }
        }
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="component"></param>
        public ApplicationComponentUserControl(IApplicationComponent component)
        {
            InitializeComponent();

            _errorProvider.DataSource           = component;
            component.ValidationVisibleChanged += ValidationVisibleChangedEventHandler;

            if (component is ApplicationComponent)
            {
                ActionModelNode menuModel = ((ApplicationComponent)component).MetaContextMenuModel;
                if (menuModel != null)
                {
                    ToolStripBuilder.BuildMenu(_contextMenu.Items, menuModel.ChildNodes);
                }
            }
        }
        /// <summary>
        /// Constructor
        /// </summary>
        public AlertViewerComponentControl(AlertViewerComponent component)
            : base(component)
        {
            InitializeComponent();

            _component = component;

            ToolStripBuilder.BuildToolStrip(ToolStripBuilder.ToolStripKind.Toolbar, _toolbar.Items, _component.AlertActions.ChildNodes);

            _alertTableView.Table     = _component.Alerts;
            _alertTableView.MenuModel = _component.AlertActions;

            // need to work with these manually, because data-binding doesn't work well with toolstrip comboboxes
            _filter.Items.AddRange(_component.FilterChoices.Cast <object>().Select(i => new FilterItem(i, _component.FormatFilter)).ToArray());
            _filter.SelectedIndex         = 0;
            _filter.SelectedIndexChanged += _activityFilter_SelectedIndexChanged;
        }