[MonoDevelop] Problem extending the project/folder context menu for "Class Wizard"

Michael Hutchinson m.j.hutchinson at gmail.com
Tue Jan 6 12:02:48 EST 2009


On Sun, Dec 28, 2008 at 6:20 AM, Christian Hunke <Chris_hunke at web.de> wrote:
> Hi,
>
> i want to help MonoDevelop an thought of just trying the sample of new functionality from the Small Tasks "Class Wizard". Just got the source from SVN, compiles fine etc. Now i tried to add my new GtkDialog into the context menu of projects and folders, so i did the following:
>
> Added this to the "MonoDevelop.GtkCore.addin.xml" to define my new command:
>                <Command id = "MonoDevelop.GtkCore.GtkCommands.AddNewClass"
>                                icon = "md-gtkcore-dialog"
>                                _label = "New Class..." />
>
> Now i added this command to the project and folder add commands:
> <Extension path = "/MonoDevelop/Ide/ContextMenu/ProjectPad/Project/Add">
>                <SeparatorItem insertafter = "MonoDevelop.Ide.Commands.ProjectCommands.AddFiles" />
>                <CommandItem id = "MonoDevelop.GtkCore.GtkCommands.AddNewClass" />
>
> Of course i added the command also to the enum:
> public enum GtkCommands
>        {
>                AddNewDialog,
>                AddNewWindow,
>                AddNewWidget,
>                AddNewActionGroup,
>                ImportGladeFile,
>                EditIcons,
>                GtkSettings,
>                AddNewClass
>        }
>
> Then i extended the "UserInterfaceCommandHandler" class inside of "ProjectFolderNodeBuilderExtension.cs" with the following two methods to provide my context menu item functionality:
> [CommandHandler (MonoDevelop.GtkCore.GtkCommands.AddNewClass)]
>                public void AddNewClassToProject()
>                {
>                        DotNetProject project = CurrentNode.GetParentDataItem (typeof(Project), true) as DotNetProject;
>                        if (project == null)
>                                return;
>
>                        object dataItem = CurrentNode.DataItem;
>
>                        ProjectFolder folder = CurrentNode.GetParentDataItem (typeof(ProjectFolder), true) as ProjectFolder;
>
>                        string path;
>                        if (folder != null)
>                                path = folder.Path;
>                        else
>                                path = project.BaseDirectory;
>
>                        IdeApp.ProjectOperations.CreateClass(project, path);
>                }
>
>                [CommandUpdateHandler (MonoDevelop.GtkCore.GtkCommands.AddNewClass)]
>                public void UpdateAddNewClassToProject (CommandInfo cinfo)
>                {
>                        cinfo.Visible = true;
>                }
>
> So I also added the "CreateClass" method that calls my dialog etc. but i think that is not interesting now.
>
> My problem is that my "New Class..." menu item gets displayed correctly and even works fine BUT all other menu items for dialogs are gone and the order seems to be messed up :( Here is an image (sorry its German but I hope you will recognize it):
> http://img156.imageshack.us/my.php?image=newclasscontextmenuie2.png
>
> Can someone help me with that problem, please?

Your code looks fine to me, though I'm curious why you're adding it to
the GtkCore addin. The GtkCore addin extends <Extension path =
"/MonoDevelop/Ide/ContextMenu/ProjectPad/Project/Add">... already, so
it may be that you'd need to add your commands to that extension
element -- I don't think it's possible have more than one extension
element for a particular path in each addin.

If this doesn't solve it could you attach the diff for the .addin.xml?

-- 
Michael Hutchinson
http://mjhutchinson.com


More information about the Monodevelop-list mailing list