ReSpec question

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

ReSpec question

Shane McCarron
Sorry, I know I asked something like this before, but I have hit a wall.  What I want to do is add a menu item to the respec UI.

When I look in the profile-w3c.common.js file, I see pretty clearly how to add a handler assuming I have a handle to the ui object.  But since that object is somewhat buried, it is unclear to me how I can get at it in a way that won't be brittle.  

When do I want to get at it?  Well, the easiest way would be in an event handler function:

respecEvents.sub('end-all', function() {...});

So at the end of respec processing, I add my menu and viola.  Any ideas?

--
Shane McCarron
Managing Director, Applied Testing and Technology, Inc.
Reply | Threaded
Open this post in threaded view
|

Re: ReSpec question

Robin Berjon-6
Hi Shane,

On 22/03/2015 22:22 , Shane McCarron wrote:
> Sorry, I know I asked something like this before, but I have hit a
> wall.  What I want to do is add a menu item to the respec UI.
>
> When I look in the profile-w3c.common.js file, I see pretty clearly how
> to add a handler assuming I have a handle to the ui object.  But since
> that object is somewhat buried, it is unclear to me how I can get at it
> in a way that won't be brittle.

Is this for a specific draft, or something you'd like to add across the
board for all ReSpec documents?

If the latter, then just add it in the same way as the others here:

     https://github.com/w3c/respec/blob/develop/js/profile-w3c-common.js#L59

Otherwise, you will need to write something along the lines of:

define(["core/ui"], function (ui) {
     ui.addCommand("Do Stuff", "ui/stuff-doer", "Ctrl+Shift+Alt-D");
});

And then have a module under ui/stuff.doer.js that's implemented in the
same way as the others.

> When do I want to get at it?  Well, the easiest way would be in an event
> handler function:
>
> respecEvents.sub('end-all', function() {...});

A quick look at the code makes me think it would work pretty much at any
moment, at least after the processing has started. So yeah, end-all
seems like as good a place as any.

> So at the end of respec processing, I add my menu and viola.  Any ideas?

PS: it's a common mistake, but I feel compelled to point out it's
"voilà", not "viola". The latter means "raped"; probably not what one
intends to convey!

--
Robin Berjon - http://berjon.com/ - @robinberjon

Reply | Threaded
Open this post in threaded view
|

Re: ReSpec question

Shane McCarron
Comments inline:

On Mon, Mar 23, 2015 at 4:45 AM, Robin Berjon <[hidden email]> wrote:
Hi Shane,

On 22/03/2015 22:22 , Shane McCarron wrote:
Sorry, I know I asked something like this before, but I have hit a
wall.  What I want to do is add a menu item to the respec UI.

When I look in the profile-w3c.common.js file, I see pretty clearly how
to add a handler assuming I have a handle to the ui object.  But since
that object is somewhat buried, it is unclear to me how I can get at it
in a way that won't be brittle.

Is this for a specific draft, or something you'd like to add across the board for all ReSpec documents?

It is for a specific draft.  So I can't use either of your proposed techniques.  I don't want to change ReSpec.  I just want to extend it.
 

If the latter, then just add it in the same way as the others here:

    https://github.com/w3c/respec/blob/develop/js/profile-w3c-common.js#L59

Otherwise, you will need to write something along the lines of:

define(["core/ui"], function (ui) {
    ui.addCommand("Do Stuff", "ui/stuff-doer", "Ctrl+Shift+Alt-D");
});

And then have a module under ui/stuff.doer.js that's implemented in the same way as the others.

When do I want to get at it?  Well, the easiest way would be in an event
handler function:

respecEvents.sub('end-all', function() {...});

A quick look at the code makes me think it would work pretty much at any moment, at least after the processing has started. So yeah, end-all seems like as good a place as any.

Are you suggesting that calling define from within an Event processor would work?  I guess I hadn't tried that.
 


So at the end of respec processing, I add my menu and viola.  Any ideas?

PS: it's a common mistake, but I feel compelled to point out it's "voilà", not "viola". The latter means "raped"; probably not what one intends to convey!

Yeah - I knew that.  I was too lazy to type the accented character, but damn - sloppy!
 
--
Shane McCarron
Managing Director, Applied Testing and Technology, Inc.
Reply | Threaded
Open this post in threaded view
|

Re: ReSpec question

Robin Berjon-6
On 23/03/2015 13:27 , Shane McCarron wrote:
>     A quick look at the code makes me think it would work pretty much at
>     any moment, at least after the processing has started. So yeah,
>     end-all seems like as good a place as any.
>
>
> Are you suggesting that calling define from within an Event processor
> would work?  I guess I hadn't tried that.

Yeah, I'd try something like that. I can think of no reason that
define() would not be defined (heh). Don't call define() inside the
handler, just have (in your own script, loaded after ReSpec — and making
sure ReSpec isn't loaded async):

define(["core/ui"], function (ui) {
     ui.addCommand("Do Stuff", "ui/stuff-doer", "Ctrl+Shift+Alt+D");
});

I reckon that's enough.

--
Robin Berjon - http://berjon.com/ - @robinberjon

Reply | Threaded
Open this post in threaded view
|

Re: ReSpec question

Shane McCarron


On Mon, Mar 23, 2015 at 7:35 AM, Robin Berjon <[hidden email]> wrote:
On 23/03/2015 13:27 , Shane McCarron wrote:
    A quick look at the code makes me think it would work pretty much at
    any moment, at least after the processing has started. So yeah,
    end-all seems like as good a place as any.


Are you suggesting that calling define from within an Event processor
would work?  I guess I hadn't tried that.

Yeah, I'd try something like that. I can think of no reason that define() would not be defined (heh). Don't call define() inside the handler, just have (in your own script, loaded after ReSpec — and making sure ReSpec isn't loaded async):

define(["core/ui"], function (ui) {
    ui.addCommand("Do Stuff", "ui/stuff-doer", "Ctrl+Shift+Alt+D");
});

I reckon that's enough.


Huh.  I will try that.  FYI what I did to get a jump start was I added a URI parameter handler into the end-all event handler.  It sees a query string of 'saveRoles' and then pops up a save dialog.  Silly, but it got me over the hump. 


--
Shane McCarron
Managing Director, Applied Testing and Technology, Inc.