Example #1
0
        public void ShowMenu()
        {
            ContextMenuStrip cms = new ContextMenuStrip
            {
                Font = new Font("Arial", 10f),
                AutoClose = false,
                ShowImageMargin = false
            };

            if (Program.Settings != null && Program.Settings.QuickTaskPresets != null && Program.Settings.QuickTaskPresets.Count > 0)
            {
                foreach (QuickTaskInfo taskInfo in Program.Settings.QuickTaskPresets)
                {
                    if (taskInfo.IsValid)
                    {
                        ToolStripMenuItem tsmi = new ToolStripMenuItem { Text = taskInfo.ToString().Replace("&", "&&"), Tag = taskInfo };
                        tsmi.Click += (sender, e) =>
                        {
                            QuickTaskInfo selectedTaskInfo = ((ToolStripMenuItem)sender).Tag as QuickTaskInfo;
                            cms.Close();
                            OnTaskInfoSelected(selectedTaskInfo);
                        };
                        cms.Items.Add(tsmi);
                    }
                    else
                    {
                        cms.Items.Add(new ToolStripSeparator());
                    }
                }

                cms.Items[0].Select();

                cms.Items.Add(new ToolStripSeparator());
            }

            // Translate
            ToolStripMenuItem tsmiEdit = new ToolStripMenuItem("Edit this menu...");
            tsmiEdit.Click += (sender, e) =>
            {
                cms.Close();
                new QuickTaskMenuEditorForm().ShowDialog();
            };
            cms.Items.Add(tsmiEdit);

            cms.Items.Add(new ToolStripSeparator());

            ToolStripMenuItem tsmiCancel = new ToolStripMenuItem("Cancel");
            tsmiCancel.Click += (sender, e) => cms.Close();
            cms.Items.Add(tsmiCancel);

            Point cursorPosition = CaptureHelpers.GetCursorPosition();
            cursorPosition.Offset(-10, -10);
            cms.Show(cursorPosition);
        }
Example #2
0
        private void InitializeNotifyIcon()
        {
            _notifyIcon = new NotifyIcon
            {
                Text    = Infrastructure.Constant.Wox,
                Icon    = Properties.Resources.app,
                Visible = true
            };
            var menu  = new ContextMenuStrip();
            var items = menu.Items;

            var open = items.Add(InternationalizationManager.Instance.GetTranslation("iconTrayOpen"));

            open.Click += (o, e) => Visibility = Visibility.Visible;
            var setting = items.Add(InternationalizationManager.Instance.GetTranslation("iconTraySettings"));

            setting.Click += (o, e) => App.API.OpenSettingDialog();
            var exit = items.Add(InternationalizationManager.Instance.GetTranslation("iconTrayExit"));

            exit.Click += (o, e) => Close();

            _notifyIcon.ContextMenuStrip = menu;
            _notifyIcon.MouseClick      += (o, e) =>
            {
                if (e.Button == MouseButtons.Left)
                {
                    if (menu.Visible)
                    {
                        menu.Close();
                    }
                    else
                    {
                        var p = System.Windows.Forms.Cursor.Position;
                        menu.Show(p);
                    }
                }
            };
        }
Example #3
0
        public void ShowMenu()
        {
            ContextMenuStrip cms = new ContextMenuStrip()
            {
                Font = new Font("Arial", 10f),
                AutoClose = false
            };

            ToolStripMenuItem tsmiContinue = new ToolStripMenuItem(Resources.QuickTaskMenu_ShowMenu_Continue);
            tsmiContinue.Image = Resources.control;
            tsmiContinue.Click += (sender, e) =>
            {
                cms.Close();
                OnTaskInfoSelected(null);
            };
            cms.Items.Add(tsmiContinue);

            cms.Items.Add(new ToolStripSeparator());

            if (Program.Settings != null && Program.Settings.QuickTaskPresets != null && Program.Settings.QuickTaskPresets.Count > 0)
            {
                foreach (QuickTaskInfo taskInfo in Program.Settings.QuickTaskPresets)
                {
                    if (taskInfo.IsValid)
                    {
                        ToolStripMenuItem tsmi = new ToolStripMenuItem { Text = taskInfo.ToString().Replace("&", "&&"), Tag = taskInfo };
                        tsmi.Image = FindSuitableIcon(taskInfo);
                        tsmi.Click += (sender, e) =>
                        {
                            QuickTaskInfo selectedTaskInfo = ((ToolStripMenuItem)sender).Tag as QuickTaskInfo;
                            cms.Close();
                            OnTaskInfoSelected(selectedTaskInfo);
                        };
                        cms.Items.Add(tsmi);
                    }
                    else
                    {
                        cms.Items.Add(new ToolStripSeparator());
                    }
                }

                cms.Items[0].Select();

                cms.Items.Add(new ToolStripSeparator());
            }

            ToolStripMenuItem tsmiEdit = new ToolStripMenuItem(Resources.QuickTaskMenu_ShowMenu_Edit_this_menu___);
            tsmiEdit.Image = Resources.pencil;
            tsmiEdit.Click += (sender, e) =>
            {
                cms.Close();
                new QuickTaskMenuEditorForm().ShowDialog();
            };
            cms.Items.Add(tsmiEdit);

            cms.Items.Add(new ToolStripSeparator());

            ToolStripMenuItem tsmiCancel = new ToolStripMenuItem(Resources.QuickTaskMenu_ShowMenu_Cancel);
            tsmiCancel.Image = Resources.cross;
            tsmiCancel.Click += (sender, e) => cms.Close();
            cms.Items.Add(tsmiCancel);

            Point cursorPosition = CaptureHelpers.GetCursorPosition();
            cursorPosition.Offset(-10, -10);
            cms.Show(cursorPosition);
        }
Example #4
0
        public static ContextMenuStrip CreateCodesMenu(TextBox tb, params ReplacementVariables[] ignoreList)
        {
            ContextMenuStrip cms = new ContextMenuStrip
            {
                Font = new XmlFont("Lucida Console", 8),
                AutoClose = false,
                Opacity = 0.9,
                ShowImageMargin = false
            };

            var variables = Enum.GetValues(typeof(ReplacementVariables)).Cast<ReplacementVariables>().Where(x => !ignoreList.Contains(x)).
                Select(x => new
                {
                    Name = ReplacementExtension.Prefix + Enum.GetName(typeof(ReplacementVariables), x),
                    Description = x.GetDescription(),
                    Enum = x
                });

            foreach (var variable in variables)
            {
                ToolStripMenuItem tsmi = new ToolStripMenuItem { Text = string.Format("{0} - {1}", variable.Name, variable.Description), Tag = variable.Name };
                tsmi.Click += (sender, e) =>
                {
                    string text = ((ToolStripMenuItem)sender).Tag.ToString();
                    tb.AppendTextToSelection(text);
                };
                cms.Items.Add(tsmi);
            }

            cms.Items.Add(new ToolStripSeparator());

            ToolStripMenuItem tsmiClose = new ToolStripMenuItem("Close");
            tsmiClose.Click += (sender, e) => cms.Close();
            cms.Items.Add(tsmiClose);

            tb.MouseDown += (sender, e) =>
            {
                if (cms.Items.Count > 0) cms.Show(tb, new Point(tb.Width + 1, 0));
            };

            tb.Leave += (sender, e) =>
            {
                if (cms.Visible) cms.Close();
            };

            tb.KeyDown += (sender, e) =>
            {
                if ((e.KeyCode == Keys.Enter || e.KeyCode == Keys.Escape) && cms.Visible)
                {
                    cms.Close();
                    e.SuppressKeyPress = true;
                }
            };

            tb.Disposed += (sender, e) => cms.Dispose();

            return cms;
        }
        ContextMenuStrip CreateMenu(XGEffectBlockType type)
        {
            ContextMenuStrip strip = new ContextMenuStrip();
            EffectSelectorMenu container = new EffectSelectorMenu();
            strip.Items.Add(container);

            for (int i = 0; i < XGEffect.AllEffects.Count; i++)
            {
                XGEffect efct = XGEffect.AllEffects[i];
                if (type >= XGEffectBlockType.Variation
                    || (type == XGEffectBlockType.Reverb && efct.SelectableForReverb)
                    || (type == XGEffectBlockType.Chorus && efct.SelectableForChorus))
                {
                    container.AddButton(XGEffect.AllEffects[i].Name,
                        XGEffect.AllEffects[i].Description,
                        () => { strip.Close(); DecideEffect(type, efct); },
                        efct.SelectableForReverb & efct.SelectableForChorus ? Color.DarkGray :
                        efct.SelectableForReverb ? Color.Maroon :
                        efct.SelectableForChorus ? Color.Teal :
                        Color.Navy
                        );
                }
            }
            strip.LayoutStyle = ToolStripLayoutStyle.Flow;

            return strip;
        }
Example #6
0
		/// <summary>
		/// This method will create and show the destination picker menu
		/// </summary>
		/// <param name="addDynamics">Boolean if the dynamic values also need to be added</param>
		/// <param name="surface">The surface which can be exported</param>
		/// <param name="captureDetails">Details for the surface</param>
		/// <param name="destinations">The list of destinations to show</param>
		/// <returns></returns>
		public ExportInformation ShowPickerMenu(bool addDynamics, ISurface surface, ICaptureDetails captureDetails, IEnumerable<IDestination> destinations) {
			// Generate an empty ExportInformation object, for when nothing was selected.
			ExportInformation exportInformation = new ExportInformation(Designation, Language.GetString("settings_destination_picker"));
			ContextMenuStrip menu = new ContextMenuStrip();
			menu.ImageScalingSize = configuration.IconSize;
			menu.Tag = null;

			menu.Closing += delegate(object source, ToolStripDropDownClosingEventArgs eventArgs) {
				LOG.DebugFormat("Close reason: {0}", eventArgs.CloseReason);
				switch (eventArgs.CloseReason) {
					case ToolStripDropDownCloseReason.AppFocusChange:
						if (menu.Tag == null) {
							// Do not allow the close if the tag is not set, this means the user clicked somewhere else.
							eventArgs.Cancel = true;
						} else {
							LOG.DebugFormat("Letting the menu 'close' as the tag is set to '{0}'", menu.Tag);
						}
						break;
					case ToolStripDropDownCloseReason.ItemClicked:
					case ToolStripDropDownCloseReason.CloseCalled:
						// The ContextMenuStrip can be "closed" for these reasons.
						break;
					case ToolStripDropDownCloseReason.Keyboard:
						// Dispose as the close is clicked
						if (!captureDetails.HasDestination("Editor")) {
							surface.Dispose();
							surface = null;
						}
						break;
					default:
						eventArgs.Cancel = true;
						break;
				}
			};
			menu.MouseEnter += delegate(object source, EventArgs eventArgs) {
				// in case the menu has been unfocused, focus again so that dropdown menus will still open on mouseenter
				if(!menu.ContainsFocus) menu.Focus();
			};
			foreach (IDestination destination in destinations) {
				// Fix foreach loop variable for the delegate
				ToolStripMenuItem item = destination.GetMenuItem(addDynamics, menu,
					delegate(object sender, EventArgs e) {
						ToolStripMenuItem toolStripMenuItem = sender as ToolStripMenuItem;
						if (toolStripMenuItem == null) {
							return;
						}
						IDestination clickedDestination = (IDestination)toolStripMenuItem.Tag;
						if (clickedDestination == null) {
							return;
						}
						menu.Tag = clickedDestination.Designation;
						// Export
						exportInformation = clickedDestination.ExportCapture(true, surface, captureDetails);
						if (exportInformation != null && exportInformation.ExportMade) {
							LOG.InfoFormat("Export to {0} success, closing menu", exportInformation.DestinationDescription);
							// close menu if the destination wasn't the editor
							menu.Close();

							// Cleanup surface, only if there is no editor in the destinations and we didn't export to the editor
							if (!captureDetails.HasDestination("Editor") && !"Editor".Equals(clickedDestination.Designation)) {
								surface.Dispose();
								surface = null;
							}
						} else {
							LOG.Info("Export cancelled or failed, showing menu again");

							// Make sure a click besides the menu don't close it.
							menu.Tag = null;

							// This prevents the problem that the context menu shows in the task-bar
							ShowMenuAtCursor(menu);
						}
					}
				);
				if (item != null) {
					menu.Items.Add(item);
				}
			}
			// Close
			menu.Items.Add(new ToolStripSeparator());
			ToolStripMenuItem closeItem = new ToolStripMenuItem(Language.GetString("editor_close"));
			closeItem.Image = GreenshotResources.getImage("Close.Image");
			closeItem.Click += delegate {
				// This menu entry is the close itself, we can dispose the surface
				menu.Close();
				if (!captureDetails.HasDestination("Editor")) {
					surface.Dispose();
					surface = null;
				}
			};
			menu.Items.Add(closeItem);

			ShowMenuAtCursor(menu);
			return exportInformation;
		}
		public void ShowHideTest ()
		{
			ContextMenuStrip formMenu = new ContextMenuStrip ();
			formMenu.Items.Add ("form item 1");
			Form.ContextMenuStrip = formMenu;

			Label label = new Label ();
			label.Text = "I have my own context menu";
			ContextMenuStrip labelMenu = new ContextMenuStrip ();
			labelMenu.Items.Add ("label item 1");
			label.ContextMenuStrip = labelMenu;
			Form.Controls.Add (label);
			label.Show ();

			var labelProvider = ProviderFactory.FindProvider (label);
			Assert.IsNotNull (labelProvider,
			                  "Form's label should have a provider");

			// No menu providers unless shown
			IRawElementProviderFragment formMenuProvider =
				ProviderFactory.FindProvider (formMenu);
			Assert.IsNull (formMenuProvider,
			               "Form menu provider not expected until shown");
			IRawElementProviderFragment labelMenuProvider =
				ProviderFactory.FindProvider (labelMenu);
			Assert.IsNull (labelMenuProvider,
			               "Label menu provider not expected until shown");

			bridge.ResetEventLists ();

			// Test showing Form menu
			formMenu.Show ();

			formMenuProvider =
				ProviderFactory.FindProvider (formMenu);
			Assert.IsNotNull (formMenuProvider,
			                  "Form menu provider expected once menu is shown");
			labelMenuProvider =
				ProviderFactory.FindProvider (labelMenu);
			Assert.IsNull (labelMenuProvider,
			               "Label menu provider not expected until shown");

			Assert.AreEqual (FormProvider,
			                 formMenuProvider.Navigate (NavigateDirection.Parent),
			                 "Form menu parent should be Form");
			Assert.IsTrue (ProviderContainsChild (FormProvider, formMenuProvider),
			               "Form menu should be Form's child");

			var tuple = bridge.GetAutomationEventFrom (formMenuProvider,
			                                           AEIds.MenuOpenedEvent.Id);
			Assert.IsNotNull (tuple,
			                  "MenuOpenedEvent expected");

			bridge.ResetEventLists ();

			// Test closing Form menu
			formMenu.Close ();

			tuple = bridge.GetAutomationEventFrom (formMenuProvider,
			                                       AEIds.MenuClosedEvent.Id);
			Assert.IsNotNull (tuple,
			                  "MenuClosedEvent expected");

			formMenuProvider =
				ProviderFactory.FindProvider (formMenu);
			Assert.IsNull (formMenuProvider,
			               "Form menu provider should be gone after menu closed");
			Assert.IsFalse (ProviderContainsChildOfType (FormProvider, ControlType.Menu),
			                "Form should have no menu child after menu closed");

			bridge.ResetEventLists ();

			// Test showing Label menu
			labelMenu.Show ();

			formMenuProvider =
				ProviderFactory.FindProvider (formMenu);
			Assert.IsNull (formMenuProvider,
			                  "Form menu provider not expected while closed");
			labelMenuProvider =
				ProviderFactory.FindProvider (labelMenu);
			Assert.IsNotNull (labelMenuProvider,
			               "Label menu provider expected once menu is shown");

			Assert.AreEqual (labelProvider,
			                 labelMenuProvider.Navigate (NavigateDirection.Parent),
			                 "Label menu parent should be Label");
			Assert.IsTrue (ProviderContainsChild (labelProvider, labelMenuProvider),
			               "Label menu should be Label's child");

			tuple = bridge.GetAutomationEventFrom (labelMenuProvider,
			                                           AEIds.MenuOpenedEvent.Id);
			Assert.IsNotNull (tuple,
			                  "MenuOpenedEvent expected");

			bridge.ResetEventLists ();

			// Test closing Label menu
			labelMenu.Close ();

			tuple = bridge.GetAutomationEventFrom (labelMenuProvider,
			                                       AEIds.MenuClosedEvent.Id);
			Assert.IsNotNull (tuple,
			                  "MenuClosedEvent expected");

			labelMenuProvider =
				ProviderFactory.FindProvider (labelMenu);
			Assert.IsNull (labelMenuProvider,
			               "Label menu provider should be gone after menu closed");
			Assert.IsFalse (ProviderContainsChildOfType (labelProvider, ControlType.Menu),
			                "Label should have no menu child after menu closed");
		}
Example #8
0
        private void CreateContextMenu()
        {
            cmsContextMenu = new ContextMenuStrip(form.components);
            cmsContextMenu.Renderer = new ToolStripCheckedBoldRenderer();
            cmsContextMenu.IgnoreSeparatorClick();

            cmsContextMenu.PreviewKeyDown += (sender, e) =>
            {
                if (e.KeyCode == Keys.Escape)
                {
                    e.IsInputKey = true;
                }
            };

            cmsContextMenu.KeyUp += (sender, e) =>
            {
                if (e.KeyCode == Keys.Escape)
                {
                    cmsContextMenu.Close();
                }
            };

            #region Main

            ToolStripMenuItem tsmiCancelCapture = new ToolStripMenuItem("Cancel capture");
            tsmiCancelCapture.Image = Resources.prohibition;
            tsmiCancelCapture.Click += (sender, e) => form.Close(RegionResult.Close);
            cmsContextMenu.Items.Add(tsmiCancelCapture);

            ToolStripMenuItem tsmiCloseMenu = new ToolStripMenuItem("Close menu");
            tsmiCloseMenu.Image = Resources.cross;
            tsmiCloseMenu.Click += (sender, e) => cmsContextMenu.Close();
            cmsContextMenu.Items.Add(tsmiCloseMenu);

            #endregion Main

            #region Selected object

            tssObjectOptions = new ToolStripSeparator();
            cmsContextMenu.Items.Add(tssObjectOptions);

            tsmiDeleteSelected = new ToolStripMenuItem("Delete selected object");
            tsmiDeleteSelected.Image = Resources.layer__minus;
            tsmiDeleteSelected.Click += (sender, e) => DeleteCurrentShape();
            cmsContextMenu.Items.Add(tsmiDeleteSelected);

            tsmiDeleteAll = new ToolStripMenuItem("Delete all objects");
            tsmiDeleteAll.Image = Resources.minus;
            tsmiDeleteAll.Click += (sender, e) => ClearAll();
            cmsContextMenu.Items.Add(tsmiDeleteAll);

            #endregion Selected object

            #region Tools

            cmsContextMenu.Items.Add(new ToolStripSeparator());

            foreach (ShapeType shapeType in Helpers.GetEnums<ShapeType>())
            {
                ToolStripMenuItem tsmiShapeType = new ToolStripMenuItem(shapeType.GetLocalizedDescription());

                Image img = null;

                switch (shapeType)
                {
                    case ShapeType.RegionRectangle:
                        img = Resources.layer_shape_region;
                        break;
                    case ShapeType.RegionRoundedRectangle:
                        img = Resources.layer_shape_round_region;
                        break;
                    case ShapeType.RegionEllipse:
                        img = Resources.layer_shape_ellipse_region;
                        break;
                    case ShapeType.DrawingRectangle:
                        img = Resources.layer_shape;
                        break;
                    case ShapeType.DrawingRoundedRectangle:
                        img = Resources.layer_shape_round;
                        break;
                    case ShapeType.DrawingEllipse:
                        img = Resources.layer_shape_ellipse;
                        break;
                    case ShapeType.DrawingLine:
                        img = Resources.layer_shape_line;
                        break;
                    case ShapeType.DrawingArrow:
                        img = Resources.layer_shape_arrow;
                        break;
                    case ShapeType.DrawingText:
                        img = Resources.layer_shape_text;
                        break;
                    case ShapeType.DrawingStep:
                        img = Resources.counter_reset;
                        break;
                    case ShapeType.DrawingBlur:
                        img = Resources.layer_shade;
                        break;
                    case ShapeType.DrawingPixelate:
                        img = Resources.grid;
                        break;
                    case ShapeType.DrawingHighlight:
                        img = Resources.highlighter_text;
                        break;
                }

                tsmiShapeType.Image = img;

                tsmiShapeType.Checked = shapeType == CurrentShapeType;
                tsmiShapeType.Tag = shapeType;
                tsmiShapeType.Click += (sender, e) =>
                {
                    tsmiShapeType.RadioCheck();
                    CurrentShapeType = shapeType;
                };
                cmsContextMenu.Items.Add(tsmiShapeType);
            }

            #endregion Tools

            #region Shape options

            tssShapeOptions = new ToolStripSeparator();
            cmsContextMenu.Items.Add(tssShapeOptions);

            tsmiBorderColor = new ToolStripMenuItem("Border color...");
            tsmiBorderColor.Click += (sender, e) =>
            {
                PauseForm();

                ShapeType shapeType = CurrentShapeType;

                Color borderColor;

                if (shapeType == ShapeType.DrawingText)
                {
                    borderColor = AnnotationOptions.TextBorderColor;
                }
                else if (shapeType == ShapeType.DrawingStep)
                {
                    borderColor = AnnotationOptions.StepBorderColor;
                }
                else
                {
                    borderColor = AnnotationOptions.BorderColor;
                }

                using (ColorPickerForm dialogColor = new ColorPickerForm(borderColor))
                {
                    if (dialogColor.ShowDialog() == DialogResult.OK)
                    {
                        if (shapeType == ShapeType.DrawingText)
                        {
                            AnnotationOptions.TextBorderColor = dialogColor.NewColor;
                        }
                        else if (shapeType == ShapeType.DrawingStep)
                        {
                            AnnotationOptions.StepBorderColor = dialogColor.NewColor;
                        }
                        else
                        {
                            AnnotationOptions.BorderColor = dialogColor.NewColor;
                        }

                        UpdateContextMenu();
                        UpdateCurrentShape();
                    }
                }

                ResumeForm();
            };
            cmsContextMenu.Items.Add(tsmiBorderColor);

            tslnudBorderSize = new ToolStripLabeledNumericUpDown("Border size:");
            tslnudBorderSize.Content.Minimum = 0;
            tslnudBorderSize.Content.Maximum = 20;
            tslnudBorderSize.Content.ValueChanged = (sender, e) =>
            {
                ShapeType shapeType = CurrentShapeType;

                int borderSize = (int)tslnudBorderSize.Content.Value;

                if (shapeType == ShapeType.DrawingText)
                {
                    AnnotationOptions.TextBorderSize = borderSize;
                }
                else if (shapeType == ShapeType.DrawingStep)
                {
                    AnnotationOptions.StepBorderSize = borderSize;
                }
                else
                {
                    AnnotationOptions.BorderSize = borderSize;
                }

                UpdateCurrentShape();
            };
            cmsContextMenu.Items.Add(tslnudBorderSize);

            tsmiFillColor = new ToolStripMenuItem("Fill color...");
            tsmiFillColor.Click += (sender, e) =>
            {
                PauseForm();

                ShapeType shapeType = CurrentShapeType;

                Color fillColor;

                if (shapeType == ShapeType.DrawingText)
                {
                    fillColor = AnnotationOptions.TextFillColor;
                }
                else if (shapeType == ShapeType.DrawingStep)
                {
                    fillColor = AnnotationOptions.StepFillColor;
                }
                else
                {
                    fillColor = AnnotationOptions.FillColor;
                }

                using (ColorPickerForm dialogColor = new ColorPickerForm(fillColor))
                {
                    if (dialogColor.ShowDialog() == DialogResult.OK)
                    {
                        if (shapeType == ShapeType.DrawingText)
                        {
                            AnnotationOptions.TextFillColor = dialogColor.NewColor;
                        }
                        else if (shapeType == ShapeType.DrawingStep)
                        {
                            AnnotationOptions.StepFillColor = dialogColor.NewColor;
                        }
                        else
                        {
                            AnnotationOptions.FillColor = dialogColor.NewColor;
                        }

                        UpdateContextMenu();
                        UpdateCurrentShape();
                    }
                }

                ResumeForm();
            };
            cmsContextMenu.Items.Add(tsmiFillColor);

            tslnudRoundedRectangleRadius = new ToolStripLabeledNumericUpDown("Corner radius:");
            tslnudRoundedRectangleRadius.Content.Minimum = 0;
            tslnudRoundedRectangleRadius.Content.Maximum = 150;
            tslnudRoundedRectangleRadius.Content.Increment = 3;
            tslnudRoundedRectangleRadius.Content.ValueChanged = (sender, e) =>
            {
                AnnotationOptions.RoundedRectangleRadius = (int)tslnudRoundedRectangleRadius.Content.Value;
                UpdateCurrentShape();
            };
            cmsContextMenu.Items.Add(tslnudRoundedRectangleRadius);

            tslnudBlurRadius = new ToolStripLabeledNumericUpDown("Blur radius:");
            tslnudBlurRadius.Content.Minimum = 2;
            tslnudBlurRadius.Content.Maximum = 100;
            tslnudBlurRadius.Content.ValueChanged = (sender, e) =>
            {
                AnnotationOptions.BlurRadius = (int)tslnudBlurRadius.Content.Value;
                UpdateCurrentShape();
            };
            cmsContextMenu.Items.Add(tslnudBlurRadius);

            tslnudPixelateSize = new ToolStripLabeledNumericUpDown("Pixel size:");
            tslnudPixelateSize.Content.Minimum = 2;
            tslnudPixelateSize.Content.Maximum = 100;
            tslnudPixelateSize.Content.ValueChanged = (sender, e) =>
            {
                AnnotationOptions.PixelateSize = (int)tslnudPixelateSize.Content.Value;
                UpdateCurrentShape();
            };
            cmsContextMenu.Items.Add(tslnudPixelateSize);

            tsmiHighlightColor = new ToolStripMenuItem("Highlight color...");
            tsmiHighlightColor.Click += (sender, e) =>
            {
                PauseForm();

                using (ColorPickerForm dialogColor = new ColorPickerForm(AnnotationOptions.HighlightColor))
                {
                    if (dialogColor.ShowDialog() == DialogResult.OK)
                    {
                        AnnotationOptions.HighlightColor = dialogColor.NewColor;
                        UpdateContextMenu();
                        UpdateCurrentShape();
                    }
                }

                ResumeForm();
            };
            cmsContextMenu.Items.Add(tsmiHighlightColor);

            #endregion Shape options

            #region Capture

            cmsContextMenu.Items.Add(new ToolStripSeparator());

            ToolStripMenuItem tsmiFullscreenCapture = new ToolStripMenuItem("Capture fullscreen");
            tsmiFullscreenCapture.Image = Resources.layer_fullscreen;
            tsmiFullscreenCapture.Click += (sender, e) => form.Close(RegionResult.Fullscreen);
            cmsContextMenu.Items.Add(tsmiFullscreenCapture);

            ToolStripMenuItem tsmiActiveMonitorCapture = new ToolStripMenuItem("Capture active monitor");
            tsmiActiveMonitorCapture.Image = Resources.monitor;
            tsmiActiveMonitorCapture.Click += (sender, e) => form.Close(RegionResult.ActiveMonitor);
            cmsContextMenu.Items.Add(tsmiActiveMonitorCapture);

            ToolStripMenuItem tsmiMonitorCapture = new ToolStripMenuItem("Capture monitor");
            tsmiMonitorCapture.HideImageMargin();
            tsmiMonitorCapture.Image = Resources.monitor_window;
            cmsContextMenu.Items.Add(tsmiMonitorCapture);

            tsmiMonitorCapture.DropDownItems.Clear();

            Screen[] screens = Screen.AllScreens;

            for (int i = 0; i < screens.Length; i++)
            {
                Screen screen = screens[i];
                ToolStripMenuItem tsmi = new ToolStripMenuItem(string.Format("{0}. {1}x{2}", i + 1, screen.Bounds.Width, screen.Bounds.Height));
                int index = i;
                tsmi.Click += (sender, e) =>
                {
                    form.MonitorIndex = index;
                    form.Close(RegionResult.Monitor);
                };
                tsmiMonitorCapture.DropDownItems.Add(tsmi);
            }

            #endregion Capture

            #region Options

            cmsContextMenu.Items.Add(new ToolStripSeparator());

            ToolStripMenuItem tsmiOptions = new ToolStripMenuItem("Options");
            tsmiOptions.Image = Resources.gear;
            cmsContextMenu.Items.Add(tsmiOptions);

            ToolStripMenuItem tsmiQuickCrop = new ToolStripMenuItem("Multi region mode");
            tsmiQuickCrop.Checked = !Config.QuickCrop;
            tsmiQuickCrop.CheckOnClick = true;
            tsmiQuickCrop.Click += (sender, e) => Config.QuickCrop = !tsmiQuickCrop.Checked;
            tsmiOptions.DropDownItems.Add(tsmiQuickCrop);

            ToolStripMenuItem tsmiTips = new ToolStripMenuItem("Show tips");
            tsmiTips.Checked = Config.ShowTips;
            tsmiTips.CheckOnClick = true;
            tsmiTips.Click += (sender, e) => Config.ShowTips = tsmiTips.Checked;
            tsmiOptions.DropDownItems.Add(tsmiTips);

            ToolStripMenuItem tsmiShowInfo = new ToolStripMenuItem("Show position and size info");
            tsmiShowInfo.Checked = Config.ShowInfo;
            tsmiShowInfo.CheckOnClick = true;
            tsmiShowInfo.Click += (sender, e) => Config.ShowInfo = tsmiShowInfo.Checked;
            tsmiOptions.DropDownItems.Add(tsmiShowInfo);

            ToolStripMenuItem tsmiShowMagnifier = new ToolStripMenuItem("Show magnifier");
            tsmiShowMagnifier.Checked = Config.ShowMagnifier;
            tsmiShowMagnifier.CheckOnClick = true;
            tsmiShowMagnifier.Click += (sender, e) => Config.ShowMagnifier = tsmiShowMagnifier.Checked;
            tsmiOptions.DropDownItems.Add(tsmiShowMagnifier);

            ToolStripMenuItem tsmiUseSquareMagnifier = new ToolStripMenuItem("Square shape magnifier");
            tsmiUseSquareMagnifier.Checked = Config.UseSquareMagnifier;
            tsmiUseSquareMagnifier.CheckOnClick = true;
            tsmiUseSquareMagnifier.Click += (sender, e) => Config.UseSquareMagnifier = tsmiUseSquareMagnifier.Checked;
            tsmiOptions.DropDownItems.Add(tsmiUseSquareMagnifier);

            ToolStripLabeledNumericUpDown tslnudMagnifierPixelCount = new ToolStripLabeledNumericUpDown("Magnifier pixel count:");
            tslnudMagnifierPixelCount.Content.Minimum = 1;
            tslnudMagnifierPixelCount.Content.Maximum = 35;
            tslnudMagnifierPixelCount.Content.Increment = 2;
            tslnudMagnifierPixelCount.Content.Value = Config.MagnifierPixelCount;
            tslnudMagnifierPixelCount.Content.ValueChanged = (sender, e) => Config.MagnifierPixelCount = (int)tslnudMagnifierPixelCount.Content.Value;
            tsmiOptions.DropDownItems.Add(tslnudMagnifierPixelCount);

            ToolStripLabeledNumericUpDown tslnudMagnifierPixelSize = new ToolStripLabeledNumericUpDown("Magnifier pixel size:");
            tslnudMagnifierPixelSize.Content.Minimum = 2;
            tslnudMagnifierPixelSize.Content.Maximum = 30;
            tslnudMagnifierPixelSize.Content.Value = Config.MagnifierPixelSize;
            tslnudMagnifierPixelSize.Content.ValueChanged = (sender, e) => Config.MagnifierPixelSize = (int)tslnudMagnifierPixelSize.Content.Value;
            tsmiOptions.DropDownItems.Add(tslnudMagnifierPixelSize);

            ToolStripMenuItem tsmiShowCrosshair = new ToolStripMenuItem("Show screen wide crosshair");
            tsmiShowCrosshair.Checked = Config.ShowCrosshair;
            tsmiShowCrosshair.CheckOnClick = true;
            tsmiShowCrosshair.Click += (sender, e) => Config.ShowCrosshair = tsmiShowCrosshair.Checked;
            tsmiOptions.DropDownItems.Add(tsmiShowCrosshair);

            ToolStripMenuItem tsmiFixedSize = new ToolStripMenuItem("Fixed size region mode");
            tsmiFixedSize.Checked = Config.IsFixedSize;
            tsmiFixedSize.CheckOnClick = true;
            tsmiFixedSize.Click += (sender, e) => Config.IsFixedSize = tsmiFixedSize.Checked;
            tsmiOptions.DropDownItems.Add(tsmiFixedSize);

            ToolStripDoubleLabeledNumericUpDown tslnudFixedSize = new ToolStripDoubleLabeledNumericUpDown("Width:", "Height:");
            tslnudFixedSize.Content.Minimum = 5;
            tslnudFixedSize.Content.Maximum = 10000;
            tslnudFixedSize.Content.Increment = 10;
            tslnudFixedSize.Content.Value = Config.FixedSize.Width;
            tslnudFixedSize.Content.Value2 = Config.FixedSize.Height;
            tslnudFixedSize.Content.ValueChanged = (sender, e) => Config.FixedSize = new Size((int)tslnudFixedSize.Content.Value, (int)tslnudFixedSize.Content.Value2);
            tsmiOptions.DropDownItems.Add(tslnudFixedSize);

            ToolStripMenuItem tsmiShowFPS = new ToolStripMenuItem("Show FPS");
            tsmiShowFPS.Checked = Config.ShowFPS;
            tsmiShowFPS.CheckOnClick = true;
            tsmiShowFPS.Click += (sender, e) => Config.ShowFPS = tsmiShowFPS.Checked;
            tsmiOptions.DropDownItems.Add(tsmiShowFPS);

            #endregion Options

            CurrentShapeTypeChanged += shapeType => UpdateContextMenu();

            CurrentShapeChanged += shape => UpdateContextMenu();
        }
Example #9
0
        private void TemplateButon_Click(object sender, EventArgs e) {
            string addItemStr = Properties.Resources.SAVE_CURRENT_PREAMBLE + "...";
            string manageItemStr = Properties.Resources.MANAGE_TEMPLATES + "...";
            var menu = new ContextMenuStrip();
            foreach(var d in Properties.Settings.Default.preambleTemplates) {
                menu.Items.Add(new ToolStripMenuItem(d.Key) { Tag = d.Key });
            }
            menu.Items.Add(new ToolStripSeparator());
            menu.Items.Add(new ToolStripMenuItem(addItemStr) { Tag = addItemStr });
            menu.Items.Add(new ToolStripMenuItem(manageItemStr) { Tag = manageItemStr });
            menu.ItemClicked += ((ss, ee) => {
                menu.Close();
                var tag = (string) ee.ClickedItem.Tag;
                if(tag == manageItemStr) {
                    var managedlg = new ManageTemplateDialog(Properties.Settings.Default.preambleTemplates, preambleTextBox.Text, new List<string> { manageItemStr, addItemStr ,""});
                    if(managedlg.ShowDialog(mainForm) == System.Windows.Forms.DialogResult.OK) {
                        Properties.Settings.Default.preambleTemplates = managedlg.Templates;
                    }
                }else if(tag == addItemStr){
                    var input = new InputComboDialog(
                        Properties.Resources.ADD_TEMPLATEMSG,Properties.Resources.INPUTE_TEMPLATE_NAME,
                        Properties.Settings.Default.preambleTemplates.Select(d => d.Key).ToList());
                    input.OKButtonClicked += ((sss, eee) => {
                        if(eee.InputedText == manageItemStr || eee.InputedText == addItemStr || eee.InputedText == "") {
                            MessageBox.Show(String.Format(Properties.Resources.INPUTE_TEMPLATE_NAME, eee.InputedText), "TeX2img");
                            eee.Cancel = true;
                        } else if(Properties.Settings.Default.preambleTemplates.ContainsKey(eee.InputedText)) {
                            if(MessageBox.Show(
                                String.Format(Properties.Resources.OVERWRITETEMPLATEMSG,eee.InputedText), "TeX2img", MessageBoxButtons.YesNo) != System.Windows.Forms.DialogResult.Yes) {
                                eee.Cancel = true;
                            }
                        }
                    });
                    if(input.ShowDialog() == System.Windows.Forms.DialogResult.OK) {
                        Properties.Settings.Default.preambleTemplates[input.InputedText] = preambleTextBox.Text;
                    }
                } else {
                    try {
                        var text = Properties.Settings.Default.preambleTemplates[tag];
                        if(text != null) {
                            if(MessageBox.Show(String.Format(Properties.Resources.CHANGE_CURRENTPREAMBLE, text), "TeX2img", MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.Yes) {
                                preambleTextBox.Text = ChangeReturnCode(text);

                                var latex = Properties.Settings.Default.GuessPlatexPath(text, "");
                                var dvipdfmx = Properties.Settings.Default.GuessDvipdfmxPath(text, "");
                                string str = "";
                                if(latex != "") str += "\nlatex: " + latex;
                                if(dvipdfmx != "") str += "\nDVI driver: " + dvipdfmx;
                                if(str != "") {
                                    if(MessageBox.Show(String.Format(Properties.Resources.DETECT_RECOMMENDED_PATH, str), "TeX2img", MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.Yes) {
                                        if(latex != "") Properties.Settings.Default.platexPath = latex;
                                        if(dvipdfmx != "") Properties.Settings.Default.dvipdfmxPath = dvipdfmx;
                                    }
                                }
                            }
                        }
                    }
                    catch(KeyNotFoundException) { }
                    catch(ArgumentNullException) { }
                }
            });

            var btn = (Button) sender;
            menu.Show(btn, new Point(0, btn.Height));
        }
        public static ContextMenuStrip CreatePickerMenu(bool addDynamics, ISurface surface, ICaptureDetails captureDetails, IEnumerable<IDestination> destinations)
        {
            ContextMenuStrip menu = new ContextMenuStrip();
            menu.Closing += delegate(object source, ToolStripDropDownClosingEventArgs eventArgs) {
                LOG.DebugFormat("Close reason: {0}", eventArgs.CloseReason);
                if (eventArgs.CloseReason != ToolStripDropDownCloseReason.ItemClicked && eventArgs.CloseReason != ToolStripDropDownCloseReason.CloseCalled) {
                    eventArgs.Cancel = true;
                }
            };
            foreach (IDestination destination in destinations) {
                // Fix foreach loop variable for the delegate
                ToolStripMenuItem item = destination.GetMenuItem(addDynamics,
                    delegate(object sender, EventArgs e) {
                        ToolStripMenuItem toolStripMenuItem = sender as ToolStripMenuItem;
                        if (toolStripMenuItem == null) {
                            return;
                        }
                        IDestination clickedDestination = (IDestination)toolStripMenuItem.Tag;
                        if (clickedDestination == null) {
                            return;
                        }
                        // Make sure the menu is closed
                        menu.Close();
                        bool result = clickedDestination.ExportCapture(true, surface, captureDetails);
                        // TODO: Find some better way to detect that we exported to the editor
                        if (!EditorDestination.DESIGNATION.Equals(clickedDestination.Designation) || result == false) {
                            LOG.DebugFormat("Disposing as Destination was {0} and result {1}", clickedDestination.Description, result);
                            // Cleanup surface
                            surface.Dispose();
                        }
                    }
                );
                if (item != null) {
                    menu.Items.Add(item);
                }
            }
            // Close
            menu.Items.Add(new ToolStripSeparator());
            ToolStripMenuItem closeItem = new ToolStripMenuItem(Language.GetString(LangKey.editor_close));
            closeItem.Image = ((System.Drawing.Image)(new System.ComponentModel.ComponentResourceManager(typeof(ImageEditorForm)).GetObject("closeToolStripMenuItem.Image")));
            closeItem.Click += delegate {
                // This menu entry is the close itself, we can dispose the surface
                menu.Close();
                // Dispose as the close is clicked
                surface.Dispose();
            };
            menu.Items.Add(closeItem);

            return menu;
        }