The last two day's work has complete rewritten the big text code, with a major, essential, change in point of view.
This post will be pre-writing for documentation. The recent work fixes three big-text-related bugs: https://github.com/leo-editor/leo-editor/issues/28 Fixed: Leo hangs when a node with too large body is selected https://github.com/leo-editor/leo-editor/issues/64 Fixed: big text status re-evaluated on find in current body https://github.com/leo-editor/leo-editor/issues/63 Fixed: refresh-from-disk does not clear big text load delay UI I am about to mark all three bugs as closed. Please reopen if necessary, but please do read *all* this post before doing so. To mark this milestone, and to encourage more testing, the big-text gui is now enabled by default in leoSettings.leo as follows:: @int max-pre-loaded-body-chars = 30000 Setting this to zero disables the big-text gui. It remains to be seen whether this feature will be enabled for a1. Note that making the colorizer work incrementally means that users can quickly step over large text nodes without having to wait for them to load completely. ===== Background This entire project arises from a terrible Qt bug, completely unrelated to Leo: https://bugreports.qt-project.org/browse/QTBUG-41153 As a result of this bug, Leo's users must be *extremely* careful not to change body text before Qt has completely loaded it, that is, before the vertical scrollbars in the body pane stop moving. Changing the text in *any* way, say by typing any letter, will prematurely stop Qt from loading the text. If the user then saves the outline, all unloaded text will be lost! As a workaround, Terry created an optional warning interface, consisting of warning gui: text (in the body text area) and buttons that reload the body text or copied the text to the clipboard. The warning text now has a pink background. To change this color, change the new QTextEdit#bigtextwarning to the Qt stylesheet. Yes, there should be an @color node to make changing the background easier. I'll do this today. One more note: The new interface does work with multiple body editors, albeit in a quirky way. Please don't file a bug report about this unless you find something other than a quirk. ===== User interface changes - The "Load" button is now the "Remove These Buttons" button. - The "Load Text with @killcolor" is shown only if the text doesn't already start with @killcolor. What follows is an Engineering Notebook post: notes for the usual suspects. Feel free to ignore. ===== Redesign The original code injected ivars into c.frame.body.wrapper.widget (the QTextBrowser for the body pane). These ivars maintained state in a complex way. A previous recoding created a LeoBigTextDialog class, a subclass of QWidget, to handle some of the details. For the last two days I have been reworking the code. Yesterday, a lucky accident happened. As the result of difficulties with the layout manager, I threw up my hands and decided to **leave the body pane alone** when adding the big-text gui. So now, the body pane *remains* in the gui, with the warning text below it, and the various buttons below the warning text. This instantly eliminated some state-switching when creating and destroying the gui. Much more importantly, it allows Leo to work *as before*, regardless of whether the big-text gui is showing. In effect, this fixes #64. Imo, leaving the body text in the body pane is also the *only* sane way forward. We can not tolerate any interaction between Leo's commands and the big-text gui!! Yes, the user must be careful not to change big text (say with a replace command), before the text is loaded. But that can't be helped. The big-text gui never changed this unhappy fact. ===== Recoding The overall goals of the recoding were: 1. To put all big-text-related code in a single class, the BigTextController class. 2. To eliminate all injected ivars. 3. To simplify LeoTree.select and helpers. Here's how these goals were met: 1. The LeoBigTextDialog class (in leo.plugins.qt_big_text) became the BigTextController class. This class is now a true controller class. It *has* gui elements, but is not a subclass of any Qt class. This change makes the class more flexible. c.initObjects creates c.bigTextController, a singleton instance of this class for every commander, *provided* that the g.app.gui.bigTextControllerClass ivar exists. Only the qt_gui class has such an ivar. 2. Ivars of c.bigTextController replace all injected ivars. 3. The all-important select logic now knows nothing about the internals of big text. Here is the new "select" logic in LeoTree.select_new_node:: btc = c.bigTextController if btc: if btc.should_add_buttons(old_p,p): btc.add_buttons(old_p,p) elif btc.should_go_away(p): btc.go_away() And here is the "unselect" logic in LeoTree.unselect_helper:: btc = c.bigTextController if btc and btc.active_flag: btc.go_away() The two "should" methods, btc.should_add_buttons and btc.should_go_away, hide all implementation details from the selection logic. This is important! Leo's already-way-too-complex select/unselect code is spared further complications. ===== Summary of techy details Retaining the body text in the big-text gui simplifies everything. c.bigTextController hides all implementation details from Leo's node select/unselect logic. All questions and comments welcome. Edward -- You received this message because you are subscribed to the Google Groups "leo-editor" group. To unsubscribe from this group and stop receiving emails from it, send an email to leo-editor+unsubscr...@googlegroups.com. To post to this group, send email to leo-editor@googlegroups.com. Visit this group at http://groups.google.com/group/leo-editor. For more options, visit https://groups.google.com/d/optout.