Add key generator to text index
This commit is contained in:
@@ -30,6 +30,7 @@ from __future__ import annotations
|
|||||||
import json
|
import json
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
|
from random import randint
|
||||||
from time import time
|
from time import time
|
||||||
from typing import TYPE_CHECKING
|
from typing import TYPE_CHECKING
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
@@ -1309,6 +1310,9 @@ class IndexHeading:
|
|||||||
# The Text Index Object
|
# The Text Index Object
|
||||||
# =============================================================================================== #
|
# =============================================================================================== #
|
||||||
|
|
||||||
|
KEY_SOURCE = "0123456789bcdfghjklmnopqrstvwxyz"
|
||||||
|
|
||||||
|
|
||||||
class TextIndex:
|
class TextIndex:
|
||||||
"""Core: Text Index Wrapper Class
|
"""Core: Text Index Wrapper Class
|
||||||
|
|
||||||
@@ -1318,8 +1322,8 @@ class TextIndex:
|
|||||||
__slots__ = ("_comments", "_footnotes")
|
__slots__ = ("_comments", "_footnotes")
|
||||||
|
|
||||||
def __init__(self) -> None:
|
def __init__(self) -> None:
|
||||||
self._comments = TextRegistry()
|
self._comments = TextRegistry("c_")
|
||||||
self._footnotes = TextRegistry()
|
self._footnotes = TextRegistry("f_")
|
||||||
return
|
return
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@@ -1374,11 +1378,12 @@ class TextRegistry:
|
|||||||
A wrapper class that holds a category of text entries.
|
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._map: dict[str, str] = {}
|
||||||
self._text: dict[str, str] = {}
|
self._text: dict[str, str] = {}
|
||||||
|
self._prefix = prefix
|
||||||
return
|
return
|
||||||
|
|
||||||
def __len__(self) -> int:
|
def __len__(self) -> int:
|
||||||
@@ -1416,6 +1421,13 @@ class TextRegistry:
|
|||||||
del self._text[key]
|
del self._text[key]
|
||||||
return
|
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
|
# Pack/Unpack
|
||||||
##
|
##
|
||||||
|
|||||||
@@ -69,6 +69,8 @@ class nwComment(Enum):
|
|||||||
SHORT = 2
|
SHORT = 2
|
||||||
NOTE = 3
|
NOTE = 3
|
||||||
FOOTNOTE = 4
|
FOOTNOTE = 4
|
||||||
|
COMMENT = 5
|
||||||
|
STORY = 6
|
||||||
|
|
||||||
# END Enum nwComment
|
# END Enum nwComment
|
||||||
|
|
||||||
@@ -147,6 +149,7 @@ class nwDocInsert(Enum):
|
|||||||
VSPACE_S = 8
|
VSPACE_S = 8
|
||||||
VSPACE_M = 9
|
VSPACE_M = 9
|
||||||
LIPSUM = 10
|
LIPSUM = 10
|
||||||
|
FOOTNOTE = 11
|
||||||
|
|
||||||
# END Enum nwDocInsert
|
# END Enum nwDocInsert
|
||||||
|
|
||||||
|
|||||||
@@ -597,6 +597,12 @@ class GuiMainMenu(QMenuBar):
|
|||||||
lambda: self.requestDocInsert.emit(nwDocInsert.LIPSUM)
|
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
|
return
|
||||||
|
|
||||||
def _buildFormatMenu(self) -> None:
|
def _buildFormatMenu(self) -> None:
|
||||||
|
|||||||
Reference in New Issue
Block a user