public DocumentFormatter() { citationstyle = null; bForceReload = false; editor = new DocumentEditor(); listCurrentCitedReferences = new Dictionary<int, ItemMasterRow>(); }
private void UpdateContent() { CitationStyle style = (CitationStyle)cbStyle.SelectedItem; CitationType type = (CitationType)cbType.SelectedItem; citationDetails.title = tbTitle.Text; citationDetails.authors = GetAuthors(); citationDetails.year = tbYear.Text; if (type == CitationType.Book) { citationDetails.publisher = new Publisher(tbPublisher.Text); } if (type == CitationType.Article) { citationDetails.journal = new Journal(tbJournal.Text); citationDetails.doi = tbDoi.Text; } citationDetails.style = style; citationDetails.type = type; Citation citation = citationFactory.CreateCitation(citationDetails); commandFactory.Execute(citation); Close(); }
public static string NewShortTitle(Reference reference) { try { if (reference == null) { return(null); } string newShortTitle = string.Empty; Project project = Program.ActiveProjectShell.Project; string styleName = "ShortTitleGenerator.ccs"; string folder = project.Addresses.GetFolderPath(CitaviFolder.UserData).ToString(); string fullPath = folder + @"\Custom Citation Styles\" + styleName; if (!System.IO.File.Exists(fullPath)) { System.Windows.Forms.MessageBox.Show(ShortTitleGeneratorLocalization.CitationStyleNotFound); return(null); } Uri uri = new Uri(fullPath); CitationStyle citationStyle = CitationStyle.Load(uri.AbsoluteUri); List <Reference> references = new List <Reference>(); references.Add(reference); CitationManager citationManager = new CitationManager(Program.ActiveProjectShell.Project.Engine, citationStyle, references); if (citationManager == null) { return(null); } BibliographyCitation bibliographyCitation = citationManager.BibliographyCitations.FirstOrDefault(); if (bibliographyCitation == null) { return(null); } List <ITextUnit> textUnits = bibliographyCitation.GetTextUnits(); if (textUnits == null) { return(null); } var output = new TextUnitCollection(); foreach (ITextUnit textUnit in textUnits) { output.Add(textUnit); } newShortTitle = output.ToString(); return(newShortTitle); } catch { return(null); } }
public Citation(List <Author> authors, string title, string year, Publisher publisher, CitationStyle style, CitationType type) { this.authors = authors; this.year = year; this.publisher = publisher; this.Style = style; this.Type = type; this.title = title; }
public Citation(List <Author> authors, string title, string year, CitationStyle style, CitationType type, Journal journal, string doi) { this.authors = authors; this.year = year; this.Style = style; this.Type = type; this.title = title; this.journal = journal; this.doi = doi; }
private void bgLoadStyle_DoWork(object sender, DoWorkEventArgs e) { try { Dictionary<string, object> data = e.Argument as Dictionary<string, object>; StyleOwner owner = (StyleOwner) data["Owner"]; string strStyleName = (string)data["StyleName"]; style = Globals.ThisAddIn.user.LoadStyle(owner, strStyleName); if (style.Name == "APA (6th edition)") { style.Reference.ItemTypes["JournalArticle"].Fields.JournalName.NameFormat = JournalNameFormat.AsIs; style.Reference.ItemTypes["JournalArticle"].Fields.JournalName.IsAPA = true; } bool bStyleAllowed = false; if(owner == StyleOwner.User) bStyleAllowed = true; else { bStyleAllowed = checkStyleAccess(strStyleName); } this.Invoke(this.allowStyle, new Object[] { bStyleAllowed }); } catch {} }
public IEnumerable <ITextUnit> GetTextUnits(ComponentPart componentPart, Template template, Citation citation, out bool handled) { handled = false; var useNonBreakingSpacesInAndBetweenFirstAndMiddleNames = true; //if true, then e.g. Meyers, J.°R. var useNonBreakingSpaceBetweenLastAndFirstName = true; //if true, then e.g. Meyers,°John Richard var useNonBreakingSpaceBetweenPrefixAndName = true; //if true, then e.g. von°Bülow, V. var useNonBreakingHyphenInFirstAndMiddleName = true; //if true, then e.g. Ewing, J.-R. if (componentPart == null) { return(null); } if (componentPart.Elements == null || componentPart.Elements.Count == 0) { return(null); } CitationStyle citationStyle = componentPart.CitationStyle; if (citationStyle == null) { return(null); } IEnumerable <PersonFieldElement> personFieldElements = componentPart.Elements.OfType <PersonFieldElement>(); if (personFieldElements == null || personFieldElements.Count() == 0) { return(null); } foreach (PersonFieldElement element in personFieldElements) { if (useNonBreakingSpacesInAndBetweenFirstAndMiddleNames) { element.FirstGroupUseNonBreakingSpaceInAndBetweenFirstAndMiddleNames = true; element.SecondGroupUseNonBreakingSpaceInAndBetweenFirstAndMiddleNames = true; element.LastPersonUseNonBreakingSpaceInAndBetweenFirstAndMiddleNames = true; } if (useNonBreakingSpaceBetweenLastAndFirstName) { element.FirstGroupUseNonBreakingSpaceBetweenLastAndFirstName = true; element.SecondGroupUseNonBreakingSpaceBetweenLastAndFirstName = true; element.LastPersonUseNonBreakingSpaceBetweenLastAndFirstName = true; } if (useNonBreakingSpaceBetweenPrefixAndName) { element.FirstGroupUseNonBreakingSpaceBetweenPrefixAndName = true; element.SecondGroupUseNonBreakingSpaceBetweenPrefixAndName = true; element.LastPersonUseNonBreakingSpaceBetweenPrefixAndName = true; } if (useNonBreakingHyphenInFirstAndMiddleName) { element.FirstGroupUseNonBreakingHyphenInFirstAndMiddleNames = true; element.SecondGroupUseNonBreakingHyphenInFirstAndMiddleNames = true; element.LastPersonUseNonBreakingHyphenInFirstAndMiddleNames = true; } } //for downward compatibility of this script we make sure the separator is just a comma and not "comma + space" var currentVersion = SwissAcademic.Environment.InformationalVersion; var maxVersionForWorkaround = new Version(6, 3, 5, 0); if (currentVersion <= maxVersionForWorkaround) { foreach (PersonFieldElement element in personFieldElements) { element.FirstGroupLastNameFirstNameSeparator.Text = ","; element.SecondGroupLastNameFirstNameSeparator.Text = ","; element.LastPersonLastNameFirstNameSeparator.Text = ","; } } //Citavi will do the rest, no need to return any output return(null); }
private void refreshReferences() { bool bUsingTrackChanges = Globals.ThisAddIn.Application.ActiveDocument.TrackRevisions; if (bUsingTrackChanges) { Globals.ThisAddIn.Application.ActiveDocument.TrackRevisions = false; } refreshCitedItem(); try { if (rci.StyleInfo != null && !bForceReload) { StyleOwner styleOwner = (rci.StyleInfo.UserID == -1) ? StyleOwner.Public : StyleOwner.User; if (citationstyle != null) { if(citationstyle.Name != rci.StyleInfo.StyleName) { citationstyle = Globals.ThisAddIn.user.LoadStyle(styleOwner, rci.StyleInfo.StyleName); citationstyle.OwnerUserID =rci.StyleInfo.UserID; } } if(citationstyle == null) { citationstyle = Globals.ThisAddIn.user.LoadStyle(styleOwner, rci.StyleInfo.StyleName); citationstyle.OwnerUserID =rci.StyleInfo.UserID; } citationstyle.GenerateCitation(rci, false); rci.GetRCI(Properties.Settings.Default.URL_ROOTSERVER.Replace("http://", "https://")); updateRCI(rci); if (bUsingTrackChanges) Globals.ThisAddIn.Application.ActiveDocument.TrackRevisions = true; return; } else { bForceReload = false; if(citationstyle != null) { rci.StyleInfo = new StyleInformation(citationstyle.OwnerUserID, citationstyle.Name); } else { JavaScriptSerializer sr = new JavaScriptSerializer(); ListDictionary ld = null; try { ld = sr.Deserialize<ListDictionary>(Properties.Settings.Default.LAST_USED_CITATIONSTYLES); } catch { } if(ld != null) { String[] Keys = new String[ld.Keys.Count]; ld.Keys.CopyTo(Keys, 0); rci.StyleInfo = new StyleInformation((int)ld[Keys[Keys.Length - 1]], Keys[Keys.Length - 1]); } else { rci.StyleInfo = new StyleInformation(-1, Properties.Settings.Default.DEFAULT_CITATION_STYLE_NAME); } citationstyle = Globals.ThisAddIn.user.LoadStyle(rci.StyleInfo.UserID == -1 ? StyleOwner.Public : StyleOwner.User, rci.StyleInfo.StyleName); citationstyle.OwnerUserID = rci.StyleInfo.UserID; } if(citationstyle != null) { if(citationstyle.Name.ToLower() == "apa (6th edition)") { citationstyle.Reference.ItemTypes["JournalArticle"].Fields.JournalName.NameFormat = JournalNameFormat.AsIs; citationstyle.Reference.ItemTypes["JournalArticle"].Fields.JournalName.IsAPA = true; rci.IsAPA = true; } citationstyle.GenerateCitation(rci, false); rci.GetRCI(Properties.Settings.Default.URL_ROOTSERVER.Replace("http://", "https://")); updateRCI(rci); if (bUsingTrackChanges) Globals.ThisAddIn.Application.ActiveDocument.TrackRevisions = true; return; } } } catch (Exception ex) { log.WriteLine(LogType.Error, "DocumentFormatter::refreshReferences", ex.ToString()); } if (bUsingTrackChanges) Globals.ThisAddIn.Application.ActiveDocument.TrackRevisions = true; }
public void ReapplySytle(StyleInformation styleinfo) { try { Globals.ThisAddIn.Application.ScreenUpdating = false; if (styleinfo != null) { StyleOwner styleOwner = (styleinfo.UserID == -1) ? StyleOwner.Public : StyleOwner.User; citationstyle = Globals.ThisAddIn.user.LoadStyle(styleOwner, styleinfo.StyleName); citationstyle.OwnerUserID = styleinfo.UserID; } bForceReload = true; RefreshCitations(false); Globals.ThisAddIn.Application.ScreenRefresh(); Globals.ThisAddIn.Application.ScreenUpdating = true; } catch (Exception ex) { log.WriteLine(LogType.Error, "DocumentFormatter::ReapplySytle", ex.ToString()); } }
public CitationStyle LoadStyle(StyleOwner owner, string name) { string type = (owner == StyleOwner.Public) ? "official" : "user"; CitationStyle style = new CitationStyle(); string strRequestURL = ServerAddress + Properties.Settings.Default.URI_LOCALDATASERVICE + "?op=style&from=" + DeviceTypes.MSWordWin.ToString() + "&authentication=" + Authentication + "&type=" + type + "&name=" + name; CustomHttpRequest req = new CustomHttpRequest(strRequestURL); JavaScriptSerializer js = new JavaScriptSerializer(); style = js.Deserialize<CitationStyle>(req.GetResponse()); return style; }
public APACitation(List <Author> authors, string title, string year, CitationStyle style, CitationType type, Journal journal, string doi) : base(authors, title, year, style, type, journal, doi) { }
public APACitation(List <Author> authors, string title, string year, Publisher publisher, CitationStyle style, CitationType type) : base(authors, title, year, publisher, style, type) { }