The editable flag for files is now respected by the editor, and trash files are not editable

This commit is contained in:
Veronica K. B. Olsen
2019-10-31 13:37:27 +01:00
parent 7969c58351
commit 9fea45b7df
6 changed files with 67 additions and 34 deletions
+18 -7
View File
@@ -25,11 +25,12 @@ class NWDoc():
def __init__(self, theProject, theParent):
self.mainConf = nw.CONFIG
self.theProject = theProject
self.theParent = theParent
self.theItem = None
self.docHandle = None
self.mainConf = nw.CONFIG
self.theProject = theProject
self.theParent = theParent
self.theItem = None
self.docHandle = None
self.docEditable = False
# Internal Mapping
self.makeAlert = self.theParent.makeAlert
@@ -37,8 +38,9 @@ class NWDoc():
return
def clearDocument(self):
self.theItem = None
self.docHandle = None
self.theItem = None
self.docHandle = None
self.docEditable = False
return
def openDocument(self, tHandle, showStatus=True):
@@ -46,6 +48,15 @@ class NWDoc():
self.docHandle = tHandle
self.theItem = self.theProject.getItem(tHandle)
if self.theItem is None:
self.clearDocument()
return None
# By default, the document is editable. Except for files in the trash folder.
self.docEditable = True
if self.theItem.parHandle == self.theProject.trashRoot:
self.docEditable = False
docDir, docFile = self._assemblePath(self.FILE_MN)
logger.debug("Opening document %s" % path.join(docDir,docFile))
dataDir = path.join(self.theProject.projPath, docDir)
+13
View File
@@ -478,6 +478,19 @@ class NWProject():
logger.error("No tree item with handle %s" % str(tHandle))
return None
def getRootItem(self, tHandle):
"""Iterate upwards in the tree until we find the item with parent None, the root item.
We do this with a for loop with a maximum depth of 200 to make infinite loops impossible.
"""
tItem = self.getItem(tHandle)
if tItem is not None:
for i in range(200):
tHandle = tItem.parHandle
tItem = self.getItem(tHandle)
if tItem is None:
return tHandle
return None
def getProjectItems(self):
"""This function is called from the tree view when building the tree. Each item in the
project is returned in the order saved in the project file, but first it checks that it has