<s> """<STR_LIT>""" <EOL> import sublime <EOL> from os . path import join , exists <EOL> from os import makedirs , remove <EOL> from EasyDiff . easy_diff_global import load_settings , debug , get_external_diff <EOL> from EasyDiff . lib . multiconf import get as multiget <EOL> MENU_FOLDER = "<STR_LIT>" <EOL> CONTEXT_MENU = "<STR_LIT>" <EOL> SIDEBAR_MENU = "<STR_LIT>" <EOL> TAB_MENU = "<STR_LIT>" <EOL> DIFF_MENU = '''<STR_LIT>''' <EOL> DIFF_SUBMENU = '''<STR_LIT>''' <EOL> VC_INTERNAL_MENU = '''<STR_LIT>''' <EOL> VC_EXTERNAL_MENU = '''<STR_LIT>''' <EOL> INTERNAL_MENU = '''<STR_LIT>''' <EOL> EXTERNAL_MENU = '''<STR_LIT>''' <EOL> SVN_INTERNAL_MENU = '''<STR_LIT>''' <EOL> GIT_INTERNAL_MENU = '''<STR_LIT>''' <EOL> HG_INTERNAL_MENU = '''<STR_LIT>''' <EOL> SVN_EXTERNAL_MENU = '''<STR_LIT>''' <EOL> GIT_EXTERNAL_MENU = '''<STR_LIT>''' <EOL> HG_EXTERNAL_MENU = '''<STR_LIT>''' <EOL> INTERNAL_SIDEBAR_MENU = '''<STR_LIT>''' <EOL> EXTERNAL_SIDEBAR_MENU = '''<STR_LIT>''' <EOL> SVN_SIDEBAR_INTERNAL_MENU = '''<STR_LIT>''' <EOL> GIT_SIDEBAR_INTERNAL_MENU = '''<STR_LIT>''' <EOL> HG_SIDEBAR_INTERNAL_MENU = '''<STR_LIT>''' <EOL> SVN_SIDEBAR_EXTERNAL_MENU = '''<STR_LIT>''' <EOL> GIT_SIDEBAR_EXTERNAL_MENU = '''<STR_LIT>''' <EOL> HG_SIDEBAR_EXTERNAL_MENU = '''<STR_LIT>''' <EOL> INTERNAL_TAB_MENU = '''<STR_LIT>''' <EOL> EXTERNAL_TAB_MENU = '''<STR_LIT>''' <EOL> SVN_TAB_INTERNAL_MENU = '''<STR_LIT>''' <EOL> GIT_TAB_INTERNAL_MENU = '''<STR_LIT>''' <EOL> HG_TAB_INTERNAL_MENU = '''<STR_LIT>''' <EOL> SVN_TAB_EXTERNAL_MENU = '''<STR_LIT>''' <EOL> GIT_TAB_EXTERNAL_MENU = '''<STR_LIT>''' <EOL> HG_TAB_EXTERNAL_MENU = '''<STR_LIT>''' <EOL> class MenuUpdater ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , name ) : <EOL> """<STR_LIT>""" <EOL> self . name = name <EOL> self . menu_path = join ( sublime . packages_path ( ) , "<STR_LIT>" , MENU_FOLDER ) <EOL> if not exists ( self . menu_path ) : <EOL> makedirs ( self . menu_path ) <EOL> settings = load_settings ( ) <EOL> self . menu_types = multiget ( settings , "<STR_LIT>" , [ ] ) <EOL> self . svn_disabled = multiget ( settings , "<STR_LIT>" , False ) or multiget ( settings , "<STR_LIT>" , False ) <EOL> self . git_disabled = multiget ( settings , "<STR_LIT>" , False ) or multiget ( settings , "<STR_LIT>" , False ) <EOL> self . hg_disabled = multiget ( settings , "<STR_LIT>" , False ) or multiget ( settings , "<STR_LIT>" , False ) <EOL> self . show_ext = multiget ( settings , "<STR_LIT>" , False ) and get_external_diff ( ) is not None <EOL> self . show_int = multiget ( settings , "<STR_LIT>" , True ) <EOL> def update_menu ( self , menu_name , menus , submenu ) : <EOL> """<STR_LIT>""" <EOL> if exists ( self . menu_path ) : <EOL> menu = join ( self . menu_path , menu_name ) <EOL> vc_internal = [ ] <EOL> vc_internal_menu = None <EOL> if self . show_int : <EOL> if not self . svn_disabled : <EOL> vc_internal . append ( menus [ "<STR_LIT>" ] [ "<STR_LIT>" ] ) <EOL> if not self . git_disabled : <EOL> vc_internal . append ( menus [ "<STR_LIT>" ] [ "<STR_LIT>" ] ) <EOL> if not self . hg_disabled : <EOL> vc_internal . append ( menus [ "<STR_LIT>" ] [ "<STR_LIT>" ] ) <EOL> if len ( vc_internal ) : <EOL> vc_internal_menu = "<STR_LIT>" . join ( vc_internal ) <EOL> vc_external = [ ] <EOL> vc_external_menu = None <EOL> if self . show_ext : <EOL> if not self . svn_disabled : <EOL> vc_external . append ( menus [ "<STR_LIT>" ] [ "<STR_LIT>" ] ) <EOL> if not self . git_disabled : <EOL> vc_external . append ( menus [ "<STR_LIT>" ] [ "<STR_LIT>" ] ) <EOL> if not self . hg_disabled : <EOL> vc_external . append ( menus [ "<STR_LIT>" ] [ "<STR_LIT>" ] ) <EOL> if len ( vc_external ) : <EOL> vc_external_menu = "<STR_LIT>" . join ( vc_external ) <EOL> with open ( menu , "<STR_LIT:w>" ) as f : <EOL> f . write ( <EOL> ( DIFF_SUBMENU if submenu else DIFF_MENU ) % { <EOL> "<STR_LIT>" : ( "<STR_LIT>" if not self . show_int else menus [ "<STR_LIT>" ] % { "<STR_LIT>" : self . name } ) , <EOL> "<STR_LIT>" : ( "<STR_LIT>" if not self . show_ext else menus [ "<STR_LIT>" ] % { "<STR_LIT>" : self . name } ) , <EOL> "<STR_LIT>" : ( <EOL> "<STR_LIT>" if vc_internal_menu is None or not self . show_int else VC_INTERNAL_MENU % { <EOL> "<STR_LIT>" : vc_internal_menu <EOL> } <EOL> ) , <EOL> "<STR_LIT>" : ( <EOL> "<STR_LIT>" if vc_external_menu is None or not self . show_ext else VC_EXTERNAL_MENU % { <EOL> "<STR_LIT>" : vc_external_menu <EOL> } <EOL> ) <EOL> } <EOL> ) <EOL> def remove_menu ( self , menu_name ) : <EOL> """<STR_LIT>""" <EOL> if exists ( self . menu_path ) : <EOL> menu = join ( self . menu_path , menu_name ) <EOL> if exists ( menu ) : <EOL> remove ( menu ) <EOL> def update_context_menu ( self ) : <EOL> """<STR_LIT>""" <EOL> menus = { <EOL> "<STR_LIT>" : INTERNAL_MENU , <EOL> "<STR_LIT>" : EXTERNAL_MENU , <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT>" : SVN_INTERNAL_MENU , <EOL> "<STR_LIT>" : SVN_EXTERNAL_MENU <EOL> } , <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT>" : GIT_INTERNAL_MENU , <EOL> "<STR_LIT>" : GIT_EXTERNAL_MENU <EOL> } , <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT>" : HG_INTERNAL_MENU , <EOL> "<STR_LIT>" : HG_EXTERNAL_MENU <EOL> } <EOL> } <EOL> if "<STR_LIT>" in self . menu_types : <EOL> submenu = load_settings ( ) . get ( "<STR_LIT>" , [ ] ) <EOL> self . update_menu ( CONTEXT_MENU , menus , "<STR_LIT>" in submenu ) <EOL> else : <EOL> self . remove_menu ( CONTEXT_MENU ) <EOL> def update_sidebar_menu ( self ) : <EOL> """<STR_LIT>""" <EOL> menus = { <EOL> "<STR_LIT>" : INTERNAL_SIDEBAR_MENU , <EOL> "<STR_LIT>" : EXTERNAL_SIDEBAR_MENU , <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT>" : SVN_SIDEBAR_INTERNAL_MENU , <EOL> "<STR_LIT>" : SVN_SIDEBAR_EXTERNAL_MENU <EOL> } , <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT>" : GIT_SIDEBAR_INTERNAL_MENU , <EOL> "<STR_LIT>" : GIT_SIDEBAR_EXTERNAL_MENU <EOL> } , <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT>" : HG_SIDEBAR_INTERNAL_MENU , <EOL> "<STR_LIT>" : HG_SIDEBAR_EXTERNAL_MENU <EOL> } <EOL> } <EOL> if "<STR_LIT>" in self . menu_types : <EOL> submenu = load_settings ( ) . get ( "<STR_LIT>" , [ ] ) <EOL> self . update_menu ( SIDEBAR_MENU , menus , "<STR_LIT>" in submenu ) <EOL> else : <EOL> self . remove_menu ( SIDEBAR_MENU ) <EOL> def update_tab_menu ( self ) : <EOL> """<STR_LIT>""" <EOL> menus = { <EOL> "<STR_LIT>" : INTERNAL_TAB_MENU , <EOL> "<STR_LIT>" : EXTERNAL_TAB_MENU , <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT>" : SVN_TAB_INTERNAL_MENU , <EOL> "<STR_LIT>" : SVN_TAB_EXTERNAL_MENU <EOL> } , <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT>" : GIT_TAB_INTERNAL_MENU , <EOL> "<STR_LIT>" : GIT_TAB_EXTERNAL_MENU <EOL> } , <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT>" : HG_TAB_INTERNAL_MENU , <EOL> "<STR_LIT>" : HG_TAB_EXTERNAL_MENU <EOL> } <EOL> } <EOL> if "<STR_LIT>" in self . menu_types : <EOL> submenu = load_settings ( ) . get ( "<STR_LIT>" , [ ] ) <EOL> self . update_menu ( TAB_MENU , menus , "<STR_LIT>" in submenu ) <EOL> else : <EOL> self . remove_menu ( TAB_MENU ) <EOL> def update_menu ( name = "<STR_LIT>" ) : <EOL> """<STR_LIT>""" <EOL> menu_updater = MenuUpdater ( name ) <EOL> menu_updater . update_context_menu ( ) <EOL> menu_updater . update_sidebar_menu ( ) <EOL> menu_updater . update_tab_menu ( ) <EOL> def refresh_menu ( ) : <EOL> """<STR_LIT>""" <EOL> update_menu ( ) <EOL> debug ( "<STR_LIT>" ) <EOL> settings = load_settings ( ) <EOL> settings . clear_on_change ( '<STR_LIT>' ) <EOL> settings . add_on_change ( '<STR_LIT>' , refresh_menu ) <EOL> def plugin_loaded ( ) : <EOL> """<STR_LIT>""" <EOL> refresh_menu ( ) </s>
