Exemplo n.º 1
0
			public MenuConnector(CheckAction action, CheckMenuItem menuItem)
			{
				this.action = action;
				this.menuItem = menuItem;
				this.menuItem.Click += menuItem_Clicked;
				this.action.EnabledChanged += new EventHandler<EventArgs>(action_EnabledChanged).MakeWeak(e => this.action.EnabledChanged -= e);
				this.action.CheckedChanged += new EventHandler<EventArgs>(action_CheckedChanged).MakeWeak(e => this.action.CheckedChanged -= e);
			}
Exemplo n.º 2
0
 public override MenuItem Generate(ActionItem actionItem, ISubMenuWidget menu)
 {
     CheckMenuItem mi = new CheckMenuItem(menu.Generator);
     mi.Text = MenuText;
     mi.Shortcut = Accelerator;
     mi.Enabled = this.Enabled;
     mi.Checked = Checked;
     new MenuConnector(this, mi);
     return mi;
 }
Exemplo n.º 3
0
		public override MenuItem GenerateMenuItem(Generator generator)
		{
			var mi = new CheckMenuItem(generator);
			mi.Text = MenuText;
			mi.Shortcut = Accelerator;
			mi.Enabled = Enabled;
			mi.Checked = Checked;
			if (!string.IsNullOrEmpty(MenuItemStyle))
				mi.Style = MenuItemStyle;

			new MenuConnector(this, mi);
			return mi;
		}
Exemplo n.º 4
0
		public override MenuItem Generate(ActionItem actionItem, ISubMenuWidget menu)
		{
			CheckMenuItem mi = new CheckMenuItem(menu.Generator);
			mi.Text = MenuText;
			mi.Shortcut = Accelerator;
			mi.Enabled = this.Enabled;
			mi.Checked = Checked;
			if (!string.IsNullOrEmpty (MenuItemStyle))
				mi.Style = MenuItemStyle;

			new MenuConnector(this, mi);
			return mi;
		}
Exemplo n.º 5
0
 /// <summary>
 /// Raises the checked changed event.
 /// </summary>
 public void OnCheckedChanged(CheckMenuItem widget, EventArgs e)
 {
     widget.Platform.Invoke(() => widget.OnCheckedChanged(e));
 }
Exemplo n.º 6
0
			/// <summary>
			/// Raises the checked changed event.
			/// </summary>
			public void OnCheckedChanged(CheckMenuItem widget, EventArgs e)
			{
				widget.Platform.Invoke(() => widget.OnCheckedChanged(e));
			}
Exemplo n.º 7
0
 /// <summary>
 /// Raises the checked changed event.
 /// </summary>
 public void OnCheckedChanged(CheckMenuItem widget, EventArgs e)
 {
     using (widget.Platform.Context)
         widget.OnCheckedChanged(e);
 }
Exemplo n.º 8
0
		void CreateMenuToolBar()
		{
			var about = new Commands.About();
			var quit = new Commands.Quit();

			if (Platform.Supports<MenuBar>())
			{
				var fileCommand = new Command { MenuText = "File Command", Shortcut = Application.Instance.CommonModifier | Keys.F };
				fileCommand.Executed += (sender, e) => Log.Write(sender, "Executed");
				var editCommand = new Command { MenuText = "Edit Command", Shortcut = Keys.Shift | Keys.E };
				editCommand.Executed += (sender, e) => Log.Write(sender, "Executed");
				var viewCommand = new Command { MenuText = "View Command", Shortcut = Keys.Control | Keys.V };
				viewCommand.Executed += (sender, e) => Log.Write(sender, "Executed");
				var windowCommand = new Command { MenuText = "Window Command" };
				windowCommand.Executed += (sender, e) => Log.Write(sender, "Executed");

				var file = new ButtonMenuItem { Text = "&File", Items = { fileCommand } };
				var edit = new ButtonMenuItem { Text = "&Edit", Items = { editCommand } };
                var view = new ButtonMenuItem { Text = "&View", Items = { viewCommand } };
				var window = new ButtonMenuItem { Text = "&Window", Order = 1000, Items = { windowCommand } };

				if (Platform.Supports<CheckMenuItem>())
				{
					edit.Items.AddSeparator();

					var checkMenuItem1 = new CheckMenuItem { Text = "Check Menu Item", Shortcut = Keys.Shift | Keys.K };
					checkMenuItem1.Click += (sender, e) => Log.Write(checkMenuItem1, "Click, {0}, Checked: {1}", checkMenuItem1.Text, checkMenuItem1.Checked);
					checkMenuItem1.CheckedChanged += (sender, e) => Log.Write(checkMenuItem1, "CheckedChanged, {0}: {1}", checkMenuItem1.Text, checkMenuItem1.Checked);
					edit.Items.Add(checkMenuItem1);

					var checkMenuItem2 = new CheckMenuItem { Text = "Initially Checked Menu Item", Checked = true };
					checkMenuItem2.Click += (sender, e) => Log.Write(checkMenuItem2, "Click, {0}, Checked: {1}", checkMenuItem2.Text, checkMenuItem2.Checked);
					checkMenuItem2.CheckedChanged += (sender, e) => Log.Write(checkMenuItem2, "CheckedChanged, {0}: {1}", checkMenuItem2.Text, checkMenuItem2.Checked);
					edit.Items.Add(checkMenuItem2);
				}

				if (Platform.Supports<RadioMenuItem>())
				{
					edit.Items.AddSeparator();

					RadioMenuItem controller = null;
					for (int i = 0; i < 5; i++)
					{
						var radio = new RadioMenuItem(controller) { Text = "Radio Menu Item " + (i + 1) };
						radio.Click += (sender, e) => Log.Write(radio, "Click, {0}, Checked: {1}", radio.Text, radio.Checked);
						radio.CheckedChanged += (sender, e) => Log.Write(radio, "CheckedChanged, {0}: {1}", radio.Text, radio.Checked);
						edit.Items.Add(radio);

						if (controller == null)
						{
							radio.Checked = true; // check the first item initially
							controller = radio;
						}
					}

				}

				Menu = new MenuBar
				{
					Items =
					{
						// custom top-level menu items
						file, edit, view, window
					},
					ApplicationItems =
					{
						// custom menu items for the application menu (Application on OS X, File on others)
						new Command { MenuText = "Application command" },
						new ButtonMenuItem { Text = "Application menu item" }
					},
					HelpItems =
					{
						new Command { MenuText = "Help Command" }
					},
					QuitItem = quit,
					AboutItem = about
				};
			}

			if (Platform.Supports<ToolBar>())
			{
				// create and set the toolbar
				ToolBar = new ToolBar();

				ToolBar.Items.Add(about);
				if (Platform.Supports<CheckToolItem>())
				{
					ToolBar.Items.Add(new SeparatorToolItem { Type = SeparatorToolItemType.Divider });
					ToolBar.Items.Add(new CheckToolItem { Text = "Check", Image = TestIcons.TestImage });
				}
				if (Platform.Supports<RadioToolItem>())
				{
					ToolBar.Items.Add(new SeparatorToolItem { Type = SeparatorToolItemType.FlexibleSpace });
					ToolBar.Items.Add(new RadioToolItem { Text = "Radio1", Image = TestIcons.TestIcon, Checked = true });
					ToolBar.Items.Add(new RadioToolItem { Text = "Radio2", Image = TestIcons.TestImage });
				};
			}

		}
Exemplo n.º 9
0
		static Control TextReplacementsDropDown(TextArea text)
		{
			var control = new Button { Text = "TextReplacements" };
			control.Click += (sender, e) => {
				var replacements = text.TextReplacements;
				var supported = text.SupportedTextReplacements;
				var contextMenu = new ContextMenu();
				foreach (var val in Enum.GetValues(typeof(TextReplacements)).OfType<TextReplacements>())
				{
					if (val == TextReplacements.All || val == TextReplacements.None)
					{
						var item = new ButtonMenuItem { Text = val.ToString() };
						item.Click += (sender2, e2) => text.TextReplacements = val;
						contextMenu.Items.Add(item);
						continue;
					}
					if (!supported.HasFlag(val))
						continue;
					var checkItem = new CheckMenuItem { Text = val.ToString(), Checked = replacements.HasFlag(val) };
					checkItem.CheckedChanged += (sender2, e2) => {
						var rep = text.TextReplacements;
						if (checkItem.Checked)
							rep |= val;
						else
							rep &= ~val;
						text.TextReplacements = rep;
					};
					contextMenu.Items.Add(checkItem);
				}
				contextMenu.Show(control);
			};
			return control;
		}
Exemplo n.º 10
0
		void LogEvents(CheckMenuItem item)
		{
			if (item == null)
				return;
			item.CheckedChanged += delegate
			{
				Log.Write(item, "CheckedChanged, Item: {0}, Checked: {1}", item.Text, item.Checked);
			};
		}