mirror of
https://github.com/olivierkes/manuskript.git
synced 2024-05-16 10:52:29 +12:00
Improve visual formatting of editor text
Signed-off-by: TheJackiMonster <thejackimonster@gmail.com>
This commit is contained in:
parent
8110b204ca
commit
fdb5f854f6
|
@ -212,19 +212,28 @@ class EditorView:
|
|||
self.counterProgressBar.set_text("{0} / {1} {2}".format(textCount, goalCount, goalKind.name.lower()))
|
||||
self.counterProgressBar.set_fraction(safeFraction(textCount, 0, goalCount))
|
||||
|
||||
def __appendOutlineItemText(self, outlineItem: OutlineItem):
|
||||
def __appendOutlineItemText(self, outlineItem: OutlineItem, level: int = 1):
|
||||
end_iter = self.editorTextBuffer.get_end_iter()
|
||||
|
||||
if type(outlineItem) is OutlineFolder:
|
||||
if self.editorTextBuffer.get_line_count() > 1:
|
||||
self.editorTextBuffer.insert_with_tags_by_name(end_iter, "\n", "none")
|
||||
|
||||
headerTag = "h{0}".format(min(level, 6))
|
||||
end_iter = self.editorTextBuffer.get_end_iter()
|
||||
|
||||
self.editorTextBuffer.insert_with_tags_by_name(end_iter, outlineItem.title + "\n", "h1")
|
||||
self.editorTextBuffer.insert_with_tags_by_name(end_iter, outlineItem.title + "\n", headerTag)
|
||||
|
||||
firstItem = True
|
||||
|
||||
for item in outlineItem:
|
||||
self.__appendOutlineItemText(item)
|
||||
if firstItem:
|
||||
firstItem = False
|
||||
else:
|
||||
end_iter = self.editorTextBuffer.get_end_iter()
|
||||
self.editorTextBuffer.insert_with_tags_by_name(end_iter, "\n", "none")
|
||||
|
||||
self.__appendOutlineItemText(item, level + 1)
|
||||
|
||||
return True
|
||||
elif type(outlineItem) is OutlineText:
|
||||
|
@ -233,7 +242,19 @@ class EditorView:
|
|||
if (outlineText.text is None) or (len(outlineText.text) <= 0):
|
||||
return False
|
||||
|
||||
self.editorTextBuffer.insert(end_iter, outlineText.text)
|
||||
paragraphs = outlineText.text.split("\n")
|
||||
firstParagraph = True
|
||||
|
||||
for paragraph in paragraphs:
|
||||
if firstParagraph:
|
||||
firstParagraph = False
|
||||
else:
|
||||
self.editorTextBuffer.insert_with_tags_by_name(end_iter, "\n", "none")
|
||||
end_iter = self.editorTextBuffer.get_end_iter()
|
||||
|
||||
self.editorTextBuffer.insert_with_tags_by_name(end_iter, paragraph, "p")
|
||||
end_iter = self.editorTextBuffer.get_end_iter()
|
||||
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
@ -252,14 +273,17 @@ class EditorView:
|
|||
elif type(outlineItem) is OutlineText:
|
||||
self.__appendOutlineItemText(outlineItem)
|
||||
|
||||
if outlineItem is None:
|
||||
for item in self.editorItems:
|
||||
self.__appendOutlineItemText(item)
|
||||
else:
|
||||
self.__appendOutlineItemText(outlineItem)
|
||||
|
||||
self.editorFlowbox.foreach(self.editorFlowbox.remove)
|
||||
if len(self.editorItems) <= 0:
|
||||
self.outlineItem = outlineItem
|
||||
return
|
||||
|
||||
for item in self.editorItems:
|
||||
self.__appendOutlineItemText(item)
|
||||
|
||||
for item in self.editorItems:
|
||||
self.editorFlowbox.insert(GridItem(item).widget, -1)
|
||||
|
||||
|
|
|
@ -75,11 +75,6 @@ along with Manuskript. If not, see <http://www.gnu.org/licenses/>.
|
|||
<property name="font">Normal</property>
|
||||
</object>
|
||||
</child>
|
||||
<child type="tag">
|
||||
<object class="GtkTextTag">
|
||||
<property name="font">Normal</property>
|
||||
</object>
|
||||
</child>
|
||||
<child type="tag">
|
||||
<object class="GtkTextTag" id="h2_tag">
|
||||
<property name="name">h2</property>
|
||||
|
@ -174,6 +169,13 @@ along with Manuskript. If not, see <http://www.gnu.org/licenses/>.
|
|||
<property name="editable">False</property>
|
||||
</object>
|
||||
</child>
|
||||
<child type="tag">
|
||||
<object class="GtkTextTag" id="p_tag">
|
||||
<property name="name">p</property>
|
||||
<property name="font">Normal</property>
|
||||
<property name="indent">20</property>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
<object class="GtkTextBuffer" id="editor_text">
|
||||
<property name="tag-table">editor_tag_table</property>
|
||||
|
|
Loading…
Reference in a new issue