cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Displaying info on the status bar

Highlighted
Newbie

Displaying info on the status bar

Dear Adepters -

We hold page tags in our SGML data. I'd like to display the value of the
"number" attribute of the current page element on the Adept Editor status
bar, and have it continually updated, in the same way that the element
hierarchy is displayed. This way, the user can see at a glance which page
they're looking at, without having to do a search for the previous page
element.

Is this possible using ACL?

Thanks

Matt Clifton
Tags (2)
18 REPLIES 18

Displaying info on the status bar

Matt,

There is an undocumented callback "caretMovedCallback" which you may want
to use.

See $ADEPTHOME/packages/tools/_toptags.cmd and .../html/_www.cmd for
example code.

As always, undocumented stuff is (usually) undocumented for a reason,
so think twice before using this approach in production grade code.

/ Svante Kleist - NEMESIS systemDesign, Stockholm, Sweden

Displaying info on the status bar

Thanks Svante.

I can see how this calls a function on each shift in caret position, but
what I really need is that function - to locate the value of an attribute
and put it to the status bar (or a separate window, I don't mind which).

If there isn't a simple solution to this, don't worry - it was just a
nice-to-have feature that our editors would find useful.

Matt

Displaying info on the status bar

Well, shouldn't be too hard using the oid_ family of functions in ACL.

Use oid_current_tag() to find the OID of the tag just before the caret,
then oid_parent() until you find an element of the type
you are interested in, then oid_attr() to get your attribute value.

To display the value of the attribute, use the "message" command.

I wouldn't expect to be too fast, though. For huge documents it will
likely clog your machine quite a bit.

/ Svante

Displaying info on the status bar

message "$attribute_value"

will display the attribute value at the lower left status line of the
pane (of course, you have to initialize the variable $attribute_value
to it; for that you'd probably want to use oid_attr(oid_caret(),
attr_name) ) or some variation thereof -- more info available through
"help oid") . If the window is too narrow to accomodate the value, it
will display a dismissable message window.

Eduardo

Displaying info on the status bar

--On den 7 juli 1999, 07:15 -0700 eduardo
wrote:

> message "$attribute_value"
>
> [ . . . ]
>
> If the window is too narrow to accomodate the value, it
> will display a dismissable message window.

This can be confusing indeed, if the (blocking) message window
is rendered by the window manager _below_ the editor window.
(Yes: I have seen this happen!)

An alternative is to use window_set( ... , 'message' , ... ) instead,
at the price of possibly having a truncated message displayed.

/ Svante

Displaying info on the status bar

Hi Matt (& Svante),

You _can_ freely use the caretMovedCallback, it's a normal, documented
feature since Adept 5.4 (but not listed in the callback list, You must
use the window_set function to use it), but it's not adviced: You can
substitute it with a simple timer function (see timer_add_callback for
details) which makes Your program be much faster. E.g. if You update the
statusbar once per 5 second, it's enough for most users but has no
chance to overwhelm the CPU. (ACL it not too slow for an interpreter but
placing a longer function for each cursor movement will surely slow the
system.)

Bye:
Peter Krassoi

Displaying info on the status bar

OK, I've followed the advice of Svante, Eduardo and Peter, and come up with
the following:
(It's my first piece of ACL code, so please don't laugh...).

The timer works, the message display works...and the attribute locating
function fails dismally. All that comes up is "Page: ".

I tried using both oid_parent and oid_prev to get the previous element, and
neither returned a success.

The page element is the only element with a "number" attribute, and it's an
inclusion (ie allowed everywhere) if that makes a difference.

I can't help feeling it's something to do with the oid_has_attr function,
which I'm not sure I'm invoking properly.

Can anyone see what I'm doing wrong?

Matt

--

# Code to find the previous "page" element and put the value of the "number"
attribute to the screen

global nticks=0

# get_number tracks up the elements and finds one with a "number" attribute,
# returning the value of "number"

function get_number()
{
$numvalue=0
$object=oid_current_tag()

while ($numvalue=0)
{
$test_oid = oid_has_attr($object, 'number')
if ($test_oid = 1)
{
$numvalue=oid_attr($object, 'number')
return $numvalue
}
$object=oid_prev($object)

}
}

# display_page_no runs the get_number function
# and puts the result to the status bar

function display_page_no()
{
$num=get_number()
message "Page: $num"
}

# update_page runs the get_number function

function update_page()
{
display_page_no()
return 1;
}

# and here's my callback to run the update_page function every 5 seconds

timer_add_callback(500, 'update_page', doc_window())

# end of code.

Displaying info on the status bar

Matt,

Certainly no laughs from me, since I've done the same
blunder as you many, many times...

if ($test_oid = 1)

This always evaluates to true, should be

if ($test_oid == 1)

Now a days, I have the habit to write

if ( 1 == test_oid )

the "reversed" order ensures that I don't make the mistake,
since that would be a syntax error.

/ Svante Kleist - NEMESIS systemDesign, Stockholm, Sweden

Displaying info on the status bar

Thanks, and I've also set the WHILE rule accordingly, but still no luck.

My while rule is now