Connect the bits for the file template feature
This commit is contained in:
+14
-15
@@ -135,6 +135,7 @@ class GuiProjectView(QWidget):
|
||||
# Signals
|
||||
self.selectedItemChanged.connect(self.projBar.treeSelectionChanged)
|
||||
self.projTree.itemRefreshed.connect(self.projBar.treeItemRefreshed)
|
||||
self.projBar.newDocumentFromTemplate.connect(self.createFileFromTemplate)
|
||||
|
||||
# Function Mappings
|
||||
self.emptyTrash = self.projTree.emptyTrash
|
||||
@@ -215,10 +216,17 @@ class GuiProjectView(QWidget):
|
||||
|
||||
@pyqtSlot(str)
|
||||
def updateItemValues(self, tHandle: str) -> None:
|
||||
"""Update tree item"""
|
||||
"""Update tree item."""
|
||||
self.projTree.setTreeItemValues(tHandle)
|
||||
return
|
||||
|
||||
@pyqtSlot(str)
|
||||
def createFileFromTemplate(self, tHandle: str) -> None:
|
||||
"""Create a new document from a template."""
|
||||
logger.debug("Template selected: '%s'", tHandle)
|
||||
self.projTree.newTreeItem(nwItemType.FILE, copyDoc=tHandle)
|
||||
return
|
||||
|
||||
@pyqtSlot(str, int, int, int)
|
||||
def updateCounts(self, tHandle: str, cCount: int, wCount: int, pCount: int) -> None:
|
||||
"""Slot for updating the word count of a specific item."""
|
||||
@@ -310,7 +318,7 @@ class GuiProjectToolBar(QWidget):
|
||||
|
||||
self.mTemplates = _UpdatableMenu(self.mAdd)
|
||||
self.mTemplates.setActionsVisible(False)
|
||||
self.mTemplates.menuItemTriggered.connect(self._templateSelected)
|
||||
self.mTemplates.menuItemTriggered.connect(lambda h: self.newDocumentFromTemplate.emit(h))
|
||||
self.mAdd.addMenu(self.mTemplates)
|
||||
|
||||
self.mAddRoot = self.mAdd.addMenu(trConst(nwLabels.ITEM_DESCRIPTION["root"]))
|
||||
@@ -443,17 +451,6 @@ class GuiProjectToolBar(QWidget):
|
||||
self.aAddScene.setVisible(allowDoc)
|
||||
return
|
||||
|
||||
##
|
||||
# Private Slots
|
||||
##
|
||||
|
||||
@pyqtSlot(str)
|
||||
def _templateSelected(self, tHandle: str) -> None:
|
||||
"""Forward the template menu signal."""
|
||||
logger.debug("Template selected: '%s'", tHandle)
|
||||
self.newDocumentFromTemplate.emit(tHandle)
|
||||
return
|
||||
|
||||
##
|
||||
# Internal Functions
|
||||
##
|
||||
@@ -622,7 +619,7 @@ class GuiProjectTree(QTreeWidget):
|
||||
return False
|
||||
|
||||
def newTreeItem(self, itemType: nwItemType, itemClass: nwItemClass | None = None,
|
||||
hLevel: int = 1, isNote: bool = False) -> bool:
|
||||
hLevel: int = 1, isNote: bool = False, copyDoc: str | None = None) -> bool:
|
||||
"""Add new item to the tree, with a given itemType (and
|
||||
itemClass if Root), and attach it to the selected handle. Also
|
||||
make sure the item is added in a place it can be added, and that
|
||||
@@ -710,7 +707,9 @@ class GuiProjectTree(QTreeWidget):
|
||||
return True
|
||||
|
||||
# Handle new file creation
|
||||
if itemType == nwItemType.FILE and hLevel > 0:
|
||||
if itemType == nwItemType.FILE and copyDoc:
|
||||
SHARED.project.copyFileContent(tHandle, copyDoc)
|
||||
elif itemType == nwItemType.FILE and hLevel > 0:
|
||||
SHARED.project.writeNewFile(tHandle, hLevel, not isNote)
|
||||
|
||||
# Add the new item to the project tree
|
||||
|
||||
@@ -1,7 +1,12 @@
|
||||
%%~name: Chapter
|
||||
%%~path: f4ed1ae756a1f/2a60782759c6f
|
||||
%%~kind: TEMPLATE/NOTE
|
||||
%%~hash: d09e26b73443ca5592973b954fb8d34b406765cc
|
||||
%%~date: 2024-02-04 12:13:08/2024-02-08 00:02:03
|
||||
%%~kind: TEMPLATE/DOCUMENT
|
||||
%%~hash: da17bc023f9fcf9d739f19ce4b49a4f95dd7acc2
|
||||
%%~date: 2024-02-04 12:13:08/2024-02-08 21:45:26
|
||||
## Chapter
|
||||
|
||||
@pov: Name
|
||||
|
||||
%Synopsis: A brief note about the chapter content.
|
||||
|
||||
Text
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?xml version='1.0' encoding='utf-8'?>
|
||||
<novelWriterXML appVersion="2.3a4" hexVersion="0x020300a4" fileVersion="1.5" fileRevision="2" timeStamp="2024-02-08 00:03:11">
|
||||
<project id="e2be99af-f9bf-4403-857a-c3d1ac25abea" saveCount="1671" autoCount="262" editTime="82534">
|
||||
<novelWriterXML appVersion="2.3a4" hexVersion="0x020300a4" fileVersion="1.5" fileRevision="2" timeStamp="2024-02-08 21:45:35">
|
||||
<project id="e2be99af-f9bf-4403-857a-c3d1ac25abea" saveCount="1680" autoCount="263" editTime="82745">
|
||||
<name>Sample Project</name>
|
||||
<author>Jane Smith</author>
|
||||
</project>
|
||||
@@ -35,7 +35,7 @@
|
||||
<entry key="i56be10" count="1" red="117" green="0" blue="175">Main</entry>
|
||||
</importance>
|
||||
</settings>
|
||||
<content items="31" novelWords="990" notesWords="416">
|
||||
<content items="31" novelWords="991" notesWords="416">
|
||||
<item handle="7031beac91f75" parent="None" root="7031beac91f75" order="0" type="ROOT" class="NOVEL">
|
||||
<meta expanded="yes" />
|
||||
<name status="sc24b8f" import="ia857f0">Novel</name>
|
||||
@@ -141,11 +141,11 @@
|
||||
<name status="sf12341" import="ia857f0">Templates</name>
|
||||
</item>
|
||||
<item handle="5aec885635c85" parent="f4ed1ae756a1f" root="f4ed1ae756a1f" order="0" type="FILE" class="TEMPLATE" layout="DOCUMENT">
|
||||
<meta expanded="no" heading="H3" charCount="9" wordCount="2" paraCount="1" cursorPos="79" />
|
||||
<meta expanded="no" heading="H3" charCount="9" wordCount="2" paraCount="1" cursorPos="78" />
|
||||
<name status="sf12341" import="ia857f0" active="yes">Scene</name>
|
||||
</item>
|
||||
<item handle="2a60782759c6f" parent="f4ed1ae756a1f" root="f4ed1ae756a1f" order="1" type="FILE" class="TEMPLATE" layout="DOCUMENT">
|
||||
<meta expanded="no" heading="H2" charCount="7" wordCount="1" paraCount="0" cursorPos="3" />
|
||||
<meta expanded="no" heading="H2" charCount="11" wordCount="2" paraCount="1" cursorPos="81" />
|
||||
<name status="sf12341" import="ia857f0" active="yes">Chapter</name>
|
||||
</item>
|
||||
<item handle="5ee8aebcdebc9" parent="f4ed1ae756a1f" root="f4ed1ae756a1f" order="2" type="FILE" class="TEMPLATE" layout="NOTE">
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<?xml version='1.0' encoding='utf-8'?>
|
||||
<novelWriterXML appVersion="2.3a1" hexVersion="0x020300a1" fileVersion="1.5" fileRevision="2" timeStamp="2024-01-26 22:50:57">
|
||||
<novelWriterXML appVersion="2.3a4" hexVersion="0x020300a4" fileVersion="1.5" fileRevision="2" timeStamp="2024-02-08 21:34:07">
|
||||
<project id="d0f3fe10-c6e6-4310-8bfd-181eb4224eed" saveCount="1" autoCount="1" editTime="0">
|
||||
<name>New Project</name>
|
||||
<author>Jane Doe</author>
|
||||
@@ -22,13 +22,13 @@
|
||||
<entry key="s000003" count="0" red="50" green="200" blue="0">Finished</entry>
|
||||
</status>
|
||||
<importance>
|
||||
<entry key="i000004" count="4" red="100" green="100" blue="100">New</entry>
|
||||
<entry key="i000004" count="5" red="100" green="100" blue="100">New</entry>
|
||||
<entry key="i000005" count="0" red="200" green="50" blue="0">Minor</entry>
|
||||
<entry key="i000006" count="0" red="200" green="150" blue="0">Major</entry>
|
||||
<entry key="i000007" count="0" red="50" green="200" blue="0">Main</entry>
|
||||
</importance>
|
||||
</settings>
|
||||
<content items="11" novelWords="10" notesWords="3">
|
||||
<content items="12" novelWords="10" notesWords="6">
|
||||
<item handle="0000000000008" parent="None" root="0000000000008" order="0" type="ROOT" class="NOVEL">
|
||||
<meta expanded="no" />
|
||||
<name status="s000000" import="i000004">Novel</name>
|
||||
@@ -73,5 +73,9 @@
|
||||
<meta expanded="no" heading="H1" charCount="11" wordCount="3" paraCount="1" cursorPos="0" />
|
||||
<name status="s000000" import="i000004" active="yes">Jane</name>
|
||||
</item>
|
||||
<item handle="0000000000013" parent="000000000000a" root="000000000000a" order="0" type="FILE" class="CHARACTER" layout="NOTE">
|
||||
<meta expanded="no" heading="H1" charCount="11" wordCount="3" paraCount="1" cursorPos="0" />
|
||||
<name status="s000000" import="i000004" active="yes">John</name>
|
||||
</item>
|
||||
</content>
|
||||
</novelWriterXML>
|
||||
|
||||
Reference in New Issue
Block a user