Skip to content
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

Re-implement the status and importance flags #1034

Merged
merged 10 commits into from
Apr 16, 2022
13 changes: 13 additions & 0 deletions novelwriter/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,12 @@ def checkIntRange(value, first, last, default):
return default


def minmax(value, minVal, maxVal):
"""Make sure an integer is between min and max value (inclusive).
"""
return min(maxVal, max(minVal, value))


def checkIntTuple(value, valid, default):
"""Check that an int is an element of a tuple. If it isn't, return
the default value.
Expand Down Expand Up @@ -245,6 +251,13 @@ def formatTime(tS):
# String Functions
# =============================================================================================== #

def simplified(string):
"""Take a string an strip leading and trailing whitespaces, and
replace all occurences of (multiple) whitespaces with a 0x20 space.
"""
return " ".join(str(string).strip().split())


def splitVersionNumber(value):
"""Split a version string on the form aa.bb.cc into major, minor
and patch, and computes an integer value aabbcc.
Expand Down
12 changes: 6 additions & 6 deletions novelwriter/core/item.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,11 +280,11 @@ def getImportStatus(self):
the current item based on its class.
"""
if self._class in nwLists.CLS_NOVEL:
stName = self.theProject.statusItems.checkEntry(self._status)
stIcon = self.theProject.statusItems.getIcon(stName)
stName = self.theProject.statusItems.name(self._status)
stIcon = self.theProject.statusItems.icon(self._status)
else:
stName = self.theProject.importItems.checkEntry(self._import)
stIcon = self.theProject.importItems.getIcon(stName)
stName = self.theProject.importItems.name(self._import)
stIcon = self.theProject.importItems.icon(self._import)
return stName, stIcon

def setImportStatus(self, theLabel):
Expand Down Expand Up @@ -383,14 +383,14 @@ def setStatus(self, theStatus):
"""Set the item status by looking it up in the valid status
items of the current project.
"""
self._status = self.theProject.statusItems.checkEntry(theStatus)
self._status = self.theProject.statusItems.check(theStatus)
return

def setImport(self, theImport):
"""Set the item importance by looking it up in the valid import
items of the current project.
"""
self._import = self.theProject.importItems.checkEntry(theImport)
self._import = self.theProject.importItems.check(theImport)
return

def setExpanded(self, expState):
Expand Down
72 changes: 47 additions & 25 deletions novelwriter/core/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,16 +218,16 @@ def clearProject(self):
}
self.spellCheck = False
self.autoOutline = True
self.statusItems = NWStatus()
self.statusItems.addEntry(self.tr("New"), (100, 100, 100))
self.statusItems.addEntry(self.tr("Note"), (200, 50, 0))
self.statusItems.addEntry(self.tr("Draft"), (200, 150, 0))
self.statusItems.addEntry(self.tr("Finished"), (50, 200, 0))
self.importItems = NWStatus()
self.importItems.addEntry(self.tr("New"), (100, 100, 100))
self.importItems.addEntry(self.tr("Minor"), (200, 50, 0))
self.importItems.addEntry(self.tr("Major"), (200, 150, 0))
self.importItems.addEntry(self.tr("Main"), (50, 200, 0))
self.statusItems = NWStatus(NWStatus.STATUS)
self.statusItems.write(None, self.tr("New"), (100, 100, 100))
self.statusItems.write(None, self.tr("Note"), (200, 50, 0))
self.statusItems.write(None, self.tr("Draft"), (200, 150, 0))
self.statusItems.write(None, self.tr("Finished"), (50, 200, 0))
self.importItems = NWStatus(NWStatus.IMPORT)
self.importItems.write(None, self.tr("New"), (100, 100, 100))
self.importItems.write(None, self.tr("Minor"), (200, 50, 0))
self.importItems.write(None, self.tr("Major"), (200, 150, 0))
self.importItems.write(None, self.tr("Main"), (50, 200, 0))
self.lastEdited = None
self.lastViewed = None
self.lastWCount = 0
Expand Down Expand Up @@ -267,6 +267,7 @@ def newProject(self, projData):
logger.error("No project path set for the new project")
return False

self.clearProject()
if not self.setProjectPath(projPath, newProject=True):
return False

Expand Down Expand Up @@ -687,6 +688,8 @@ def saveProject(self, autoSave=False):
if len(aKey) > 0:
self._packProjectValue(xTitleFmt, aKey, aValue)

# Save Status/Importance
self.countStatus()
xStatus = etree.SubElement(xSettings, "status")
self.statusItems.packXML(xStatus)
xStatus = etree.SubElement(xSettings, "importance")
Expand Down Expand Up @@ -1018,7 +1021,8 @@ def setSpellLang(self, theLang):
if self.projSpell != theLang:
self.projSpell = theLang
self.setProjectChanged(True)
return True
return True
return False

def setProjectLang(self, theLang):
"""Set the project-specific language.
Expand Down Expand Up @@ -1065,28 +1069,46 @@ def setLastViewed(self, tHandle):
self.setProjectChanged(True)
return True

def setStatusColours(self, newCols):
def setStatusColours(self, newCols, delCols):
"""Update the list of novel file status flags. Also iterate
through the project and replace keys that have been renamed.
"""
replaceMap = self.statusItems.setNewEntries(newCols)
for nwItem in self.projTree:
if nwItem.itemClass in nwLists.CLS_NOVEL:
if nwItem.itemStatus in replaceMap:
nwItem.setStatus(replaceMap[nwItem.itemStatus])
if not (newCols or delCols):
return False

for entry in newCols:
key = entry.get("key", None)
name = entry.get("name", "")
cols = entry.get("cols", (100, 100, 100))
if name:
self.statusItems.write(key, name, cols)

for key in delCols:
self.statusItems.remove(key)

self.setProjectChanged(True)

return True

def setImportColours(self, newCols):
def setImportColours(self, newCols, delCols):
"""Update the list of note file importance flags. Also iterate
through the project and replace keys that have been renamed.
"""
replaceMap = self.importItems.setNewEntries(newCols)
for nwItem in self.projTree:
if nwItem.itemClass not in nwLists.CLS_NOVEL:
if nwItem.itemImport in replaceMap:
nwItem.setImport(replaceMap[nwItem.itemImport])
if not (newCols or delCols):
return False

for entry in newCols:
key = entry.get("key", None)
name = entry.get("name", "")
cols = entry.get("cols", (100, 100, 100))
if name:
self.importItems.write(key, name, cols)

for key in delCols:
self.importItems.remove(key)

self.setProjectChanged(True)

return True

def setAutoReplace(self, autoReplace):
Expand Down Expand Up @@ -1207,9 +1229,9 @@ def countStatus(self):
self.importItems.resetCounts()
for nwItem in self.projTree:
if nwItem.itemClass in nwLists.CLS_NOVEL:
self.statusItems.countEntry(nwItem.itemStatus)
self.statusItems.increment(nwItem.itemStatus)
else:
self.importItems.countEntry(nwItem.itemImport)
self.importItems.increment(nwItem.itemImport)
return

def localLookup(self, theWord):
Expand Down
Loading