本文整理汇总了C#中MonoMac.AppKit.NSMenuItem类的典型用法代码示例。如果您正苦于以下问题:C# NSMenuItem类的具体用法?C# NSMenuItem怎么用?C# NSMenuItem使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
NSMenuItem类属于MonoMac.AppKit命名空间,在下文中一共展示了NSMenuItem类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Update
public void Update (MDMenu parent, ref NSMenuItem lastSeparator, ref int index)
{
var info = manager.GetCommandInfo (ce.CommandId);
if (!isArrayItem) {
SetItemValues (this, info);
if (!Hidden)
MDMenu.ShowLastSeparator (ref lastSeparator);
return;
}
Hidden = true;
if (index < parent.Count - 1) {
for (int i = index + 1; i < parent.Count; i++) {
var nextItem = parent.ItemAt (i);
if (nextItem == null || nextItem.Target != this)
break;
parent.RemoveItemAt (i);
i--;
}
}
PopulateArrayItems (info.ArrayInfo, parent, ref lastSeparator, ref index);
}
示例2: CreateNsMenu
private void CreateNsMenu() {
var menu = new NSMenu ();
statusItem = NSStatusBar.SystemStatusBar.CreateStatusItem(30);
statusItem.Menu = menu;
statusItem.Image = NSImage.ImageNamed("statusicon");
statusItem.HighlightMode = true;
menu.RemoveAllItems ();
browseMenuItem = new NSMenuItem ("Browse Media Library", "b", delegate {
Browse (NSApplication.SharedApplication);
});
menu.AddItem (browseMenuItem);
configureMenuItem = new NSMenuItem ("Configure Media Browser", "c", delegate {
Configure (NSApplication.SharedApplication);
});
menu.AddItem (configureMenuItem);
communityMenuItem = new NSMenuItem ("Visit Community", "v", delegate {
Community (NSApplication.SharedApplication);
});
menu.AddItem (communityMenuItem);
quitMenuItem = new NSMenuItem ("Quit", "q", delegate {
Quit (NSApplication.SharedApplication);
});
menu.AddItem (quitMenuItem);
}
示例3: Update
public void Update (MDMenu parent, ref NSMenuItem lastSeparator, ref int index)
{
Enabled = true;
Hidden = Submenu != NSApplication.SharedApplication.ServicesMenu;
if (!Hidden)
MDMenu.ShowLastSeparator (ref lastSeparator);
}
示例4: Run
public void Run (NSMenuItem sender)
{
var a = sender as MDExpandedArrayItem;
if (a != null) {
manager.DispatchCommand (ce.CommandId, a.Info.DataItem, CommandSource.MainMenu);
} else {
manager.DispatchCommand (ce.CommandId, CommandSource.MainMenu);
}
}
示例5: ValidateMenuItem
public bool ValidateMenuItem(NSMenuItem item)
{
var h = Handler;
if (h != null)
{
h.Widget.OnValidate(EventArgs.Empty);
return h.Enabled;
}
return false;
}
示例6: Update
public void Update (MDMenu parent, ref NSMenuItem lastSeparator, ref int index)
{
if (ces.AutoHide) {
((MDMenu)Submenu).UpdateCommands ();
Hidden = Submenu.ItemArray ().All (item => item.Hidden);
}
if (!Hidden) {
MDMenu.ShowLastSeparator (ref lastSeparator);
}
}
示例7: FinishedLaunching
public override void FinishedLaunching(NSObject notification)
{
// mainWindowController = new MainWindowController ();
// mainWindowController.Window.MakeKeyAndOrderFront (this);
// Construct menu that will be displayed when tray icon is clicked
var notifyMenu = new NSMenu();
var exitMenuItem = new NSMenuItem("Quit",
(a,b) => {
NSApplication.SharedApplication.Terminate(this);
//System.Environment.Exit(0);
});
var startMidiModMenuItem = new NSMenuItem("Run",
(a,b) => { RunMidiMod(); });
var mappingmodMidiModMenuItem = new NSMenuItem("Mapping Mod",
(a,b) => { ActivateMappingMod(); });
statusMenuItem = new NSMenuItem("STATUS",
(a,b) => { });
statusMenuItem.Enabled = false;
var versionMenuItem = new NSMenuItem("Version 1.0",
(a,b) => { });
versionMenuItem.Enabled = false;
var seperatorItem = NSMenuItem.SeparatorItem;
notifyMenu.AutoEnablesItems = false;
// Just add 'Quit' command
notifyMenu.AddItem (statusMenuItem);
notifyMenu.AddItem (versionMenuItem);
notifyMenu.AddItem (seperatorItem);
notifyMenu.AddItem (startMidiModMenuItem);
notifyMenu.AddItem (mappingmodMidiModMenuItem);
notifyMenu.AddItem(exitMenuItem);
// Display tray icon in upper-right-hand corner of the screen
sItem = NSStatusBar.SystemStatusBar.CreateStatusItem(16); //def 16
sItem.Menu = notifyMenu;
sItem.Title = "MidiMod";
sItem.ToolTip = "Midi Mod";
sItem.Image = NSImage.FromStream(System.IO.File.OpenRead(NSBundle.MainBundle.ResourcePath + @"/9b244f1232672041.icns"));
sItem.HighlightMode = true;
UpdateStatus ("Mod not startet");
// Remove the system tray icon from upper-right hand corner of the screen
// (works without adjusting the LSUIElement setting in Info.plist)
NSApplication.SharedApplication.ActivationPolicy =
NSApplicationActivationPolicy.Accessory;
}
示例8: RepositoryMenuItem
public RepositoryMenuItem(Repository repo, StatusIconController controller) : base(repo.Name) {
this.repository = repo;
this.controller = controller;
this.Image = this.folderImage;
this.Image.Size = new SizeF(16, 16);
this.repository.PropertyChanged += (object sender, System.ComponentModel.PropertyChangedEventArgs e) => {
if (e.PropertyName == CmisSync.Lib.Utils.NameOf((Repository r) => r.Status)) {
this.Status = this.repository.Status;
}
if (e.PropertyName == CmisSync.Lib.Utils.NameOf((Repository r) => r.LastFinishedSync)) {
this.changesFoundAt = this.repository.LastFinishedSync;
this.UpdateStatusText();
}
if (e.PropertyName == CmisSync.Lib.Utils.NameOf((Repository r) => r.NumberOfChanges)) {
this.changesFound = this.repository.NumberOfChanges;
this.UpdateStatusText();
}
};
this.openLocalFolderItem = new NSMenuItem(Properties_Resources.OpenLocalFolder) {
Image = this.folderImage
};
this.openLocalFolderItem.Image.Size = new SizeF(16, 16);
this.openLocalFolderItem.Activated += this.OpenFolderDelegate();
this.editItem = new NSMenuItem(Properties_Resources.Settings);
this.editItem.Activated += this.EditFolderDelegate();
this.suspendItem = new NSMenuItem(Properties_Resources.PauseSync);
this.Status = repo.Status;
this.suspendItem.Activated += this.SuspendSyncFolderDelegate();
this.statusItem = new NSMenuItem(Properties_Resources.StatusSearchingForChanges) {
Enabled = false
};
this.removeFolderFromSyncItem = new NSMenuItem(Properties_Resources.RemoveFolderFromSync);
this.removeFolderFromSyncItem.Activated += this.RemoveFolderFromSyncDelegate();
var subMenu = new NSMenu();
subMenu.AddItem(this.statusItem);
subMenu.AddItem(NSMenuItem.SeparatorItem);
subMenu.AddItem(this.openLocalFolderItem);
subMenu.AddItem(this.suspendItem);
subMenu.AddItem(this.editItem);
subMenu.AddItem(NSMenuItem.SeparatorItem);
subMenu.AddItem(this.removeFolderFromSyncItem);
this.Submenu = subMenu;
}
示例9: Run
public void Run (NSMenuItem sender)
{
var a = sender as MDExpandedArrayItem;
//if the command opens a modal subloop, give cocoa a chance to unhighlight the menu item
GLib.Timeout.Add (1, () => {
if (a != null) {
manager.DispatchCommand (ce.CommandId, a.Info.DataItem, CommandSource.MainMenu);
} else {
manager.DispatchCommand (ce.CommandId, CommandSource.MainMenu);
}
return false;
});
}
示例10: ValidateMenuItem
public bool ValidateMenuItem(NSMenuItem menuItem)
{
switch ((MenuTag) (int)menuItem.Tag)
{
case MenuTag.AlwaysEnable:
return true;
case MenuTag.RequiresFile:
return mediaListController.Count > 0;
}
logger.Info("ValidateMenuItem: unexpected tag {0} for menu item '{1}'", menuItem.Tag, menuItem.Title);
return false;
}
示例11: DidFinishLaunching
public override void DidFinishLaunching(NSNotification notification)
{
var menu = new NSMenu ();
var menuItem = new NSMenuItem ();
menu.AddItem (menuItem);
var appMenu = new NSMenu ();
var quitItem = new NSMenuItem ("Quit " + NSProcessInfo.ProcessInfo.ProcessName, "q", (s, e) => NSApplication.SharedApplication.Terminate (menu));
appMenu.AddItem (quitItem);
var window = new NSWindow ();
menuItem.Submenu = appMenu;
NSApplication.SharedApplication.MainMenu = menu;
}
示例12: CreateNsMenu
private void CreateNsMenu() {
var menu = new NSMenu ();
statusItem = NSStatusBar.SystemStatusBar.CreateStatusItem(30);
statusItem.Menu = menu;
statusItem.Image = NSImage.ImageNamed("statusicon");
statusItem.HighlightMode = true;
menu.RemoveAllItems ();
browseMenuItem = new NSMenuItem ("Browse Media Library", "b", delegate {
Browse (NSApplication.SharedApplication);
});
menu.AddItem (browseMenuItem);
configureMenuItem = new NSMenuItem ("Configure Media Browser", "c", delegate {
Configure (NSApplication.SharedApplication);
});
menu.AddItem (configureMenuItem);
developerMenuItem = new NSMenuItem ("Developer Resources");
menu.AddItem (developerMenuItem);
var developerMenu = new NSMenu ();
developerMenuItem.Submenu = developerMenu;
apiMenuItem = new NSMenuItem ("Api Documentation", "a", delegate {
ApiDocs (NSApplication.SharedApplication);
});
developerMenu.AddItem (apiMenuItem);
githubMenuItem = new NSMenuItem ("Github", "g", delegate {
Github (NSApplication.SharedApplication);
});
developerMenu.AddItem (githubMenuItem);
communityMenuItem = new NSMenuItem ("Visit Community", "v", delegate {
Community (NSApplication.SharedApplication);
});
menu.AddItem (communityMenuItem);
quitMenuItem = new NSMenuItem ("Quit", "q", delegate {
Quit (NSApplication.SharedApplication);
});
menu.AddItem (quitMenuItem);
}
示例13: MenuItemWrapper
public MenuItemWrapper(string text, Duplicati.GUI.TrayIcon.MenuIcons icon, Action callback, IList<Duplicati.GUI.TrayIcon.IMenuItem> subitems)
{
if (text == "-")
m_item = NSMenuItem.SeparatorItem;
else
{
m_item = new NSMenuItem(text, ClickHandler);
m_callback = callback;
if (subitems != null && subitems.Count > 0)
{
m_item.Submenu = new NSMenu();
foreach(var itm in subitems)
m_item.Submenu.AddItem(((MenuItemWrapper)itm).MenuItem);
}
}
}
示例14: SelectEncodingPopUpButton
public SelectEncodingPopUpButton (bool showAutoDetected)
{
Cell.UsesItemFromMenu = false;
if (showAutoDetected) {
autoDetectedItem = new NSMenuItem () {
Title = GettextCatalog.GetString ("Auto Detected"),
Tag = -1,
Target = this,
Action = itemActivationSel,
};
}
addRemoveItem = new NSMenuItem () {
Title = GettextCatalog.GetString ("Add or Remove..."),
Tag = -20,
Target = this,
Action = addRemoveActivationSel,
};
Populate (false);
SelectedEncodingId = 0;
}
示例15: AwakeFromNib
public override void AwakeFromNib ()
{
base.AwakeFromNib ();
#region first two buttons
// add the image menu item back to the first menu item
NSMenuItem menuItem = new NSMenuItem ("", new Selector (""), "");
menuItem.Image = NSImage.ImageNamed ("moof.png");
buttonMenu.InsertItematIndex (menuItem, 0);
nibBasedPopUpDown.Menu = buttonMenu;
nibBasedPopUpRight.Menu = buttonMenu;
// create the pull down button pointing DOWN
RectangleF buttonFrame = placeHolder1.Frame;
codeBasedPopUpDown = new NSPopUpButton (buttonFrame, true);
((NSPopUpButtonCell)codeBasedPopUpDown.Cell).ArrowPosition = NSPopUpArrowPosition.Bottom;
((NSPopUpButtonCell)codeBasedPopUpDown.Cell).BezelStyle = NSBezelStyle.ThickSquare;
codeBasedPopUpDown.Menu = buttonMenu;
popupBox.AddSubview (codeBasedPopUpDown);
placeHolder1.RemoveFromSuperview ();
// create the pull down button pointing RIGHT
buttonFrame = placeHolder2.Frame;
codeBasedPopUpRight = new NSPopUpButton (buttonFrame, true);
((NSPopUpButtonCell)codeBasedPopUpRight.Cell).ArrowPosition = NSPopUpArrowPosition.Bottom;
((NSPopUpButtonCell)codeBasedPopUpRight.Cell).PreferredEdge = NSRectEdge.MaxXEdge;
((NSPopUpButtonCell)codeBasedPopUpRight.Cell).BezelStyle = NSBezelStyle.Circular;
codeBasedPopUpRight.Menu = buttonMenu;
((NSPopUpButtonCell)codeBasedPopUpRight.Cell).HighlightsBy = (int)NSCellMask.ChangeGrayCell;
popupBox.AddSubview (codeBasedPopUpRight);
placeHolder2.RemoveFromSuperview ();
#endregion
#region second two buttons
// create the rounded button
buttonFrame = placeHolder3.Frame;
// note: this button we want alternate title and image, so we need to call this:
codeBasedButtonRound = new NSButton (buttonFrame) {
Title = "NSButton",
AlternateTitle = "(pressed)",
Image = NSImage.ImageNamed ("moof.png"),
AlternateImage = NSImage.ImageNamed ("moof2.png"),
BezelStyle = NSBezelStyle.RegularSquare,
ImagePosition = NSCellImagePosition.ImageLeft,
Font = NSFont.SystemFontOfSize (NSFont.SmallSystemFontSize),
Sound = NSSound.FromName ("Pop"),
};
// Two choices, either use the .NET event system:
// foo.Activated += delegate {..} or += SomeMethod
//
// Or you can use the Target = this Action = new Selector ("buttonAction:")
// pattern
codeBasedButtonRound.Activated += delegate {
buttonAction (null);
};
codeBasedButtonRound.SetButtonType (NSButtonType.MomentaryChange);
codeBasedButtonRound.Cell.Alignment = NSTextAlignment.Left;
buttonBox.AddSubview (codeBasedButtonRound);
placeHolder3.RemoveFromSuperview (); // we are done with the place holder, remove it from the window
// create the square button
buttonFrame = placeHolder4.Frame;
codeBasedButtonSquare = new NSButton (buttonFrame){
Title = "NSButton",
BezelStyle = NSBezelStyle.ShadowlessSquare,
ImagePosition = NSCellImagePosition.ImageLeft,
Image = NSImage.ImageNamed ("moof.png"),
Font = NSFont.SystemFontOfSize (NSFont.SmallSystemFontSize),
Sound = NSSound.FromName ("Pop"),
};
codeBasedButtonSquare.Activated += delegate { buttonAction (null); };
codeBasedButtonSquare.Cell.Alignment = NSTextAlignment.Left;
buttonBox.AddSubview (codeBasedButtonSquare);
placeHolder4.RemoveFromSuperview (); // we are done with the place holder, remove it from the window
#endregion
#region segmented control
buttonFrame = placeHolder5.Frame;
codeBasedSegmentControl = new NSSegmentedControl(buttonFrame) {
SegmentCount = 3,
Target = this,
Action = new Selector("segmentAction:")
};
codeBasedSegmentControl.SetWidth (nibBasedSegControl.GetWidth(0), 0);
codeBasedSegmentControl.SetWidth (nibBasedSegControl.GetWidth (1), 1);
codeBasedSegmentControl.SetWidth (nibBasedSegControl.GetWidth (2), 2);
codeBasedSegmentControl.SetLabel ("One", 0);
codeBasedSegmentControl.SetLabel ("Two", 1);
codeBasedSegmentControl.SetLabel ("Three", 2);
segmentBox.AddSubview (codeBasedSegmentControl);
//.........这里部分代码省略.........