当前位置: 首页>>代码示例>>C#>>正文


C# MenuItem.Select方法代码示例

本文整理汇总了C#中Gtk.MenuItem.Select方法的典型用法代码示例。如果您正苦于以下问题:C# MenuItem.Select方法的具体用法?C# MenuItem.Select怎么用?C# MenuItem.Select使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Gtk.MenuItem的用法示例。


在下文中一共展示了MenuItem.Select方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: OnPopulateContextMenu

        /// <summary>
        /// Called when the context menu is being populated.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="args">The event arguments.</param>
        private void OnPopulateContextMenu(
			object sender,
			PopulateContextMenuArgs args)
        {
            // Remove the existing items from the list.
            var menuItems = new HashSet<Widget>(args.Menu.Children);

            foreach (Widget menuItem in menuItems)
            {
                args.Menu.Remove(menuItem);
            }

            // We need a read lock on both the collection and the specific block
            // for the given line index.
            TextPosition position = editorView.Caret.Position;
            int blockIndex =
                position.LinePosition.GetLineIndex(editorView.LineBuffer.LineCount);
            int characterIndex = position.GetCharacterIndex(editorView.LineBuffer);
            Block block;

            var context = new BlockCommandContext(project);

            using (blocks.AcquireBlockLock(RequestLock.Read, blockIndex, out block))
            {
                // Figure out if we have any spans for this position.
                if (!block.TextSpans.Contains(characterIndex))
                {
                    // Nothing to add, so we can stop processing.
                    return;
                }

                // Gather up all the text spans for the current position in the line.
                var textSpans = new List<TextSpan>();

                textSpans.AddRange(block.TextSpans.GetAll(characterIndex));

                // Gather up the menu items for this point.
                bool firstItem = true;

                foreach (TextSpan textSpan in textSpans)
                {
                    IList<IEditorAction> actions = textSpan.Controller.GetEditorActions(
                        block, textSpan);

                    foreach (IEditorAction action in actions)
                    {
                        // Create a menu item and hook up events.
                        IEditorAction doAction = action;

                        var menuItem = new MenuItem(action.DisplayName);

                        menuItem.Activated += delegate
                        {
                            doAction.Do(context);
                            RaiseLineChanged(new LineChangedArgs(blockIndex));
                        };

                        // If this is the first item, then make the initial
                        // selection to avoid scrolling.
                        if (firstItem)
                        {
                            menuItem.Select();
                        }

                        firstItem = false;

                        // Add the item to the popup menu.
                        args.Menu.Add(menuItem);
                    }
                }
            }
        }
开发者ID:dmoonfire,项目名称:author-intrusion-cil,代码行数:77,代码来源:ProjectLineBuffer.cs


注:本文中的Gtk.MenuItem.Select方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。