Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

dirty editor

 [1/7] from: hijim:pronet at: 28-Jun-2002 8:01


I've solved the dirty problem. I'm not sure this will work very well when I get all the keys put into code. It may slow down data entry. Anyway, using the code below does not set the dirty flag. I can go between buttons and keys now and not lose focus on the text area. The keys now work just like the buttons. put: func [str num][ if my-area <> system/view/focal-face [return] if not system/view/caret [return] insert system/view/caret str system/view/caret: skip system/view/caret num show my-area ] key #"a" [put "a" 1] key #"A" [put "A" 1] key #"b" [put "b" 1] key #"B" [put "B" 1] button "P" #"^P" [put "<P>" 3] My question is, can I get this into a block or series? Or do I have to repeat this statement for each key? I'm sure Rebol wouldn't make me do that. Can someone tell me how to get the key statments into a single statement that will put"A" when I press"A", and all the other keys too. (Also, how do I see the code for the editor built into Rebol. I've been away from Rebol for almost a year, and I've forgotten how. I seem to remember the word dirty from that code. Maybe it shows how to turn dirty off. That would be even easier. I just can't remember how to list that code.) Thanks for the help, Jim

 [2/7] from: g:santilli:tiscalinet:it at: 29-Jun-2002 21:08


Hi Jim, On Friday, June 28, 2002, 5:01:48 PM, you wrote: JC> put: func [str num][ JC> if my-area <> system/view/focal-face [return] JC> if not system/view/caret [return] JC> insert system/view/caret str JC> system/view/caret: skip system/view/caret num JC> show my-area JC> ] How about: put: func [str] [ if my-area <> system/view/focal-face [return] if not system/view/caret [return] system/view/caret: insert system/view/caret str show my-area ] JC> My question is, can I get this into a block or series? You'd better change your Area's feel; it handles keys this way: engage: func [face act event][ switch act [ down [ either not-equal? face view*/focal-face [ focus face view*/caret: offset-to-caret face event/offset ] [ view*/highlight-start: view*/highlight-end: none view*/caret: offset-to-caret face event/offset ] show face ] over [ if not-equal? view*/caret offset-to-caret face event/offset [ if not view*/highlight-start [view*/highlight-start: view*/caret] view*/highlight-end: view*/caret: offset-to-caret face event/offset show face ] ] key [edit-text face event get in face 'action] ] ] i.e. calling the EDIT-TEXT function that you can find in the CTX-TEXT object:
>> probe get in ctx-text 'edit-text
func [ face event action /local key set-caret liney hi swap-text tmp tmp2 page-up page-down ][ key: event/key if flag-face? face hide swap-text: [ tmp: face/text face/text: face/data face/data: tmp view*/caret: either error? try [index? view*/caret] [tail face/text] [ at face/text index? view*/caret ] ] if word? key [ either event/shift [ hi: view*/caret if not view*/highlight-start [view*/highlight-start: hi] ] [unlight-text] tmp: caret-to-offset face view*/caret textinfo face view*/line-info view*/caret liney: view*/line-info/size/y hi: event/shift ] if char? key [ either find keys-to-insert key [insert-char face key] [key: select keymap key] ] if word? key [ set-caret: [view*/caret: offset-to-caret face tmp] page-up: [ tmp/y: tmp/y - face/size/y if not head? view*/line-info/start set-caret ] page-down: [ tmp/y: tmp/y + face/size/y if not tail? offset-to-caret face tmp set-caret ] switch key [ back-char [ if all [not delete-selected-text not head? view*/caret] [ either event/control [ tmp2: view*/caret remove/part view*/caret: back-word tmp2 tmp2 ] [ remove view*/caret: back view*/caret ] ] face/dirty?: true ] del-char [ if all [not delete-selected-text not tail? view*/caret] [ either event/control [ remove/part view*/caret next-word view*/caret ] [ remove view*/caret ] ] face/dirty?: true ] up [ either event/control page-up [ tmp/y: tmp/y - liney if not head? view*/line-info/start set-caret ] ] down [ either event/control page-down [ tmp/y: tmp/y + liney if not tail? offset-to-caret face tmp set-caret ] ] home [ view*/caret: either event/control [head view*/caret] [beg-of-line view*/caret] ] end [ view*/caret: either event/control [tail view*/caret] [end-of-line view*/caret] ] left [ if not head? view*/caret [ view*/caret: either event/control [back-word view*/caret] [back view*/caret] ] ] right [ if not tail? view*/caret [ view*/caret: either event/control [next-word view*/caret] [next view*/caret] ] ] page-up page-up page-down page-down enter [ either flag-face? face return [ if flag-face? face hide swap-text action face face/data if flag-face? face tabbed [focus next-field face] exit ] [insert-char face newline] ] copy-text [copy-text face unlight-text] cut-text [copy-text face delete-selected-text face/dirty?: true] paste-text [ delete-selected-text face/line-list: none face/dirty?: true view*/caret: insert view*/caret read clipboard:// ] clear-tail [ remove/part view*/caret end-of-line view*/caret face/dirty?: true ] all-text [hilight-all face] tab-char [ if flag-face? face tabbed [ either in face 'refocus [face/refocus event/shift] [ tmp2: either event/shift [back-field face] [next-field face] if flag-face? face hide swap-text action face face/data focus tmp2 ] exit ] insert-char face tab ] ] ] if hi [view*/highlight-end: view*/caret] if face: view*/focal-face [ if flag-face? face hide [ insert/dup clear face/data "*" length? face/text do swap-text ] textinfo face view*/line-info view*/caret liney: view*/line-info/size/y tmp: caret-to-offset face view*/caret tmp2: face/para/scroll if all [tmp/x <= 0 tmp2/x < 0] [face/para/scroll/x: tmp2/x - tmp/x] if all [tmp/y <= 0 tmp2/y < 0] [face/para/scroll/y: tmp2/y - tmp/y] action: face/size - tmp - face/para/margin if action/x - 5 <= 0 [face/para/scroll/x: tmp2/x + action/x - 5] if action/y - liney <= 0 [face/para/scroll/y: tmp2/y + action/y - liney] show face ] ] Notice the lines with: face/dirty?: true But I still think it would be easier to remove or change the event func instead of having to patch edit-text... Regards, Gabriele. -- Gabriele Santilli <[g--santilli--tiscalinet--it]> -- REBOL Programmer Amigan -- AGI L'Aquila -- REB: http://web.tiscali.it/rebol/index.r

 [3/7] from: greggirwin:mindspring at: 29-Jun-2002 9:28


Hi Jim, I have to run so can't delve into your first question, but the second one is easy. << (Also, how do I see the code for the editor built into Rebol. >> probe get in ctx-text 'edit-text --Gregg

 [4/7] from: gerardcote:sympatico:ca at: 30-Jun-2002 10:39


Hello Jim and Gregg, Just for sake of helping everyone (be it a newbie or not) that needs some way to get a similar information, here is the way I asked myself how I could get more information when Jim asked Gregg - sort of personal challenge :
> << (Also, how do I see the code for the editor built into Rebol. >>
May be the process I used to get my answer is not the only one that can be used but it worked and I would share it with others that didn't think about it already. It could also serve as a basis for discussion about the differences there are between the way Gregg did it and others too. Here is my short work session tracing my way of doing things :
>> help edit
Found these words: ctx-edit (block) editor (function)
>> source editor
editor: func [file /local tmp][ either exists? tmp: view-root/desktop/scripts/edit.r [do/args tmp file] [ if block? ctx-edit [ctx-edit: context ctx-edit] ctx-edit/view-file file ] ]
>> ctx-edit
== [ prefs: view-root/edit-prefs.r dirty-edit: false this-file: none this-app: none t1: s1: h1: f1: none ... <-- Here REBOL seems to report a truncated information !!!
>> print type? ctx-edit
block
>> probe ctx-edit <-- This way of doing will clearly reveal the internals of the
ctx-edit BLOCK [ prefs: view-root/edit-prefs.r dirty-edit: false this-file: none this-app: none t1: s1: h1: f1: none edit-prefs: context [ offset: 40x40 size: 640x480 wrap: on ] ed-lo: layout/offset [ style tx vtext bold 40x22 font [colors: [0.0.0 200.200.200]] middle center size 640x320 origin 0 space 0 across ... <--- Here I cut the listing myself just to keep it short Here is the solution offered by Gregg for discussion purposes only :
> probe get in ctx-text 'edit-text >
I know this one has to do with "contexts" but how does it differ from mine? Is there more to know about this way of doing things that could be of interest to me and others too that I didn't find yet ? What is the impact of requiring the content of ctx-text by the way of the "get in" instead of probing it directly as I did? I don't see any real difference here but may be in other situations it could be different ... Just one more thing. The last time I asked VIEW to "print block? ctx-edit" the answer was not "true". ? Can it really be so or did I goofed my VIEW somewhere ? For which situation can ctx-edit not be a BLOCK if this is possible? I think it must effectively be possible for "ctx-edit" to not be a BLOCK because of the test the EDITOR function is doing about it. But whatever is the reason for doing so this doesn't answer my question either. Thanks for any explanation (or where I can find one), Gerard

 [5/7] from: greggirwin:mindspring at: 30-Jun-2002 13:46


Hi Gerard, I have only a little time, so I'll be brief and I'm sure others will chime in as well. <<
> probe get in ctx-text 'edit-text >
I know this one has to do with "contexts" but how does it differ from mine? Is there more to know about this way of doing things that could be of interest to me and others too that I didn't find yet ? What is the impact of requiring the content of ctx-text by the way of the get in instead of probing it directly as I did? I don't see any real difference here but may be in other situations it could be different ...
>>
As you have found, there are many ways to locate information reflectively in REBOL. I was trying to show just the function responsible for the editing operation, so I used "get in" to look inside its parent context (in order to make PROBE happy). << The last time I asked VIEW to "print block? ctx-edit" the answer was not true . ? Can it really be so or did I goofed my VIEW somewhere ? For which situation can ctx-edit not be a BLOCK if this is possible? >> There are similarly named items that are not quite the same, and may be confusing. I haven't spent time analyzing their relationships in detail, but you can do this to see that ctx-text and ctx-edit are different datatypes.
>> type? ctx-text
== object!
>> type? get in ctx-text 'edit-text
== function!
>> type? ctx-edit
== block! ctx-text also contains a reference to view*, which contains many circular references so, while you can PROBE ctx-edit, doing a PROBE on ctx-text will give you a very long listing indeed. --Gregg

 [6/7] from: ingo:2b1 at: 30-Jun-2002 23:51


Hi Gerard, Gerard Cote wrote: <...>
> Just one more thing. > > The last time I asked VIEW to "print block? ctx-edit" the answer was not "true". ? > Can it really be so or did I goofed my VIEW somewhere ? For which situation can ctx-edit not be a BLOCK if this is possible? > > I think it must effectively be possible for "ctx-edit" to not be a BLOCK because of the test the EDITOR function is doing about it. > But whatever is the reason for doing so this doesn't answer my question either.
Look at this fresh Rebol/View Session:
>> type? ctx-edit
== block!
>> editor %/tmp/x >> type? ctx-edit
== object! On Rebol startup, ctx-edit is a block containing the the blueprint for the "real" ctx-edit object!. It's done this way mainly because a block needs much less memory than an object! created from it (especially if it contains 'view elements). To not waste this memory, the object! is only created when it is really needed. I hope that sheds a little light on that one. Kind regards, Ingo

 [7/7] from: gerardcote:sympatico:ca at: 30-Jun-2002 22:49


Ingo wrote :
> On Rebol startup, ctx-edit is a block containing the the blueprint for > the "real" ctx-edit object!.
<<quoted lines omitted: 3>>
> needed. > I hope that sheds a little light on that one.
For sure it did. It was informative to me having this info Ingo, thanks a lot! Regards, Gerard

Notes
  • Quoted lines have been omitted from some messages.
    View the message alone to see the lines that have been omitted