本文整理汇总了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);
}
}
}
}