<s> import sublime , sublime_plugin <EOL> from os import path <EOL> gte_st3 = int ( sublime . version ( ) ) >= <NUM_LIT> <EOL> if gte_st3 : <EOL> from . config import * <EOL> else : <EOL> from config import * <EOL> class HiveAddToFavorCommand ( sublime_plugin . WindowCommand ) : <EOL> def run ( self ) : <EOL> filename = self . get_file_name ( ) <EOL> conf = sublime . load_settings ( CONFIG_BASE_NAME ) <EOL> index = self . index_in_list ( filename , conf ) <EOL> if index == - <NUM_LIT:1> : <EOL> self . add_to_list ( filename , conf ) <EOL> sublime . status_message ( '<STR_LIT>' % filename ) <EOL> else : <EOL> self . remove_from_list ( index , conf ) <EOL> sublime . status_message ( '<STR_LIT>' % filename ) <EOL> def is_visible ( self ) : <EOL> return bool ( self . get_file_name ( ) ) <EOL> def description ( self ) : <EOL> filename = self . get_file_name ( ) <EOL> if not filename : return '<STR_LIT>' <EOL> if self . index_in_list ( filename ) == - <NUM_LIT:1> : <EOL> return '<STR_LIT>' <EOL> else : <EOL> return '<STR_LIT>' <EOL> def index_in_list ( self , filename , conf = None ) : <EOL> if conf == None : <EOL> conf = sublime . load_settings ( CONFIG_BASE_NAME ) <EOL> file_list = [ item [ <NUM_LIT:0> ] for item in conf . get ( '<STR_LIT>' , [ ] ) ] <EOL> return file_list . index ( filename ) if filename in file_list else - <NUM_LIT:1> <EOL> def add_to_list ( self , filename , conf ) : <EOL> file_list = conf . get ( '<STR_LIT>' , [ ] ) <EOL> basename = path . basename ( filename ) <EOL> name , ext = path . splitext ( basename ) <EOL> desc = name if ext in [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] else basename <EOL> file_list . append ( [ filename , desc ] ) <EOL> conf . set ( '<STR_LIT>' , file_list ) <EOL> sublime . save_settings ( CONFIG_BASE_NAME ) <EOL> def remove_from_list ( self , index , conf ) : <EOL> file_list = conf . get ( '<STR_LIT>' , [ ] ) <EOL> file_list . pop ( index ) <EOL> conf . set ( '<STR_LIT>' , file_list ) <EOL> sublime . save_settings ( CONFIG_BASE_NAME ) <EOL> def get_file_name ( self ) : <EOL> view = self . window . active_view ( ) <EOL> return ( view . file_name ( ) or '<STR_LIT>' if view else '<STR_LIT>' ) </s>
