Merge 2.6.1 release into main

This commit is contained in:
Veronica Berglyd Olsen
2025-02-02 18:54:08 +01:00
34 changed files with 3462 additions and 3069 deletions
+28 -13
View File
@@ -34,7 +34,7 @@ from __future__ import annotations
import bisect
import logging
from enum import Enum
from enum import Enum, IntFlag
from time import time
from PyQt6.QtCore import (
@@ -59,7 +59,7 @@ from novelwriter.constants import nwConst, nwKeyWords, nwShortcode, nwUnicode
from novelwriter.core.document import NWDocument
from novelwriter.enum import (
nwChange, nwComment, nwDocAction, nwDocInsert, nwDocMode, nwItemClass,
nwItemType, nwTrinary
nwItemType
)
from novelwriter.extensions.configlayout import NColorLabel
from novelwriter.extensions.eventfilters import WheelEventFilter
@@ -86,6 +86,13 @@ class _SelectAction(Enum):
MOVE_AFTER = 3
class _TagAction(IntFlag):
NONE = 0b00
FOLLOW = 0b01
CREATE = 0b10
class GuiDocEditor(QPlainTextEdit):
"""Gui Widget: Main Document Editor"""
@@ -1146,11 +1153,11 @@ class GuiDocEditor(QPlainTextEdit):
# Follow
status = self._processTag(cursor=pCursor, follow=False)
if status == nwTrinary.POSITIVE:
if status & _TagAction.FOLLOW:
action = qtAddAction(ctxMenu, self.tr("Follow Tag"))
action.triggered.connect(qtLambda(self._processTag, cursor=pCursor, follow=True))
ctxMenu.addSeparator()
elif status == nwTrinary.NEGATIVE:
elif status & _TagAction.CREATE:
action = qtAddAction(ctxMenu, self.tr("Create Note for Tag"))
action.triggered.connect(qtLambda(self._processTag, cursor=pCursor, create=True))
ctxMenu.addSeparator()
@@ -1916,7 +1923,7 @@ class GuiDocEditor(QPlainTextEdit):
def _processTag(
self, cursor: QTextCursor | None = None, follow: bool = True, create: bool = False
) -> nwTrinary:
) -> _TagAction:
"""Activated by Ctrl+Enter. Checks that we're in a block
starting with '@'. We then find the tag under the cursor and
check that it is not the tag itself. If all this is fine, we
@@ -1926,19 +1933,22 @@ class GuiDocEditor(QPlainTextEdit):
if cursor is None:
cursor = self.textCursor()
status = _TagAction.NONE
block = cursor.block()
text = block.text()
if len(text) == 0:
return nwTrinary.NEUTRAL
return status
if text.startswith("@") and self._docHandle:
isGood, tBits, tPos = SHARED.project.index.scanThis(text)
if (
not isGood or not tBits or tBits[0] == nwKeyWords.TAG_KEY
or tBits[0] not in nwKeyWords.VALID_KEYS
not isGood
or not tBits
or (key := tBits[0]) == nwKeyWords.TAG_KEY
or key not in nwKeyWords.VALID_KEYS
):
return nwTrinary.NEUTRAL
return status
tag = ""
exist = False
@@ -1955,7 +1965,14 @@ class GuiDocEditor(QPlainTextEdit):
if not tag or tag.startswith("@"):
# The keyword cannot be looked up, so we ignore that
return nwTrinary.NEUTRAL
return status
if not exist and key in nwKeyWords.CAN_CREATE:
# Must only be set if we have a tag selected
status |= _TagAction.CREATE
if exist:
status |= _TagAction.FOLLOW
if follow and exist:
logger.debug("Attempting to follow tag '%s'", tag)
@@ -1967,9 +1984,7 @@ class GuiDocEditor(QPlainTextEdit):
itemClass = nwKeyWords.KEY_CLASS.get(tBits[0], nwItemClass.NO_CLASS)
self.requestNewNoteCreation.emit(tag, itemClass)
return nwTrinary.POSITIVE if exist else nwTrinary.NEGATIVE
return nwTrinary.NEUTRAL
return status
def _emitRenameItem(self, block: QTextBlock) -> None:
"""Emit a signal to request an item be renamed."""
+6 -7
View File
@@ -34,7 +34,6 @@ from PyQt6.QtWidgets import QApplication, QLabel, QStatusBar, QWidget
from novelwriter import CONFIG, SHARED
from novelwriter.common import formatTime
from novelwriter.constants import nwConst
from novelwriter.enum import nwTrinary
from novelwriter.extensions.modified import NClickableLabel
from novelwriter.extensions.statusled import StatusLED
@@ -119,8 +118,8 @@ class GuiMainStatus(QStatusBar):
self.setRefTime(-1.0)
self.setLanguage(*SHARED.spelling.describeDict())
self.setProjectStats(0, 0)
self.setProjectStatus(nwTrinary.NEUTRAL)
self.setDocumentStatus(nwTrinary.NEUTRAL)
self.setProjectStatus(None)
self.setDocumentStatus(None)
self.updateTime()
return
@@ -150,12 +149,12 @@ class GuiMainStatus(QStatusBar):
self._refTime = refTime
return
def setProjectStatus(self, state: nwTrinary) -> None:
def setProjectStatus(self, state: bool | None) -> None:
"""Set the project status colour icon."""
self.projIcon.setState(state)
return
def setDocumentStatus(self, state: nwTrinary) -> None:
def setDocumentStatus(self, state: bool | None) -> None:
"""Set the document status colour icon."""
self.docIcon.setState(state)
return
@@ -218,13 +217,13 @@ class GuiMainStatus(QStatusBar):
@pyqtSlot(bool)
def updateProjectStatus(self, status: bool) -> None:
"""Update the project status."""
self.setProjectStatus(nwTrinary.NEGATIVE if status else nwTrinary.POSITIVE)
self.setProjectStatus(not status)
return
@pyqtSlot(bool)
def updateDocumentStatus(self, status: bool) -> None:
"""Update the document status."""
self.setDocumentStatus(nwTrinary.NEGATIVE if status else nwTrinary.POSITIVE)
self.setDocumentStatus(not status)
return
##