From a9229e81f2bc01e7335b3480e612f52e4c2f1afa Mon Sep 17 00:00:00 2001 From: RalfBarkow Date: Mon, 10 Jun 2024 19:49:25 +0200 Subject: [PATCH 1/2] index on playground: 242e162 test(ZettelkastenView): testUpdateEntryPaneAndKeywordsPaneInvalidEntry --- .../zettelkasten/ZettelkastenView.java | 46 ++++++++++--------- .../zettelkasten/data/History.java | 8 ++++ .../zettelkasten/database/Daten.java | 5 ++ .../zettelkasten/util/HtmlUbbUtil.java | 2 +- 4 files changed, 38 insertions(+), 23 deletions(-) diff --git a/src/main/java/de/danielluedecke/zettelkasten/ZettelkastenView.java b/src/main/java/de/danielluedecke/zettelkasten/ZettelkastenView.java index 244415d8..f365413d 100644 --- a/src/main/java/de/danielluedecke/zettelkasten/ZettelkastenView.java +++ b/src/main/java/de/danielluedecke/zettelkasten/ZettelkastenView.java @@ -112,8 +112,8 @@ public class ZettelkastenView extends FrameView implements WindowListener, DropT */ public SearchRequests searchRequests; - private Daten data; - private History historyManager; + public Daten data; + private History history; private final TasksData taskinfo; public final Bookmarks bookmarks; private final BibTeX bibtex; @@ -222,8 +222,6 @@ public class ZettelkastenView extends FrameView implements WindowListener, DropT private boolean isbnc = false; - private ApplicationContext context; - public boolean isBackupNecessary() { return isbnc; } @@ -244,14 +242,14 @@ public void setUpdateURI(String uri) { /** * This string contains an added keyword that was added to the jTableKeywords, - * so the new added value can be selected immediatley after adding in to the + * so the new added value can be selected immediately after adding in to the * table. */ private String newAddedKeyword = null; /** * This string contains an added author that was added to the jTableAuthors, so - * the new added value can be selected immediatley after adding in to the table. + * the new added value can be selected immediately after adding in to the table. */ private String newAddedAuthor = null; @@ -418,7 +416,7 @@ public ZettelkastenView(SingleFrameApplication app, Settings st, TasksData td) t bookmarks = new Bookmarks(this, settings); bibtex = new BibTeX(this, settings); data = new Daten(this, settings, settings.getSynonyms(), bibtex); - display = new Display(this, historyManager); + display = new Display(this, history); } else { // Handle the case where settings is null bookmarks = null; // or initialize with default value @@ -2750,7 +2748,7 @@ private void updateFrameTitle() { } /** - * This method is used to update the content of the textfields/lists, but not + * This method is used to update the content of the text fields/lists, but not * the whole display like tabbed pane as well. Usually this method is called * when a link to another entry or a follower entry or any entry in one of the * tabbed pane's tables is selected. This selection does just show the content @@ -2760,26 +2758,31 @@ private void updateFrameTitle() { * this only occurs, when an entry is activated. e.g. by double-clicking * on an entry in on of the tabbed pane's tables. * - * @param inputDisplayedEntry the number of the entry that should be displayed + * @param entryNumber the number of the entry to display */ - void updateEntryPaneAndKeywordsPane(int inputDisplayedEntry) { + void updateEntryPaneAndKeywordsPane(int entryNumber) { // If we have an invalid entry, reset panes. - if (data.getCount(Daten.ZKNCOUNT) == 0 || inputDisplayedEntry == 0) { + if (isInvalidEntry(entryNumber)) { resetEntryPaneAndKeywordsPane(); return; } // If the user wants to add all displayed entries to the history, include new // displayed entry to the history. - if (settings.getAddAllToHistory()) { - data.addToHistory(inputDisplayedEntry); - // Update buttons for navigating through history. - buttonHistoryBack.setEnabled(data.canHistoryBack()); - buttonHistoryForward.setEnabled(data.canHistoryForward()); + if (settings.getAddAllToHistory() && history != null) { + history.updateHistory(this, entryNumber); } - displaySelectedEntry(inputDisplayedEntry); + displaySelectedEntry(entryNumber); + + updateStatus(); + } + + private boolean isInvalidEntry(int inputDisplayedEntry) { + return data.getCount(Daten.ZKNCOUNT) == 0 || inputDisplayedEntry == 0; + } + private void updateStatus() { statusOfEntryLabel.setText( getResourceMap().getString("entryOfText") + " " + String.valueOf(data.getCount(Daten.ZKNCOUNT))); } @@ -6455,7 +6458,6 @@ public EditorFrame getEditorFrame() { } public void setContext(ApplicationContext applicationContext) { - this.context = applicationContext; } @@ -14639,8 +14641,8 @@ private void initViewMenuLinks() { private javax.swing.JMenuItem addSelectionToKeywordMenuItem; private javax.swing.JMenuItem addSelectionToTitleMenuItem; private javax.swing.JMenuItem addToDesktopMenuItem; - javax.swing.JButton buttonHistoryBack; - javax.swing.JButton buttonHistoryForward; + public javax.swing.JButton buttonHistoryBack; + public javax.swing.JButton buttonHistoryForward; private javax.swing.JMenuItem copyMenuItem; private javax.swing.JMenuItem copyPlainMenuItem; private javax.swing.JMenuItem deleteKwFromListMenuItem; @@ -15173,11 +15175,11 @@ public Zettel getDisplayedZettel() { } public void setHistoryManager(History historyManager) { - this.historyManager = historyManager; + this.history = historyManager; } public History getHistoryManager() { - return historyManager; + return history; } public void displayHistory(int[] history, int historyCount) { diff --git a/src/main/java/de/danielluedecke/zettelkasten/data/History.java b/src/main/java/de/danielluedecke/zettelkasten/data/History.java index 2ccacd9e..e83737aa 100644 --- a/src/main/java/de/danielluedecke/zettelkasten/data/History.java +++ b/src/main/java/de/danielluedecke/zettelkasten/data/History.java @@ -1,5 +1,6 @@ package de.danielluedecke.zettelkasten.data; +import de.danielluedecke.zettelkasten.ZettelkastenView; import de.danielluedecke.zettelkasten.history.NavigationListener; import de.danielluedecke.zettelkasten.util.Constants; import de.danielluedecke.zettelkasten.view.Display; @@ -127,4 +128,11 @@ public int navigateForwardInHistory() { public void navigateBackwardInHistory() { historyBack(); } + + public void updateHistory(ZettelkastenView zettelkastenView, int inputDisplayedEntry) { + zettelkastenView.data.addToHistory(inputDisplayedEntry); + // Update buttons for navigating through history. + zettelkastenView.buttonHistoryBack.setEnabled(zettelkastenView.data.canHistoryBack()); + zettelkastenView.buttonHistoryForward.setEnabled(zettelkastenView.data.canHistoryForward()); + } } \ No newline at end of file diff --git a/src/main/java/de/danielluedecke/zettelkasten/database/Daten.java b/src/main/java/de/danielluedecke/zettelkasten/database/Daten.java index 63066a59..3446dc7c 100644 --- a/src/main/java/de/danielluedecke/zettelkasten/database/Daten.java +++ b/src/main/java/de/danielluedecke/zettelkasten/database/Daten.java @@ -7627,4 +7627,9 @@ public void addEntry(int validEntryNumber, String string) { } + public boolean isInHistory(int entryNumber) { + // TODO Auto-generated method stub + return false; + } + } diff --git a/src/main/java/de/danielluedecke/zettelkasten/util/HtmlUbbUtil.java b/src/main/java/de/danielluedecke/zettelkasten/util/HtmlUbbUtil.java index ae8ae47b..7ba3dfed 100644 --- a/src/main/java/de/danielluedecke/zettelkasten/util/HtmlUbbUtil.java +++ b/src/main/java/de/danielluedecke/zettelkasten/util/HtmlUbbUtil.java @@ -2291,7 +2291,7 @@ private static String getCommonStyleDefinition(Settings settings, String[] segme */ public static String getCommonStyleDefinition(Settings settings, boolean isDesktop, boolean isExport, boolean isPrint) { // check whether we have custom css settings - if (settings.getUseCustomCSS((isDesktop) ? Settings.CUSTOM_CSS_DESKTOP : Settings.CUSTOM_CSS_ENTRY)) { + if (settings != null && settings.getUseCustomCSS((isDesktop) ? Settings.CUSTOM_CSS_DESKTOP : Settings.CUSTOM_CSS_ENTRY)) { // retrieve custom style sheet String customCss = settings.getCustomCSS((isDesktop) ? Settings.CUSTOM_CSS_DESKTOP : Settings.CUSTOM_CSS_ENTRY); // check for valid value From c43b64287495c4955a435125bd2c8a85558def88 Mon Sep 17 00:00:00 2001 From: RalfBarkow Date: Mon, 10 Jun 2024 19:53:08 +0200 Subject: [PATCH 2/2] fix(initDefaultMainKeysIfMissing): log messages Now the log messages correctly reflect the key binding configuration: * historyForward logs historykey + " RIGHT". * historyBack logs historykey + " LEFT". --- .../danielluedecke/zettelkasten/settings/AcceleratorKeys.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/de/danielluedecke/zettelkasten/settings/AcceleratorKeys.java b/src/main/java/de/danielluedecke/zettelkasten/settings/AcceleratorKeys.java index 83096906..45f877c1 100644 --- a/src/main/java/de/danielluedecke/zettelkasten/settings/AcceleratorKeys.java +++ b/src/main/java/de/danielluedecke/zettelkasten/settings/AcceleratorKeys.java @@ -398,7 +398,7 @@ void initDefaultMainKeysIfMissing() { acceleratorKeysMain.getRootElement().addContent(acckey); // Log the key binding configuration - Constants.zknlogger.info("Key binding set for historyForward: " + historykey + " LEFT"); + Constants.zknlogger.info("Key binding set for historyForward: " + historykey + " RIGHT"); }