Some changes to item classes, and added a sample context menu to the tree view
This commit is contained in:
+3
-2
@@ -26,7 +26,8 @@ class nwItemClass(Enum):
|
||||
NONE = 0
|
||||
NOVEL = 1
|
||||
CHAPTER = 2
|
||||
CHARACTER = 3
|
||||
WORLD = 4
|
||||
SCENE = 3
|
||||
CHARACTER = 4
|
||||
WORLD = 5
|
||||
|
||||
# END Enum nwItemClass
|
||||
|
||||
+36
-9
@@ -16,7 +16,7 @@ import nw
|
||||
from os import path
|
||||
from PyQt5.QtGui import QIcon
|
||||
from PyQt5.QtCore import Qt, QSize
|
||||
from PyQt5.QtWidgets import QTreeWidget, QTreeWidgetItem, QTreeWidgetItemIterator, QAbstractItemView
|
||||
from PyQt5.QtWidgets import QTreeWidget, QTreeWidgetItem, QTreeWidgetItemIterator, QAbstractItemView, QMenu, QAction
|
||||
|
||||
from nw.enum import nwItemType, nwItemClass
|
||||
|
||||
@@ -42,6 +42,10 @@ class GuiDocTree(QTreeWidget):
|
||||
if not self.debugGUI:
|
||||
self.hideColumn(3)
|
||||
|
||||
# Context Menu
|
||||
self.setContextMenuPolicy(Qt.CustomContextMenu)
|
||||
self.customContextMenuRequested.connect(self._openContextMenu)
|
||||
|
||||
# Allow Move by Drag & Drop
|
||||
self.setDragEnabled(True)
|
||||
self.setDragDropMode(QAbstractItemView.InternalMove)
|
||||
@@ -102,6 +106,37 @@ class GuiDocTree(QTreeWidget):
|
||||
self.theProject.setTreeOrder(theList)
|
||||
return True
|
||||
|
||||
def getColumnSizes(self):
|
||||
retVals = [
|
||||
self.columnWidth(0),
|
||||
self.columnWidth(1),
|
||||
self.columnWidth(2),
|
||||
]
|
||||
return retVals
|
||||
|
||||
##
|
||||
# Context Menu
|
||||
##
|
||||
|
||||
def _openContextMenu(self, thePos):
|
||||
|
||||
sIDs = self.selectedIndexes()
|
||||
print(sIDs)
|
||||
|
||||
ctxMenu = QMenu(self)
|
||||
|
||||
menuNewObject = QAction(QIcon.fromTheme("folder-new"), "New Object", ctxMenu)
|
||||
# menuNewObject.triggered.connect(self.newProject)
|
||||
ctxMenu.addAction(menuNewObject)
|
||||
|
||||
ctxMenu.exec_(self.viewport().mapToGlobal(thePos))
|
||||
|
||||
return
|
||||
|
||||
##
|
||||
# Internal Functions
|
||||
##
|
||||
|
||||
def _scanChildren(self, theList, theItem, theIndex):
|
||||
tHandle = theItem.text(3)
|
||||
nwItem = self.theProject.projTree[tHandle]
|
||||
@@ -155,12 +190,4 @@ class GuiDocTree(QTreeWidget):
|
||||
return selItem[0].text(3)
|
||||
return None
|
||||
|
||||
def getColumnSizes(self):
|
||||
retVals = [
|
||||
self.columnWidth(0),
|
||||
self.columnWidth(1),
|
||||
self.columnWidth(2),
|
||||
]
|
||||
return retVals
|
||||
|
||||
# END Class GuiDocTree
|
||||
|
||||
+9
-10
@@ -40,12 +40,13 @@ class NWDoc():
|
||||
with open(docPath,mode="r") as inFile:
|
||||
return inFile.read()
|
||||
else:
|
||||
logger.debug("Document does not exist.")
|
||||
logger.debug("The requested document does not exist.")
|
||||
return ""
|
||||
return None
|
||||
|
||||
def saveDocument(self, docHtml):
|
||||
if self.docHandle is None: return False
|
||||
if self.docHandle is None:
|
||||
return False
|
||||
docDir, docFile = self._assemblePath(self.FILE_MN)
|
||||
logger.debug("Saving document %s" % path.join(docDir,docFile))
|
||||
dataDir = path.join(self.theProject.projPath, docDir)
|
||||
@@ -55,17 +56,15 @@ class NWDoc():
|
||||
logger.debug("Created folder %s" % dataDir)
|
||||
with open(docPath,mode="w") as outFile:
|
||||
outFile.write(docHtml)
|
||||
# docData = html.fromstring(docHtml)
|
||||
# outFile.write(html.tostring(
|
||||
# docData,
|
||||
# pretty_print = True,
|
||||
# encoding = "utf-8",
|
||||
# method = "html",
|
||||
# ))
|
||||
return True
|
||||
|
||||
##
|
||||
# Internal Functions
|
||||
##
|
||||
|
||||
def _assemblePath(self, docExt):
|
||||
if self.docHandle is None: return None
|
||||
if self.docHandle is None:
|
||||
return None
|
||||
docDir = "data_"+self.docHandle[0]
|
||||
docFile = self.docHandle[1:13]+"_"+docExt
|
||||
return docDir, docFile
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<?xml version='1.0' encoding='utf-8'?>
|
||||
<novelWriterXML appVersion="0.0.1" fileVersion="1.0" timeStamp="2018-11-02 23:17:55">
|
||||
<novelWriterXML appVersion="0.0.1" fileVersion="1.0" timeStamp="2019-04-13 21:07:45">
|
||||
<project>
|
||||
<name>Sample Project</name>
|
||||
<title>Sample Project</title>
|
||||
@@ -22,13 +22,13 @@
|
||||
<item handle="96b68994dfa3d" order="0" parent="e7ded148d6e4a">
|
||||
<name>New Scene</name>
|
||||
<type>FILE</type>
|
||||
<class>NONE</class>
|
||||
<class>SCENE</class>
|
||||
<expanded>False</expanded>
|
||||
</item>
|
||||
<item handle="636b6aa9b697b" order="1" parent="e7ded148d6e4a">
|
||||
<name>New File</name>
|
||||
<type>FILE</type>
|
||||
<class>NONE</class>
|
||||
<class>SCENE</class>
|
||||
<expanded>False</expanded>
|
||||
</item>
|
||||
<item handle="f6622b4617424" order="1" parent="None">
|
||||
|
||||
Reference in New Issue
Block a user