Skip to content

Commit

Permalink
Add alert when reflist is not exist
Browse files Browse the repository at this point in the history
  • Loading branch information
Wikidepia committed May 5, 2024
1 parent cc9b36e commit a4d1ccd
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,13 @@ function getGroups() {
}

function doCite(documentIDs: string[]) {
var ui = DocumentApp.getUi();
if (!isBibliographyExist()) {
ui.alert(`You need to insert reference list to your document. Follow these steps:
1. Place your cursor on where you want to insert the reference list.
2. Go to Extensions -> Bibs for Mendeley -> Insert Bibliography`);
return;
}
var tempText = insertCitation("(BibliographyIsNotInserted)", documentIDs);

try {
Expand Down Expand Up @@ -377,7 +384,9 @@ function insertBibliography(createNew: boolean = true) {
var cursorChild = baseDoc.getBody().getChildIndex(cursor.getElement());
} catch (e) {
ui.alert("Cannot insert bibliography here, please try on another place.");
throw new Error("failed to insert bibliography, element does not like table");
throw new Error(
"failed to insert bibliography, element does not like table"
);
}

table = body.insertTable(cursorChild);
Expand Down Expand Up @@ -466,3 +475,16 @@ function insertBibliography(createNew: boolean = true) {
citesSearch = body.findText(`​`, citesSearch);
}
}

function isBibliographyExist(): boolean {
var body = DocumentApp.getActiveDocument().getBody();
var allTables = body.getTables();
for (var i = 0; i < allTables.length; i++) {
var tableText =
allTables[i]?.getCell(0, 0).editAsText().getLinkUrl(0) || "";
if (tableText.includes("#bibs-mendeley")) {
return true;
}
}
return false;
}

0 comments on commit a4d1ccd

Please sign in to comment.