Skip to content

Improve GUI text #1727

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Mar 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions novelwriter/core/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ def _scanActive(self, tHandle: str, nwItem: NWItem, text: str, tags: dict[str, b
nTitle = 0 # Line Number of the previous title
cTitle = TT_NONE # Tag of the current title
pTitle = TT_NONE # Tag of the previous title
canSetHeader = True # First header has not yet been set
canSetHead = True # First heading has not yet been set

lines = text.splitlines()
for n, line in enumerate(lines, start=1):
Expand All @@ -320,9 +320,9 @@ def _scanActive(self, tHandle: str, nwItem: NWItem, text: str, tags: dict[str, b
if hDepth == "H0":
continue

if canSetHeader:
if canSetHead:
nwItem.setMainHeading(hDepth)
canSetHeader = False
canSetHead = False

cTitle = self._itemIndex.addItemHeading(tHandle, n, hDepth, hText)
if cTitle != TT_NONE:
Expand Down Expand Up @@ -383,7 +383,7 @@ def _scanInactive(self, nwItem: NWItem, text: str) -> None:
return

def _splitHeading(self, line: str) -> tuple[str, str]:
"""Split a heading into its header level and text value."""
"""Split a heading into its heading level and text value."""
if line.startswith("# "):
return "H1", line[2:].strip()
elif line.startswith("## "):
Expand Down Expand Up @@ -515,8 +515,8 @@ def getItemData(self, tHandle: str) -> IndexItem | None:
"""Get the index data for a given item."""
return self._itemIndex[tHandle]

def getItemHeader(self, tHandle: str, sTitle: str) -> IndexHeading | None:
"""Get the header entry for a specific item and heading."""
def getItemHeading(self, tHandle: str, sTitle: str) -> IndexHeading | None:
"""Get the heading entry for a specific item and heading."""
tItem = self._itemIndex[tHandle]
if isinstance(tItem, IndexItem):
return tItem[sTitle]
Expand Down Expand Up @@ -825,7 +825,7 @@ class ItemIndex:
class around a single storage dictionary with a set of utility
functions for setting and accessing the index data. Each indexed
item is stored in an IndexItem object, which again holds an
IndexHeading object for each header of the text.
IndexHeading object for each heading of the text.
"""

__slots__ = ("_project", "_items")
Expand Down Expand Up @@ -1200,7 +1200,7 @@ def references(self) -> dict[str, set[str]]:
##

def setLevel(self, level: str) -> None:
"""Set the level of the header if it's a valid value."""
"""Set the level of the heading if it's a valid value."""
if level in nwHeaders.H_VALID:
self._level = level
return
Expand Down
66 changes: 33 additions & 33 deletions novelwriter/core/tokenizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,10 @@ class Tokenizer(ABC):
T_KEYWORD = 5 # Command line
T_TITLE = 6 # Title
T_UNNUM = 7 # Unnumbered
T_HEAD1 = 8 # Header 1
T_HEAD2 = 9 # Header 2
T_HEAD3 = 10 # Header 3
T_HEAD4 = 11 # Header 4
T_HEAD1 = 8 # Heading 1
T_HEAD2 = 9 # Heading 2
T_HEAD3 = 10 # Heading 3
T_HEAD4 = 11 # Heading 4
T_TEXT = 12 # Text line
T_SEP = 13 # Scene separator
T_SKIP = 14 # Paragraph break
Expand Down Expand Up @@ -158,10 +158,10 @@ def __init__(self, project: NWProject) -> None:
self._fmtScene = nwHeadFmt.TITLE # Formatting for scenes
self._fmtSection = nwHeadFmt.TITLE # Formatting for sections

self._hideScene = False # Do not include scene headers
self._hideSection = False # Do not include section headers
self._hideScene = False # Do not include scene headings
self._hideSection = False # Do not include section headings

self._linkHeaders = False # Add an anchor before headers
self._linkHeaders = False # Add an anchor before headings

self._titleStyle = self.A_CENTRE | self.A_PBB
self._chapterStyle = self.A_PBB
Expand Down Expand Up @@ -309,22 +309,22 @@ def setTitleMargins(self, upper: float, lower: float) -> None:
return

def setHead1Margins(self, upper: float, lower: float) -> None:
"""Set the upper and lower header 1 margin."""
"""Set the upper and lower heading 1 margin."""
self._marginHead1 = (float(upper), float(lower))
return

def setHead2Margins(self, upper: float, lower: float) -> None:
"""Set the upper and lower header 2 margin."""
"""Set the upper and lower heading 2 margin."""
self._marginHead2 = (float(upper), float(lower))
return

def setHead3Margins(self, upper: float, lower: float) -> None:
"""Set the upper and lower header 3 margin."""
"""Set the upper and lower heading 3 margin."""
self._marginHead3 = (float(upper), float(lower))
return

def setHead4Margins(self, upper: float, lower: float) -> None:
"""Set the upper and lower header 4 margin."""
"""Set the upper and lower heading 4 margin."""
self._marginHead4 = (float(upper), float(lower))
return

Expand All @@ -338,8 +338,8 @@ def setMetaMargins(self, upper: float, lower: float) -> None:
self._marginMeta = (float(upper), float(lower))
return

def setLinkHeaders(self, state: bool) -> None:
"""Enable or disable adding an anchor before headers."""
def setLinkHeadings(self, state: bool) -> None:
"""Enable or disable adding an anchor before headings."""
self._linkHeaders = state
return

Expand Down Expand Up @@ -442,15 +442,15 @@ def doPreProcessing(self) -> None:

def tokenizeText(self) -> None:
"""Scan the text for either lines starting with specific
characters that indicate headers, comments, commands etc, or
characters that indicate headings, comments, commands etc, or
just contain plain text. In the case of plain text, apply the
same RegExes that the syntax highlighter uses and save the
locations of these formatting tags into the token array.

The format of the token list is an entry with a five-tuple for
each line in the file. The tuple is as follows:
1: The type of the block, self.T_*
2: The header number under which the text is placed
2: The heading number under which the text is placed
3: The text content of the block, without leading tags
4: The internal formatting map of the text, self.FMT_*
5: The style of the block, self.A_*
Expand Down Expand Up @@ -557,9 +557,9 @@ def tokenizeText(self) -> None:
tmpMarkdown.append(f"{aLine}\n")

elif aLine[:2] == "# ":
# Partition Headers
# =================
# Partition headers are only formatted in novel documents, and
# Partition Headings
# ==================
# Partition headings are only formatted in novel documents, and
# otherwise unchanged. Scene separators are disabled
# immediately after partitions, and scene numbers are reset.

Expand All @@ -579,12 +579,12 @@ def tokenizeText(self) -> None:
tmpMarkdown.append(f"{aLine}\n")

elif aLine[:3] == "## ":
# Chapter Headers
# ===============
# Chapter headers are only formatted in novel documents, and
# Chapter Headings
# ================
# Chapter headings are only formatted in novel documents, and
# otherwise unchanged. Chapter numbers are bumped before the
# heading is formatted. Scene separators are disabled
# immediately after chapter headers, and scene numbers are
# immediately after chapter headings, and scene numbers are
# reset.

nHead += 1
Expand All @@ -604,15 +604,15 @@ def tokenizeText(self) -> None:
tmpMarkdown.append(f"{aLine}\n")

elif aLine[:4] == "### ":
# Scene Headers
# =============
# Scene headers in novel documents are treated as centred
# Scene Headings
# ==============
# Scene headings in novel documents are treated as centred
# separators if the formatting does not change the text. If the
# format is empty, the scene can be hidden or a blank paragraph
# (skip). When the scene title has static text or no text, it
# is always ignored if the noSep flag is set. This prevents
# separators immediately after other titles. Scene numbers are
# always incremented before formatting. For notes, the header
# always incremented before formatting. For notes, the heading
# is unchanged.

nHead += 1
Expand All @@ -639,12 +639,12 @@ def tokenizeText(self) -> None:
tmpMarkdown.append(f"{aLine}\n")

elif aLine[:5] == "#### ":
# Section Headers
# ===============
# Section headers in novel docs are treated as centred
# Section Headings
# =================
# Section headings in novel docs are treated as centred
# separators if the formatting does not change the text. If the
# format is empty, the section can be hidden or a blank
# paragraph (skip). For notes, the header is unchanged.
# paragraph (skip). For notes, the heading is unchanged.

nHead += 1
tText = aLine[5:].strip()
Expand Down Expand Up @@ -682,10 +682,10 @@ def tokenizeText(self) -> None:
tmpMarkdown.append(f"{aLine}\n")

elif aLine[:4] == "##! ":
# Unnumbered Chapter Header
# =========================
# Unnumbered Chapter Headings
# ===========================
# Unnumbered chapters are only meaningful in Novel docs, so if
# we're in a note, we convert them to a plain level 2 header.
# we're in a note, we convert them to a plain level 2 heading.

nHead += 1
tText = aLine[4:].strip()
Expand Down
12 changes: 6 additions & 6 deletions novelwriter/dialogs/docsplit.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def __init__(self, parent: QWidget, sHandle: str) -> None:

self.setWindowTitle(self.tr("Split Document"))

self.headLabel = QLabel("<b>{0}</b>".format(self.tr("Document Headers")))
self.headLabel = QLabel("<b>{0}</b>".format(self.tr("Document Headings")))
self.helpLabel = NColourLabel(
self.tr("Select the maximum level to split into files."),
SHARED.theme.helpText, parent=self, wrap=True
Expand All @@ -74,17 +74,17 @@ def __init__(self, parent: QWidget, sHandle: str) -> None:
intoFolder = pOptions.getBool("GuiDocSplit", "intoFolder", True)
docHierarchy = pOptions.getBool("GuiDocSplit", "docHierarchy", True)

# Header Selection
# Heading Selection
self.listBox = QListWidget()
self.listBox.setDragDropMode(QAbstractItemView.NoDragDrop)
self.listBox.setMinimumWidth(CONFIG.pxInt(400))
self.listBox.setMinimumHeight(CONFIG.pxInt(180))

self.splitLevel = QComboBox(self)
self.splitLevel.addItem(self.tr("Split on Header Level 1 (Title)"), 1)
self.splitLevel.addItem(self.tr("Split up to Header Level 2 (Chapter)"), 2)
self.splitLevel.addItem(self.tr("Split up to Header Level 3 (Scene)"), 3)
self.splitLevel.addItem(self.tr("Split up to Header Level 4 (Section)"), 4)
self.splitLevel.addItem(self.tr("Split on Heading Level 1 (Partition)"), 1)
self.splitLevel.addItem(self.tr("Split up to Heading Level 2 (Chapter)"), 2)
self.splitLevel.addItem(self.tr("Split up to Heading Level 3 (Scene)"), 3)
self.splitLevel.addItem(self.tr("Split up to Heading Level 4 (Section)"), 4)
spIndex = self.splitLevel.findData(spLevel)
if spIndex != -1:
self.splitLevel.setCurrentIndex(spIndex)
Expand Down
28 changes: 14 additions & 14 deletions novelwriter/gui/dochighlight.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,10 @@ def initHighlighter(self) -> None:
"header2": self._makeFormat(SHARED.theme.colHead, "bold", 1.6),
"header3": self._makeFormat(SHARED.theme.colHead, "bold", 1.4),
"header4": self._makeFormat(SHARED.theme.colHead, "bold", 1.2),
"header1h": self._makeFormat(SHARED.theme.colHeadH, "bold", 1.8),
"header2h": self._makeFormat(SHARED.theme.colHeadH, "bold", 1.6),
"header3h": self._makeFormat(SHARED.theme.colHeadH, "bold", 1.4),
"header4h": self._makeFormat(SHARED.theme.colHeadH, "bold", 1.2),
"head1h": self._makeFormat(SHARED.theme.colHeadH, "bold", 1.8),
"head2h": self._makeFormat(SHARED.theme.colHeadH, "bold", 1.6),
"head3h": self._makeFormat(SHARED.theme.colHeadH, "bold", 1.4),
"head4h": self._makeFormat(SHARED.theme.colHeadH, "bold", 1.2),
"bold": self._makeFormat(colEmph, "bold"),
"italic": self._makeFormat(colEmph, "italic"),
"strike": self._makeFormat(SHARED.theme.colHidden, "strike"),
Expand Down Expand Up @@ -303,28 +303,28 @@ def highlightBlock(self, text: str) -> None:
elif text.startswith(("# ", "#! ", "## ", "##! ", "### ", "#### ")):
self.setCurrentBlockState(self.BLOCK_TITLE)

if text.startswith("# "): # Header 1
self.setFormat(0, 1, self._hStyles["header1h"])
if text.startswith("# "): # Heading 1
self.setFormat(0, 1, self._hStyles["head1h"])
self.setFormat(1, len(text), self._hStyles["header1"])

elif text.startswith("## "): # Header 2
self.setFormat(0, 2, self._hStyles["header2h"])
elif text.startswith("## "): # Heading 2
self.setFormat(0, 2, self._hStyles["head2h"])
self.setFormat(2, len(text), self._hStyles["header2"])

elif text.startswith("### "): # Header 3
self.setFormat(0, 3, self._hStyles["header3h"])
elif text.startswith("### "): # Heading 3
self.setFormat(0, 3, self._hStyles["head3h"])
self.setFormat(3, len(text), self._hStyles["header3"])

elif text.startswith("#### "): # Header 4
self.setFormat(0, 4, self._hStyles["header4h"])
elif text.startswith("#### "): # Heading 4
self.setFormat(0, 4, self._hStyles["head4h"])
self.setFormat(4, len(text), self._hStyles["header4"])

elif text.startswith("#! "): # Title
self.setFormat(0, 2, self._hStyles["header1h"])
self.setFormat(0, 2, self._hStyles["head1h"])
self.setFormat(2, len(text), self._hStyles["header1"])

elif text.startswith("##! "): # Unnumbered
self.setFormat(0, 3, self._hStyles["header2h"])
self.setFormat(0, 3, self._hStyles["head2h"])
self.setFormat(3, len(text), self._hStyles["header2"])

elif text.startswith("%"): # Comments
Expand Down
2 changes: 1 addition & 1 deletion novelwriter/gui/docviewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ def loadText(self, tHandle: str, updateHistory: bool = True) -> bool:
sPos = self.verticalScrollBar().value()
aDoc = ToHtml(SHARED.project)
aDoc.setPreview(CONFIG.viewComments, CONFIG.viewSynopsis)
aDoc.setLinkHeaders(True)
aDoc.setLinkHeadings(True)

# Be extra careful here to prevent crashes when first opening a
# project as a crash here leaves no way of recovering.
Expand Down
24 changes: 12 additions & 12 deletions novelwriter/gui/mainmenu.py
Original file line number Diff line number Diff line change
Expand Up @@ -693,29 +693,29 @@ def _buildFormatMenu(self) -> None:
# Format > Separator
self.fmtMenu.addSeparator()

# Format > Header 1 (Partition)
self.aFmtHead1 = self.fmtMenu.addAction(self.tr("Header 1 (Partition)"))
# Format > Heading 1 (Partition)
self.aFmtHead1 = self.fmtMenu.addAction(self.tr("Heading 1 (Partition)"))
self.aFmtHead1.setShortcut("Ctrl+1")
self.aFmtHead1.triggered.connect(
lambda: self.requestDocAction.emit(nwDocAction.BLOCK_H1)
)

# Format > Header 2 (Chapter)
self.aFmtHead2 = self.fmtMenu.addAction(self.tr("Header 2 (Chapter)"))
# Format > Heading 2 (Chapter)
self.aFmtHead2 = self.fmtMenu.addAction(self.tr("Heading 2 (Chapter)"))
self.aFmtHead2.setShortcut("Ctrl+2")
self.aFmtHead2.triggered.connect(
lambda: self.requestDocAction.emit(nwDocAction.BLOCK_H2)
)

# Format > Header 3 (Scene)
self.aFmtHead3 = self.fmtMenu.addAction(self.tr("Header 3 (Scene)"))
# Format > Heading 3 (Scene)
self.aFmtHead3 = self.fmtMenu.addAction(self.tr("Heading 3 (Scene)"))
self.aFmtHead3.setShortcut("Ctrl+3")
self.aFmtHead3.triggered.connect(
lambda: self.requestDocAction.emit(nwDocAction.BLOCK_H3)
)

# Format > Header 4 (Section)
self.aFmtHead4 = self.fmtMenu.addAction(self.tr("Header 4 (Section)"))
# Format > Heading 4 (Section)
self.aFmtHead4 = self.fmtMenu.addAction(self.tr("Heading 4 (Section)"))
self.aFmtHead4.setShortcut("Ctrl+4")
self.aFmtHead4.triggered.connect(
lambda: self.requestDocAction.emit(nwDocAction.BLOCK_H4)
Expand Down Expand Up @@ -804,14 +804,14 @@ def _buildFormatMenu(self) -> None:
# Format > Separator
self.fmtMenu.addSeparator()

# Format > Replace Single Quotes
self.aFmtReplSng = self.fmtMenu.addAction(self.tr("Convert Single Quotes"))
# Format > Replace Straight Single Quotes
self.aFmtReplSng = self.fmtMenu.addAction(self.tr("Replace Straight Single Quotes"))
self.aFmtReplSng.triggered.connect(
lambda: self.requestDocAction.emit(nwDocAction.REPL_SNG)
)

# Format > Replace Double Quotes
self.aFmtReplDbl = self.fmtMenu.addAction(self.tr("Convert Double Quotes"))
# Format > Replace Straight Double Quotes
self.aFmtReplDbl = self.fmtMenu.addAction(self.tr("Replace Straight Double Quotes"))
self.aFmtReplDbl.triggered.connect(
lambda: self.requestDocAction.emit(nwDocAction.REPL_DBL)
)
Expand Down
2 changes: 1 addition & 1 deletion novelwriter/gui/noveltree.py
Original file line number Diff line number Diff line change
Expand Up @@ -750,7 +750,7 @@ def _popMetaBox(self, qPos: QPoint, tHandle: str, sTitle: str) -> None:
logger.debug("Generating meta data tooltip for '%s:%s'", tHandle, sTitle)

pIndex = SHARED.project.index
novIdx = pIndex.getItemHeader(tHandle, sTitle)
novIdx = pIndex.getItemHeading(tHandle, sTitle)
refTags = pIndex.getReferences(tHandle, sTitle)
if not novIdx:
return
Expand Down
2 changes: 1 addition & 1 deletion novelwriter/gui/outline.py
Original file line number Diff line number Diff line change
Expand Up @@ -1020,7 +1020,7 @@ def showItem(self, tHandle: str, sTitle: str) -> None:
"""
pIndex = SHARED.project.index
nwItem = SHARED.project.tree[tHandle]
novIdx = pIndex.getItemHeader(tHandle, sTitle)
novIdx = pIndex.getItemHeading(tHandle, sTitle)
novRefs = pIndex.getReferences(tHandle, sTitle)
if nwItem and novIdx:
self.titleLabel.setText("<b>%s</b>" % self.tr(self.LVL_MAP.get(novIdx.level, "H1")))
Expand Down
Loading
Loading