diff --git a/nw/enum.py b/nw/enum.py index 830e8953..f619d7dd 100644 --- a/nw/enum.py +++ b/nw/enum.py @@ -90,6 +90,11 @@ class nwDocAction(Enum): REPL_SNG = 19 REPL_DBL = 20 RM_BREAKS = 21 + ALIGN_L = 22 + ALIGN_C = 23 + ALIGN_R = 24 + INDENT_L = 25 + INDENT_R = 26 # END Enum nwDocAction diff --git a/nw/gui/doceditor.py b/nw/gui/doceditor.py index 9209ab4c..a03c5927 100644 --- a/nw/gui/doceditor.py +++ b/nw/gui/doceditor.py @@ -787,6 +787,16 @@ class GuiDocEditor(QTextEdit): self._replaceQuotes("\"", self._typDQOpen, self._typDQClose) elif theAction == nwDocAction.RM_BREAKS: self._removeInParLineBreaks() + elif theAction == nwDocAction.ALIGN_L: + self._formatBlock(nwDocAction.ALIGN_L) + elif theAction == nwDocAction.ALIGN_C: + self._formatBlock(nwDocAction.ALIGN_C) + elif theAction == nwDocAction.ALIGN_R: + self._formatBlock(nwDocAction.ALIGN_R) + elif theAction == nwDocAction.INDENT_L: + self._formatBlock(nwDocAction.INDENT_L) + elif theAction == nwDocAction.INDENT_R: + self._formatBlock(nwDocAction.INDENT_R) else: logger.debug("Unknown or unsupported document action %s" % str(theAction)) self._allowAutoReplace(True) @@ -1733,10 +1743,32 @@ class GuiDocEditor(QTextEdit): elif theText.startswith("#### "): newText = theText[5:] cOffset = 5 + elif theText.startswith(">> "): + newText = theText[3:] + cOffset = 3 + elif theText.startswith("> ") and docAction != nwDocAction.INDENT_R: + newText = theText[2:] + cOffset = 2 + elif theText.startswith(">>"): + newText = theText[2:] + cOffset = 2 + elif theText.startswith(">") and docAction != nwDocAction.INDENT_R: + newText = theText[1:] + cOffset = 1 else: newText = theText cOffset = 0 + # Also remove formatting tags at the end + if theText.endswith(" <<"): + newText = newText[:-3] + elif theText.endswith(" <") and docAction != nwDocAction.INDENT_L: + newText = newText[:-2] + elif theText.endswith("<<"): + newText = newText[:-2] + elif theText.endswith("<") and docAction != nwDocAction.INDENT_L: + newText = newText[:-1] + # Apply new format if docAction == nwDocAction.BLOCK_COM: theText = "% "+newText @@ -1753,9 +1785,21 @@ class GuiDocEditor(QTextEdit): elif docAction == nwDocAction.BLOCK_H4: theText = "#### "+newText cOffset -= 5 + elif docAction == nwDocAction.ALIGN_L: + theText = newText+" <<" + elif docAction == nwDocAction.ALIGN_C: + theText = ">> "+newText+" <<" + cOffset -= 3 + elif docAction == nwDocAction.ALIGN_R: + theText = ">> "+newText + cOffset -= 3 + elif docAction == nwDocAction.INDENT_L: + theText = "> "+newText + cOffset -= 2 + elif docAction == nwDocAction.INDENT_R: + theText = newText+" <" elif docAction == nwDocAction.BLOCK_TXT: theText = newText - cOffset -= 0 else: logger.error("Unknown or unsupported block format requested: %s" % str(docAction)) return False diff --git a/nw/gui/mainmenu.py b/nw/gui/mainmenu.py index d0c4c491..b9cf5e6e 100644 --- a/nw/gui/mainmenu.py +++ b/nw/gui/mainmenu.py @@ -830,6 +830,50 @@ class GuiMainMenu(QMenuBar): self.aFmtHead4.triggered.connect(lambda: self._docAction(nwDocAction.BLOCK_H4)) self.fmtMenu.addAction(self.aFmtHead4) + # Format > Separator + self.fmtMenu.addSeparator() + + # Format > Align Left + self.aFmtAlignLeft = QAction(self.tr("Align Left"), self) + self.aFmtAlignLeft.setStatusTip(self.tr("Change the block alignment to left")) + self.aFmtAlignLeft.setShortcut("Ctrl+5") + self.aFmtAlignLeft.triggered.connect(lambda: self._docAction(nwDocAction.ALIGN_L)) + self.fmtMenu.addAction(self.aFmtAlignLeft) + + # Format > Align Centre + self.aFmtAlignCentre = QAction(self.tr("Align Centre"), self) + self.aFmtAlignCentre.setStatusTip(self.tr("Change the block alignment to centre")) + self.aFmtAlignCentre.setShortcut("Ctrl+6") + self.aFmtAlignCentre.triggered.connect(lambda: self._docAction(nwDocAction.ALIGN_C)) + self.fmtMenu.addAction(self.aFmtAlignCentre) + + # Format > Align Right + self.aFmtAlignRight = QAction(self.tr("Align Right"), self) + self.aFmtAlignRight.setStatusTip(self.tr("Change the block alignment to right")) + self.aFmtAlignRight.setShortcut("Ctrl+7") + self.aFmtAlignRight.triggered.connect(lambda: self._docAction(nwDocAction.ALIGN_R)) + self.fmtMenu.addAction(self.aFmtAlignRight) + + # Format > Separator + self.fmtMenu.addSeparator() + + # Format > Indent Left + self.aFmtIndentLeft = QAction(self.tr("Indent Left"), self) + self.aFmtIndentLeft.setStatusTip(self.tr("Increase the block's left margin")) + self.aFmtIndentLeft.setShortcut("Ctrl+8") + self.aFmtIndentLeft.triggered.connect(lambda: self._docAction(nwDocAction.INDENT_L)) + self.fmtMenu.addAction(self.aFmtIndentLeft) + + # Format > Indent Right + self.aFmtIndentRight = QAction(self.tr("Indent Right"), self) + self.aFmtIndentRight.setStatusTip(self.tr("Increase the block's right margin")) + self.aFmtIndentRight.setShortcut("Ctrl+9") + self.aFmtIndentRight.triggered.connect(lambda: self._docAction(nwDocAction.INDENT_R)) + self.fmtMenu.addAction(self.aFmtIndentRight) + + # Format > Separator + self.fmtMenu.addSeparator() + # Format > Comment self.aFmtComment = QAction(self.tr("Comment"), self) self.aFmtComment.setStatusTip(self.tr("Change the block format to comment")) diff --git a/nw/guimain.py b/nw/guimain.py index 700f670e..039f1100 100644 --- a/nw/guimain.py +++ b/nw/guimain.py @@ -1345,6 +1345,11 @@ class GuiMain(QMainWindow): self.addAction(self.mainMenu.aFmtHead2) self.addAction(self.mainMenu.aFmtHead3) self.addAction(self.mainMenu.aFmtHead4) + self.addAction(self.mainMenu.aFmtAlignLeft) + self.addAction(self.mainMenu.aFmtAlignCentre) + self.addAction(self.mainMenu.aFmtAlignRight) + self.addAction(self.mainMenu.aFmtIndentLeft) + self.addAction(self.mainMenu.aFmtIndentRight) self.addAction(self.mainMenu.aFmtComment) self.addAction(self.mainMenu.aFmtNoFormat) diff --git a/sample/content/636b6aa9b697b.nwd b/sample/content/636b6aa9b697b.nwd index 514b4bf1..9db44eec 100644 --- a/sample/content/636b6aa9b697b.nwd +++ b/sample/content/636b6aa9b697b.nwd @@ -25,7 +25,7 @@ If you need to split a scene file up into further pieces, you can do so with the Both scene and section titles can be left out of the final exported document. The formatting of titles can be selected from the Build Novel Project dialog. You can also have them replaced with scene separators like “* * *”. -#### Text Alignment and Indent +#### Text Alignment The text by default will have the left or justified alignment in the main text files in your project. You can also specify alignment for a specific paragraph by “pushing” it away from an edge with a set of ‘>>’ or ‘<<’ symbols, like so: @@ -35,6 +35,8 @@ This text is left-aligned. << >> This text is centred. << -You can also indent a paragraph from both the left and right margin with ‘>’ and ‘<’ symbols. +#### Text Indent + +You can indent a paragraph from both the left and right margin with ‘>’ and ‘<’ symbols. > This paragraph is indented from both the left margin and the right margin. This is useful for when you want to quote a large chunk of text for instance. < diff --git a/sample/nwProject.nwx b/sample/nwProject.nwx index c1960d23..067fa0a3 100644 --- a/sample/nwProject.nwx +++ b/sample/nwProject.nwx @@ -1,13 +1,13 @@ - + Sample Project Sample Project Jane Smith Jay Doh - 1096 - 188 - 52328 + 1107 + 189 + 52789 False @@ -17,8 +17,8 @@ True 636b6aa9b697b 636b6aa9b697b - 1217 - 841 + 1216 + 840 376 B @@ -118,10 +118,10 @@ 1st Draft True SCENE - 2434 - 433 + 2429 + 432 14 - 61 + 1329 Another Scene