/// <summary> /// Finds a shape. /// </summary> internal void FindShape() { if (this.Application.ActivePage == null) { return; } try { FindShape(this.Application.ActivePage); } catch (Exception ex) { ExceptionMessageBox.Show("Unhandled exception: FindShape", ex); } }
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ * * Shape commands * * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ /// <summary> /// Handles marker events, as emitted by the shapes. /// </summary> /// <param name="app">Visio application.</param> /// <param name="sequenceNum">Sequence number.</param> /// <param name="contextString">Context string, as defined in shape.</param> private void Application_MarkerEvent(Visio.Application app, int sequenceNum, string contextString) { #region Validations if (app == null) { throw new ArgumentNullException(nameof(app)); } #endregion try { Application_MarkerEventDo(app, sequenceNum, contextString); } catch (Exception ex) { ExceptionMessageBox.Show("Unhandled exception: Application_MarkerEvent", ex); } }
/// <summary> /// Executes the .ExportAll command. /// </summary> internal void ExportAll(ValidationMode mode) { if (this.Application.ActivePage == null) { return; } ModelCommand command = new ModelCommand() { Operation = ModelOperation.ExportAll, Document = this.Application.ActiveDocument, }; try { CommandExecute(command, mode); } catch (Exception ex) { ExceptionMessageBox.Show("Unhandled exception: ExportAll", ex); } }
private void ThisAddIn_Startup(object sender, System.EventArgs e) { try { /* * With regards to shapes/events, we're only interested in responding to * the MarkerEvent callback: the marker events are queued when interacting * directly with the shape itself (ie, double-clicking on the shape). */ this.Application.MarkerEvent += new Visio.EApplication_MarkerEventEventHandler(Application_MarkerEvent); /* * */ _initializedOk = true; } catch (Exception ex) { ExceptionMessageBox.Show("Unhandled exception: ThisAddIn_Startup", ex); } }
/// <summary> /// Implementation of the marker event logic. /// </summary> /// <param name="app">Visio application.</param> /// <param name="sequenceNum">Sequence number.</param> /// <param name="contextString">Context string, as defined in shape.</param> private void Application_MarkerEventDo(Visio.Application app, int sequenceNum, string contextString) { /* * */ if (_initializedOk == false) { return; } if (contextString == null) { return; } if (contextString.Contains("/au=1") == false) { return; } /* * Don't process any marker events that are being fired as a result * of a redo. */ if (this.Application.IsUndoingOrRedoing == true) { return; } /* * */ Dictionary <string, string> ctx = VU.ParseContext(contextString); if (ctx.ContainsKey("cmd") == false) { return; } /* * */ Visio.Shape shape = VU.GetShape(app, ctx); if (shape == null) { return; } string modelName = VU.GetProperty(shape, "User", "ModelName"); string shapeName = VU.GetProperty(shape, "User", "ModelShape"); if (string.IsNullOrEmpty(modelName) == true || string.IsNullOrEmpty(shapeName) == true) { return; } /* * Model */ IModelDefinition model; try { model = ModelCache.Load(modelName); } catch (Exception ex) { ExceptionMessageBox.Show("Model failed to load.", ex); return; } if (model == null) { ExceptionMessageBox.Show($"Model '{ modelName }' not found."); return; } /* * */ IShapeDefinition shapeDef = model.Shapes.Where(x => x.Name == shapeName).FirstOrDefault(); if (shapeDef == null) { ExceptionMessageBox.Show($"No shape definition for '{ shapeName }' found."); return; } /* * Drop command */ if (ctx["cmd"] == "drop") { /* * .Id */ string shapeId = Guid.NewGuid().ToString(); VU.SetProperty(shape, "Prop", "ShapeId", shapeId); /* * .Code */ string shapeCode = null; if (string.IsNullOrEmpty(shapeDef.ShapeCodePrefix) == false) { int sequence = PageIncrementSequence(shape, shapeDef.ShapeCodePrefix); shapeCode = string.Format(CultureInfo.InvariantCulture, shapeDef.ShapeCodeFormat, shapeDef.ShapeCodePrefix, sequence); VU.SetProperty(shape, "Prop", "ShapeCode", shapeCode); } /* * .Text */ string shapeXml = VU.GetProperty(shape, "Prop", "ShapeXml"); string shapeText = shapeDef.TextGet(shapeCode, shapeXml); if (string.IsNullOrEmpty(shapeText) == false) { VU.TextSet(shape, shapeText); } } /* * */ if (ctx["cmd"] == "edit") { string mode = "analysis"; //_toolbar.CurrentMode; string shapeCode = VU.GetProperty(shape, "Prop", "ShapeCode"); string shapeXml = VU.GetProperty(shape, "Prop", "ShapeXml"); XmlForm form = new XmlForm(); form.Initialize(shapeDef, mode, shapeCode, shapeXml); DialogResult result = form.ShowDialog(); if (result == DialogResult.OK) { VU.SetProperty(shape, "Prop", "ShapeXml", form.ShapeXml); VU.ShapeColorSet(shape, Visio.VisDefaultColors.visBlack); string shapeText = shapeDef.TextGet(shapeCode, form.ShapeXml); if (string.IsNullOrEmpty(shapeText) == false) { VU.TextSet(shape, shapeText); } } } }