public void EditCitation(Field field, JSInlineCitation citation) { try { SuspendRedraw(); var fieldCodeText = CreateFieldCodeText(citation); field.Code.Text = fieldCodeText; // Update the cache RemoveCitation(fieldCodeText); SetCitation(fieldCodeText, citation); FormatCitationField(field); var jsCitations = Reset(); var jsResult = citeProc.RestoreProcessorState(jsCitations); ApplyResult(jsResult); UpdateBibliographyFields(); } finally { ResumeRedraw(); } }
JSInlineCitation CreateInlineCitation(IEnumerable <EntryAndPagePair> itemSources, object idToUse = null) { // ****IMPORTANT**** // This is called from InsertCitationSequence, InsertCitation, EditCitation and CitationInserter.UpdateCitationsFromDatabase // // It is imperative that calls from the first 3 work on an empty CiteProc otherwise the cache gets used to create // the citation items. Other than first-use, this means using the item after CiteProc has seen it and maybe modified it // (it appears to change the Date Parts to strings in some cases) // The next refresh is then comparing incorrect JSON and will want to update it from the database. // // (CitationInserter.UpdateCitationsFromDatabase calls here but this is always within a Refresh which means a brand new CiteProc anyway // and so multiple resets here are not a problem because the raw cache would be empty anyway) CiteProc.ResetProcessorState(); var result = new JSInlineCitation(CiteProc); if (idToUse != null) { result.CitationID = idToUse; } result.Properties.NoteIndex = 0; foreach (var itemSource in itemSources) { var inlineCitationItem = CiteProc.CreateJSInlineCitationItem(itemSource); result.CitationItems.Add(inlineCitationItem); } // We store this before Citeproc gets hold of it! result.FieldCodeJSON = CiteProc.ToJSON(result.JSObject, JSONWhitespace).Replace('\n', '\v') + FieldCodeSeparator; return(result); }
public string AppendCitation(JSInlineCitation citation) { var jsResult = CallMethod(AppendCitationClusterCommand, citation.JSObject, true); var result = CreateJSProcessCitationResult(jsResult); return(result.Items[0].String); }
public static JSInlineCitation FromJSON(IJSContext context, string json) { var jsObject = context.CreateJSObjectFromJSON(json); var result = new JSInlineCitation(context, jsObject) { FieldCodeJSON = json }; return result; }
public static JSInlineCitation FromJSON(IJSContext context, string json) { var jsObject = context.CreateJSObjectFromJSON(json); var result = new JSInlineCitation(context, jsObject) { FieldCodeJSON = json }; return(result); }
Field InsertCitationField(Range range, JSInlineCitation citation) { var field = range.Fields.Add(range, WdFieldType.wdFieldQuote, InsertingCitationMessage, false); var fieldCodeText = CreateFieldCodeText(citation); field.Code.Text = fieldCodeText; SetCitation(fieldCodeText, citation); FormatCitationField(field); return field; }
Field InsertCitationField(Range range, JSInlineCitation citation) { var field = range.Fields.Add(range, WdFieldType.wdFieldQuote, InsertingCitationMessage, false); var fieldCodeText = CreateFieldCodeText(citation); field.Code.Text = fieldCodeText; SetCitation(fieldCodeText, citation); FormatCitationField(field); return(field); }
JSInlineCitation GetCitation(string fieldCodeText) { JSInlineCitation result; if (!inlineCitationCache.TryGetValue(fieldCodeText, out result)) { var citationJSON = Helper.ExtractCitationJSON(fieldCodeText); result = JSInlineCitation.FromJSON(citeProc, citationJSON); SetCitation(fieldCodeText, result); } return(result); }
void InsertCitationCore(JSInlineCitation citation) { try { isUpdating = true; var selection = document.Application.Selection; selection.Collapse(WdCollapseDirection.wdCollapseEnd); var range = selection.Range; var inserter = new CitationInserter(this); inserter.InsertCitation(range, citation); } finally { isUpdating = false; } }
public static List <EntryAndPagePair> ExtractSources(JSInlineCitation inlineCitation, BibTexDatabase currentDatabase) { var result = new List <EntryAndPagePair>(inlineCitation.CitationItems.Length); for (var i = 0; i < inlineCitation.CitationItems.Length; i++) { var id = inlineCitation.CitationItems[i].ID; if (string.IsNullOrEmpty(id)) { continue; } // This shouldn't be needed but the pre-release version included // the '#<Page>' suffix here as well as in the item ID // We remove it here; use the Locator and the document // will correct itself on the next Refresh var hashIndex = id.IndexOf('#'); if (hashIndex != -1) { id = id.Substring(0, hashIndex); } var entry = currentDatabase[id]; // If an entry cannot be found, we skip it if (entry == null) { continue; } var authorProcessorControl = GetAuthorProcessorControl(inlineCitation.CitationItems[i]); result.Add(new EntryAndPagePair(entry, inlineCitation.CitationItems[i].Locator) { AuthorProcessorControl = authorProcessorControl }); } return(result); }
static string CreateFieldCodeText(JSInlineCitation citation) { // No point in putting in \n (which is what we had originally // since Word replaces them with \r and that buggers up // the cache lookups! var sb = new StringBuilder(); sb.Append(AddInMarker); sb.Append(" "); sb.Append(DocearMarker); sb.Append(" "); sb.Append(CslCitationMarker); sb.Append(FieldCodeSeparator); sb.Append(DoNotModifyWarningMessage); sb.Append(FieldCodeSeparator); // This must be done BEFORE the citation is sent to citeproc // otherwise additional fields are added!! sb.Append(citation.FieldCodeJSON); return(sb.ToString()); }
public void InsertCitation(Range range, JSInlineCitation newCitation) { try { SuspendRedraw(); // Insert a field into the document InsertCitationField(range, newCitation); var jsCitations = Reset(); var jsResult = citeProc.RestoreProcessorState(jsCitations); ApplyResult(jsResult); UpdateBibliographyFields(); } finally { ResumeRedraw(); } }
static bool DatabaseVersionIsDifferent(JSInlineCitation inlineCitation, JSInlineCitation databaseCitation) { return(databaseCitation.FieldCodeJSON != inlineCitation.FieldCodeJSON); }
static bool DatabaseVersionIsDifferent(JSInlineCitation inlineCitation, JSInlineCitation databaseCitation) { return databaseCitation.FieldCodeJSON != inlineCitation.FieldCodeJSON; }
JSInlineCitation CreateInlineCitation(IEnumerable<EntryAndPagePair> itemSources, object idToUse = null) { // ****IMPORTANT**** // This is called from InsertCitationSequence, InsertCitation, EditCitation and CitationInserter.UpdateCitationsFromDatabase // // It is imperative that calls from the first 3 work on an empty CiteProc otherwise the cache gets used to create // the citation items. Other than first-use, this means using the item after CiteProc has seen it and maybe modified it // (it appears to change the Date Parts to strings in some cases) // The next refresh is then comparing incorrect JSON and will want to update it from the database. // // (CitationInserter.UpdateCitationsFromDatabase calls here but this is always within a Refresh which means a brand new CiteProc anyway // and so multiple resets here are not a problem because the raw cache would be empty anyway) CiteProc.ResetProcessorState(); var result = new JSInlineCitation(CiteProc); if (idToUse != null) { result.CitationID = idToUse; } result.Properties.NoteIndex = 0; foreach(var itemSource in itemSources) { var inlineCitationItem = CiteProc.CreateJSInlineCitationItem(itemSource); result.CitationItems.Add(inlineCitationItem); } // We store this before Citeproc gets hold of it! result.FieldCodeJSON = CiteProc.ToJSON(result.JSObject, JSONWhitespace).Replace('\n', '\v') + FieldCodeSeparator; return result; }
public JSInlineCitation CreateInlineCitationFromFieldJSON(Field field) { var citationJSON = Helper.ExtractCitationJSON(field); return(JSInlineCitation.FromJSON(this, citationJSON)); }
public InlineCitationInsertionEntry(JSInlineCitation jsInlineCitation) { this.jsInlineCitation = jsInlineCitation; }
public JSProcessCitationResult ProcessCitation(JSInlineCitation citation, object citationsPre, object citationsPost) { var jsResult = CallMethod(ProcessCitationClusterCommand, citation.JSObject, citationsPre, citationsPost); return(CreateJSProcessCitationResult(jsResult)); }
public static List<EntryAndPagePair> ExtractSources(JSInlineCitation inlineCitation, BibTexDatabase currentDatabase) { var result = new List<EntryAndPagePair>(inlineCitation.CitationItems.Length); for(var i = 0; i < inlineCitation.CitationItems.Length; i++) { var id = inlineCitation.CitationItems[i].ID; if (string.IsNullOrEmpty(id)) continue; // This shouldn't be needed but the pre-release version included // the '#<Page>' suffix here as well as in the item ID // We remove it here; use the Locator and the document // will correct itself on the next Refresh var hashIndex = id.IndexOf('#'); if (hashIndex != -1) { id = id.Substring(0, hashIndex); } var entry = currentDatabase[id]; // If an entry cannot be found, we skip it if (entry == null) continue; var authorProcessorControl = GetAuthorProcessorControl(inlineCitation.CitationItems[i]); result.Add(new EntryAndPagePair(entry, inlineCitation.CitationItems[i].Locator) { AuthorProcessorControl = authorProcessorControl }); } return result; }
void SetCitation(string fieldCodeText, JSInlineCitation citation) { inlineCitationCache[fieldCodeText] = citation; }
public void NewInlineCitation() { var citeproc = new CiteProcRunner(HavardCslStyle, () => DocearDatabase); var citation = new JSInlineCitation(citeproc); Console.WriteLine(citeproc.ToJSON(citation)); Assert.NotNull(citation.CitationItems); Assert.NotNull(citation.Properties); Console.WriteLine(citeproc.ToJSON(citation)); var citationItem = citation.CitationItems.AddNew(); Console.WriteLine(citeproc.ToJSON(citation)); citationItem.ID = "123"; citationItem.Prefix = "bollox"; Console.WriteLine(citeproc.ToJSON(citation)); }
static string CreateFieldCodeText(JSInlineCitation citation) { // No point in putting in \n (which is what we had originally // since Word replaces them with \r and that buggers up // the cache lookups! var sb = new StringBuilder(); sb.Append(AddInMarker); sb.Append(" "); sb.Append(DocearMarker); sb.Append(" "); sb.Append(CslCitationMarker); sb.Append(FieldCodeSeparator); sb.Append(DoNotModifyWarningMessage); sb.Append(FieldCodeSeparator); // This must be done BEFORE the citation is sent to citeproc // otherwise additional fields are added!! sb.Append(citation.FieldCodeJSON); return sb.ToString(); }
public JSProcessCitationResult ProcessCitation(JSInlineCitation citation, object citationsPre, object citationsPost) { var jsResult = CallMethod(ProcessCitationClusterCommand, citation.JSObject, citationsPre, citationsPost); return CreateJSProcessCitationResult(jsResult); }
public string AppendCitation(JSInlineCitation citation) { var jsResult = CallMethod(AppendCitationClusterCommand, citation.JSObject, true); var result = CreateJSProcessCitationResult(jsResult); return result.Items[0].String; }