[SOLVED] Custom context menus, how to pass context?

Development of XChat itself. Talk about code, patches and other technical stuff. No feature requests!
Formal bug reports should go to http://xchat.org/cvs/#bugs instead.
This forum is for developers writing xchat code, not end-user questions.

[SOLVED] Custom cont

Postby dash9 » 13 Apr 2009 20:50

If I add an item to the $TAB or $CHAN context menus, how do I know, in the called function, which channel/server has been right-clicked?
Last edited by dash9 on 31 May 2009 21:12, edited 1 time in total.
dash9
 
Posts: 13
Joined: 13 Apr 2009 17:28

Postby Khisanth » 14 Apr 2009 16:57

You can't call functions directly, you can only specific commands to run. If those commands are created a script you can obvious call get_info and get_context. If it's a User Command then you can setup the command to pass %c
Khisanth
 
Posts: 1724
Joined: 10 Jun 2004 05:23

Postby dash9 » 16 Apr 2009 10:45

Khisanth wrote:You can't call functions directly, you can only specific commands to run.


Ok, I understand that.

Khisanth wrote: If those commands are created a script you can obvious call get_info and get_context.

The command is created in a script, but that does not change anything. I have for example:
xchat.command('MENU ADD "$CHAN/Bookmark" "myfunction" ')
How exactly do I tell myfunction which channel has been right-clicked?

I want the same functionality as in Firefox:
- press Ctrl+D to bookmark the current channel get_info(channel).
- right click a channel and have a "Bookmark This Channel" menu item.

Khisanth wrote: If it's a User Command then you can setup the command to pass %c

What is this "%c" and where can I read the documentation about it?
dash9
 
Posts: 13
Joined: 13 Apr 2009 17:28

Postby Khisanth » 16 Apr 2009 20:49

xchat.command('MENU ADD "$CHAN/Bookmark" "myfunction" ') executes a command, it does not create one. Commands are created with hook_command
Khisanth
 
Posts: 1724
Joined: 10 Jun 2004 05:23

Postby dash9 » 16 Apr 2009 21:42

Khisanth wrote:xchat.command('MENU ADD "$CHAN/Bookmark" "myfunction" ') executes a command, it does not create one. Commands are created with hook_command
Thanks for your time.

If anybody else is still reading this thread, this is my question, which has not been answered yet:
If I add an item to the $TAB or $CHAN context menus, [which will execute a command when clicked, and that command, being hooked to a function in my script, will call that function] how do I know, in the called function, which channel/server has been right-clicked?
dash9
 
Posts: 13
Joined: 13 Apr 2009 17:28

Postby Khisanth » 17 Apr 2009 02:58

Then you can use xchat.get_info( "channel" ) inside the callback for hook_command as I mentioned originally
Khisanth
 
Posts: 1724
Joined: 10 Jun 2004 05:23

Postby dash9 » 26 May 2009 23:32

Khisanth wrote:Then you can use xchat.get_info( "channel" ) inside the callback for hook_command as I mentioned originally

I'm afraid that does not work.

This is what I have:
Code: Select all
def doBookmark(word, word_eol, userdata):
   xchat.prnt("xchat.get_info('channel') = %s" % xchat.get_info("channel"))
   return xchat.EAT_ALL
xchat.command('MENU ADD "$CHAN/Bookmark" BOOKMARK')
xchat.hook_command("BOOKMARK", doBookmark)


I right-click a channel in the text area and click Bookmark, it will print the name of the current channel, not the name of the clicked channel.

Of course, the same is true for $TAB/Bookmark: I join #x, then #y, then right-click #x, I see "#x" as the first item in the menu, but if I choose Bookmark, it prints the name of the current channel, #y.

How can I obtain, in doBookmark() the name of the channel which has been right-clicked by the user?
dash9
 
Posts: 13
Joined: 13 Apr 2009 17:28

Postby dash9 » 27 May 2009 00:45

dash9 wrote:How can I obtain, in doBookmark() the name of the channel which has been right-clicked by the user?

To answer my own question: Use %s.
Code: Select all
def doBookmark(word, word_eol, userdata):
   channel = word[1]
   xchat.prnt(channel)
   return xchat.EAT_ALL
xchat.command('MENU ADD "$CHAN/Bookmark" "BOOKMARK %s"')
xchat.hook_command("BOOKMARK", doBookmark)
dash9
 
Posts: 13
Joined: 13 Apr 2009 17:28


Return to Development

Who is online

Users browsing this forum: No registered users and 1 guest