# -*- coding: utf-8 -*-
from functools import partial

import maya.utils as utils
import maya.mel as mel
import maya.cmds as cmds


import mayaenveditor as editor


def create_menu():
    cmd = '''
    global string $gMainFileMenu; // Retrieve the menu name
    buildViewMenu("MayaWindow|mainWindowMenu");
    buildPreferenceMenu mainOptionsMenu;
    buildSettingsMenu MayaWindow|mainWindowMenu;

    '''

    mel.eval(cmd)
    cmds.menuItem(divider=True)
    cmds.menuItem(label="Edit Maya.env", command=partial(editor.run))


def later():
    """
    Creates mGear menu
    """
    try:
        print "create_menu"
        create_menu()
        print "finish create_menu"

    except Exception as e:
        import traceback
        traceback.print_exc()
        print e


utils.executeDeferred('later()')

@@ -199,82 +199,116 @@
     
-global string $gMainFileMenu; // Retrieve the menu name%0A    buildViewMenu(
+buildViewMenu MayaWindow%7CmainWindowMenu;%0A    buildPreferenceMenu mainOptionsMenu;%0A%0A    string $parentName = 
 %22May
@@ -334,101 +334,423 @@
 enu%22
-)
 ;%0A    
-buildPreferenceMenu mainOptionsMenu;%0A    buildSettingsMenu MayaWindow%7CmainWindowMenu;%0A
+string $menuItems%5B%5D = %60menu -q -ia $parentName%60;%0A%0A    for ($i = 0; $i %3C size($menuItems); $i += 1) %7B%0A        string $label = %60menuItem -q -label $menuItems%5B$i%5D%60;%0A        string $match = %60match %22Settings%22 $label%60;%0A        if (0 %3C size($match))%7B%0A            $parentName = $parentName + %22%7C%22 + $menuItems%5B$i%5D;%0A            break;%0A        %7D%0A    %7D%0A%0A    buildSettingsMenu $parentName;%0A    setParent -menu $parentName;
 %0A   
@@ -773,16 +773,17 @@
 al(cmd)%0A
+%0A
     cmds
@@ -965,16 +965,34 @@
 ate_menu
+ for mayaenveditor
 %22%0A      

fix registering menu