Skip to content

Commit

Permalink
refactor(addToHistory): log all history positions
Browse files Browse the repository at this point in the history
before adding a new entry

See "Prevent History Addition when Main Data is Not Loaded and Ensure Proper Display Interaction" #528
  • Loading branch information
RalfBarkow committed Jun 7, 2024
1 parent 23d6f97 commit 9f40773
Show file tree
Hide file tree
Showing 7 changed files with 230 additions and 154 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -739,7 +739,7 @@ protected Object doInBackground() {
// only create content/new entry, if any abstract was found...
if (content != null && !content.isEmpty()) {
// finally, add entry to dataset
dataObj.addEntryFromBibTex("", content, new String[]{au.toString()}, keywords, Tools.getTimeStamp());
dataObj.addEntryFromBibTeX("", content, new String[]{au.toString()}, keywords, Tools.getTimeStamp());
// and increase entry counter
newEntries++;
} // if nothing found, add at least the keywords
Expand Down Expand Up @@ -816,7 +816,7 @@ else if (keywords != null && keywords.length > 0) {
keywords = (jRadioButtonSourceDB.isSelected()) ? bibtexObj.getKeywords(bibkey.toString()) : bibtexObj.getKeywordsFromAttachedFile(bibkey.toString());
}
// finally, add entry to dataset
dataObj.addEntryFromBibTex("", content, new String[]{au.toString()}, keywords, Tools.getTimeStamp());
dataObj.addEntryFromBibTeX("", content, new String[]{au.toString()}, keywords, Tools.getTimeStamp());
// and delete BibTeX attribute from the *old* entry...
dataObj.setContentFromBibTexRemark(counter, false);
// update found-variable
Expand Down Expand Up @@ -877,7 +877,7 @@ else if (keywords != null && keywords.length > 0) {
keywords = (jRadioButtonSourceDB.isSelected()) ? bibtexObj.getKeywords(bibkey.toString()) : bibtexObj.getKeywordsFromAttachedFile(bibkey.toString());
}
// finally, add entry to dataset
dataObj.addEntryFromBibTex("", content, new String[]{au.toString()}, keywords, Tools.getTimeStamp());
dataObj.addEntryFromBibTeX("", content, new String[]{au.toString()}, keywords, Tools.getTimeStamp());
// and increase entry counter
newEntries++;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2734,7 +2734,7 @@ public final void updateDisplay(UpdateDisplayOptions options) {
}

/**
* Changes the text in the application's titlebar, by adding the filename of the
* Changes the text in the application's title bar, by adding the filename of the
* currently opened file to it.
*/
private void updateFrameTitle() {
Expand Down Expand Up @@ -8801,8 +8801,8 @@ private boolean loadMainDataZipDocument(File filepath, Daten daten, Bookmarks bo

/**
* load the document by opening a modal dialog, which opens the data via a
* background task. the dialog only displays a progressbar and an animated
* busyicon while opening the file, no user-interaction possible.... <br>
* background task. the dialog only displays a progress bar and an animated
* busy icon while opening the file, no user-interaction possible.... <br>
* <br>
* We have this part of code "outsourced" into an own method because we need
* this more often, e.g. when automatically loading the data at program
Expand Down
83 changes: 27 additions & 56 deletions src/main/java/de/danielluedecke/zettelkasten/database/Daten.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import de.danielluedecke.zettelkasten.history.History;
import de.danielluedecke.zettelkasten.settings.Settings;
import de.danielluedecke.zettelkasten.util.classes.Comparer;
import de.danielluedecke.zettelkasten.view.Display;
import de.danielluedecke.zettelkasten.util.Constants;
import de.danielluedecke.zettelkasten.util.HtmlUbbUtil;
import de.danielluedecke.zettelkasten.util.Tools;
Expand Down Expand Up @@ -133,7 +134,7 @@ public class Daten {
* previously accessed entries and so on...
*/
//private int[] history;
private History history;
private History history = new History();

/**
* Stores the files which we want to retrieve from the main data file
Expand Down Expand Up @@ -2923,7 +2924,7 @@ public int addEntry(String title, String content, String[] authors, String[] key
this.activatedEntryNumber = getCount(ZKNCOUNT);
}
// and add the new position to the history...
addToHistory();
addToHistory(activatedEntryNumber);
// set modified state
setModified(true);
} catch (IllegalAddException | IllegalDataException ex) {
Expand Down Expand Up @@ -3032,7 +3033,7 @@ public int addEntry(String title, String content, String[] authors, String[] key
* {@link #ADD_LUHMANNENTRY_ERR ADD_LUHMANNENTRY_ERR} if an error
* occured when adding a follower-entry (trailing entry)
*/
public int addEntryFromBibTex(String title, String content, String[] authors, String[] keywords, String timestamp) {
public int addEntryFromBibTeX(String title, String content, String[] authors, String[] keywords, String timestamp) {
// add entry
int succeeded = addEntry(title, content, authors, keywords, "", null, timestamp, -1, false, -1);
// if operation was successful...
Expand Down Expand Up @@ -3308,7 +3309,7 @@ public boolean changeEntry(String title, String content, String[] authors, Strin
// update the current zettel-position
this.activatedEntryNumber = entrynumber;
// and add the new position to the history...
addToHistory();
addToHistory(activatedEntryNumber);
// set modified state
setModified(true);
} catch (IllegalAddException | IllegalDataException ex) {
Expand Down Expand Up @@ -4965,12 +4966,7 @@ public int getCount(int what) {
/**
* This method adds the new zettel-position to the history, so the user can go
* back and fore to previous selected entries.
*/
private void addToHistory() {
addToHistory(activatedEntryNumber);
}


*/
public void addToHistory(int entryNr) {
history.addToHistory(entryNr);
}
Expand Down Expand Up @@ -5014,7 +5010,7 @@ public boolean activateEntry(int entryNumber) {
activatedEntryNumber = entryNumber;

// Update history with the new activated entry
addToHistory();
addToHistory(activatedEntryNumber);

return true;
}
Expand All @@ -5030,7 +5026,7 @@ public void nextEntry() {
activatedEntryNumber = 1;
}
// update History
addToHistory();
addToHistory(activatedEntryNumber);
}

/**
Expand All @@ -5044,7 +5040,7 @@ public void prevEntry() {
activatedEntryNumber = getCount(ZKNCOUNT);
}
// update History
addToHistory();
addToHistory(activatedEntryNumber);
}

/**
Expand All @@ -5055,7 +5051,7 @@ public void firstEntry() {
// set counter for currently display entry to 1
activatedEntryNumber = 1;
// update History
addToHistory();
addToHistory(activatedEntryNumber);
}

/**
Expand All @@ -5066,7 +5062,7 @@ public void lastEntry() {
// set counter for currently display entry to last element
activatedEntryNumber = getCount(ZKNCOUNT);
// update History
addToHistory();
addToHistory(activatedEntryNumber);
}

/**
Expand All @@ -5076,7 +5072,7 @@ public void lastEntry() {
*
* It adds a the new entry (first parent entry) to the history.
*/
public void goToFirstParentEntry() {
public void goToFirstTopOfTopic() { // was: goToFirstParentEntry ; cf. "Inhaltlich-logische Navigation" in https://niklas-luhmann-archiv.de/bestand/zettelkasten/tutorial
int firstParentEntry = findParentlLuhmann(activatedEntryNumber, /* firstParent= */true);
if (firstParentEntry == -1) {
// No valid parent entry, do nothing.
Expand All @@ -5087,7 +5083,7 @@ public void goToFirstParentEntry() {
activatedEntryNumber = firstParentEntry;

// Update history.
addToHistory();
addToHistory(activatedEntryNumber);
}

/**
Expand Down Expand Up @@ -7484,50 +7480,25 @@ public boolean isTopLevelLuhmann(int nr) {
* {@code -1} if the entry {@code nr} has no luhmann (follower) parent,
* resp. if the entry {@code nr} also has no follower entries.
*/
public int findParentlLuhmann(int nr, boolean firstParent) {
// init find value
boolean found = true;
//
int retval = -1;
//
while (found) {
// indicates, whether any luhmann parent was found
boolean innerLoopFound = false;
// counter for looping through entries
int cnt = 1;
// get current entry number as string
String currentEntry = String.valueOf(nr);
// go through complete data set
while (!innerLoopFound && cnt <= getCount(Daten.ZKNCOUNT)) {
// get the luhmann numbers of each entry
String[] lnrs = getSubEntriesCsv(cnt).split(",");
// now check each number for the occurrence of the current entry number
for (String l : lnrs) {
// when one of the luhmann numbers equals the current entry number...
if (l.equals(currentEntry)) {
// we found a parent
nr = retval = cnt;
// find only first parent?
if (firstParent) {
return retval;
}
// indicate that parent was found
innerLoopFound = true;
break;
}
public int findParentLuhmann(int entryNumber, boolean firstParent) {
int parentNumber = -1;

for (int currentEntry = 1; currentEntry <= getCount(Daten.ZKNCOUNT); currentEntry++) {
String subEntriesCsv = getSubEntriesCsv(currentEntry);
String[] subEntries = subEntriesCsv.split(",");

if (Arrays.asList(subEntries).contains(String.valueOf(entryNumber))) {
parentNumber = currentEntry;
if (firstParent) {
break; // Found the first parent, so exit loop
}
// increase loop counter
cnt++;
}
// when all entries have been checked and no parent was found
// leave complete routine and return result.
if (!innerLoopFound) {
found = false;
}
}
return retval;

return parentNumber;
}


/**
* This method retrieves all follower and follower's follower of the entry
* {@code zettelpos} and stores the index numbers in the global integer array
Expand Down
Loading

0 comments on commit 9f40773

Please sign in to comment.