diff --git a/novelwriter/core/index.py b/novelwriter/core/index.py index 05554aa7..a75dbf7d 100644 --- a/novelwriter/core/index.py +++ b/novelwriter/core/index.py @@ -30,6 +30,7 @@ from __future__ import annotations import json import logging +from random import randint from time import time from typing import TYPE_CHECKING from pathlib import Path @@ -1309,6 +1310,9 @@ class IndexHeading: # The Text Index Object # =============================================================================================== # +KEY_SOURCE = "0123456789bcdfghjklmnopqrstvwxyz" + + class TextIndex: """Core: Text Index Wrapper Class @@ -1318,8 +1322,8 @@ class TextIndex: __slots__ = ("_comments", "_footnotes") def __init__(self) -> None: - self._comments = TextRegistry() - self._footnotes = TextRegistry() + self._comments = TextRegistry("c_") + self._footnotes = TextRegistry("f_") return @property @@ -1374,11 +1378,12 @@ class TextRegistry: A wrapper class that holds a category of text entries. """ - __slots__ = ("_map", "_text") + __slots__ = ("_map", "_text", "_prefix") - def __init__(self) -> None: + def __init__(self, prefix: str) -> None: self._map: dict[str, str] = {} self._text: dict[str, str] = {} + self._prefix = prefix return def __len__(self) -> int: @@ -1416,6 +1421,13 @@ class TextRegistry: del self._text[key] return + def newKey(self) -> str: + """Generate a new key.""" + key = self._prefix + "".join([KEY_SOURCE[randint(0, 31)] for _ in range(4)]) + if key in self._text: + key = self.newKey() + return key + ## # Pack/Unpack ## diff --git a/novelwriter/enum.py b/novelwriter/enum.py index 3f630165..4750ef5d 100644 --- a/novelwriter/enum.py +++ b/novelwriter/enum.py @@ -69,6 +69,8 @@ class nwComment(Enum): SHORT = 2 NOTE = 3 FOOTNOTE = 4 + COMMENT = 5 + STORY = 6 # END Enum nwComment @@ -147,6 +149,7 @@ class nwDocInsert(Enum): VSPACE_S = 8 VSPACE_M = 9 LIPSUM = 10 + FOOTNOTE = 11 # END Enum nwDocInsert diff --git a/novelwriter/gui/mainmenu.py b/novelwriter/gui/mainmenu.py index 4a9c198d..96fe2b2c 100644 --- a/novelwriter/gui/mainmenu.py +++ b/novelwriter/gui/mainmenu.py @@ -597,6 +597,12 @@ class GuiMainMenu(QMenuBar): lambda: self.requestDocInsert.emit(nwDocInsert.LIPSUM) ) + # Insert > Footnote + self.aFootnote = self.insMenu.addAction(self.tr("Footnote")) + self.aFootnote.triggered.connect( + lambda: self.requestDocInsert.emit(nwDocInsert.FOOTNOTE) + ) + return def _buildFormatMenu(self) -> None: