-
Notifications
You must be signed in to change notification settings - Fork 19
Text_edit_box
[update 2015-09-06] text_edit_box is the chosen name. Because that's how Shoes names things and I couldn't think of anything better. Not a permanent decision.
[update 2015-09-09] Changed names for some methods. Some of that is embedded in C now so it going to be harder to change.
Insertion point is going to be troublesome.
Just add append and scroll_to methods to exiting edit_box.
This is a proposed design for a new widget that might appear in 3.2.25 (or later). I've called it multi_line_box (or maybe text_edit or ...) It would look similar to a Shoes edit_box but it is more complicated and feature rich. This would not replace edit_box.
When writing the show_console code for Shoes 3.2.24 I used Gtk Widgets and OSX facilities that Shoes does not have a mappings to some very rich capabilities and that's OK for the consoles. The console is just barely connected to Shoes. I was also struck by the common things I saw in the GtkTextView widget and NSTextField + some Cocoa delegaters/protocols. Could they merged into a new Shoes widget with it's own unique methods and simplified a bit (the native API's are huge)?
This is not a widget for beginners to use in place of edit_box and may not respond to all styles and methods for a edit_box. Backwards compatibly with edit_box is not a goal.
That Gtk link above gives you a good idea. There is any array of lines in a scrolled window. The buffer. You can delete lines and characters, insert and append lines and characters. That is very painful to do with edit_box (to be kind).
There are several open issues that might be solved with this widget.
The isp.rb script that I use for various examples that monitors pings would be much simpler. I'm aware of other folks that like to use Shoes to monitor processes or computations and have it appear in a edit_box like widget.
It could be used to write a much nicer IRB console for example. Think larger. One could write a simple text editor. One could eval the contents of the editor buffer (or a selection of it) with the proper App.context in selt. That would make Shoes an IDE doing REPL things. Byebug would still be a problem but there's probably a way to fix that since they are friendly folk. Yes, that's dreaming but it's not an impossible dream.
But first we need that widget and an API.
We'll try to implement the Shoe common methods for widgets of course where they make sense. We'll implement the current edit_box methods. focus() yes. text() and text= will work on the entire buffer. The string is suitable for writing to a file so it's got embedded new line characters in it. Just like it does now for edit_box.
This will be different. Its called with an arg that is the keystroke before actually modifying the contents. Returning true
will insert it where ever the insertion point is set. Return false or nil means don't insert the character.
The insertion point is the place in the buffer (think line#+character# although the details are not determined yet) We will need some methods to get and set what ever that is.
Appends string at the end of the buffer. By default, this scrolls the view up. The internal insertion point is modified to be at the end of the modified buffer. If the string has newlines inside then new lines will be created.
[2015-09-09] returns the updated insertion point
puts the characters at the insertion point in the buffer and returns the insertion point after the last character(and line) inserted. It does not change the internal insertion point. Think undo - see delete;
deletes characters from insertion_1 to insertion_2 and returns the deleted string. The internal insertion point does not change. If only one argument is given, text is deleted from internal insertion point to insertion_point_1)
returns the string between point 1 and point 2.
For this buffer, creates an buffer relative pointer an returns a new object Shoes::insertion_point
This may need to be another Shoes object with different platform implementations to fit this api. For now, assume its a Ruby array [line_number, character_number]. This is not GUI x and y pixels on the screen or widget. We need to get the internal one. Set the internal one and create one.
[update 2015-09-09] Insertion point is going to be troublesome. NSTextStorage doesn't know lines and columns just a NSRange(start,length). So we need a Shoes (Ruby) class with native methods. Whether this is good enough to write a text editor - I don't know.
returns an Array [line_number, character_number] for the internal insertion point maintained by the native code.
More thinking is needed. The native code does have them and may process them internally without our help. I'd like to have an implementations to work with before digging too deep here.
This is supported by both GTK and OSX and obviously it should to be mapped conceptually,syntacticly with Shoes para styles if possible. Not trivial to implement (I expect). It would also change the API above: Add a :styles hash arg to some methods and some returns might have to return [string, styles_hash] or something like that. May be very complicated. Or just create a new text_fragment object. Yes, that is the right thing to do. Plan ahead.
These will be the standard shoes keys unless the native code process them first (OSX). change(key) may not get cut/copy/paste and really that's what we want
We will need a few methods. I don't know which ones until I've written some code or thought it about more.
moves the widget view so the given insertion point is visible. Does not change the internal insertion point. if no argument is given it uses the internal insertion_point.
like calling scroll_to_insertion() without an argument.
If done properly this could be used to replace para although that is pango/cairo drawing and this is widget contents. Who hasn't tried to append to a para with `@mypara << para "new",:color =>"blue" and discovered para text segments only look like arrays. It could be different but that's outside the scope of the proposed widget and should be kept in mind when implementing this API.