Пример #1
0
		public TitleMenuItem (MonoDevelop.Components.Commands.CommandManager manager, CommandEntry entry, CommandInfo commandArrayInfo = null, CommandSource commandSource = CommandSource.MainMenu, object initialCommandTarget = null, Menu menu = null)
		{
			this.manager = manager;
			this.initialCommandTarget = initialCommandTarget;
			this.commandSource = commandSource;
			this.commandArrayInfo = commandArrayInfo;

			this.menu = menu;
			menuEntry = entry;
			menuEntrySet = entry as CommandEntrySet;
			menuLinkEntry = entry as LinkCommandEntry;

			if (commandArrayInfo != null) {
				Header = commandArrayInfo.Text;

				var commandArrayInfoSet = commandArrayInfo as CommandInfoSet;
				if (commandArrayInfoSet != null) {
					foreach (var item in commandArrayInfoSet.CommandInfos) {
						if (item.IsArraySeparator)
							Items.Add (new Separator { UseLayoutRounding = true, });
						else
							Items.Add (new TitleMenuItem (manager, entry, item, commandSource, initialCommandTarget, menu));
					}
				}
			}

			if (menuEntrySet != null) {
				Header = menuEntrySet.Name;

				foreach (CommandEntry item in menuEntrySet) {
					if (item.CommandId == MonoDevelop.Components.Commands.Command.Separator) {
						Items.Add (new Separator { UseLayoutRounding = true, });
					} else
						Items.Add (new TitleMenuItem (manager, item, menu: menu));
				}
			} else if (menuLinkEntry != null) {
				Header = menuLinkEntry.Text;
				Click += OnMenuLinkClicked;
			} else if (entry != null) {
				actionCommand = manager.GetCommand (menuEntry.CommandId) as ActionCommand;
				if (actionCommand == null)
					return;

				IsCheckable = actionCommand.ActionType == ActionType.Check;

				// FIXME: Use proper keybinding text.
				if (actionCommand.KeyBinding != null)
					InputGestureText = actionCommand.KeyBinding.ToString ();
				
				if (!actionCommand.Icon.IsNull)
					Icon = new Image { Source = actionCommand.Icon.GetImageSource (Xwt.IconSize.Small) };
				Click += OnMenuClicked;
			}

			Height = SystemParameters.CaptionHeight;
			UseLayoutRounding = true;
		}
Пример #2
0
		public MDMenuItem (CommandManager manager, CommandEntry ce, ActionCommand command)
		{
			this.ce = ce;
			this.manager = manager;

			isArrayItem = command.CommandArray;

			Target = this;
			Action = ActionSel;
		}
		public void Add (CommandEntry entry)
		{
			Widget w = CreateWidget (entry);
			if (w is Button) {
				buttons.Add (new ToolButtonStatus (entry.CommandId, (Gtk.Button) w));
				((Gtk.Button) w).Clicked += delegate {
					IdeApp.CommandService.DispatchCommand (entry.CommandId, null, initialTarget, CommandSource.MainToolbar);
				};
			}
			toolbar.Add (w);
		}
Пример #4
0
		public MDMenuItem (CommandManager manager, CommandEntry ce, ActionCommand command, CommandSource commandSource, object initialCommandTarget)
		{
			this.ce = ce;
			this.manager = manager;
			this.initialCommandTarget = initialCommandTarget;
			this.commandSource = commandSource;

			isArrayItem = command.CommandArray;

			Target = this;
			Action = ActionSel;
		}
Пример #5
0
		void Update (CommandInfo cmdInfo)
		{
			lastCmdInfo = cmdInfo;
			if (isArray && !isArrayItem) {
				this.Visible = false;
				Gtk.Menu menu = (Gtk.Menu) Parent;  
				
				if (itemArray != null) {
					foreach (Gtk.MenuItem item in itemArray)
						menu.Remove (item);
				}
				
				itemArray = new ArrayList ();
				int i = Array.IndexOf (menu.Children, this);
				
				if (cmdInfo.ArrayInfo != null) {
					foreach (CommandInfo info in cmdInfo.ArrayInfo) {
						Gtk.MenuItem item;
						if (info.IsArraySeparator) {
							item = new Gtk.SeparatorMenuItem ();
							item.Show ();
						} else {
							item = CommandEntry.CreateMenuItem (commandManager, commandId, false);
							ICommandMenuItem mi = (ICommandMenuItem) item; 
							mi.SetUpdateInfo (info, initialTarget);
						}
						menu.Insert (item, ++i);
						itemArray.Add (item);
					}
				}
			} else {
				Gtk.Widget child = Child;
				if (child == null)
					return;
				
				Gtk.Label accel_label = null;
				Gtk.Label label = null;
				
				if (!(child is Gtk.HBox)) {
					child = new Gtk.HBox (false, 0);
					accel_label = new Gtk.Label ("");
					accel_label.UseUnderline = false;
					accel_label.Xalign = 1.0f;
					accel_label.Show ();
					
					label = new Gtk.Label ("");
					label.UseUnderline = true;
					label.Xalign = 0.0f;
					label.Show ();
					
					((Gtk.Box) child).PackStart (label);
					((Gtk.Box) child).PackStart (accel_label);
					child.Show ();
					
					this.Remove (Child);
					this.Add (child);
				} else {
					accel_label = (Gtk.Label) ((Gtk.Box) child).Children[1];
					label = (Gtk.Label) ((Gtk.Box) child).Children[0];
				}
				
				if (cmdInfo.AccelKey != null)
					accel_label.Text = "    " + KeyBindingManager.BindingToDisplayLabel (cmdInfo.AccelKey, true);
				else
					accel_label.Text = String.Empty;
				
				if (cmdInfo.UseMarkup) {
					label.Markup = overrideLabel ?? cmdInfo.Text;
					label.UseMarkup = true;
				} else {
					label.Text = overrideLabel ?? cmdInfo.Text;
					label.UseMarkup = false;
				}

				if (!string.IsNullOrEmpty (cmdInfo.Description) && label.TooltipText != cmdInfo.Description)
					label.TooltipText = cmdInfo.Description;
				label.UseUnderline = true;
				
				this.Sensitive = cmdInfo.Enabled;
				this.Visible = cmdInfo.Visible && (disabledVisible || cmdInfo.Enabled);
				
				if (!cmdInfo.Icon.IsNull && cmdInfo.Icon != lastIcon) {
					Image = new Gtk.Image (cmdInfo.Icon, Gtk.IconSize.Menu);
					lastIcon = cmdInfo.Icon;
				}
				
				if (cmdInfo is CommandInfoSet) {
					CommandInfoSet ciset = (CommandInfoSet) cmdInfo;
					Gtk.Menu smenu = new Gtk.Menu ();
					Submenu = smenu;
					foreach (CommandInfo info in ciset.CommandInfos) {
						Gtk.MenuItem item;
						if (info.IsArraySeparator) {
							item = new Gtk.SeparatorMenuItem ();
							item.Show ();
						} else {
							item = CommandEntry.CreateMenuItem (commandManager, commandId, false);
							ICommandMenuItem mi = (ICommandMenuItem) item; 
							mi.SetUpdateInfo (info, initialTarget);
						}
						smenu.Add (item);
					}
				}
			}			
		}
		public CommandEntry AddItem (object cmdId)
		{
			CommandEntry cmd = new CommandEntry (cmdId);
			cmds.Add (cmd);
			return cmd;
		}
		public void Add (CommandEntry entry)
		{
			cmds.Add (entry);
		}
		static Gtk.Widget CreateWidget (CommandEntry entry)
		{
			if (entry.CommandId == Command.Separator)
				return new Gtk.SeparatorToolItem ();

			Command cmd = entry.GetCommand (IdeApp.CommandService);
			if (cmd == null)
				return new Gtk.Label ();
			
			if (cmd is CustomCommand) {
				Gtk.Widget ti = (Gtk.Widget) Activator.CreateInstance (((CustomCommand)cmd).WidgetType);
				if (cmd.Text != null && cmd.Text.Length > 0) {
					//strip "_" accelerators from tooltips
					string text = cmd.Text;
					while (true) {
						int underscoreIndex = text.IndexOf ('_');
						if (underscoreIndex > -1)
							text = text.Remove (underscoreIndex, 1);
						else
							break;
					}
					ti.TooltipText = text;
				}
				return ti;
			}
			
			ActionCommand acmd = cmd as ActionCommand;
			if (acmd == null)
				throw new InvalidOperationException ("Unknown cmd type.");

			if (acmd.CommandArray) {
				throw new InvalidOperationException ("Command arrays not supported.");
			}
			else if (acmd.ActionType == ActionType.Normal)
				return new Button ();
			else
				return new ToggleButton ();
		}
 public void Add(CommandEntry entry)
 {
     cmds.Add(entry);
 }