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
|
||||
|
||||
@@ -1 +1,3 @@
|
||||
# Very Deep File
|
||||
# Very Deep File
|
||||
|
||||
This file is still editable.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<?xml version='1.0' encoding='utf-8'?>
|
||||
<novelWriterXML appVersion="0.3.2" fileVersion="1.0" timeStamp="2019-10-31 11:33:41">
|
||||
<novelWriterXML appVersion="0.3.2" fileVersion="1.0" timeStamp="2019-10-31 13:36:33">
|
||||
<project>
|
||||
<name>Sample Project</name>
|
||||
<title>Sample Project</title>
|
||||
@@ -11,7 +11,7 @@
|
||||
<spellCheck>True</spellCheck>
|
||||
<lastEdited>b8136a5a774a0</lastEdited>
|
||||
<lastViewed>ba8a28a246524</lastViewed>
|
||||
<lastWordCount>879</lastWordCount>
|
||||
<lastWordCount>884</lastWordCount>
|
||||
<autoReplace>
|
||||
<A>B</A>
|
||||
<B>E</B>
|
||||
@@ -142,7 +142,7 @@
|
||||
<charCount>567</charCount>
|
||||
<wordCount>112</wordCount>
|
||||
<paraCount>6</paraCount>
|
||||
<cursorPos>634</cursorPos>
|
||||
<cursorPos>326</cursorPos>
|
||||
</item>
|
||||
<item handle="f6622b4617424" order="1" parent="None">
|
||||
<name>Characters</name>
|
||||
@@ -220,19 +220,7 @@
|
||||
<status>None</status>
|
||||
<expanded>True</expanded>
|
||||
</item>
|
||||
<item handle="4cd0bd12b087d" order="0" parent="98acd8c76c93a">
|
||||
<name>Orphaned File 2</name>
|
||||
<type>FILE</type>
|
||||
<class>NO_CLASS</class>
|
||||
<status>None</status>
|
||||
<expanded>False</expanded>
|
||||
<layout>NO_LAYOUT</layout>
|
||||
<charCount>14</charCount>
|
||||
<wordCount>3</wordCount>
|
||||
<paraCount>0</paraCount>
|
||||
<cursorPos>1</cursorPos>
|
||||
</item>
|
||||
<item handle="b8136a5a774a0" order="1" parent="98acd8c76c93a">
|
||||
<item handle="b8136a5a774a0" order="0" parent="98acd8c76c93a">
|
||||
<name>Delete Me!</name>
|
||||
<type>FILE</type>
|
||||
<class>NOVEL</class>
|
||||
@@ -244,5 +232,17 @@
|
||||
<paraCount>1</paraCount>
|
||||
<cursorPos>36</cursorPos>
|
||||
</item>
|
||||
<item handle="4cd0bd12b087d" order="1" parent="98acd8c76c93a">
|
||||
<name>Orphaned File 1</name>
|
||||
<type>FILE</type>
|
||||
<class>NO_CLASS</class>
|
||||
<status>None</status>
|
||||
<expanded>False</expanded>
|
||||
<layout>NO_LAYOUT</layout>
|
||||
<charCount>42</charCount>
|
||||
<wordCount>8</wordCount>
|
||||
<paraCount>1</paraCount>
|
||||
<cursorPos>47</cursorPos>
|
||||
</item>
|
||||
</content>
|
||||
</novelWriterXML>
|
||||
|
||||
Reference in New Issue
Block a user