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)