public override void AddToTree(Shape s, bool allowAddInChildren) { //make s into an rcomponent for access to wrapper VisioShape shapeComponent = new VisioShape(Page) { Shape = s }; if (shapeComponent.Index == Index) { if (CheckBoxComponent.IsCheckBoxComponent(s.Name)) { if (Children.All(c => c.Index != shapeComponent.Index)) //there is no stub with this index { Children.Add(new CheckBoxComponent(Page, s)); } else { //remove stub, insert s as new containers CheckBoxStubComponent stub = (CheckBoxStubComponent)Children.First(c => c.Index == shapeComponent.Index); Children.Remove(stub); CheckBoxComponent con = new CheckBoxComponent(Page, s); if (Children.Count < con.Index) //TODO implement index { Children.Add(con); } else { Children.Insert(con.Index, con); } } } else if (PlanningItemTextComponent.IsPlanningItemTextComponent(s.Name)) { PlanningItemTextComponent com = new PlanningItemTextComponent(Page, s); if (com.Index == Index) //TODO implement index { Children.Add(com); } } else { if (CheckBoxStateComponent.IsCheckBoxStateComponent(s.Name) && Children.All(c => c.Index != shapeComponent.Index)) //if parent not exists { CheckBoxStubComponent stub = new CheckBoxStubComponent(Page, shapeComponent.Index); Children.Insert(stub.Index, stub); Children.ForEach(r => r.AddToTree(s, allowAddInChildren)); } else { Children.ForEach(r => r.AddToTree(s, allowAddInChildren)); } } } }
private void Application_MouseDown(int button, int keyButtonState, double x, double y, ref bool cancelDefault) { if (button != 1) //if other than the left mouse button was clicked { return; } PlanningContainer planningContainer = View.Children.FirstOrDefault(c => c is PlanningContainer) as PlanningContainer; //locate all checkbox elements in the view List <CheckBoxStateComponent> candidates = planningContainer?.Children //map all planning items to their checkbox child, and that checkbox to its state component .Select(planningItemComponent => ((PlanningItemComponent)planningItemComponent).Children .First(c => c is CheckBoxComponent)).Cast <CheckBoxComponent>() .Select(checkBox => (CheckBoxStateComponent)checkBox.Children.First()).ToList(); if (candidates == null) { return; } CheckBoxStateComponent stateComponent = null; //for all the candidates, check if the clicked location was within its bounds. Stop as soon as a match if found. foreach (CheckBoxStateComponent candidate in candidates) { if (candidate.WasClicked(x, y)) { int scopeId = Application.BeginUndoScope(Messages.Scope_CheckboxClick); candidate.Toggle(); //actual changing of the clicked checkbox's state Application.EndUndoScope(scopeId, true); break; } } //locate parent of stateComponent //PlanningItemComponent toStrikeThrough = planningContainer?.Children.Cast<PlanningItemComponent>().First(item => (item.Children.First(c => c is CheckBoxComponent) as CheckBoxComponent).Children.Contains(stateComponent)); //toStrikeThrough.Children.First(c => c is PlanningItemTextComponent).StrikeThrough = !toStrikeThrough.Children.First(c => c is PlanningItemTextComponent).StrikeThrough; }
private void Application_CellChangedEvent(Cell cell) { Shape changedShape = cell.Shape; // ReSharper disable once MergeSequentialChecksWhenPossible if ((changedShape == null) || !changedShape.Document.Template.Contains(Information.TemplateName) || (changedShape.CellExistsU[VisioFormulas.Cell_RationallyType, (short)VisExistsFlags.visExistsAnywhere] != Constants.CellExists)) //No need to continue when the shape is not part of our model. { return; } try { if (RelatedUrlComponent.IsRelatedUrlComponent(changedShape.Name) && cell.LocalName.Equals(VisioFormulas.Cell_HyperlinkAddress)) //Link has updated { Log.Debug("Cell changed of hyperlink shape:" + changedShape.Name); //find the container that holds all Related Documents RelatedDocumentsContainer relatedDocumentsContainer = (RelatedDocumentsContainer)View.Children.First(c => c is RelatedDocumentsContainer); //find the related document holding the changed shape (one of his children has Shape equal to changedShape) RelatedDocumentContainer relatedDocumentContainer = relatedDocumentsContainer.Children.Where(c => c is RelatedDocumentContainer).Cast <RelatedDocumentContainer>().First(dc => dc.Children.Where(c => c.Shape.Equals(changedShape)).ToList().Count > 0); //update the text of the URL display component to the new url RelatedURLURLComponent relatedURLURLComponent = (RelatedURLURLComponent)relatedDocumentContainer.Children.First(c => c is RelatedURLURLComponent); relatedURLURLComponent.Text = changedShape.Hyperlink.Address; } else if (Application.IsUndoingOrRedoing && CheckBoxStateComponent.IsCheckBoxStateComponent(changedShape.Name) && cell.LocalName.Equals(VisioFormulas.Cell_BackGroundColour)) { CheckBoxStateComponent checkBoxState = View.GetComponentByShape(changedShape) as CheckBoxStateComponent; if (checkBoxState != null) { Model.PlanningItems[checkBoxState.Index].Finished = checkBoxState.Checked; } } else if (Application.IsUndoingOrRedoing && ForceContainer.IsForceContainer(changedShape.Name) && cell.LocalName.Equals(VisioFormulas.Cell_Index)) { Log.Debug("Forceindex cell changed of forcecontainer. shape:" + changedShape.Name); VisioShape forcesComponent = View.Children.FirstOrDefault(x => x is ForcesContainer); if (forcesComponent != null) { rebuildTree = true; //Wait with the rebuild till the undo is done } } else if (Application.IsUndoingOrRedoing && AlternativeShape.IsAlternativeContainer(changedShape.Name) && cell.LocalName.Equals(VisioFormulas.Cell_Index)) { Log.Debug("Alternative index cell changed of alternativecontainer. shape:" + changedShape.Name); VisioShape alternativesComponent = View.Children.FirstOrDefault(x => x is AlternativesContainer); if (alternativesComponent != null) { rebuildTree = true; //Wait with the rebuild till the undo is done } } else if (Application.IsUndoingOrRedoing && RelatedDocumentContainer.IsRelatedDocumentContainer(changedShape.Name) && cell.LocalName.Equals(VisioFormulas.Cell_Index)) { Log.Debug("Document index cell changed of documentcontainer. shape:" + changedShape.Name); VisioShape docComponent = View.Children.FirstOrDefault(x => x is RelatedDocumentsContainer); if (docComponent != null) { rebuildTree = true; //Wait with the rebuild till the undo is done } } else if (Application.IsUndoingOrRedoing && StakeholderContainer.IsStakeholderContainer(changedShape.Name) && cell.LocalName.Equals(VisioFormulas.Cell_Index)) { Log.Debug("Stakeholder index cell changed of stakeholdercontainer. shape:" + changedShape.Name); VisioShape stakeholderComponent = View.Children.FirstOrDefault(x => x is StakeholdersContainer); if (stakeholderComponent != null) { rebuildTree = true; //Wait with the rebuild till the undo is done } } } catch (Exception ex) { Log.Error(ex, ex); #if DEBUG throw; #endif } }