Clean up old heading format usage
This commit is contained in:
@@ -208,7 +208,7 @@ class nwLabels:
|
||||
# END Class nwLabels
|
||||
|
||||
|
||||
class nwHeadingFormats:
|
||||
class nwHeadFmt:
|
||||
|
||||
TITLE = "{Title}"
|
||||
CH_NUM = "{Chapter}"
|
||||
@@ -218,7 +218,9 @@ class nwHeadingFormats:
|
||||
SC_NUM = "{Scene}"
|
||||
SC_ABS = "{Scene:Abs}"
|
||||
|
||||
# END Class nwHeadingFormats
|
||||
ALL = [TITLE, CH_NUM, CH_WORD, CH_ROMU, CH_ROML, SC_NUM, SC_ABS]
|
||||
|
||||
# END Class nwHeadFmt
|
||||
|
||||
|
||||
class nwQuotes:
|
||||
|
||||
@@ -36,7 +36,7 @@ from pathlib import Path
|
||||
from PyQt5.QtCore import QT_TRANSLATE_NOOP
|
||||
|
||||
from novelwriter.common import checkUuid, isHandle, jsonEncode
|
||||
from novelwriter.constants import nwConst, nwFiles, nwHeadingFormats
|
||||
from novelwriter.constants import nwConst, nwFiles, nwHeadFmt
|
||||
from novelwriter.core.item import NWItem
|
||||
from novelwriter.core.project import NWProject
|
||||
from novelwriter.error import logException
|
||||
@@ -52,9 +52,9 @@ SETTINGS_TEMPLATE = {
|
||||
"filter.includeNovel": (bool, True),
|
||||
"filter.includeNotes": (bool, False),
|
||||
"filter.includeInactive": (bool, False),
|
||||
"headings.fmtTitle": (str, nwHeadingFormats.TITLE),
|
||||
"headings.fmtChapter": (str, nwHeadingFormats.TITLE),
|
||||
"headings.fmtUnnumbered": (str, nwHeadingFormats.TITLE),
|
||||
"headings.fmtTitle": (str, nwHeadFmt.TITLE),
|
||||
"headings.fmtChapter": (str, nwHeadFmt.TITLE),
|
||||
"headings.fmtUnnumbered": (str, nwHeadFmt.TITLE),
|
||||
"headings.fmtScene": (str, "* * *"),
|
||||
"headings.fmtSection": (str, ""),
|
||||
"headings.hideScene": (bool, False),
|
||||
|
||||
@@ -35,7 +35,7 @@ from PyQt5.QtCore import QCoreApplication, QRegularExpression
|
||||
|
||||
from novelwriter.enum import nwItemLayout, nwItemType
|
||||
from novelwriter.common import numberToRoman, checkInt
|
||||
from novelwriter.constants import nwConst, nwHeadingFormats, nwRegEx, nwUnicode
|
||||
from novelwriter.constants import nwConst, nwHeadFmt, nwRegEx, nwUnicode
|
||||
from novelwriter.core.project import NWProject
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
@@ -126,11 +126,11 @@ class Tokenizer(ABC):
|
||||
self._marginMeta = (0.000, 0.584)
|
||||
|
||||
# Title Formats
|
||||
self._fmtTitle = "%title%" # Formatting for titles
|
||||
self._fmtChapter = "%title%" # Formatting for numbered chapters
|
||||
self._fmtUnNum = "%title%" # Formatting for unnumbered chapters
|
||||
self._fmtScene = "%title%" # Formatting for scenes
|
||||
self._fmtSection = "%title%" # Formatting for sections
|
||||
self._fmtTitle = nwHeadFmt.TITLE # Formatting for titles
|
||||
self._fmtChapter = nwHeadFmt.TITLE # Formatting for numbered chapters
|
||||
self._fmtUnNum = nwHeadFmt.TITLE # Formatting for unnumbered chapters
|
||||
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
|
||||
@@ -751,19 +751,19 @@ class HeadingFormatter:
|
||||
def apply(self, hFormat: str, text: str):
|
||||
"""Apply formatting to a specific heading.
|
||||
"""
|
||||
hFormat = hFormat.replace(nwHeadingFormats.TITLE, text)
|
||||
hFormat = hFormat.replace(nwHeadingFormats.CH_NUM, str(self._chCount))
|
||||
hFormat = hFormat.replace(nwHeadingFormats.SC_NUM, str(self._scChCount))
|
||||
hFormat = hFormat.replace(nwHeadingFormats.SC_ABS, str(self._scAbsCount))
|
||||
if nwHeadingFormats.CH_WORD in hFormat:
|
||||
hFormat = hFormat.replace(nwHeadFmt.TITLE, text)
|
||||
hFormat = hFormat.replace(nwHeadFmt.CH_NUM, str(self._chCount))
|
||||
hFormat = hFormat.replace(nwHeadFmt.SC_NUM, str(self._scChCount))
|
||||
hFormat = hFormat.replace(nwHeadFmt.SC_ABS, str(self._scAbsCount))
|
||||
if nwHeadFmt.CH_WORD in hFormat:
|
||||
chWord = self._project.localLookup(self._chCount)
|
||||
hFormat = hFormat.replace(nwHeadingFormats.CH_WORD, chWord)
|
||||
if nwHeadingFormats.CH_ROML in hFormat:
|
||||
hFormat = hFormat.replace(nwHeadFmt.CH_WORD, chWord)
|
||||
if nwHeadFmt.CH_ROML in hFormat:
|
||||
chRom = numberToRoman(self._chCount, True)
|
||||
hFormat = hFormat.replace(nwHeadingFormats.CH_ROML, chRom)
|
||||
if nwHeadingFormats.CH_ROMU in hFormat:
|
||||
hFormat = hFormat.replace(nwHeadFmt.CH_ROML, chRom)
|
||||
if nwHeadFmt.CH_ROMU in hFormat:
|
||||
chRom = numberToRoman(self._chCount, False)
|
||||
hFormat = hFormat.replace(nwHeadingFormats.CH_ROMU, chRom)
|
||||
hFormat = hFormat.replace(nwHeadFmt.CH_ROMU, chRom)
|
||||
|
||||
return hFormat
|
||||
|
||||
|
||||
@@ -41,7 +41,7 @@ from PyQt5.QtWidgets import (
|
||||
)
|
||||
|
||||
from novelwriter import CONFIG
|
||||
from novelwriter.constants import nwConst, nwHeadingFormats
|
||||
from novelwriter.constants import nwConst, nwHeadFmt
|
||||
from novelwriter.core.buildsettings import BuildSettings, FilterMode
|
||||
from novelwriter.extensions.switch import NSwitch
|
||||
from novelwriter.extensions.switchbox import NSwitchBox
|
||||
@@ -706,13 +706,13 @@ class GuiBuildHeadingsTab(QWidget):
|
||||
self.aInsScNum = self.menuInsert.addAction(self.tr("Scene Number (In Chapter)"))
|
||||
self.aInsScAbs = self.menuInsert.addAction(self.tr("Scene Number (Absolute)"))
|
||||
|
||||
self.aInsTitle.triggered.connect(lambda: self._insertIntoForm(nwHeadingFormats.TITLE))
|
||||
self.aInsChNum.triggered.connect(lambda: self._insertIntoForm(nwHeadingFormats.CH_NUM))
|
||||
self.aInsChWord.triggered.connect(lambda: self._insertIntoForm(nwHeadingFormats.CH_WORD))
|
||||
self.aInsChRomU.triggered.connect(lambda: self._insertIntoForm(nwHeadingFormats.CH_ROMU))
|
||||
self.aInsChRomL.triggered.connect(lambda: self._insertIntoForm(nwHeadingFormats.CH_ROML))
|
||||
self.aInsScNum.triggered.connect(lambda: self._insertIntoForm(nwHeadingFormats.SC_NUM))
|
||||
self.aInsScAbs.triggered.connect(lambda: self._insertIntoForm(nwHeadingFormats.SC_ABS))
|
||||
self.aInsTitle.triggered.connect(lambda: self._insertIntoForm(nwHeadFmt.TITLE))
|
||||
self.aInsChNum.triggered.connect(lambda: self._insertIntoForm(nwHeadFmt.CH_NUM))
|
||||
self.aInsChWord.triggered.connect(lambda: self._insertIntoForm(nwHeadFmt.CH_WORD))
|
||||
self.aInsChRomU.triggered.connect(lambda: self._insertIntoForm(nwHeadFmt.CH_ROMU))
|
||||
self.aInsChRomL.triggered.connect(lambda: self._insertIntoForm(nwHeadFmt.CH_ROML))
|
||||
self.aInsScNum.triggered.connect(lambda: self._insertIntoForm(nwHeadFmt.SC_NUM))
|
||||
self.aInsScAbs.triggered.connect(lambda: self._insertIntoForm(nwHeadFmt.SC_ABS))
|
||||
|
||||
self.btnInsert = QPushButton(self.tr("Insert"))
|
||||
self.btnInsert.setMenu(self.menuInsert)
|
||||
@@ -845,31 +845,17 @@ class GuiHeadingSyntax(QSyntaxHighlighter):
|
||||
|
||||
def __init__(self, document: QTextDocument, mainTheme: GuiTheme):
|
||||
super().__init__(document)
|
||||
|
||||
self._valid = [
|
||||
nwHeadingFormats.TITLE.lower(),
|
||||
nwHeadingFormats.CH_NUM.lower(),
|
||||
nwHeadingFormats.CH_WORD.lower(),
|
||||
nwHeadingFormats.CH_ROMU.lower(),
|
||||
nwHeadingFormats.CH_ROML.lower(),
|
||||
nwHeadingFormats.SC_NUM.lower(),
|
||||
nwHeadingFormats.SC_ABS.lower(),
|
||||
]
|
||||
|
||||
self._fmtSymbol = QTextCharFormat()
|
||||
self._fmtSymbol.setForeground(QColor(*mainTheme.colHead))
|
||||
|
||||
self._fmtFormat = QTextCharFormat()
|
||||
self._fmtFormat.setForeground(QColor(*mainTheme.colEmph))
|
||||
|
||||
return
|
||||
|
||||
def highlightBlock(self, text: str):
|
||||
"""Add syntax highlighting to the text block.
|
||||
"""
|
||||
check = text.lower()
|
||||
for heading in self._valid:
|
||||
pos = check.find(heading)
|
||||
for heading in nwHeadFmt.ALL:
|
||||
pos = text.find(heading)
|
||||
if pos >= 0:
|
||||
chars = len(heading)
|
||||
self.setFormat(pos, chars, self._fmtSymbol)
|
||||
|
||||
Reference in New Issue
Block a user