Beispiel #1
0
        void RibbonSubGroupUpdateItemsRecursive(KryptonContextMenuCollection contextMenuItems, out bool existsEnabled)
        {
            existsEnabled = false;

            foreach (var item in contextMenuItems)
            {
                var items = item as KryptonContextMenuItems;
                if (items != null)
                {
                    foreach (var item2 in items.Items)
                    {
                        var item3 = item2 as KryptonContextMenuItem;
                        if (item3 != null)
                        {
                            var action = item3.Tag as EditorAction;
                            if (action != null)
                            {
                                var state = EditorAPI.EditorActionGetState(EditorAction.HolderEnum.RibbonQAT, action);

                                item3.Enabled = state.Enabled;
                                if (item3.Checked != state.Checked)
                                {
                                    item3.Checked = state.Checked;
                                }

                                if (item3.Enabled)
                                {
                                    existsEnabled = true;
                                }
                            }
                        }
                    }
                }
            }
        }
 void QATButtonsUpdateProperties(ref bool needRepaint)
 {
     foreach (KryptonRibbonQATButton button in kryptonRibbon.QATButtons)
     {
         if (button.Visible)
         {
             var action = button.Tag as EditorAction;
             if (action != null)
             {
                 var state = EditorAPI.EditorActionGetState(EditorAction.HolderEnum.RibbonQAT, action);
                 if (button.Enabled != state.Enabled)
                 {
                     button.Enabled = state.Enabled;
                     needRepaint    = true;
                 }
                 if (button.Checked != state.Checked)
                 {
                     button.Checked = state.Checked;
                     needRepaint    = true;
                 }
             }
         }
     }
 }
Beispiel #3
0
        public static void AddActionsToMenu(MenuTypeEnum menuType, ICollection <KryptonContextMenuItemBase> items)         //, DocumentWindow documentWindow )
        {
            bool firstItem = true;

            foreach (var action in EditorActions.Actions)
            {
                if (action.ContextMenuSupport != MenuTypeEnum.None && action.ContextMenuSupport == menuType)
                {
                    var state = EditorAPI.EditorActionGetState(EditorAction.HolderEnum.ContextMenu, action);
                    //bool enabled = false;
                    //action.PerformUpdateContextMenuEvent( documentWindow, ref enabled );

                    if (state.Enabled)
                    {
                        if (firstItem)
                        {
                            if (items.Count != 0)
                            {
                                items.Add(new KryptonContextMenuSeparator());
                            }

                            firstItem = false;
                        }

                        var image = EditorAPI.GetImageForDispalyScale(action.GetImageSmall(), action.GetImageBig());
                        var item  = new KryptonContextMenuItem(Translate(action.GetContextMenuText()), image, delegate(object s, EventArgs e2)
                        {
                            ////var a = (EditorAction)item.Tag;

                            ////!!!!так?
                            var state2 = EditorAPI.EditorActionGetState(EditorAction.HolderEnum.ContextMenu, action);
                            //check still enabled
                            if (state2.Enabled)
                            {
                                EditorAPI.EditorActionClick(EditorAction.HolderEnum.ContextMenu, action.Name);
                            }

                            //action.PerformClickContextMenuEvent( documentWindow );
                        });

                        if (action.ActionType == EditorAction.ActionTypeEnum.DropDown)
                        {
                            var args = new CancelEventArgs();
                            action.DropDownContextMenu.PerformOpening(args);
                            //!!!!?
                            //if( !args.Cancel)
                            //{

                            foreach (var child in action.DropDownContextMenu.Items)
                            {
                                item.Items.Add(child);
                            }
                        }

                        //!!!!
                        //item.Enabled = !rootNodeSelected;
                        item.Tag = action;
                        item.ShortcutKeyDisplayString = EditorActions.GetFirstShortcutKeyString(action.Name);
                        items.Add(item);
                    }
                }
            }
        }
        void RibbonButtonsUpdateProperties()
        {
            //update tabs visibility
            {
                Metadata.TypeInfo selectedType = null;
                {
                    var obj = workspaceController.SelectedDocumentWindow?.ObjectOfWindow;
                    if (obj != null)
                    {
                        selectedType = MetadataManager.MetadataGetType(obj);
                    }
                }
                foreach (var ribbonTab in kryptonRibbon.RibbonTabs)
                {
                    var tab = ribbonTab.Tag as EditorRibbonDefaultConfiguration.Tab;
                    if (tab != null)
                    {
                        bool visible = true;
                        if (tab.VisibleOnlyForType != null && visible)
                        {
                            visible = selectedType != null && tab.VisibleOnlyForType.IsAssignableFrom(selectedType);
                        }
                        if (tab.VisibleCondition != null && visible)
                        {
                            visible = tab.VisibleCondition();
                        }
                        if (visible && !EditorUtility.PerformRibbonTabVisibleFilter(tab))
                        {
                            visible = false;
                        }

                        if (ribbonTab.Visible != visible)
                        {
                            ribbonLastSelectedTabTypeByUser_DisableUpdate = true;
                            ribbonTab.Visible = visible;
                            ribbonLastSelectedTabTypeByUser_DisableUpdate = false;
                        }

                        if (ribbonTab.Visible && ribbonLastSelectedTabTypeByUser != "" && ribbonLastSelectedTabTypeByUser == tab.Type)
                        {
                            ribbonLastSelectedTabTypeByUser_DisableUpdate = true;
                            kryptonRibbon.SelectedTab = ribbonTab;
                            ribbonLastSelectedTabTypeByUser_DisableUpdate = false;
                        }
                    }
                }
            }

            //update controls
            foreach (var ribbonTab in kryptonRibbon.RibbonTabs)
            {
                foreach (var ribbonGroup in ribbonTab.Groups)
                {
                    foreach (var groupItem in ribbonGroup.Items)
                    {
                        var tripple = groupItem as KryptonRibbonGroupTriple;
                        if (tripple != null)
                        {
                            foreach (var trippleItem in tripple.Items)
                            {
                                //Button, DropDown
                                var button = trippleItem as KryptonRibbonGroupButton;
                                if (button != null)
                                {
                                    //sub group
                                    if (button.Tag as string == "SubGroup" && button.KryptonContextMenu != null)
                                    {
                                        RibbonSubGroupUpdateItemsRecursive(button.KryptonContextMenu.Items, out var existsEnabled);

                                        //disable group when all items are disabled
                                        button.Enabled = existsEnabled;
                                    }

                                    //action
                                    var action = button.Tag as EditorAction;
                                    if (action != null)
                                    {
                                        var state = EditorAPI.EditorActionGetState(EditorAction.HolderEnum.RibbonQAT, action);

                                        button.Enabled = state.Enabled;

                                        //кнопка меняет тип, т.к. в действиях не указывается может ли она быть Checked.
                                        //сделано так, что меняет при первом изменении isChecked.
                                        if (state.Checked && action.ActionType == EditorAction.ActionTypeEnum.Button)
                                        {
                                            button.ButtonType = GroupButtonType.Check;
                                        }

                                        button.Checked = state.Checked;

                                        if (!EditorUtility.PerformEditorActionVisibleFilter(action))
                                        {
                                            button.Visible = false;
                                        }
                                    }
                                }

                                //Slider
                                var slider = trippleItem as KryptonRibbonGroupSlider;
                                if (slider != null)
                                {
                                    var action = slider.Tag as EditorAction;
                                    if (action != null)
                                    {
                                        var lastValue = action.Slider.Value;

                                        var state = EditorAPI.EditorActionGetState(EditorAction.HolderEnum.RibbonQAT, action);

                                        slider.Enabled = state.Enabled;
                                        if (lastValue != action.Slider.Value)
                                        {
                                            slider.Control.SetValue(action.Slider.Value);
                                            //trackBar.Value = action.Slider.Value;
                                        }

                                        if (!EditorUtility.PerformEditorActionVisibleFilter(action))
                                        {
                                            slider.Visible = false;
                                        }
                                    }
                                }

                                ////ComboBox
                                //var comboBox = trippleItem as KryptonRibbonGroupComboBox;
                                //if( comboBox != null )
                                //{
                                //	var action = comboBox.Tag as EditorAction;
                                //	if( action != null )
                                //	{
                                //		var lastItems = action.ComboBox.Items;
                                //		var lastSelectedIndex = action.ComboBox.SelectedIndex;

                                //		var state = EditorAPI.GetEditorActionState( EditorAction.HolderEnum.RibbonQAT, action );

                                //		comboBox.Enabled = state.Enabled;

                                //		if( !action.ComboBox.Items.SequenceEqual( lastItems ) )
                                //		{
                                //			var oldSelectedIndex = comboBox.SelectedIndex;

                                //			comboBox.Items.Clear();
                                //			foreach( var item in action.ComboBox.Items )
                                //				comboBox.Items.Add( item );

                                //			if( oldSelectedIndex >= 0 && oldSelectedIndex < comboBox.Items.Count )
                                //				comboBox.SelectedIndex = oldSelectedIndex;
                                //			else if( comboBox.Items.Count != 0 )
                                //				comboBox.SelectedIndex = 0;
                                //		}
                                //		if( lastSelectedIndex != action.ComboBox.SelectedIndex )
                                //			comboBox.SelectedIndex = action.ComboBox.SelectedIndex;
                                //	}
                                //}

                                //ListBox
                                var listBox = trippleItem as KryptonRibbonGroupListBox;
                                if (listBox != null)
                                {
                                    var action = listBox.Tag as EditorAction;
                                    if (action != null)
                                    {
                                        var lastItems         = action.ListBox.Items;
                                        var lastSelectedIndex = action.ListBox.SelectedIndex;

                                        var state = EditorAPI.EditorActionGetState(EditorAction.HolderEnum.RibbonQAT, action);

                                        //!!!!не listBox2?
                                        listBox.Enabled = state.Enabled;

                                        var browser = listBox.Control.contentBrowser1;

                                        //update items
                                        if (!action.ListBox.Items.SequenceEqual(lastItems))
                                        {
                                            listBox.SetItems(action.ListBox.Items);
                                        }

                                        //update selected item
                                        if (action.ListBox.SelectIndex != null)
                                        {
                                            int selectIndex = action.ListBox.SelectIndex.Value;

                                            var itemToSelect = browser.Items.FirstOrDefault(i => (int)i.Tag == selectIndex);
                                            if (itemToSelect != null)
                                            {
                                                var toSelect = new ContentBrowser.Item[] { itemToSelect };
                                                if (!toSelect.SequenceEqual(browser.SelectedItems))
                                                {
                                                    browser.SelectItems(toSelect);
                                                }
                                            }
                                            else
                                            {
                                                if (browser.SelectedItems.Length != 0)
                                                {
                                                    browser.SelectItems(null);
                                                }
                                            }

                                            action.ListBox.SelectIndex = null;
                                        }

                                        if (!EditorUtility.PerformEditorActionVisibleFilter(action))
                                        {
                                            listBox.Visible = false;
                                        }

                                        //{
                                        //	int selectIndex = action.ListBox.SelectedIndex;
                                        //	int currentSelectedIndex = -1;
                                        //	if( browser.SelectedItems.Length == 1 )
                                        //		currentSelectedIndex = (int)browser.SelectedItems[ 0 ].Tag;
                                        //	//if( browser.SelectedItems.Length == 1 )
                                        //	//	currentSelectedIndex = browser.RootItems.IndexOf( browser.SelectedItems[ 0 ] );

                                        //	if( selectIndex != currentSelectedIndex )
                                        //	{
                                        //		var itemToSelect = browser.Items.FirstOrDefault( i => (int)i.Tag == selectIndex );
                                        //		if( itemToSelect != null )
                                        //			browser.SelectItems( new ContentBrowser.Item[] { itemToSelect } );
                                        //		else
                                        //			browser.SelectItems( null );
                                        //	}
                                        //}

                                        //!!!!?
                                        //if( lastSelectedIndex != action.ListBox.SelectedIndex )
                                        //{
                                        //	if(browser.Items
                                        //	browser.SelectItems( new ContentBrowser.Item[] { items[ 0 ] } );

                                        //	//browser.SelectedIndex = action.ListBox.SelectedIndex;
                                        //}
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }