public OfficePart(PackagePart part, XmlParts partType, string relationshipId) { this.Part = part; this.PartType = partType; this.id = relationshipId; this.Name = Path.GetFileName(this.Part.Uri.ToString()); }
public OfficePart CreateCustomPart(XmlParts partType) { string relativePath; string relType; switch (partType) { case XmlParts.RibbonX12: relativePath = "/customUI/customUI.xml"; relType = CustomUiPartRelType; break; case XmlParts.RibbonX14: relativePath = "/customUI/customUI14.xml"; relType = CustomUi14PartRelType; break; case XmlParts.Qat12: relativePath = "/customUI/qat.xml"; relType = QatPartRelType; break; default: Debug.Assert(false, "Unknown type"); // ReSharper disable once HeuristicUnreachableCode return(null); } var customUiUri = new Uri(relativePath, UriKind.Relative); var relationship = this.UnderlyingPackage.CreateRelationship(customUiUri, TargetMode.Internal, relType); OfficePart part; if (!this.UnderlyingPackage.PartExists(customUiUri)) { part = new OfficePart(this.UnderlyingPackage.CreatePart(customUiUri, "application/xml"), partType, relationship.Id); } else { part = new OfficePart(this.UnderlyingPackage.GetPart(customUiUri), partType, relationship.Id); } Debug.Assert(part != null, "Fail to create custom part."); this.Parts.Add(part); this.IsDirty = true; return(part); }
public void InsertPart(XmlParts type) { // Check if the part does not exist yet var part = this.document.RetrieveCustomPart(type); if (part != null) { return; } part = this.document.CreateCustomPart(type); var partModel = new OfficePartViewModel(part, this); this.Children.Add(partModel); partModel.IsSelected = true; }
public OfficePart RetrieveCustomPart(XmlParts partType) { Debug.Assert(this.Parts != null, "Document has no xmlParts to retrieve"); if (this.Parts == null || this.Parts.Count == 0) { return(null); } foreach (var part in this.Parts) { if (part.PartType == partType) { return(part); } } return(null); }
public void RemoveCustomPart(XmlParts partType) { for (var i = this.Parts.Count - 1; i >= 0; i--) { if (this.Parts[i].PartType != partType) { continue; } var part = this.Parts[i]; part.Remove(); this.Parts.RemoveAt(i); this.UnderlyingPackage.Flush(); this.IsDirty = true; } }
public void RemovePart(XmlParts type) { this.document.RemoveCustomPart(type); for (var i = 0; i < this.Children.Count; ++i) { if (!(this.Children[i] is OfficePartViewModel part)) { continue; } if (part.Part.PartType == type) { this.Children.RemoveAt(i); return; } } }
public void SaveCustomPart(XmlParts partType, string text, bool isCreatingNewPart) { var targetPart = this.RetrieveCustomPart(partType); if (targetPart == null) { if (isCreatingNewPart) { targetPart = this.CreateCustomPart(partType); } else { return; } } Debug.Assert(targetPart != null, "targetPart is null when saving custom part"); targetPart.Save(text); this.IsDirty = true; }
public void SaveCustomPart(XmlParts partType, string text) { this.SaveCustomPart(partType, text, false /*isCreatingNewPart*/); }
private Tuple <OfficeDocumentViewModel, OfficePartViewModel> OpenAndInsertPart(XmlParts partType = XmlParts.RibbonX12, bool select = true) { var doc = this.OpenSource(); if (partType == XmlParts.RibbonX12) { this.viewModel.InsertXml12Command.Execute(); } else { this.viewModel.InsertXml14Command.Execute(); } Assume.That(doc.Children, Is.Not.Empty, "XML part was not inserted"); Assume.That(doc.Children[0], Is.InstanceOf <OfficePartViewModel>(), "Wrong class was inserted"); if (select) { this.viewModel.SelectedItem = doc.Children[0]; } return(Tuple.Create(doc, (OfficePartViewModel)doc.Children[0])); }