Add menu entries for align and indent

This commit is contained in:
Veronica Berglyd Olsen
2021-06-13 18:28:23 +02:00
parent 618461b1ff
commit cb797fe903
6 changed files with 112 additions and 12 deletions
+5
View File
@@ -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
+45 -1
View File
@@ -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
+44
View File
@@ -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"))
+5
View File
@@ -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)
+4 -2
View File
@@ -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. <
+9 -9
View File
@@ -1,13 +1,13 @@
<?xml version='1.0' encoding='utf-8'?>
<novelWriterXML appVersion="1.4a0" hexVersion="0x010400a0" fileVersion="1.2" timeStamp="2021-06-10 23:37:32">
<novelWriterXML appVersion="1.4a0" hexVersion="0x010400a0" fileVersion="1.2" timeStamp="2021-06-13 18:27:21">
<project>
<name>Sample Project</name>
<title>Sample Project</title>
<author>Jane Smith</author>
<author>Jay Doh</author>
<saveCount>1096</saveCount>
<autoCount>188</autoCount>
<editTime>52328</editTime>
<saveCount>1107</saveCount>
<autoCount>189</autoCount>
<editTime>52789</editTime>
</project>
<settings>
<doBackup>False</doBackup>
@@ -17,8 +17,8 @@
<autoOutline>True</autoOutline>
<lastEdited>636b6aa9b697b</lastEdited>
<lastViewed>636b6aa9b697b</lastViewed>
<lastWordCount>1217</lastWordCount>
<novelWordCount>841</novelWordCount>
<lastWordCount>1216</lastWordCount>
<novelWordCount>840</novelWordCount>
<notesWordCount>376</notesWordCount>
<autoReplace>
<entry key="A">B</entry>
@@ -118,10 +118,10 @@
<status>1st Draft</status>
<exported>True</exported>
<layout>SCENE</layout>
<charCount>2434</charCount>
<wordCount>433</wordCount>
<charCount>2429</charCount>
<wordCount>432</wordCount>
<paraCount>14</paraCount>
<cursorPos>61</cursorPos>
<cursorPos>1329</cursorPos>
</item>
<item handle="bc0cbd2a407f3" order="2" parent="e7ded148d6e4a">
<name>Another Scene</name>