diff --git a/manuskript/ui/views/editorView.py b/manuskript/ui/views/editorView.py index f9bb9e2..fc35b61 100644 --- a/manuskript/ui/views/editorView.py +++ b/manuskript/ui/views/editorView.py @@ -4,12 +4,14 @@ import gi gi.require_version("Gtk", "3.0") -from gi.repository import Gtk +from gi.repository import Gtk, Pango from manuskript.data import Project, Outline, OutlineFolder, OutlineText, OutlineItem, OutlineState, Plots, PlotLine, Characters, Character, Importance, Goal from manuskript.ui.util import rgbaFromColor, pixbufFromColor from manuskript.util import validString, invalidString, validInt, invalidInt, CounterKind, countText +import inspect + class EditorView: @@ -30,6 +32,11 @@ class EditorView: self.outlineStore = builder.get_object("outline_store") self.refreshOutlineStore() + self.editorTextBuffer = builder.get_object("editor_text") + + self.editorFlowbox = builder.get_object("editor_flowbox") + self.loadEditorData(None) + def refreshLabelStore(self): self.labelStore.clear() @@ -53,6 +60,15 @@ class EditorView: self.statusStore.set_value(tree_iter, 0, validString(status.name)) + @classmethod + def __getIconByOutlineType(cls, outlineItem: OutlineItem): + if type(outlineItem) is OutlineFolder: + return "folder-symbolic" + elif type(outlineItem) is OutlineText: + return "emblem-documents-symbolic" + else: + return "folder-documents-symbolic" + def __appendOutlineItem(self, outlineItem: OutlineItem, parent_iter=None): tree_iter = self.outlineStore.append(parent_iter) @@ -62,15 +78,11 @@ class EditorView: if outlineItem.state != OutlineState.COMPLETE: outlineItem.load(False) - if type(outlineItem) is OutlineFolder: - icon = "folder-symbolic" + icon = EditorView.__getIconByOutlineType(outlineItem) + if type(outlineItem) is OutlineFolder: for item in outlineItem: self.__appendOutlineItem(item, tree_iter) - elif type(outlineItem) is OutlineText: - icon = "emblem-documents-symbolic" - else: - icon = "folder-documents-symbolic" wordCount = validInt(outlineItem.textCount()) goal = validInt(outlineItem.goalCount()) @@ -97,5 +109,65 @@ class EditorView: for item in self.project.outline.items: self.__appendOutlineItem(item) + def __appendOutlineItemText(self, outlineItem: OutlineItem): + 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") + + end_iter = self.editorTextBuffer.get_end_iter() + + self.editorTextBuffer.insert_with_tags_by_name(end_iter, outlineItem.title + "\n", "h1") + + for item in outlineItem: + self.__appendOutlineItemText(item) + + return True + elif type(outlineItem) is OutlineText: + outlineText: OutlineText = outlineItem + + if (outlineText.text is None) or (len(outlineText.text) <= 0): + return False + + self.editorTextBuffer.insert(end_iter, outlineText.text) + return True + else: + return False + + def loadEditorData(self, outlineItem: OutlineItem | None): + self.editorTextBuffer.set_text("") + + for item in self.project.outline.items: + self.__appendOutlineItemText(item) + + for item in self.project.outline.items: + child = Gtk.FlowBoxChild() + + hbox = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL) + vbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL) + + icon = EditorView.__getIconByOutlineType(item) + + iconImage = Gtk.Image.new_from_icon_name(icon, Gtk.IconSize.MENU) + titleLabel = Gtk.Label(item.title) + summaryLabel = Gtk.Label(item.summaryFull) + + titleLabel.set_ellipsize(Pango.EllipsizeMode.END) + summaryLabel.set_ellipsize(Pango.EllipsizeMode.END) + summaryLabel.set_line_wrap_mode(Pango.WrapMode.WORD_CHAR) + summaryLabel.set_line_wrap(True) + summaryLabel.set_max_width_chars(20) + + hbox.pack_start(iconImage, False, True, 4) + hbox.pack_start(titleLabel, False, True, 4) + + vbox.pack_start(hbox, False, True, 4) + vbox.pack_start(summaryLabel, False, True, 4) + + child.add(vbox) + + self.editorFlowbox.add(child) + def show(self): self.widget.show_all() diff --git a/ui/editor.glade b/ui/editor.glade index 0823ac6..7f33fcc 100644 --- a/ui/editor.glade +++ b/ui/editor.glade @@ -30,6 +30,132 @@ along with Manuskript. If not, see . 1 10 + + + + h1 + Normal + title-caps + 700 + 2 + 4 + 4 + False + + + + + Normal + + + + + Normal + + + + + Normal + + + + + h2 + Normal + title-caps + 700 + 1.5 + 8 + 8 + False + + + + + h3 + Normal + title-caps + 700 + 1.1699999999999999 + 12 + 12 + False + + + + + h4 + Normal + title-caps + 700 + 16 + 16 + False + + + + + h5 + Normal + title-caps + 700 + 0.82999999999999996 + 20 + 20 + False + + + + + h6 + Normal + title-caps + 700 + 0.67 + 24 + 24 + False + + + + + b + Normal + 700 + + + + + i + Normal + italic + + + + + s + Normal + True + + + + + u + Normal + single + + + + + none + Normal + False + + + + + editor_tag_table + @@ -246,6 +372,8 @@ along with Manuskript. If not, see . True True + word-char + editor_text @@ -267,9 +395,10 @@ along with Manuskript. If not, see . True False - + True False + True