processing button click in a plugin (1 Viewer)

zombiepig

Portal Pro
March 21, 2005
408
0
Melb, Aus
Home Country
i'm wanting to add a button to an existing screen (myvideosinfo), which when clicked runs a function from my process plugin.

at the moment the way i'm doing this is manually adding the button to the skin xml and giving it a new id (say 5555). then in the plugin Start() function i've got a line:
GUIWindowManager.Receivers += new SendMessageHandler(OnMessage);

the OnMessage function looks like this:

private void OnMessage(GUIMessage message)
{
if (message.Message == GUIMessage.MessageType.GUI_MSG_CLICKED && message.SenderControlId == 5555)
{
// run my function
}
}

is this the correct way of doing this? is there a better way?
 

patrick

Portal Pro
April 20, 2005
608
45
Southeast
Home Country
United States of America United States of America
Re: what's the correct way to do this?

EqualRightsForWerewolves said:
is this the correct way of doing this? is there a better way?

I am not sure about correct or better but
they way I have usually seen it done is to put it into
the override of OnClicked and check the control.
(If you are changing code in an existing plugin the override is probably already there)

So after you add the button to the skin.xml file
something like the code below should work.


Code:
[SkinControlAttribute(5555)] protected GUIButtonControl btnRunMyProcessPlugin = null;

protected override void OnClicked(int controlId, GUIControl control, MediaPortal.GUI.Library.Action.ActionType actionType)
{
   base.OnClicked(controlId, control, actionType);
   
   if (control == btnSomeOtherButton)
   {
      // 
   }
   else if (control == btnRunMyProcessPlugin)
   {
      // Insert code here
   }
}

HTH
patrick
 

zombiepig

Portal Pro
March 21, 2005
408
0
Melb, Aus
Home Country
i just tried putting the code you suggested in the plugin but i'm getting a compilation error:

"'MyHTTrailers.Class1.OnClicked(int, MediaPortal.GUI.Library.GUIControl, MediaPortal.GUI.Library.Action.ActionType)': no suitable method found to override C:\Documents and Settings\Nyall\My Documents\Visual Studio 2005\Projects\MyHTTrailers\MyHTTrailers\Class1.cs 267 33 MyHTTrailers
"

is there something I'm missing?
 

patrick

Portal Pro
April 20, 2005
608
45
Southeast
Home Country
United States of America United States of America
Is your class inheriting from MediaPortal.GUI.Library.GUIWindow?

Code:
public class Class1 : GUIWindow
{
}

HTH,
patrick
 

zombiepig

Portal Pro
March 21, 2005
408
0
Melb, Aus
Home Country
ok - i got it to compile but the OnClicked function isn't triggering. is this because my plugin is a process plugin which i'm trying to trigger from another skin page, and doesn't have it's own page?

also - is there any way to add an item to an existing mp context menu from a plugin?

thanks for all the assistance btw!
 

patrick

Portal Pro
April 20, 2005
608
45
Southeast
Home Country
United States of America United States of America
EqualRightsForWerewolves said:
is this because my plugin is a process plugin which i'm trying to trigger from another skin page, and doesn't have it's own page?

I think I read your first post too quickly...Sorry :oops:

I thought you were creating or modifying the code
in a windows plugin to start something in a process
plugin when you said adding a button to an existing screen.

So pretty much ignore everything I said... :(

It looks like you were doing it right.
The only other thing you may want to do is check
if the current window is the window you added the
button to so you do not act on the clicks on any
button with id=5555.

EqualRightsForWerewolves said:
also - is there any way to add an item to an existing mp context menu from a plugin?

Not sure on that one.

Again, sorry I caused you extra work.

patrick
 

Users who are viewing this thread

Top Bottom