The editable flag for files is now respected by the editor, and trash files are not editable
This commit is contained in:
+4
-1
@@ -164,6 +164,7 @@ class GuiDocEditor(QTextEdit):
|
||||
# If we have a document open, we should reload it in case the font changed, otherwise
|
||||
# we just clear the editor entirely, which makes it read only.
|
||||
if self.theHandle is not None:
|
||||
# We must save the current handle as clearEditor() sets it to None
|
||||
tHandle = self.theHandle
|
||||
self.clearEditor()
|
||||
self.loadText(tHandle)
|
||||
@@ -194,9 +195,11 @@ class GuiDocEditor(QTextEdit):
|
||||
self._runCounter()
|
||||
self.wcTimer.start()
|
||||
self.setDocumentChanged(False)
|
||||
self.setReadOnly(False)
|
||||
self.theHandle = tHandle
|
||||
|
||||
if self.nwDocument.docEditable:
|
||||
self.setReadOnly(False)
|
||||
|
||||
return True
|
||||
|
||||
def saveText(self):
|
||||
|
||||
+13
-9
@@ -41,8 +41,8 @@ class GuiDocTree(QTreeWidget):
|
||||
self.theProject = theProject
|
||||
|
||||
# Tree Settings
|
||||
self.theMap = None
|
||||
self.orphRoot = None
|
||||
self.theMap = None
|
||||
self.orphRoot = None
|
||||
|
||||
self.clearTree()
|
||||
|
||||
@@ -97,15 +97,23 @@ class GuiDocTree(QTreeWidget):
|
||||
return False
|
||||
|
||||
if itemClass is None and pHandle is not None:
|
||||
itemClass = self.theProject.getItem(pHandle).itemClass
|
||||
pItem = self.theProject.getItem(pHandle)
|
||||
if pItem is not None:
|
||||
itemClass = pItem.itemClass
|
||||
|
||||
if itemClass is None:
|
||||
if itemType is not None:
|
||||
if itemType == nwItemType.FILE:
|
||||
self.makeAlert("Please select a location in the tree to add a document.", nwAlert.ERROR)
|
||||
self.makeAlert(
|
||||
"Please select a valid location in the tree to add a document.",
|
||||
nwAlert.ERROR
|
||||
)
|
||||
return False
|
||||
elif itemType == nwItemType.FOLDER:
|
||||
self.makeAlert("Please select a location in the tree to add a folder.", nwAlert.ERROR)
|
||||
self.makeAlert(
|
||||
"Please select a valid location in the tree to add a folder.",
|
||||
nwAlert.ERROR
|
||||
)
|
||||
return False
|
||||
self.makeAlert("Failed to add new item.", nwAlert.BUG)
|
||||
return False
|
||||
@@ -141,10 +149,6 @@ class GuiDocTree(QTreeWidget):
|
||||
self.makeAlert("Cannot add new files or folders to the trash folder.", nwAlert.ERROR)
|
||||
return False
|
||||
|
||||
if pHandle == self.orphRoot:
|
||||
self.makeAlert("Cannot add new files or folders to the orphaned folder.", nwAlert.ERROR)
|
||||
return False
|
||||
|
||||
# If we're still here, add the file or folder
|
||||
if itemType == nwItemType.FILE:
|
||||
tHandle = self.theProject.newFile("New File", itemClass, pHandle)
|
||||
|
||||
+18
-7
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user