Save more meta data to the top of files
This commit is contained in:
+31
-3
@@ -30,8 +30,10 @@ import nw
|
||||
|
||||
from os import path, mkdir, rename, unlink
|
||||
|
||||
from nw.core.item import NWItem
|
||||
from nw.constants import nwAlert
|
||||
from nw.common import isHandle
|
||||
from nw.constants import nwItemLayout, nwItemClass
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -139,8 +141,18 @@ class NWDoc():
|
||||
docPath = path.join(self.theProject.projContent, docFile)
|
||||
docTemp = path.join(self.theProject.projContent, docFile+"~")
|
||||
|
||||
itemPath = self.theProject.projTree.getItemPath(self.docHandle)
|
||||
docMeta = "%%~ "+":".join(itemPath)+":"+self.theItem.itemName+"\n"
|
||||
if isinstance(self.theItem, NWItem):
|
||||
itemPath = self.theProject.projTree.getItemPath(self.docHandle)
|
||||
docMeta = (
|
||||
"%%~ {handlepath:s}:{itemclass:s}:{itemlayout:s}:{itemname:s}\n"
|
||||
).format(
|
||||
handlepath = ":".join(itemPath),
|
||||
itemclass = self.theItem.itemClass.name,
|
||||
itemlayout = self.theItem.itemLayout.name,
|
||||
itemname = self.theItem.itemName,
|
||||
)
|
||||
else:
|
||||
docMeta = ""
|
||||
|
||||
try:
|
||||
with open(docTemp, mode="w", encoding="utf8") as outFile:
|
||||
@@ -213,6 +225,22 @@ class NWDoc():
|
||||
else:
|
||||
break
|
||||
|
||||
return theMeta, thePath
|
||||
theClass = nwItemClass.NO_CLASS
|
||||
theLayout = nwItemLayout.NO_LAYOUT
|
||||
theData = theMeta.split(":")
|
||||
|
||||
if (n := len(theData)) > 1:
|
||||
if theData[0] in nwItemClass.__members__:
|
||||
theClass = nwItemClass[theData[0]]
|
||||
if n > 2:
|
||||
if theData[1] in nwItemLayout.__members__:
|
||||
theLayout = nwItemLayout[theData[1]]
|
||||
theName = theData[2]
|
||||
else:
|
||||
theName = theData[1]
|
||||
else:
|
||||
theName = theData[0]
|
||||
|
||||
return theName, thePath, theClass, theLayout
|
||||
|
||||
# END Class NWDoc
|
||||
|
||||
+3
-3
@@ -1075,7 +1075,7 @@ class NWProject():
|
||||
# Look for meta data
|
||||
oName = ""
|
||||
if aDoc.openDocument(oHandle, showStatus=False, isOrphan=True):
|
||||
oName, oPath = aDoc.getMeta()
|
||||
oName, oPath, oClass, oLayout = aDoc.getMeta()
|
||||
|
||||
if oName == "":
|
||||
nOrph += 1
|
||||
@@ -1084,8 +1084,8 @@ class NWProject():
|
||||
orphItem = NWItem(self)
|
||||
orphItem.setName(oName)
|
||||
orphItem.setType(nwItemType.FILE)
|
||||
orphItem.setClass(nwItemClass.NO_CLASS)
|
||||
orphItem.setLayout(nwItemLayout.NO_LAYOUT)
|
||||
orphItem.setClass(oClass)
|
||||
orphItem.setLayout(oLayout)
|
||||
self.projTree.append(oHandle, None, orphItem)
|
||||
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user