r3wp [groups: 83 posts: 189283]
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

World: r3wp

[Core] Discuss core issues

Graham
15-Aug-2010
[17810]
untested??
Anton
15-Aug-2010
[17811x3]
I just tested it and it seems to work.
Here's another way, also tested:
Here's another way, also tested:
Graham
15-Aug-2010
[17814]
What about Gabriele's vid-context ?
Anton
15-Aug-2010
[17815x2]
window-functions: [
	hello: does [f/text: copy "hello" show f]
]

open-window: has [ctx] [
	view/new center-face layout bind vid-context/to [
		f: field
		button "Hello" [hello]
		button "Clear" [clear-face f]
		button "New window" [open-window]
	] 'ctx context bind window-functions ctx
]

open-window
do-events
Gabriele's vid-context is a pretty nice function.
Graham
15-Aug-2010
[17817x2]
So, how can I use it?
oops ...
Anton
15-Aug-2010
[17819]
Well... what do you need to do again?
Graham
15-Aug-2010
[17820]
Sorry ..didn't read your example with care
Anton
15-Aug-2010
[17821]
oh ok
Graham
15-Aug-2010
[17822x2]
What I want to do is the working example I posted above.
Your last example works
Anton
15-Aug-2010
[17824]
Your 'c function is my 'hello function.
Graham
15-Aug-2010
[17825]
why is it wrapped in a block?
Anton
15-Aug-2010
[17826]
Because I need to bind that code in open-window.
Graham
15-Aug-2010
[17827]
my functions already exist in the global context
Anton
15-Aug-2010
[17828]
It creates new copies of the functions in window-functions each time 
a new window is opened.
Graham
15-Aug-2010
[17829]
that's cheating!
Anton
15-Aug-2010
[17830x2]
I see.
Ok, in that case, go back to the first example I posted. I'll need 
to modify it a little bit..
Graham
15-Aug-2010
[17832x3]
the situation is that I have a lot of screens inside tabs.  now sometimes 
I want to re-use those screens outside the tabs ... so I just copy 
the code and put into a new window .. but then I want to be able 
to make the functions that operate on the original sceens work on 
my new ones.
I did actually try copying the functions but they still operated 
on the original windows and not the new ones ... :(
I got it all working using Gregg's suggestion .. but I'm open to 
others
Anton
15-Aug-2010
[17835x3]
Well, here's the modified code.
hello: does [f/text: copy "hello" show f]

bind-funcs: func [word] [

 foreach window-function [hello][bind second get window-function word]
]

open-window: does [
	view/new center-face layout vid-context [
		f: field

  button "Hello" [bind-funcs 'f hello] ;  Pass to BIND-FUNCS any one 
  of the words in this context (here 'f).
		button "Clear" [clear-face f]
	]
]

open-window
open-window
do-events
It's not brilliant; in each button action you have to call bind-funcs 
before calling any of the window functions (eg. hello).
Graham
15-Aug-2010
[17838]
which is what I am doing at present .. binding before calling the 
function
Anton
15-Aug-2010
[17839]
Yeah, so I've just made it more complex than necessary.
Graham
15-Aug-2010
[17840x2]
now if the functions could access the 'self of the object, it could 
bind automatically?
just rewrite every function ...
Anton
15-Aug-2010
[17842]
It's the same problem; how could the functions know which object 
to bind to?
Graham
15-Aug-2010
[17843x2]
so I would pass the context to each function as a parameter
so these would be self aware functions :)
Anton
15-Aug-2010
[17845]
Usually I just write functions and pass the face(s) that they need 
to work on. Passing the context could cut down the number of arguments 
passed to one. But usually I don't need to pass more than one face, 
so it doesn't seem of that much benefit.
Graham
15-Aug-2010
[17846x3]
So, rewrite the function to take a parameter word from the context 
it is to work in, and let it bind itself to that context ...
well, I have named fields ... and a bunch of data coming in which 
I need to fill the fields
either I fill by position, or by name
Anton
15-Aug-2010
[17849]
You can bind directly to a context now, you don't need to pass an 
example word, unless you are using a very old rebol version...
Graham
15-Aug-2010
[17850]
anonymous contexts ??
Anton
15-Aug-2010
[17851x6]
Alright, well, if you have a function which manipulates many faces, 
then there are arguments to be cut down, and there is a benefit.
Anonymous, yes.
ctx: context [a: 1]
bind [a] ctx
You no longer have to do:
bind [a] in ctx 'self
or
bind [a] in ctx 'a
Ok, so you can rewrite each of your window functions to take, and 
bind itself to, a context argument; or, you can add a "BIND-FUNCS" 
function, taking a context argument, which rebinds all your window 
functions to the context.
Similar to what I've done above.
So, each function binds itself:
hello: func [ctx] [do bind [f/text: copy "hello" show f] ctx]

open-window: does [
	view/new center-face layout vid-context [
		f: field

  button "Hello" [hello self] ;  Pass to HELLO this context (created 
  by VID-CONTEXT).
		button "Clear" [clear-face f]
	]
]

open-window
open-window
do-events
Graham
15-Aug-2010
[17857]
yes ...
Anton
15-Aug-2010
[17858]
Or, all the functions are rebinded by BIND-FUNCS:
Graham
15-Aug-2010
[17859]
That might be the easier way .. .to get the binding be handled by 
the function itself