[SOLVED] C# and OnMenuItemClick

This forum is for questions / discussions regarding development of addons / tweaks for MediaMonkey.

Moderator: Gurus

Melloware
Posts: 339
Joined: Mon Aug 18, 2008 9:46 am
Location: Philadelphia, PA, US
Contact:

[SOLVED] C# and OnMenuItemClick

Post by Melloware » Sat Nov 21, 2009 11:12 am

OK so I am trying to add a Right Click Context Menu to my Custom Tree Node. I can get the menu item to appear in the context menu but when I try and execute it nothing happens. I have noticed this with other C# Events where there is a similar "Func" Value. So for SDBMenuItem there is an OnClick event and an OnClickFunc property for Script assignment.

Here is my code...

Code: Select all

// create the menu item
SDBMenuItem mnuLogFile = MediaMonkey.UI.AddMenuItem(MediaMonkey.UI.Menu_Pop_Tree, 0, 0);
mnuLogFile.Caption = "&View Log File...";
mnuLogFile.IconIndex = 43;
mnuLogFile.Visible = false;
mnuLogFile.Enabled = true;
mnuLogFile.OnClick += new ISDBMenuItemEvents_OnClickEventHandler(MenuViewLogFile_OnClick);

MediaMonkey.OnChangedSelection += new ISDBApplicationEvents_OnChangedSelectionEventHandler(MediaMonkey_MenuVisible);
MediaMonkey.set_Objects("mnuLogFile", mnuLogFile);

/// Event Called whenever the Treeview selection is changed.
/// Only display this item if my custom node was selected
void MediaMonkey_MenuVisible() {
    SDBTreeNode node = MediaMonkey.MainTree.CurrentNode;
    SDBMenuItem menu = (SDBMenuItem)MediaMonkey.get_Objects("mnuLogFile");
    menu.Visible = (node.CustomNodeId == MENU_VIEW_LOG);
}

/// Event fired when the View Log File... menu is clicked.
void MenuViewLogFile_OnClick(Object menuItem) {
     LOG.Info("View Log File Clicked");       //NEVER EXECUTES!!!
}
From what I can tell I have all my code correct but the menu item never fires. Any thoughts?
Last edited by Melloware on Sat Nov 21, 2009 5:04 pm, edited 1 time in total.
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Melloware Inc.
MonkeyTunes - DACP Server for MediaMonkey
Intelliremote - Take Back Control of your HTPC!
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

Bex
Posts: 6316
Joined: Fri May 21, 2004 5:44 am
Location: Sweden

Re: C# and OnMenuItemClick

Post by Bex » Sat Nov 21, 2009 3:05 pm

I know nothing about C# but if you use the old OnClick event in a Menu you need to add which script it should read from. Perhaps something like this?

Code: Select all

// create the menu item
SDBMenuItem mnuLogFile = MediaMonkey.UI.AddMenuItem(MediaMonkey.UI.Menu_Pop_Tree, 0, 0);
mnuLogFile.Caption = "&View Log File...";
mnuLogFile.IconIndex = 43;
mnuLogFile.Visible = false;
mnuLogFile.Enabled = true;
mnuLogFile.OnClick += new ISDBMenuItemEvents_OnClickEventHandler(MenuViewLogFile_OnClick);
mnuLogFile.UseScript=Script.ScriptPath; '<-----
But you can also use the new event handling which is better and faster. Perhaps like this?

Code: Select all

// create the menu item
SDBMenuItem mnuLogFile = MediaMonkey.UI.AddMenuItem(MediaMonkey.UI.Menu_Pop_Tree, 0, 0);
mnuLogFile.Caption = "&View Log File...";
mnuLogFile.IconIndex = 43;
mnuLogFile.Visible = false;
mnuLogFile.Enabled = true;
Script.RegisterEvent mnuLogFile, "OnClick", new ISDBMenuItemEvents_OnClickEventHandler(MenuViewLogFile_OnClick);
Advanced Duplicate Find & Fix Find More From Same - Custom Search. | Transfer PlayStat & Copy-Paste Tags/AlbumArt between any tracks.
Tagging Inconsistencies Do you think you have your tags in order? Think again...
Play History & Stats Node Like having your Last-FM account stored locally, but more advanced.
Case & Leading Zero Fixer Works on filenames too!

All My Scripts

Melloware
Posts: 339
Joined: Mon Aug 18, 2008 9:46 am
Location: Philadelphia, PA, US
Contact:

Re: C# and OnMenuItemClick

Post by Melloware » Sat Nov 21, 2009 3:17 pm

Bex,

Thanks for responding. I think you helped me figure it out. So the OnClick is the old version and isn't meant to be used in C#. However everything is based on using Scripts and not using straight code. So it appears I have to mix a combination of the two. I do all the work in the C# code however I register the OnClick code in the VBS script and just call my C# code when the menu item is pressed. So here is my VBS code...

Code: Select all

' Declare all variables
Dim application
Dim mnuViewLog

' Called for all Auto-Scripts when MM starts
Sub OnStartup
    Set application= CreateObject("Melloware.MyApp")
    application.Init(SDB)
    
    ' get the menu object created in the C# code and assign OnClick
    Set mnuViewLog = SDB.Objects("mnuViewLog")
    Script.RegisterEvent mnuViewLog, "OnClick", "OnViewLogClick"
End Sub

' Event when View Log menu item is clicked
Sub OnViewLogClick( Item)
    ' use this like a callback and call this method in the C# code when menu item is clicked
    application.MenuViewLogFile_OnClick()
End Sub
Thanks for your help!
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Melloware Inc.
MonkeyTunes - DACP Server for MediaMonkey
Intelliremote - Take Back Control of your HTPC!
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

Bex
Posts: 6316
Joined: Fri May 21, 2004 5:44 am
Location: Sweden

Re: C# and OnMenuItemClick

Post by Bex » Sat Nov 21, 2009 3:31 pm

Glad you sorted it out!
Advanced Duplicate Find & Fix Find More From Same - Custom Search. | Transfer PlayStat & Copy-Paste Tags/AlbumArt between any tracks.
Tagging Inconsistencies Do you think you have your tags in order? Think again...
Play History & Stats Node Like having your Last-FM account stored locally, but more advanced.
Case & Leading Zero Fixer Works on filenames too!

All My Scripts

Post Reply