public void ConnectionPoints_DeleteAll() { var page1 = this.GetNewPage(); var s1 = page1.DrawRectangle(0, 0, 4, 1); Assert.AreEqual(0, ConnectionPointHelper.GetCount(s1)); var cp_type = VisioScripting.Models.ConnectionPointType.Inward; var xpositions = new[] { "Width*0.25", "Width*0.30", "Width*0.75", "Width*0.90" }; var ypos = "Height*0"; foreach (var xpos in xpositions) { var cp = new ConnectionPointCells(); cp.X = xpos; cp.Y = ypos; cp.DirX = 0; cp.DirY = 0; cp.Type = (int)cp_type; ConnectionPointHelper.Add(s1, cp); } Assert.AreEqual(4, ConnectionPointHelper.GetCount(s1)); int num_deleted = ConnectionPointHelper.Delete(s1); Assert.AreEqual(4, num_deleted); Assert.AreEqual(0, ConnectionPointHelper.GetCount(s1)); page1.Delete(0); }
public void ConnectionPoints_Set() { var page1 = this.GetNewPage(); var s1 = page1.DrawRectangle(0, 0, 4, 1); Assert.AreEqual(0, ConnectionPointHelper.GetCount(s1)); var cp_type = VisioScripting.Models.ConnectionPointType.Inward; var xpositions = new[] { "Width*0.25", "Width*0.30", "Width*0.75", "Width*0.90" }; var ypositions = new[] { "Height*0.15", "Height*0.21", "Height*0.65", "Height*0.89" }; foreach (int i in Enumerable.Range(0, xpositions.Length)) { var xpos = xpositions[i]; var ypos = ypositions[i]; var cp = new ConnectionPointCells(); cp.X = xpos; cp.Y = ypos; cp.DirX = 0; cp.DirY = 0; cp.Type = (int)cp_type; ConnectionPointHelper.Add(s1, cp); } Assert.AreEqual(4, ConnectionPointHelper.GetCount(s1)); var desired_cp0 = new ConnectionPointCells(); desired_cp0.X = "Width*0.025"; desired_cp0.Y = "Height*0.015"; var desired_cp1 = new ConnectionPointCells(); desired_cp1.X = "Width*0.0025"; desired_cp1.Y = "Height*0.0015"; ConnectionPointHelper.Set(s1, 0, desired_cp0); ConnectionPointHelper.Set(s1, 1, desired_cp1); var actual_cp = ConnectionPointCells.GetCells(s1, CellValueType.Formula); Assert.AreEqual(desired_cp0.X, actual_cp[0].X); Assert.AreEqual(desired_cp0.Y, actual_cp[0].Y); Assert.AreEqual(desired_cp1.X, actual_cp[1].X); Assert.AreEqual(desired_cp1.Y, actual_cp[1].Y); page1.Delete(0); }
public void DeleteConnectionPointAtIndex(Models.TargetShapes targets, int index) { targets = targets.ResolveShapes(this._client); if (targets.Shapes.Count < 1) { return; } // restrict the operation to those shapes that actually have enough // connection points to qualify for deleting var qualified_shapes = targets.Shapes.Where(shape => ConnectionPointHelper.GetCount(shape) > index); using (var undoscope = this._client.Undo.NewUndoScope(nameof(DeleteConnectionPointAtIndex))) { foreach (var shape in qualified_shapes) { ConnectionPointHelper.Delete(shape, index); } } }
public void Delete(TargetShapes targets, int index) { this._client.Application.AssertApplicationAvailable(); this._client.Document.AssertDocumentAvailable(); var shapes = targets.ResolveShapes(this._client); if (shapes.Shapes.Count < 1) { return; } var target_shapes = shapes.Shapes.Where(shape => ConnectionPointHelper.GetCount(shape) > index); using (var undoscope = this._client.Application.NewUndoScope("Delete Connection Point")) { foreach (var shape in target_shapes) { ConnectionPointHelper.Delete(shape, index); } } }
public List <int> Add(TargetShapes targets, string fx, string fy, ConnectionPointType type) { this._client.Application.AssertApplicationAvailable(); this._client.Document.AssertDocumentAvailable(); targets = targets.ResolveShapes(this._client); if (targets.Shapes.Count < 1) { return(new List <int>(0)); } int dirx = 0; int diry = 0; var indices = new List <int>(targets.Shapes.Count); using (var undoscope = this._client.Application.NewUndoScope("Add Connection Point")) { var cp = new ConnectionPointCells(); cp.X = fx; cp.Y = fy; cp.DirX = dirx; cp.DirY = diry; cp.Type = (int)type; foreach (var shape in targets.Shapes) { int index = ConnectionPointHelper.Add(shape, cp); indices.Add(index); } } return(indices); }
public List <int> AddConnectionPoint( Models.TargetShapes targets, string fx, string fy, Models.ConnectionPointType type) { targets = targets.ResolveShapes(this._client); if (targets.Shapes.Count < 1) { return(new List <int>(0)); } int dirx = 0; int diry = 0; var indices = new List <int>(targets.Shapes.Count); using (var undoscope = this._client.Undo.NewUndoScope(nameof(AddConnectionPoint))) { var cp = new ConnectionPointCells(); cp.X = fx; cp.Y = fy; cp.DirX = dirx; cp.DirY = diry; cp.Type = (int)type; foreach (var shape in targets.Shapes) { int index = ConnectionPointHelper.Add(shape, cp); indices.Add(index); } } return(indices); }
public void ConnectionPoints_AddRemove() { var page1 = this.GetNewPage(); var s1 = page1.DrawRectangle(0, 0, 4, 1); Assert.AreEqual(0, ConnectionPointHelper.GetCount(s1)); var cp_type = VisioScripting.Models.ConnectionPointType.Inward; var cpd1 = new ConnectionPointCells(); cpd1.X = "Width*0.25"; cpd1.Y = "Height*0"; cpd1.Type = (int)cp_type; var cpd2 = new ConnectionPointCells(); cpd2.X = "Width*0.75"; cpd2.Y = "Height*0"; cpd2.Type = (int)cp_type; ConnectionPointHelper.Add(s1, cpd1); Assert.AreEqual(1, ConnectionPointHelper.GetCount(s1)); ConnectionPointHelper.Add(s1, cpd2); Assert.AreEqual(2, ConnectionPointHelper.GetCount(s1)); var controlpoints_f = ConnectionPointCells.GetCells(s1, CellValueType.Formula); var controlpoints_r = ConnectionPointCells.GetCells(s1, CellValueType.Result); Assert.AreEqual(2, controlpoints_f.Count); Assert.AreEqual(2, controlpoints_r.Count); var cp_f0 = controlpoints_f[0]; var cp_r0 = controlpoints_r[0]; Assert.AreEqual("0 in", cp_f0.DirX.Value); Assert.AreEqual("0 in", cp_f0.DirY.Value); Assert.AreEqual("0", cp_f0.Type.Value); Assert.AreEqual("Width*0.25", cp_f0.X.Value); Assert.AreEqual("Height*0", cp_f0.Y.Value); Assert.AreEqual("0.0000 in.", cp_r0.DirX.Value); Assert.AreEqual("0.0000 in.", cp_r0.DirY.Value); Assert.AreEqual("0", cp_r0.Type.Value); Assert.AreEqual("1.0000 in.", cp_r0.X.Value); Assert.AreEqual("0.0000 in.", cp_r0.Y.Value); var cp_f1 = controlpoints_f[1]; var cp_r1 = controlpoints_r[1]; Assert.AreEqual("0 in", cp_f1.DirX.Value); Assert.AreEqual("0 in", cp_f1.DirY.Value); Assert.AreEqual("0", cp_f1.Type.Value); Assert.AreEqual("Width*0.75", cp_f1.X.Value); Assert.AreEqual("Height*0", cp_f1.Y.Value); Assert.AreEqual("0.0000 in.", cp_r1.DirX.Value); Assert.AreEqual("0.0000 in.", cp_r1.DirY.Value); Assert.AreEqual("0", cp_r1.Type.Value); Assert.AreEqual("3.0000 in.", cp_r1.X.Value); Assert.AreEqual("0.0000 in.", cp_r1.Y.Value); ConnectionPointHelper.Delete(s1, 1); Assert.AreEqual(1, ConnectionPointHelper.GetCount(s1)); ConnectionPointHelper.Delete(s1, 0); Assert.AreEqual(0, ConnectionPointHelper.GetCount(s1)); page1.Delete(0); }
public void ConnectionPoints_AddRemove() { var page1 = this.GetNewPage(); var s1 = page1.DrawRectangle(0, 0, 4, 1); Assert.AreEqual(0, ConnectionPointHelper.GetCount(s1)); var cp_type = ConnectionPointType.Inward; var cpd1 = new ConnectionPointCells(); cpd1.X = "Width*0.25"; cpd1.Y = "Height*0"; cpd1.Type = (int)cp_type; var cpd2 = new ConnectionPointCells(); cpd2.X = "Width*0.75"; cpd2.Y = "Height*0"; cpd2.Type = (int)cp_type; ConnectionPointHelper.Add(s1, cpd1); Assert.AreEqual(1, ConnectionPointHelper.GetCount(s1)); ConnectionPointHelper.Add(s1, cpd2); Assert.AreEqual(2, ConnectionPointHelper.GetCount(s1)); var controlpoints = ConnectionPointCells.GetCells(s1); Assert.AreEqual(2, controlpoints.Count); var cp_0 = controlpoints[0]; Assert.AreEqual("0 in", cp_0.DirX.Formula); Assert.AreEqual("0 in", cp_0.DirY.Formula); Assert.AreEqual("0", cp_0.Type.Formula); Assert.AreEqual("Width*0.25", cp_0.X.Formula); Assert.AreEqual("Height*0", cp_0.Y.Formula); Assert.AreEqual("0.0000 in.", cp_0.DirX.Result); Assert.AreEqual("0.0000 in.", cp_0.DirY.Result); Assert.AreEqual("0", cp_0.Type.Result); Assert.AreEqual("1.0000 in.", cp_0.X.Result); Assert.AreEqual("0.0000 in.", cp_0.Y.Result); var cp_1 = controlpoints[1]; Assert.AreEqual("0 in", cp_1.DirX.Formula); Assert.AreEqual("0 in", cp_1.DirY.Formula); Assert.AreEqual("0", cp_1.Type.Formula); Assert.AreEqual("Width*0.75", cp_1.X.Formula); Assert.AreEqual("Height*0", cp_1.Y.Formula); Assert.AreEqual("0.0000 in.", cp_1.DirX.Result); Assert.AreEqual("0.0000 in.", cp_1.DirY.Result); Assert.AreEqual("0", cp_1.Type.Result); Assert.AreEqual("3.0000 in.", cp_1.X.Result); Assert.AreEqual("0.0000 in.", cp_1.Y.Result); ConnectionPointHelper.Delete(s1, 1); Assert.AreEqual(1, ConnectionPointHelper.GetCount(s1)); ConnectionPointHelper.Delete(s1, 0); Assert.AreEqual(0, ConnectionPointHelper.GetCount(s1)); page1.Delete(0); }
public void ViewCreationWithLanguage() { using (OleServiceProvider provider = OleServiceProvider.CreateOleServiceProviderWithBasicServices()) { // Create a mock text buffer for the console. BaseMock textLinesMock = MockFactories.TextBufferFactory.GetInstance(); // The buffer have to handle a few of connection points in order to enable the // creation of a Source object from the language service. ConnectionPointHelper.AddConnectionPointsToContainer( textLinesMock, new Type[] { typeof(IVsFinalTextChangeCommitEvents), typeof(IVsTextLinesEvents), typeof(IVsUserDataEvents) }); // Create the local registry mock and add the text buffer to it. LocalRegistryMock mockLocalRegistry = new LocalRegistryMock(); mockLocalRegistry.AddClass(typeof(VsTextBufferClass), textLinesMock); // Define the mock object for the text view. BaseMock textViewMock = MockFactories.TextViewFactory.GetInstance(); // Create the connection point for IVsTextViewEvents (needed for the language service). ConnectionPointHelper.AddConnectionPointsToContainer(textViewMock, new Type[] { typeof(IVsTextViewEvents) }); // Add the text view to the local registry. mockLocalRegistry.AddClass(typeof(VsTextViewClass), textViewMock); MockPackage package = new MockPackage(); ((IVsPackage)package).SetSite(provider); provider.AddService(typeof(Microsoft.VisualStudio.Shell.Package), package, true); // Create the language service and add it to the list of services. PythonLanguage language = new MockLanguage(); provider.AddService(typeof(PythonLanguage), language, true); language.SetSite(provider); // We need to add a method tip window to the local registry in order to create // a Source object. IVsMethodTipWindow methodTip = MockFactories.MethodTipFactory.GetInstance() as IVsMethodTipWindow; mockLocalRegistry.AddClass(typeof(VsMethodTipWindowClass), methodTip); // Create a mock expansion manager that is needed for the language service. BaseMock expansionManager = MockFactories.ExpansionManagerFactory.GetInstance(); ConnectionPointHelper.AddConnectionPointsToContainer(expansionManager, new Type[] { typeof(IVsExpansionEvents) }); Assembly asm = typeof(Microsoft.VisualStudio.Package.LanguageService).Assembly; Type expMgrType = asm.GetType("Microsoft.VisualStudio.Package.SVsExpansionManager"); provider.AddService(expMgrType, expansionManager, false); // Add the local registry to the list of services. provider.AddService(typeof(SLocalRegistry), mockLocalRegistry, false); using (ToolWindowPane windowPane = CommandWindowHelper.CreateConsoleWindow(provider) as ToolWindowPane) { Assert.IsNotNull(windowPane); // Call the CreatePaneWindow method that will force the creation of the text view. IntPtr newHwnd; Assert.IsTrue(Microsoft.VisualStudio.ErrorHandler.Succeeded( ((IVsWindowPane)windowPane).CreatePaneWindow(IntPtr.Zero, 0, 0, 0, 0, out newHwnd))); // Verify that the language service contains a special view for this text view. FieldInfo specialSourcesField = typeof(PythonLanguage).GetField("specialSources", BindingFlags.Instance | BindingFlags.NonPublic); Assert.IsNotNull(specialSourcesField); Dictionary <IVsTextView, PythonSource> specialSources = (Dictionary <IVsTextView, PythonSource>)specialSourcesField.GetValue(language); PythonSource source; Assert.IsTrue(specialSources.TryGetValue(textViewMock as IVsTextView, out source)); Assert.IsNotNull(source); // Set ColorState to null so that Dispose will not call Marshal.ReleaseComObject on it. source.ColorState = null; } } }