/// <summary> /// A simple helper method which will call ExportCapture for the destination with the specified designation /// </summary> /// <param name="designation"></param> /// <param name="surface"></param> /// <param name="captureDetails"></param> public static ExportInformation ExportCapture(bool manuallyInitiated, string designation, ISurface surface, ICaptureDetails captureDetails) { IDestination destination = GetDestination(designation); if (destination != null && destination.isActive) { return(destination.ExportCapture(manuallyInitiated, surface, captureDetails)); } return(null); }
/// <summary> /// A simple helper method which will call ExportCapture for the destination with the specified designation /// </summary> /// <param name="designation"></param> /// <param name="surface"></param> /// <param name="captureDetails"></param> public static void ExportCapture(bool manuallyInitiated, string designation, ISurface surface, ICaptureDetails captureDetails) { if (RegisteredDestinations.ContainsKey(designation)) { IDestination destination = RegisteredDestinations[designation]; if (destination.isActive) { if (destination.ExportCapture(manuallyInitiated, surface, captureDetails)) { // Export worked, set the modified flag surface.Modified = false; } } } }
void AddDestinationButton(IDestination toolstripDestination) { if (toolstripDestination.isDynamic) { ToolStripSplitButton destinationButton = new ToolStripSplitButton(); //ToolStripDropDownButton destinationButton = new ToolStripDropDownButton(); destinationButton.DisplayStyle = ToolStripItemDisplayStyle.Image; destinationButton.Size = new Size(23, 22); destinationButton.Text = toolstripDestination.Description; destinationButton.Image = toolstripDestination.DisplayIcon; ToolStripMenuItem defaultItem = new ToolStripMenuItem(toolstripDestination.Description); defaultItem.Tag = toolstripDestination; defaultItem.Image = toolstripDestination.DisplayIcon; defaultItem.Click += delegate { toolstripDestination.ExportCapture(true, surface, surface.CaptureDetails); }; // The ButtonClick, this is for the icon, gets the current default item destinationButton.ButtonClick += delegate(object sender, EventArgs e) { toolstripDestination.ExportCapture(true, surface, surface.CaptureDetails); }; // Generate the entries for the drop down destinationButton.DropDownOpening += delegate(object sender, EventArgs e) { ClearItems(destinationButton.DropDownItems); destinationButton.DropDownItems.Add(defaultItem); List<IDestination> subDestinations = new List<IDestination>(); subDestinations.AddRange(toolstripDestination.DynamicDestinations()); if (subDestinations.Count > 0) { subDestinations.Sort(); foreach(IDestination subDestination in subDestinations) { IDestination closureFixedDestination = subDestination; ToolStripMenuItem destinationMenuItem = new ToolStripMenuItem(closureFixedDestination.Description); destinationMenuItem.Tag = closureFixedDestination; destinationMenuItem.Image = closureFixedDestination.DisplayIcon; destinationMenuItem.Click += delegate { closureFixedDestination.ExportCapture(true, surface, surface.CaptureDetails); }; destinationButton.DropDownItems.Add(destinationMenuItem); } } }; destinationsToolStrip.Items.Insert(destinationsToolStrip.Items.IndexOf(toolStripSeparator16), destinationButton); } else { ToolStripButton destinationButton = new ToolStripButton(); destinationsToolStrip.Items.Insert(destinationsToolStrip.Items.IndexOf(toolStripSeparator16), destinationButton); destinationButton.DisplayStyle = ToolStripItemDisplayStyle.Image; destinationButton.Size = new Size(23, 22); destinationButton.Text = toolstripDestination.Description; destinationButton.Image = toolstripDestination.DisplayIcon; destinationButton.Click += delegate(object sender, EventArgs e) { toolstripDestination.ExportCapture(true, surface, surface.CaptureDetails); }; } }
/// <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")); var menu = new ContextMenuStrip { ImageScalingSize = CoreConfig.IconSize, Tag = null, TopLevel = true }; 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 { // 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; 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")) { 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); }