/// ----------------------------------------------------------------------------------- /// <summary> /// Static method to create a new structured text. It creates an StText object owned by /// hvoOwner in property tag, then creates an StTxtPara owned by the new StText. It /// sets the contents of the paragraph to be an empty string in the specified writing system, /// and Normal paragraph style. /// </summary> /// ENHANCE JohnT: probably we will identify styles by something other than name. /// REVIEW JohnT(TomB): Are we supposed to be supplying a style name rather than just /// using "Normal"? /// /// <param name="cache">FieldWorks database access</param> /// <param name="hvoOwner">id of object to own the new StText</param> /// <param name="propTag">property (field) type of the new StText</param> /// <param name="ws">language writing system of empty paragraph</param> /// <returns>HVO of the newly created StText object</returns> /// ----------------------------------------------------------------------------------- public static int MakeEmptyStText(FdoCache cache, int hvoOwner, int propTag, int ws) { // REVIEW TomB: Lastparm should really be null if Randy changes CreateObject. // Response from RandyR: I changed CreateObject. Null should work for // everything now. // Most of this code could be moved into the FDO objects, if desired. int hvoStText = cache.CreateObject(StText.kclsidStText, hvoOwner, propTag, 0); int hvoPara = cache.CreateObject(StTxtPara.kclsidStTxtPara, hvoStText, (int)StText.StTextTags.kflidParagraphs, 0); // Set the style of the paragraph to Normal ITsTextProps ttpNormal; ITsPropsBldr tsPropsBldr = TsPropsBldrClass.Create(); tsPropsBldr.SetStrPropValue((int)FwTextPropType.ktptNamedStyle, StyleNames.ksNormal); ttpNormal = tsPropsBldr.GetTextProps(); cache.MainCacheAccessor.SetUnknown(hvoPara, (int)StPara.StParaTags.kflidStyleRules, ttpNormal); // Set its contents to an empty string in the right writing system. ITsStrFactory tsFactory = TsStrFactoryClass.Create(); cache.SetTsStringProperty(hvoPara, (int)StTxtPara.StTxtParaTags.kflidContents, tsFactory.MakeStringRgch("", 0, ws)); return(hvoStText); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Sanity check to ensure the scripture texts are valid. /// </summary> /// ------------------------------------------------------------------------------------ protected void EnsureScriptureTextsValid() { foreach (ScrBook book in m_scr.ScriptureBooksOS) { int[] sectionHvos = book.SectionsOS.HvoArray; // Don't crash if we don't have any sections (TE-5380) if (sectionHvos.Length == 0) { continue; } ContextValues sectionContext; foreach (ScrSection section in book.SectionsOS) { // Check the heading paragraphs. if (section.HeadingOA == null) { m_cache.CreateObject(StText.kClassId, section.Hvo, (int)ScrSection.ScrSectionTags.kflidHeading, 0); } if (section.HeadingOA.ParagraphsOS.Count == 0) { StTxtPara para = new StTxtPara(); section.HeadingOA.ParagraphsOS.Append(para); para.StyleRules = StyleUtils.ParaStyleTextProps(ScrStyleNames.SectionHead); sectionContext = ContextValues.Text; } else { IStStyle style = m_scr.FindStyle(section.HeadingOA.ParagraphsOS[0].StyleRules); // style could be null. set default context if possible sectionContext = style == null ? ContextValues.Text : style.Context; } // Check the content paragraphs. if (section.ContentOA == null) { m_cache.CreateObject(StText.kClassId, section.Hvo, (int)ScrSection.ScrSectionTags.kflidContent, 0); } if (section.ContentOA.ParagraphsOS.Count == 0) { StTxtPara para = new StTxtPara(); section.ContentOA.ParagraphsOS.Append(para); para.StyleRules = StyleUtils.ParaStyleTextProps( TeEditingHelper.GetDefaultStyleForContext(sectionContext, false)); section.AdjustReferences(); } } } }
/// <summary> /// If OK, then make FS have the selected feature value(s). /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void PhonologicalFeatureChooserDlg_Closing(object sender, System.ComponentModel.CancelEventArgs e) { if (DialogResult == DialogResult.OK) { Cursor = Cursors.WaitCursor; if (m_fs == null) { // Didn't have one to begin with. See whether we want to create one. if (m_hvoOwner != 0 && CheckFeatureStructure()) { // The last argument is meaningless since we expect this property to be owning // or collection. int hvoFs = m_cache.CreateObject(FsFeatStruc.kClassId, m_hvoOwner, m_owningFlid, 0); m_fs = (IFsFeatStruc)FsFeatStruc.CreateFromDBObject(m_cache, hvoFs, false); } } if (m_fs != null) { // clean out any extant features in the feature structure foreach (IFsFeatureSpecification spec in m_fs.FeatureSpecsOC) { m_fs.FeatureSpecsOC.Remove(spec); } UpdateFeatureStructure(); } } if (m_mediator != null) { m_mediator.PropertyTable.SetProperty("phonFeatListDlgLocation", Location); m_mediator.PropertyTable.SetProperty("phonFeatListDlgSize", Size); } Cursor = Cursors.Default; }
/// ------------------------------------------------------------------------------------ /// <summary> /// Create a new picture, given string representations of most of the parameters. Used /// for creating a picture from a USFM-style Standard Format import. /// </summary> /// <param name="fcCache">FDO cache</param> /// <param name="sFolder">The name of the CmFolder where picture should be stored</param> /// <param name="anchorLoc">The anchor location that can be used to determine (may be 0).</param> /// <param name="locationParser">The location parser.</param> /// <param name="sDescription">Illustration description in English.</param> /// <param name="srcFilename">The picture filename.</param> /// <param name="sLayoutPos">The layout position (as a string).</param> /// <param name="sLocationRange">The location range (as a string).</param> /// <param name="sCopyright">The copyright.</param> /// <param name="sCaption">The caption, in the default vernacular writing system.</param> /// <param name="locRangeType">Assumed type of the location range.</param> /// <param name="sScaleFactor">The scale factor (as a string).</param> /// ------------------------------------------------------------------------------------ public CmPicture(FdoCache fcCache, string sFolder, int anchorLoc, IPictureLocationBridge locationParser, string sDescription, string srcFilename, string sLayoutPos, string sLocationRange, string sCopyright, string sCaption, PictureLocationRangeType locRangeType, string sScaleFactor) : base(fcCache, fcCache.CreateObject(CmPicture.kclsidCmPicture)) { InitializeNewPicture(sFolder, anchorLoc, locationParser, sDescription, srcFilename, sLayoutPos, sLocationRange, sCopyright, sCaption, locRangeType, sScaleFactor); }
/// <summary> /// If OK, then make FS have the selected feature value(s). /// JohnT: This is a really ugly kludge, which I have only partly repaired. /// We need the dialog to return with m_fs set to an FsFeatStruc (if OK was clicked), /// since that is what the bulk edit bar wants to copy to MoStemMsas for any items /// it is asked to modify. Also, the new FsFeatStruc needs to be in the ReferenceForms /// (which is what m_owningFlid apparently always is, currently) so that it will become /// one of the items in the combo list and can be selected. However, Andy says this is /// not the intended use of ReferenceForms at all. /// A further ugliness is that we always make a new FsFeatStruc (unless one was passed /// in to one of the SegDlgInfo methods, but AFAIK that override is never used), but /// we then delete it if it turns out to be a duplicate. There is no other straightforward /// way to detect that the current choices in the dialog correspond to an existing item. /// This may cause problems in the new world, where we can't do this "suppress sub tasks" /// trick without losing our Undo stack. /// It may be possible in the new world to create an object without initially giving it an /// owner, and only persist it if it is NOT a duplicate. But even that we don't really want /// to be undoable, nor should it clear the undo stack. Really the list of possible choices /// for the combo should not be separately persisted as model data, but it should be persisted /// somehow... /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void MsaInflectionFeatureListDlg_Closing(object sender, System.ComponentModel.CancelEventArgs e) { if (DialogResult == DialogResult.OK) { using (new SuppressSubTasks(m_cache)) // making and maybe then deleting the new item for the combo is not undoable { if (m_fs == null) { // Didn't have one to begin with. See whether we want to create one. if (CheckFeatureStructure(m_tvMsaFeatureList.Nodes)) { // The last argument is meaningless since we expect this property to be owning // or collection. int hvoFs = m_cache.CreateObject(FsFeatStruc.kClassId, m_hvoOwner, m_owningFlid, 0); m_fs = (IFsFeatStruc)FsFeatStruc.CreateFromDBObject(m_cache, hvoFs, false); } else { return; // leave it null. } } // clean out any extant features in the feature structure foreach (IFsFeatureSpecification spec in m_fs.FeatureSpecsOC) { m_fs.FeatureSpecsOC.Remove(spec); } UpdateFeatureStructure(m_tvMsaFeatureList.Nodes); // The (usually) newly created one may be a duplicate. If we find a duplicate // delete the one we just made (or were passed) and return the duplicate. int chvo = m_cache.GetVectorSize(m_hvoOwner, m_owningFlid); for (int ihvo = 0; ihvo < chvo; ihvo++) { int hvo = m_cache.GetVectorItem(m_hvoOwner, m_owningFlid, ihvo); if (hvo == m_fs.Hvo) { continue; } IFsFeatStruc fs = CmObject.CreateFromDBObject(m_cache, hvo) as IFsFeatStruc; if (FsFeatStruc.AreEquivalent(fs, m_fs)) { m_fs.DeleteUnderlyingObject(); m_fs = fs; break; } } } } if (m_mediator != null) { m_mediator.PropertyTable.SetProperty("msaInflFeatListDlgLocation", Location); m_mediator.PropertyTable.SetProperty("msaInflFeatListDlgSize", Size); } }
/// ------------------------------------------------------------------------------------ /// <summary> /// Create a new picture, given string representations of most of the parameters. Used /// for creating a picture from a Toolbox-style Standard Format import. /// </summary> /// <param name="fcCache">FDO cache</param> /// <param name="sFolder">The name of the CmFolder where picture should be stored</param> /// <param name="anchorLoc">The anchor location that the locationParser can use if /// necessary (can be 0).</param> /// <param name="locationParser">The location parser.</param> /// <param name="descriptions">The descriptions in 0 or more writing systems.</param> /// <param name="srcFilename">The picture filename.</param> /// <param name="sLayoutPos">The layout position (as a string).</param> /// <param name="sLocationRange">The location range (as a string).</param> /// <param name="sCopyright">The copyright.</param> /// <param name="tssCaption">The caption, in the default vernacular writing system.</param> /// <param name="locRangeType">Assumed type of the location range.</param> /// <param name="sScaleFactor">The scale factor (as a string).</param> /// ------------------------------------------------------------------------------------ public CmPicture(FdoCache fcCache, string sFolder, int anchorLoc, IPictureLocationBridge locationParser, Dictionary <int, string> descriptions, string srcFilename, string sLayoutPos, string sLocationRange, string sCopyright, ITsString tssCaption, PictureLocationRangeType locRangeType, string sScaleFactor) : base(fcCache, fcCache.CreateObject(CmPicture.kclsidCmPicture)) { InitializeNewPicture(sFolder, anchorLoc, locationParser, null, srcFilename, sLayoutPos, sLocationRange, sCopyright, tssCaption, locRangeType, sScaleFactor); if (descriptions != null) { foreach (int ws in descriptions.Keys) { Description.SetAlternative(descriptions[ws], ws); } } }
/// ------------------------------------------------------------------------------------ /// <summary> /// Create a picture (no caption set). /// </summary> /// <param name="para">Paragraph to insert picture into</param> /// <param name="ichPos">The 0-based character offset into the paragraph</param> /// <returns></returns> /// ------------------------------------------------------------------------------------ protected ICmPicture InsertTestPicture(StTxtPara para, int ichPos) { // Create the picture ICmFolder folder = m_fdoCache.LangProject.PicturesOC.Add(new CmFolder()); ICmFile file = folder.FilesOC.Add(new CmFile()); file.InternalPath = "there"; int newHvo = m_fdoCache.CreateObject(CmPicture.kClassId); ICmPicture picture = new CmPicture(m_fdoCache, newHvo); picture.PictureFileRA = file; // Update the paragraph contents to include the footnote marker ITsStrBldr tsStrBldr = para.Contents.UnderlyingTsString.GetBldr(); (picture as CmPicture).InsertOwningORCIntoPara(tsStrBldr, ichPos, 0); // Don't care about ws para.Contents.UnderlyingTsString = tsStrBldr.GetString(); return(picture); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Create a new picture, given a text representation (e.g., from the clipboard). /// NOTE: The caption is put into the default vernacular writing system. /// </summary> /// <param name="fcCache">FDO cache</param> /// <param name="sTextRepOfPicture">Clipboard representation of a picture</param> /// <param name="sFolder">The name of the CmFolder where picture should be stored</param> /// <param name="anchorLoc">The anchor location that can be used to determine (may be 0).</param> /// <param name="locationParser">The picture location parser (can be null).</param> /// ------------------------------------------------------------------------------------ public CmPicture(FdoCache fcCache, string sTextRepOfPicture, string sFolder, int anchorLoc, IPictureLocationBridge locationParser) : base(fcCache, fcCache.CreateObject(CmPicture.kclsidCmPicture)) { string[] tokens = sTextRepOfPicture.Split(new char[] { '|' }); if (tokens.Length < 9 || tokens[0] != "CmPicture") { throw new ArgumentException("The clipboard format for a Picture was invalid"); } string sDescription = tokens[1]; string srcFilename = tokens[2]; string sLayoutPos = tokens[3]; string sLocationRange = tokens[4]; string sCopyright = tokens[5]; string sCaption = tokens[6]; string sLocationRangeType = tokens[7]; string sScaleFactor = tokens[8]; PictureLocationRangeType locRangeType = ParseLocationRangeType(sLocationRangeType); InitializeNewPicture(sFolder, anchorLoc, locationParser, sDescription, srcFilename, sLayoutPos, sLocationRange, sCopyright, sCaption, locRangeType, sScaleFactor); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Construct a CmPicture for the given file, having the given caption, and located in /// the given folder. /// </summary> /// <param name="fcCache">FDO cache</param> /// <param name="srcFilename">The path to the original filename (an internal copy will /// be made in this method)</param> /// <param name="captionTss">The caption</param> /// <param name="sFolder">The name of the CmFolder where picture should be stored /// </param> /// ------------------------------------------------------------------------------------ public CmPicture(FdoCache fcCache, string srcFilename, ITsString captionTss, string sFolder) : base(fcCache, fcCache.CreateObject(CmPicture.kclsidCmPicture)) { InitializeNewPicture(srcFilename, captionTss, null, PictureLayoutPosition.CenterInColumn, 100, PictureLocationRangeType.AfterAnchor, 0, 0, null, sFolder); }