node context

5 views
Skip to first unread message

Kent Tenney

unread,
Oct 6, 2008, 7:50:42 AM10/6/08
to leo-e...@googlegroups.com
I'm working on some application specific buttons, which would
benefit from easy access to some attributes of the current node.

looking at dir(p) I don't see a direct way to determine where the
node is relative to @path and @<file> declarations.

what would you think of

p.getNodePath()

which would return either None or the @path this node lives in

p.getNodeFileName()

which would return either None or the filename of the @<file> this
node lives in.

Thanks,
Kent

Edward K. Ream

unread,
Oct 6, 2008, 8:22:25 AM10/6/08
to leo-e...@googlegroups.com

The following probably does what you want for getNodePath:

aList = g.get_directives_dict_list(p)
path = c.scanAtPathDirectives(aList)

And this for getNodeFileName:

aList = g.get_directives_dict_list(p)
path = c.scanAtPathDirectives(aList)
filename = p.isAnyAtFileNode()
return filename and g.os_path_finalize_join(path,filename)

These use the load directory if there is no @path. These convenience
methods would have to be methods of the commands class:

path = c.getNodePath(p)
path = c.getNodeFileName(p)

I'll add these convenience methods if they do, in fact, do what you want.

BTW, there appears to be a bug with @path: the path is created when
any child is created, even if the child is no kind of @file node.

Edward

Kent Tenney

unread,
Oct 6, 2008, 10:25:49 AM10/6/08
to leo-e...@googlegroups.com
On Mon, Oct 6, 2008 at 7:22 AM, Edward K. Ream <edre...@gmail.com> wrote:
>
> On Mon, Oct 6, 2008 at 6:50 AM, Kent Tenney <kte...@gmail.com> wrote:
>>
>> I'm working on some application specific buttons, which would
>> benefit from easy access to some attributes of the current node.
>>
>> looking at dir(p) I don't see a direct way to determine where the
>> node is relative to @path and @<file> declarations.
>>
>> what would you think of
>>
>> p.getNodePath()
>>
>> which would return either None or the @path this node lives in
>>
>> p.getNodeFileName()
>>
>> which would return either None or the filename of the @<file> this
>> node lives in.
>
> The following probably does what you want for getNodePath:
>
> aList = g.get_directives_dict_list(p)
> path = c.scanAtPathDirectives(aList)

works for me.

>
> And this for getNodeFileName:
>
> aList = g.get_directives_dict_list(p)
> path = c.scanAtPathDirectives(aList)
> filename = p.isAnyAtFileNode()
> return filename and g.os_path_finalize_join(path,filename)

again, works for me.

>
> These use the load directory if there is no @path. These convenience
> methods would have to be methods of the commands class:
>
> path = c.getNodePath(p)
> path = c.getNodeFileName(p)
>
> I'll add these convenience methods if they do, in fact, do what you want.
>
> BTW, there appears to be a bug with @path: the path is created when
> any child is created, even if the child is no kind of @file node.

This is NOT a bug, but a really nice feature!

@path is not just for @files anymore

There's much sweetness in context aware @buttons;

@button do it here
...
node_path = c.getNodePath(p)
Popen(cmd, cwd=node_path)

>
> Edward
>
> >
>

Edward K. Ream

unread,
Oct 6, 2008, 10:28:03 AM10/6/08
to leo-e...@googlegroups.com
On Mon, Oct 6, 2008 at 9:25 AM, Kent Tenney <kte...@gmail.com> wrote:

> again, works for me.

Ok. I'll add these soon.

>> BTW, there appears to be a bug with @path: the path is created when
>> any child is created, even if the child is no kind of @file node.
>
> This is NOT a bug, but a really nice feature!

I'm not sure everyone will agree, but in the interest of laziness I'll
leave things alone until somebody complains :-)

Edward

Edward K. Ream

unread,
Oct 6, 2008, 11:21:20 AM10/6/08
to leo-editor


On Oct 6, 9:28 am, "Edward K. Ream" <edream...@gmail.com> wrote:
> On Mon, Oct 6, 2008 at 9:25 AM, Kent Tenney <kten...@gmail.com> wrote:
> > again, works for me.
>
> Ok.  I'll add these soon.

Done on the trunk at rev 1220.

Edward

Kent Tenney

unread,
Oct 6, 2008, 12:10:02 PM10/6/08
to leo-e...@googlegroups.com

Thanks!


>
> Edward
> >
>

Reply all
Reply to author
Forward
0 new messages