diff --git a/nw/convert/tokenizer.py b/nw/convert/tokenizer.py new file mode 100644 index 00000000..e6ca8c05 --- /dev/null +++ b/nw/convert/tokenizer.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +"""novelWriter Text Tokenizer + + novelWriter – Text Tokenizer +============================== + Splits a piece of nW markdown text into its elements + + File History: + Created: 2019-05-05 [0.0.1] + +""" + +import logging +import nw + +from nw.project.document import NWDoc + +logger = logging.getLogger(__name__) + +class Tokenizer(): + + def __init__(self, theProject, theParent): + + self.mainConf = nw.CONFIG + self.theProject = theProject + self.theParent = theParent + + self.theHandle = None + self.theItem = None + self.theTokens = None + + return + + def tokenizeText(self, tHandle): + + self.theItem = self.theProject.getItem(tHandle) + theDoc = NWDoc(self.theProject, self.theParent) + theText = theDoc.openDocument(tHandle) + + for aLine in theText.splitlines(): + print(aLine) + + return + +# END Class Tokenizer diff --git a/nw/gui/doctree.py b/nw/gui/doctree.py index c0fe0e6c..859ff0c9 100644 --- a/nw/gui/doctree.py +++ b/nw/gui/doctree.py @@ -289,6 +289,14 @@ class GuiDocTree(QTreeWidget): return selItem[0].text(self.C_HANDLE) return None + def getSelectedHandles(self): + selItems = self.selectedItems() + selHandles = [] + for n in range(len(selItems)): + if isinstance(selItems[n], QTreeWidgetItem): + selHandles.append(selItems[n].text(self.C_HANDLE)) + return selHandles + ## # Internal Functions ## diff --git a/nw/gui/mainmenu.py b/nw/gui/mainmenu.py index d6dace0d..a148e06e 100644 --- a/nw/gui/mainmenu.py +++ b/nw/gui/mainmenu.py @@ -231,6 +231,16 @@ class GuiMainMenu(QMenuBar): # Document > Separator self.docuMenu.addSeparator() + # Document > Preview + menuItem = QAction(QIcon.fromTheme("text-html"), "Preview Document", self) + menuItem.setStatusTip("Preview Document") + menuItem.setShortcut("Ctrl+R") + menuItem.triggered.connect(self.theParent._previewDocument) + self.docuMenu.addAction(menuItem) + + # Document > Separator + self.docuMenu.addSeparator() + # Document > Split menuItem = QAction(QIcon.fromTheme("list-add"), "Split Document", self) menuItem.setStatusTip("Split Selected Document") diff --git a/nw/gui/winmain.py b/nw/gui/winmain.py index 5467c0b4..e026db58 100644 --- a/nw/gui/winmain.py +++ b/nw/gui/winmain.py @@ -28,6 +28,7 @@ from nw.gui.statusbar import GuiMainStatus from nw.project.project import NWProject from nw.project.document import NWDoc from nw.project.item import NWItem +from nw.convert.tokenizer import Tokenizer from nw.enum import nwItemType logger = logging.getLogger(__name__) @@ -189,6 +190,22 @@ class GuiMain(QMainWindow): self.docEditor.setDocumentChanged(False) return + def _previewDocument(self): + + theHandles = self.treeView.getSelectedHandles() + if len(theHandles) == 0: + return + + theDocs = [] + self.treeView.saveTreeOrder() + for tHandle in self.theProject.treeOrder: + if tHandle not in theHandles: + continue + aDoc = Tokenizer(self.theProject, self) + aDoc.tokenizeText(tHandle) + + return + ## # Tree Item Actions ##