<s> """<STR_LIT>""" <EOL> import sublime_plugin <EOL> import sublime <EOL> import time <EOL> import sys <EOL> from TabsExtra import tab_menu <EOL> from os . path import exists , split , splitext , join , normpath , basename , dirname , isdir <EOL> from os import rename <EOL> import functools <EOL> from operator import itemgetter <EOL> SHEET_WORKAROUND = int ( sublime . version ( ) ) < <NUM_LIT> <EOL> CUSTOM_OPEN_FOCUS = int ( sublime . version ( ) ) >= <NUM_LIT> <EOL> SETTINGS = "<STR_LIT>" <EOL> LEFT = <NUM_LIT:0> <EOL> RIGHT = <NUM_LIT:1> <EOL> LAST = <NUM_LIT:2> <EOL> LAST_ACTIVE = None <EOL> OVERRIDE_CONFIRM = '''<STR_LIT>''' <EOL> RESTORE_CONFIRM = '''<STR_LIT>''' <EOL> def log ( msg , status = False ) : <EOL> """<STR_LIT>""" <EOL> string = str ( msg ) <EOL> print ( "<STR_LIT>" % string ) <EOL> if status : <EOL> sublime . status_message ( string ) <EOL> def debug ( s ) : <EOL> """<STR_LIT>""" <EOL> if sublime . load_settings ( SETTINGS ) . get ( "<STR_LIT>" , False ) : <EOL> log ( s ) <EOL> def sublime_format_path ( pth ) : <EOL> """<STR_LIT>""" <EOL> import re <EOL> m = re . match ( r"<STR_LIT>" , pth ) <EOL> if sublime . platform ( ) == "<STR_LIT>" and m is not None : <EOL> pth = m . group ( <NUM_LIT:1> ) + "<STR_LIT:/>" + m . group ( <NUM_LIT:2> ) <EOL> return pth . replace ( "<STR_LIT:\\>" , "<STR_LIT:/>" ) <EOL> def is_persistent ( ) : <EOL> """<STR_LIT>""" <EOL> return sublime . load_settings ( SETTINGS ) . get ( "<STR_LIT>" , False ) <EOL> def sort_on_load_save ( ) : <EOL> """<STR_LIT>""" <EOL> return sublime . load_settings ( SETTINGS ) . get ( "<STR_LIT>" , False ) <EOL> def view_spawn_pos ( ) : <EOL> """<STR_LIT>""" <EOL> return sublime . load_settings ( SETTINGS ) . get ( "<STR_LIT>" , "<STR_LIT:none>" ) <EOL> def get_fallback_direction ( ) : <EOL> """<STR_LIT>""" <EOL> mode = LEFT <EOL> value = sublime . load_settings ( SETTINGS ) . get ( "<STR_LIT>" , "<STR_LIT:left>" ) <EOL> if value == "<STR_LIT>" : <EOL> mode = LAST <EOL> elif value == "<STR_LIT:right>" : <EOL> mode = RIGHT <EOL> return mode <EOL> def timestamp_view ( window , sheet ) : <EOL> """<STR_LIT>""" <EOL> global LAST_ACTIVE <EOL> view = window . active_view ( ) <EOL> if view is None : <EOL> return <EOL> if ( <EOL> LAST_ACTIVE is not None and <EOL> not LAST_ACTIVE . settings ( ) . get ( "<STR_LIT>" , False ) and <EOL> LAST_ACTIVE . window ( ) is None <EOL> ) : <EOL> window = view . window ( ) <EOL> active_group , active_index = window . get_sheet_index ( sheet ) <EOL> LAST_ACTIVE . settings ( ) . set ( "<STR_LIT>" , [ window . id ( ) , active_group ] ) <EOL> LAST_ACTIVE = None <EOL> allow = False <EOL> else : <EOL> allow = True <EOL> if allow : <EOL> window = view . window ( ) <EOL> active_group , active_index = window . get_sheet_index ( sheet ) <EOL> view . settings ( ) . set ( '<STR_LIT>' , time . time ( ) ) <EOL> view . settings ( ) . set ( '<STR_LIT>' , active_index ) <EOL> LAST_ACTIVE = view <EOL> debug ( "<STR_LIT>" % view . file_name ( ) ) <EOL> else : <EOL> debug ( "<STR_LIT>" % view . file_name ( ) ) <EOL> def get_group_view ( window , group , index ) : <EOL> """<STR_LIT>""" <EOL> if SHEET_WORKAROUND : <EOL> active_sheet = window . active_sheet ( ) <EOL> protect_focus = False <EOL> if TabsExtraListener . extra_command_call is False : <EOL> TabsExtraListener . extra_command_call = True <EOL> protect_focus = True <EOL> sheets = window . sheets_in_group ( int ( group ) ) <EOL> sheet = sheets [ index ] if index < len ( sheets ) else None <EOL> if SHEET_WORKAROUND : <EOL> if sheet is not None : <EOL> window . focus_sheet ( sheet ) <EOL> view = window . active_view ( ) <EOL> window . focus_sheet ( active_sheet ) <EOL> if protect_focus : <EOL> TabsExtraListener . extra_command_call = False <EOL> else : <EOL> view = sheet . view ( ) if sheet is not None else None <EOL> return view <EOL> class Focus ( object ) : <EOL> """<STR_LIT>""" <EOL> win = None <EOL> obj = None <EOL> @ classmethod <EOL> def cancel ( cls ) : <EOL> """<STR_LIT>""" <EOL> cls . win = None <EOL> cls . obj = None <EOL> @ classmethod <EOL> def defer ( cls , win , obj ) : <EOL> """<STR_LIT>""" <EOL> if cls . win is None and cls . obj is None : <EOL> cls . win = win <EOL> cls . obj = obj <EOL> sublime . set_timeout ( cls . on_focus , <NUM_LIT:100> ) <EOL> else : <EOL> cls . win = win <EOL> cls . obj = obj <EOL> @ classmethod <EOL> def on_focus ( cls ) : <EOL> """<STR_LIT>""" <EOL> cls . _focus ( ) <EOL> @ classmethod <EOL> def focus ( cls , win , obj ) : <EOL> """<STR_LIT>""" <EOL> cls . win = win <EOL> cls . obj = obj <EOL> cls . _focus ( ) <EOL> @ classmethod <EOL> def _focus ( cls ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> if cls . win is not None and cls . obj is not None : <EOL> if isinstance ( cls . obj , sublime . View ) : <EOL> cls . win . focus_view ( cls . obj ) <EOL> timestamp_view ( cls . win , cls . obj ) <EOL> elif isinstance ( cls . obj , sublime . Sheet ) : <EOL> cls . win . focus_sheet ( cls . obj ) <EOL> timestamp_view ( cls . win , cls . obj ) <EOL> except Exception : <EOL> pass <EOL> cls . cancel ( ) <EOL> class TabsExtraClearAllStickyCommand ( sublime_plugin . WindowCommand ) : <EOL> """<STR_LIT>""" <EOL> def run ( self , group = - <NUM_LIT:1> , force = False ) : <EOL> """<STR_LIT>""" <EOL> if group == - <NUM_LIT:1> : <EOL> group = self . window . active_group ( ) <EOL> if group >= <NUM_LIT:0> : <EOL> persistent = is_persistent ( ) <EOL> views = self . window . views_in_group ( int ( group ) ) <EOL> if not persistent or force : <EOL> for v in views : <EOL> v . settings ( ) . erase ( "<STR_LIT>" ) <EOL> def is_visible ( self , group = - <NUM_LIT:1> , force = False ) : <EOL> """<STR_LIT>""" <EOL> if group == - <NUM_LIT:1> : <EOL> group = self . window . active_group ( ) <EOL> marked = False <EOL> views = self . window . views_in_group ( int ( group ) ) <EOL> for v in views : <EOL> if v . settings ( ) . get ( "<STR_LIT>" , False ) : <EOL> marked = True <EOL> break <EOL> return marked <EOL> class TabsExtraToggleStickyCommand ( sublime_plugin . WindowCommand ) : <EOL> """<STR_LIT>""" <EOL> def run ( self , group = - <NUM_LIT:1> , index = - <NUM_LIT:1> ) : <EOL> """<STR_LIT>""" <EOL> if group >= <NUM_LIT:0> and index >= <NUM_LIT:0> : <EOL> view = get_group_view ( self . window , group , index ) <EOL> if view is not None : <EOL> if not view . settings ( ) . get ( "<STR_LIT>" , False ) : <EOL> view . settings ( ) . set ( "<STR_LIT>" , True ) <EOL> else : <EOL> view . settings ( ) . erase ( "<STR_LIT>" ) <EOL> def is_checked ( self , group = - <NUM_LIT:1> , index = - <NUM_LIT:1> ) : <EOL> """<STR_LIT>""" <EOL> checked = False <EOL> if group >= <NUM_LIT:0> and index >= <NUM_LIT:0> : <EOL> view = get_group_view ( self . window , group , index ) <EOL> if view is not None : <EOL> checked = view . settings ( ) . get ( "<STR_LIT>" , False ) <EOL> return checked <EOL> class TabsExtraSetStickyCommand ( sublime_plugin . TextCommand ) : <EOL> """<STR_LIT>""" <EOL> def run ( self , edit , value ) : <EOL> """<STR_LIT>""" <EOL> if self . is_enabled ( value ) : <EOL> self . view . settings ( ) . set ( "<STR_LIT>" , bool ( value ) ) <EOL> def is_enabled ( self , value ) : <EOL> """<STR_LIT>""" <EOL> enabled = False <EOL> if self . view is not None : <EOL> current_value = self . view . settings ( ) . get ( "<STR_LIT>" , False ) <EOL> if current_value != value : <EOL> enabled = True <EOL> return enabled <EOL> class TabsExtraCloseMenuCommand ( sublime_plugin . WindowCommand ) : <EOL> """<STR_LIT>""" <EOL> close_types = [ <EOL> ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ( "<STR_LIT>" , "<STR_LIT:right>" ) , <EOL> ( "<STR_LIT>" , "<STR_LIT:left>" ) , <EOL> ( "<STR_LIT>" , "<STR_LIT:all>" ) <EOL> ] <EOL> def run ( self , mode = "<STR_LIT>" , close_type = None ) : <EOL> """<STR_LIT>""" <EOL> self . mode = mode <EOL> self . group = - <NUM_LIT:1> <EOL> self . index = - <NUM_LIT:1> <EOL> sheet = self . window . active_sheet ( ) <EOL> if sheet is not None : <EOL> self . group , self . index = self . window . get_sheet_index ( sheet ) <EOL> if self . group != - <NUM_LIT:1> and self . index != - <NUM_LIT:1> : <EOL> value = None <EOL> if close_type is not None : <EOL> index = <NUM_LIT:0> <EOL> for ct in self . close_types : <EOL> if ct [ <NUM_LIT:1> ] == close_type : <EOL> value = index <EOL> index += <NUM_LIT:1> <EOL> if value is None : <EOL> self . window . show_quick_panel ( <EOL> [ x [ <NUM_LIT:0> ] for x in self . close_types ] , <EOL> self . check_selection <EOL> ) <EOL> else : <EOL> self . check_selection ( value ) <EOL> def check_selection ( self , value ) : <EOL> """<STR_LIT>""" <EOL> if value != - <NUM_LIT:1> : <EOL> close_unsaved = True <EOL> unsaved_prompt = True <EOL> if self . mode == "<STR_LIT>" : <EOL> close_unsaved = False <EOL> if self . mode == "<STR_LIT>" : <EOL> unsaved_prompt = False <EOL> close_type = self . close_types [ value ] [ <NUM_LIT:1> ] <EOL> self . window . run_command ( <EOL> "<STR_LIT>" , <EOL> { <EOL> "<STR_LIT>" : int ( self . group ) , <EOL> "<STR_LIT:index>" : int ( self . index ) , <EOL> "<STR_LIT>" : close_type , <EOL> "<STR_LIT>" : unsaved_prompt , <EOL> "<STR_LIT>" : close_unsaved <EOL> } <EOL> ) <EOL> def is_enabled ( self , mode = "<STR_LIT>" ) : <EOL> """<STR_LIT>""" <EOL> group = - <NUM_LIT:1> <EOL> index = - <NUM_LIT:1> <EOL> sheet = self . window . active_sheet ( ) <EOL> if sheet is not None : <EOL> group , index = self . window . get_sheet_index ( sheet ) <EOL> return group != - <NUM_LIT:1> and index != - <NUM_LIT:1> and mode in [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] <EOL> class TabsExtraCloseAllCommand ( sublime_plugin . WindowCommand ) : <EOL> """<STR_LIT>""" <EOL> def run ( self ) : <EOL> """<STR_LIT>""" <EOL> for group in range ( <NUM_LIT:0> , self . window . num_groups ( ) ) : <EOL> sheet = self . window . active_sheet_in_group ( group ) <EOL> if sheet is not None : <EOL> index = self . window . get_sheet_index ( sheet ) [ <NUM_LIT:1> ] <EOL> self . window . run_command ( "<STR_LIT>" , { "<STR_LIT>" : "<STR_LIT:all>" , "<STR_LIT>" : group , "<STR_LIT:index>" : index } ) <EOL> class TabsExtraCloseCommand ( sublime_plugin . WindowCommand ) : <EOL> """<STR_LIT>""" <EOL> def init ( self , close_type , group , index ) : <EOL> """<STR_LIT>""" <EOL> self . persistent = is_persistent ( ) <EOL> self . sheets = self . window . sheets_in_group ( int ( group ) ) <EOL> assert ( close_type in [ "<STR_LIT>" , "<STR_LIT:left>" , "<STR_LIT:right>" , "<STR_LIT>" , "<STR_LIT:all>" ] ) <EOL> active_sheet = self . window . active_sheet ( ) <EOL> active_index = None <EOL> self . active_index = index <EOL> self . active_group = None <EOL> if active_sheet is not None : <EOL> active_group , active_index = self . window . get_sheet_index ( active_sheet ) <EOL> if group != active_group : <EOL> active_index = None <EOL> if active_index is not None : <EOL> self . active_index = active_index <EOL> self . last_activated = [ ] <EOL> if get_fallback_direction ( ) == LAST : <EOL> for s in self . sheets : <EOL> if SHEET_WORKAROUND : <EOL> self . window . focus_sheet ( s ) <EOL> v = self . window . active_view ( ) <EOL> else : <EOL> v = s . view ( ) <EOL> if v is not None : <EOL> last_activated = v . settings ( ) . get ( "<STR_LIT>" , None ) <EOL> if last_activated is not None : <EOL> self . last_activated . append ( ( last_activated , s ) ) <EOL> else : <EOL> self . last_activated . append ( ( <NUM_LIT:0> , s ) ) <EOL> if close_type == "<STR_LIT>" : <EOL> self . targets = [ self . sheets [ index ] ] <EOL> self . cleanup = bool ( len ( self . sheets [ : index ] + self . sheets [ index + <NUM_LIT:1> : ] ) ) <EOL> elif close_type == "<STR_LIT:left>" : <EOL> self . targets = self . sheets [ : index ] <EOL> self . cleanup = bool ( len ( self . sheets [ index : ] ) ) <EOL> elif close_type == "<STR_LIT:right>" : <EOL> self . targets = self . sheets [ index + <NUM_LIT:1> : ] <EOL> self . cleanup = bool ( len ( self . sheets [ : index + <NUM_LIT:1> ] ) ) <EOL> elif close_type == "<STR_LIT>" : <EOL> self . targets = self . sheets [ : index ] + self . sheets [ index + <NUM_LIT:1> : ] <EOL> self . cleanup = True <EOL> elif close_type == "<STR_LIT:all>" : <EOL> self . targets = self . sheets [ : ] <EOL> self . cleanup = False <EOL> def select_left ( self , fallback = True ) : <EOL> """<STR_LIT>""" <EOL> selected = False <EOL> for x in reversed ( range ( <NUM_LIT:0> , self . active_index ) ) : <EOL> if self . window . get_sheet_index ( self . sheets [ x ] ) [ <NUM_LIT:1> ] != - <NUM_LIT:1> : <EOL> Focus . defer ( self . window , self . sheets [ x ] ) <EOL> selected = True <EOL> break <EOL> if fallback and not selected : <EOL> selected = self . select_left ( False ) <EOL> return selected <EOL> def select_right ( self , fallback = True ) : <EOL> """<STR_LIT>""" <EOL> selected = False <EOL> for x in range ( self . active_index + <NUM_LIT:1> , len ( self . sheets ) ) : <EOL> if self . window . get_sheet_index ( self . sheets [ x ] ) [ <NUM_LIT:1> ] != - <NUM_LIT:1> : <EOL> Focus . defer ( self . window , self . sheets [ x ] ) <EOL> selected = True <EOL> break <EOL> if fallback and not selected : <EOL> selected = self . select_right ( False ) <EOL> return selected <EOL> def select_last ( self , fallback = True ) : <EOL> """<STR_LIT>""" <EOL> selected = False <EOL> self . last_activated = sorted ( self . last_activated , key = lambda x : x [ <NUM_LIT:0> ] ) <EOL> if len ( self . last_activated ) : <EOL> for s in reversed ( self . last_activated ) : <EOL> if self . window . get_sheet_index ( s [ <NUM_LIT:1> ] ) [ <NUM_LIT:1> ] != - <NUM_LIT:1> : <EOL> Focus . defer ( self . window , s [ <NUM_LIT:1> ] ) <EOL> selected = True <EOL> break <EOL> if fallback and not selected : <EOL> selected = self . select_left ( False ) <EOL> if fallback and not selected : <EOL> selected = self . select_right ( False ) <EOL> return selected <EOL> def select_view ( self ) : <EOL> """<STR_LIT>""" <EOL> selected = False <EOL> if self . active_index is not None : <EOL> fallback_mode = get_fallback_direction ( ) <EOL> if self . window . get_sheet_index ( self . sheets [ self . active_index ] ) [ <NUM_LIT:1> ] != - <NUM_LIT:1> : <EOL> self . window . focus_sheet ( self . sheets [ self . active_index ] ) <EOL> selected = True <EOL> elif fallback_mode == LAST : <EOL> selected = self . select_last ( ) <EOL> elif fallback_mode == RIGHT : <EOL> selected = self . select_right ( ) <EOL> else : <EOL> selected = self . select_left ( ) <EOL> return selected <EOL> def run ( <EOL> self , group = - <NUM_LIT:1> , index = - <NUM_LIT:1> , <EOL> close_type = "<STR_LIT>" , unsaved_prompt = True , close_unsaved = True <EOL> ) : <EOL> """<STR_LIT>""" <EOL> TabsExtraListener . extra_command_call = True <EOL> if group >= <NUM_LIT:0> and index >= <NUM_LIT:0> : <EOL> self . init ( close_type , group , index ) <EOL> if ( <EOL> len ( self . targets ) and <EOL> not unsaved_prompt and <EOL> not sublime . ok_cancel_dialog ( <EOL> "<STR_LIT>" <EOL> ) <EOL> ) : <EOL> return <EOL> for s in self . targets : <EOL> if SHEET_WORKAROUND : <EOL> self . window . focus_sheet ( s ) <EOL> v = self . window . active_view ( ) <EOL> else : <EOL> v = s . view ( ) <EOL> if v is not None : <EOL> if not v . settings ( ) . get ( "<STR_LIT>" , False ) or close_type == "<STR_LIT>" : <EOL> if not self . persistent : <EOL> v . settings ( ) . erase ( "<STR_LIT>" ) <EOL> self . window . focus_view ( v ) <EOL> if not v . is_dirty ( ) or close_unsaved : <EOL> if not unsaved_prompt : <EOL> v . set_scratch ( True ) <EOL> self . window . run_command ( "<STR_LIT>" ) <EOL> elif not self . persistent : <EOL> v . settings ( ) . erase ( "<STR_LIT>" ) <EOL> else : <EOL> self . window . run_command ( "<STR_LIT>" ) <EOL> if not self . persistent and self . cleanup : <EOL> self . window . run_command ( "<STR_LIT>" , { "<STR_LIT>" : group } ) <EOL> self . select_view ( ) <EOL> TabsExtraListener . extra_command_call = False <EOL> class TabsExtraListener ( sublime_plugin . EventListener ) : <EOL> """<STR_LIT>""" <EOL> extra_command_call = False <EOL> def on_window_command ( self , window , command_name , args ) : <EOL> """<STR_LIT>""" <EOL> extra_command_call = TabsExtraListener . extra_command_call <EOL> cmd = None <EOL> if args is None : <EOL> view = window . active_view ( ) <EOL> if view is None : <EOL> return cmd <EOL> if extra_command_call and command_name == "<STR_LIT>" : <EOL> view . settings ( ) . set ( "<STR_LIT>" , True ) <EOL> return cmd <EOL> group , index = window . get_view_index ( view ) <EOL> args = { "<STR_LIT>" : group , "<STR_LIT:index>" : index } <EOL> if command_name in [ "<STR_LIT>" , "<STR_LIT>" ] : <EOL> command_name = "<STR_LIT>" <EOL> args [ "<STR_LIT>" ] = "<STR_LIT>" <EOL> cmd = ( command_name , args ) <EOL> elif command_name == "<STR_LIT>" : <EOL> command_name = "<STR_LIT>" <EOL> args = { } <EOL> cmd = ( command_name , args ) <EOL> elif command_name == "<STR_LIT>" : <EOL> command_name = "<STR_LIT>" <EOL> args [ "<STR_LIT>" ] = "<STR_LIT>" <EOL> cmd = ( command_name , args ) <EOL> elif command_name == "<STR_LIT>" : <EOL> command_name = "<STR_LIT>" <EOL> args [ "<STR_LIT>" ] = "<STR_LIT:right>" <EOL> cmd = ( command_name , args ) <EOL> return cmd <EOL> def on_load ( self , view ) : <EOL> """<STR_LIT>""" <EOL> Focus . cancel ( ) <EOL> if sort_on_load_save ( ) : <EOL> if not self . on_sort ( view ) : <EOL> view . settings ( ) . set ( '<STR_LIT>' , True ) <EOL> else : <EOL> if CUSTOM_OPEN_FOCUS : <EOL> self . on_spawn ( view ) <EOL> def on_spawn ( self , view ) : <EOL> """<STR_LIT>""" <EOL> window = view . window ( ) <EOL> if window and window . get_view_index ( view ) [ <NUM_LIT:1> ] != - <NUM_LIT:1> : <EOL> loaded = view . settings ( ) . get ( "<STR_LIT>" , False ) <EOL> if not loaded : <EOL> sheet = window . active_sheet ( ) <EOL> spawn = view_spawn_pos ( ) <EOL> if spawn != "<STR_LIT:none>" : <EOL> sheets = window . sheets ( ) <EOL> group , index = window . get_sheet_index ( sheet ) <EOL> last_group = None <EOL> last_index = None <EOL> if LAST_ACTIVE is not None : <EOL> for s in sheets : <EOL> v = s . view ( ) <EOL> if v is not None and LAST_ACTIVE . id ( ) == v . id ( ) : <EOL> last_group , last_index = window . get_sheet_index ( s ) <EOL> break <EOL> active_in_range = ( <EOL> last_group is not None and <EOL> last_index is not None and <EOL> last_group == group <EOL> ) <EOL> if spawn == "<STR_LIT:right>" : <EOL> group , index = window . get_sheet_index ( sheets [ - <NUM_LIT:1> ] ) <EOL> window . set_sheet_index ( sheet , group , index ) <EOL> elif spawn == "<STR_LIT:left>" : <EOL> group , index = window . get_sheet_index ( sheets [ <NUM_LIT:0> ] ) <EOL> window . set_sheet_index ( sheet , group , index ) <EOL> elif spawn == "<STR_LIT>" and active_in_range : <EOL> window . set_sheet_index ( sheet , group , last_index + <NUM_LIT:1> ) <EOL> elif spawn == "<STR_LIT>" and active_in_range : <EOL> window . set_sheet_index ( sheet , group , last_index ) <EOL> view . settings ( ) . set ( "<STR_LIT>" , True ) <EOL> def on_post_save ( self , view ) : <EOL> """<STR_LIT>""" <EOL> if sort_on_load_save ( ) : <EOL> self . on_sort ( view ) <EOL> def on_sort ( self , view ) : <EOL> """<STR_LIT>""" <EOL> sorted_views = False <EOL> window = view . window ( ) <EOL> if window and window . get_view_index ( view ) [ <NUM_LIT:1> ] != - <NUM_LIT:1> : <EOL> cmd = sublime . load_settings ( SETTINGS ) . get ( "<STR_LIT>" , { } ) <EOL> module = str ( cmd . get ( "<STR_LIT>" , "<STR_LIT>" ) ) <EOL> reverse = bool ( cmd . get ( "<STR_LIT>" , False ) ) <EOL> if module != "<STR_LIT>" : <EOL> window . run_command ( <EOL> "<STR_LIT>" , <EOL> { "<STR_LIT>" : module , "<STR_LIT>" : reverse } <EOL> ) <EOL> sorted_views = True <EOL> return sorted_views <EOL> def on_pre_close ( self , view ) : <EOL> """<STR_LIT>""" <EOL> Focus . cancel ( ) <EOL> view . settings ( ) . set ( "<STR_LIT>" , True ) <EOL> if not view . settings ( ) . get ( "<STR_LIT>" , False ) : <EOL> TabsExtraListener . extra_command_call = True <EOL> window = view . window ( ) <EOL> if window is not None : <EOL> view . settings ( ) . set ( "<STR_LIT>" , view . window ( ) . get_view_index ( view ) ) <EOL> view . settings ( ) . set ( "<STR_LIT>" , view . window ( ) . id ( ) ) <EOL> def on_close ( self , view ) : <EOL> """<STR_LIT>""" <EOL> view_info = view . settings ( ) . get ( "<STR_LIT>" , None ) <EOL> window_info = view . settings ( ) . get ( "<STR_LIT>" , None ) <EOL> if view_info is not None and window_info is not None : <EOL> for w in sublime . windows ( ) : <EOL> if w . id ( ) == window_info : <EOL> window = w <EOL> break <EOL> if window is not None : <EOL> self . select_tab ( window , int ( view_info [ <NUM_LIT:0> ] ) , view_info [ <NUM_LIT:1> ] ) <EOL> TabsExtraListener . extra_command_call = False <EOL> def on_activated ( self , view ) : <EOL> """<STR_LIT>""" <EOL> if not TabsExtraListener . extra_command_call : <EOL> window = view . window ( ) <EOL> if window is None : <EOL> return <EOL> s = window . active_sheet ( ) <EOL> timestamp_view ( window , s ) <EOL> moving = view . settings ( ) . get ( "<STR_LIT>" , None ) <EOL> if moving is not None : <EOL> win_id , group_id = moving <EOL> window = view . window ( ) <EOL> if window is None : <EOL> return <EOL> active_group = window . get_view_index ( view ) [ <NUM_LIT:0> ] <EOL> if window . id ( ) != win_id or int ( group_id ) != int ( active_group ) : <EOL> view . settings ( ) . erase ( "<STR_LIT>" ) <EOL> last_index = view . settings ( ) . get ( '<STR_LIT>' , - <NUM_LIT:1> ) <EOL> self . on_move ( view , win_id , int ( group_id ) , last_index ) <EOL> elif sort_on_load_save ( ) and view . settings ( ) . get ( '<STR_LIT>' ) : <EOL> view . settings ( ) . erase ( '<STR_LIT>' ) <EOL> self . on_sort ( view ) <EOL> def on_move ( self , view , win_id , group_id , last_index ) : <EOL> """<STR_LIT>""" <EOL> for w in sublime . windows ( ) : <EOL> if w . id ( ) == win_id : <EOL> self . select_tab ( w , group_id , last_index ) <EOL> break <EOL> def select_tab ( self , window , group_id , last_index ) : <EOL> """<STR_LIT>""" <EOL> selected = False <EOL> sheets = window . sheets_in_group ( group_id ) <EOL> fallback_mode = get_fallback_direction ( ) <EOL> if len ( sheets ) == <NUM_LIT:0> : <EOL> return <EOL> if last_index >= <NUM_LIT:0> : <EOL> if fallback_mode == LAST : <EOL> selected = self . select_last ( sheets , window , last_index ) <EOL> elif fallback_mode == RIGHT : <EOL> selected = self . select_right ( sheets , window , last_index ) <EOL> else : <EOL> selected = self . select_left ( sheets , window , last_index ) <EOL> return selected <EOL> def select_last ( self , sheets , window , closed_index , fallback = True ) : <EOL> """<STR_LIT>""" <EOL> selected = False <EOL> last_activated = [ ] <EOL> for s in sheets : <EOL> if SHEET_WORKAROUND : <EOL> window . focus_sheet ( s ) <EOL> v = window . active_view ( ) <EOL> else : <EOL> v = s . view ( ) <EOL> if v is not None : <EOL> last = v . settings ( ) . get ( "<STR_LIT>" , None ) <EOL> if last is not None : <EOL> last_activated . append ( ( last , s ) ) <EOL> else : <EOL> last_activated . append ( ( <NUM_LIT:0> , s ) ) <EOL> last_activated = sorted ( last_activated , key = lambda x : x [ <NUM_LIT:0> ] ) <EOL> if len ( last_activated ) : <EOL> Focus . defer ( window , last_activated [ - <NUM_LIT:1> ] [ <NUM_LIT:1> ] ) <EOL> selected = True <EOL> if not selected and fallback : <EOL> selected = self . select_left ( sheets , window , closed_index , False ) <EOL> if not selected and fallback : <EOL> selected = self . select_right ( sheets , window , closed_index , False ) <EOL> return selected <EOL> def select_right ( self , sheets , window , closed_index , fallback = True ) : <EOL> """<STR_LIT>""" <EOL> selected = False <EOL> if len ( sheets ) > closed_index : <EOL> Focus . defer ( window , sheets [ closed_index ] ) <EOL> selected = True <EOL> if not selected and fallback : <EOL> selected = self . select_left ( sheets , window , closed_index , False ) <EOL> return selected <EOL> def select_left ( self , sheets , window , closed_index , fallback = True ) : <EOL> """<STR_LIT>""" <EOL> selected = False <EOL> if len ( sheets ) >= closed_index : <EOL> Focus . defer ( window , sheets [ closed_index - <NUM_LIT:1> ] ) <EOL> selected = True <EOL> if not selected and fallback : <EOL> selected = self . select_right ( sheets , window , closed_index , False ) <EOL> return selected <EOL> class TabsExtraViewWrapperCommand ( sublime_plugin . WindowCommand ) : <EOL> """<STR_LIT>""" <EOL> def run ( self , command , group = - <NUM_LIT:1> , index = - <NUM_LIT:1> , args = { } ) : <EOL> """<STR_LIT>""" <EOL> if group >= <NUM_LIT:0> and index >= <NUM_LIT:0> : <EOL> view = get_group_view ( self . window , group , index ) <EOL> if view is not None : <EOL> self . window . focus_view ( view ) <EOL> self . window . run_command ( command , args ) <EOL> class TabsExtraDeleteCommand ( sublime_plugin . WindowCommand ) : <EOL> """<STR_LIT>""" <EOL> def run ( self , group = - <NUM_LIT:1> , index = - <NUM_LIT:1> ) : <EOL> """<STR_LIT>""" <EOL> if group >= <NUM_LIT:0> and index >= <NUM_LIT:0> : <EOL> view = get_group_view ( self . window , group , index ) <EOL> if view is not None : <EOL> file_name = view . file_name ( ) <EOL> if file_name is not None and exists ( file_name ) : <EOL> if sublime . ok_cancel_dialog ( "<STR_LIT>" % file_name , "<STR_LIT>" ) : <EOL> if not view . close ( ) : <EOL> return <EOL> import Default . send2trash as send2trash <EOL> send2trash . send2trash ( file_name ) <EOL> def is_visible ( self , group = - <NUM_LIT:1> , index = - <NUM_LIT:1> ) : <EOL> """<STR_LIT>""" <EOL> enabled = False <EOL> if group >= <NUM_LIT:0> and index >= <NUM_LIT:0> : <EOL> view = get_group_view ( self . window , group , index ) <EOL> if view is not None and view . file_name ( ) is not None and exists ( view . file_name ( ) ) : <EOL> enabled = True <EOL> return enabled <EOL> class TabsExtraDuplicateCommand ( sublime_plugin . WindowCommand ) : <EOL> """<STR_LIT>""" <EOL> def run ( self , group = - <NUM_LIT:1> , index = - <NUM_LIT:1> ) : <EOL> """<STR_LIT>""" <EOL> if group >= <NUM_LIT:0> and index >= <NUM_LIT:0> : <EOL> view = get_group_view ( self . window , group , index ) <EOL> if view is not None : <EOL> file_name = view . file_name ( ) <EOL> if file_name is not None and exists ( file_name ) : <EOL> v = self . window . show_input_panel ( <EOL> "<STR_LIT>" , file_name , <EOL> lambda x : self . on_done ( file_name , x ) , <EOL> None , None <EOL> ) <EOL> file_path_len = len ( file_name ) <EOL> file_name_len = len ( basename ( file_name ) ) <EOL> v . sel ( ) . clear ( ) <EOL> v . sel ( ) . add ( <EOL> sublime . Region ( <EOL> file_path_len - file_name_len , <EOL> file_path_len <EOL> ) <EOL> ) <EOL> def on_done ( self , old , new ) : <EOL> """<STR_LIT>""" <EOL> new_path = dirname ( new ) <EOL> if exists ( new_path ) and isdir ( new_path ) : <EOL> if not exists ( new ) or sublime . ok_cancel_dialog ( "<STR_LIT>" % new , "<STR_LIT>" ) : <EOL> try : <EOL> with open ( old , '<STR_LIT:rb>' ) as f : <EOL> text = f . read ( ) <EOL> with open ( new , '<STR_LIT:wb>' ) as f : <EOL> f . write ( text ) <EOL> self . window . open_file ( new ) <EOL> except Exception : <EOL> sublime . status_message ( "<STR_LIT>" ) <EOL> def is_visible ( self , group = - <NUM_LIT:1> , index = - <NUM_LIT:1> ) : <EOL> """<STR_LIT>""" <EOL> enabled = False <EOL> if group >= <NUM_LIT:0> and index >= <NUM_LIT:0> : <EOL> view = get_group_view ( self . window , group , index ) <EOL> if view is not None and view . file_name ( ) is not None and exists ( view . file_name ( ) ) : <EOL> enabled = True <EOL> return enabled <EOL> class TabsExtraRenameCommand ( sublime_plugin . WindowCommand ) : <EOL> """<STR_LIT>""" <EOL> def run ( self , group = - <NUM_LIT:1> , index = - <NUM_LIT:1> ) : <EOL> """<STR_LIT>""" <EOL> if group >= <NUM_LIT:0> and index >= <NUM_LIT:0> : <EOL> view = get_group_view ( self . window , group , index ) <EOL> if view is not None : <EOL> file_name = view . file_name ( ) <EOL> if file_name is not None and exists ( file_name ) : <EOL> branch , leaf = split ( file_name ) <EOL> v = self . window . show_input_panel ( <EOL> "<STR_LIT>" , leaf , <EOL> functools . partial ( self . on_done , file_name , branch ) , <EOL> None , None <EOL> ) <EOL> name = splitext ( leaf ) [ <NUM_LIT:0> ] <EOL> v . sel ( ) . clear ( ) <EOL> v . sel ( ) . add ( sublime . Region ( <NUM_LIT:0> , len ( name ) ) ) <EOL> def on_done ( self , old , branch , leaf ) : <EOL> """<STR_LIT>""" <EOL> new = join ( branch , leaf ) <EOL> try : <EOL> rename ( old , new ) <EOL> v = self . window . find_open_file ( old ) <EOL> if v : <EOL> v . retarget ( new ) <EOL> except Exception : <EOL> sublime . status_message ( "<STR_LIT>" ) <EOL> def is_visible ( self , group = - <NUM_LIT:1> , index = - <NUM_LIT:1> ) : <EOL> """<STR_LIT>""" <EOL> enabled = False <EOL> if group >= <NUM_LIT:0> and index >= <NUM_LIT:0> : <EOL> view = get_group_view ( self . window , group , index ) <EOL> if view is not None and view . file_name ( ) is not None and exists ( view . file_name ( ) ) : <EOL> enabled = True <EOL> return enabled <EOL> class TabsExtraRevertCommand ( TabsExtraViewWrapperCommand ) : <EOL> """<STR_LIT>""" <EOL> def is_visible ( self , command , group = - <NUM_LIT:1> , index = - <NUM_LIT:1> , args = { } ) : <EOL> """<STR_LIT>""" <EOL> enabled = False <EOL> if group >= <NUM_LIT:0> and index >= <NUM_LIT:0> : <EOL> view = get_group_view ( self . window , group , index ) <EOL> if view is not None and view . file_name ( ) is not None : <EOL> enabled = view . is_dirty ( ) <EOL> return enabled <EOL> class TabsExtraFileCommand ( TabsExtraViewWrapperCommand ) : <EOL> """<STR_LIT>""" <EOL> def is_enabled ( self , command , group = - <NUM_LIT:1> , index = - <NUM_LIT:1> , args = { } ) : <EOL> """<STR_LIT>""" <EOL> enabled = False <EOL> if group >= <NUM_LIT:0> and index >= <NUM_LIT:0> : <EOL> view = get_group_view ( self . window , group , index ) <EOL> if view is not None : <EOL> enabled = view . file_name ( ) is not None <EOL> return enabled <EOL> class TabsExtraFilePathCommand ( sublime_plugin . WindowCommand ) : <EOL> """<STR_LIT>""" <EOL> def run ( self , group = - <NUM_LIT:1> , index = - <NUM_LIT:1> , path_type = '<STR_LIT:path>' ) : <EOL> """<STR_LIT>""" <EOL> if group >= <NUM_LIT:0> and index >= <NUM_LIT:0> : <EOL> view = get_group_view ( self . window , group , index ) <EOL> if view is not None : <EOL> self . window . focus_view ( view ) <EOL> view . run_command ( '<STR_LIT>' ) <EOL> pth = sublime . get_clipboard ( ) <EOL> if path_type == '<STR_LIT:name>' : <EOL> pth = basename ( pth ) <EOL> sublime . set_clipboard ( pth ) <EOL> def is_enabled ( self , group = - <NUM_LIT:1> , index = - <NUM_LIT:1> , path_type = '<STR_LIT:path>' ) : <EOL> """<STR_LIT>""" <EOL> enabled = False <EOL> if group >= <NUM_LIT:0> and index >= <NUM_LIT:0> : <EOL> view = get_group_view ( self . window , group , index ) <EOL> if view is not None : <EOL> enabled = view . file_name ( ) is not None <EOL> return enabled <EOL> class TabsExtraSortMenuCommand ( sublime_plugin . WindowCommand ) : <EOL> """<STR_LIT>""" <EOL> def run ( self ) : <EOL> """<STR_LIT>""" <EOL> sort_layout = sublime . load_settings ( SETTINGS ) . get ( "<STR_LIT>" , [ ] ) <EOL> if len ( sort_layout ) : <EOL> self . sort_commands = [ ] <EOL> sort_menu = [ ] <EOL> for sort_entry in sort_layout : <EOL> caption = str ( sort_entry . get ( "<STR_LIT>" , "<STR_LIT>" ) ) <EOL> module = str ( sort_entry . get ( "<STR_LIT>" , "<STR_LIT>" ) ) <EOL> reverse = bool ( sort_entry . get ( "<STR_LIT>" , False ) ) <EOL> if module != "<STR_LIT>" : <EOL> self . sort_commands . append ( ( module , reverse ) ) <EOL> sort_menu . append ( caption ) <EOL> if len ( sort_menu ) : <EOL> self . window . show_quick_panel ( sort_menu , self . check_selection ) <EOL> def check_selection ( self , value ) : <EOL> """<STR_LIT>""" <EOL> if value != - <NUM_LIT:1> : <EOL> command = self . sort_commands [ value ] <EOL> self . window . run_command ( "<STR_LIT>" , { "<STR_LIT>" : command [ <NUM_LIT:0> ] , "<STR_LIT>" : command [ <NUM_LIT:1> ] } ) <EOL> class TabsExtraSortCommand ( sublime_plugin . WindowCommand ) : <EOL> """<STR_LIT>""" <EOL> def run ( self , group = - <NUM_LIT:1> , sort_by = None , reverse = False ) : <EOL> """<STR_LIT>""" <EOL> if sort_by is not None : <EOL> if group == - <NUM_LIT:1> : <EOL> group = self . window . active_group ( ) <EOL> self . group = group <EOL> self . reverse = reverse <EOL> views = self . window . views_in_group ( int ( group ) ) <EOL> if len ( views ) : <EOL> sort_module = self . get_sort_module ( sort_by ) <EOL> if sort_module is not None : <EOL> view_data = [ ] <EOL> sort_module . run ( views , view_data ) <EOL> self . sort ( view_data ) <EOL> self . window . focus_view ( self . window . active_view ( ) ) <EOL> def sort ( self , view_data ) : <EOL> """<STR_LIT>""" <EOL> indexes = tuple ( [ x for x in range ( <NUM_LIT:0> , len ( view_data [ <NUM_LIT:0> ] ) - <NUM_LIT:1> ) ] ) <EOL> sorted_views = sorted ( view_data , key = itemgetter ( * indexes ) ) <EOL> if self . reverse : <EOL> sorted_views = sorted_views [ : : - <NUM_LIT:1> ] <EOL> for index in range ( <NUM_LIT:0> , len ( sorted_views ) ) : <EOL> self . window . set_view_index ( sorted_views [ index ] [ - <NUM_LIT:1> ] , self . group , index ) <EOL> def get_sort_module ( self , module_name ) : <EOL> """<STR_LIT>""" <EOL> import imp <EOL> path_name = join ( "<STR_LIT>" , normpath ( module_name . replace ( '<STR_LIT:.>' , '<STR_LIT:/>' ) ) ) <EOL> path_name += "<STR_LIT>" <EOL> module = imp . new_module ( module_name ) <EOL> sys . modules [ module_name ] = module <EOL> exec ( <EOL> compile ( <EOL> sublime . load_resource ( sublime_format_path ( path_name ) ) , <EOL> module_name , '<STR_LIT>' <EOL> ) , <EOL> sys . modules [ module_name ] . __dict__ <EOL> ) <EOL> return module <EOL> class TabsExtraInstallOverrideMenuCommand ( sublime_plugin . ApplicationCommand ) : <EOL> """<STR_LIT>""" <EOL> def run ( self ) : <EOL> """<STR_LIT>""" <EOL> msg = OVERRIDE_CONFIRM <EOL> if sublime . ok_cancel_dialog ( msg ) : <EOL> tab_menu . upgrade_override_menu ( ) <EOL> class TabsExtraUninstallOverrideMenuCommand ( sublime_plugin . ApplicationCommand ) : <EOL> """<STR_LIT>""" <EOL> def run ( self ) : <EOL> """<STR_LIT>""" <EOL> msg = RESTORE_CONFIRM <EOL> if sublime . ok_cancel_dialog ( msg ) : <EOL> tab_menu . uninstall_override_menu ( ) <EOL> class TabsExtraInstallMenuCommand ( sublime_plugin . ApplicationCommand ) : <EOL> """<STR_LIT>""" <EOL> def run ( self ) : <EOL> """<STR_LIT>""" <EOL> tab_menu . upgrade_default_menu ( ) <EOL> def plugin_loaded ( ) : <EOL> """<STR_LIT>""" <EOL> win = sublime . active_window ( ) <EOL> if win is not None : <EOL> sheet = win . active_sheet ( ) <EOL> if sheet is not None : <EOL> timestamp_view ( win , sheet ) </s>
