<s> from collections import namedtuple <EOL> import sublime <EOL> from sublime_plugin import WindowCommand <EOL> from . . git_command import GitCommand <EOL> from ... common import util <EOL> MenuOption = namedtuple ( "<STR_LIT>" , [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:filename>" , "<STR_LIT>" ] ) <EOL> CLEAN_WORKING_DIR = "<STR_LIT>" <EOL> ADD_ALL_UNSTAGED_FILES = "<STR_LIT>" <EOL> ADD_ALL_FILES = "<STR_LIT>" <EOL> STAGED = "<STR_LIT>" <EOL> COMMIT = "<STR_LIT>" <EOL> class GsQuickStageCommand ( WindowCommand , GitCommand ) : <EOL> """<STR_LIT>""" <EOL> def run ( self ) : <EOL> sublime . set_timeout_async ( self . run_async ) <EOL> def run_async ( self ) : <EOL> menu_options = self . get_menu_options ( ) <EOL> menu_entries = [ f . menu_text for f in menu_options ] <EOL> def on_selection ( id ) : <EOL> if id == - <NUM_LIT:1> : <EOL> return <EOL> selection = menu_options [ id ] <EOL> if not selection . requires_action : <EOL> return <EOL> elif selection . menu_text == COMMIT : <EOL> self . window . run_command ( "<STR_LIT>" ) <EOL> return <EOL> elif selection . menu_text == ADD_ALL_UNSTAGED_FILES : <EOL> self . git ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:.>" ) <EOL> scope_of_action = "<STR_LIT>" <EOL> elif selection . menu_text == ADD_ALL_FILES : <EOL> self . git ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> scope_of_action = "<STR_LIT>" <EOL> elif selection . is_untracked : <EOL> self . git ( "<STR_LIT>" , "<STR_LIT>" , selection . filename ) <EOL> scope_of_action = "<STR_LIT>" . format ( selection . filename ) <EOL> else : <EOL> self . git ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , selection . filename ) <EOL> scope_of_action = "<STR_LIT>" . format ( selection . filename ) <EOL> sublime . status_message ( "<STR_LIT>" . format ( <EOL> scope_of_action ) ) <EOL> util . view . refresh_gitsavvy ( self . window . active_view ( ) ) <EOL> sublime . set_timeout_async ( self . run_async , <NUM_LIT:0> ) <EOL> self . window . show_quick_panel ( <EOL> menu_entries , <EOL> on_selection , <EOL> flags = sublime . MONOSPACE_FONT <EOL> ) <EOL> def get_menu_options ( self ) : <EOL> """<STR_LIT>""" <EOL> status_entries = self . get_status ( ) <EOL> if not status_entries : <EOL> return [ MenuOption ( False , CLEAN_WORKING_DIR , None , None ) ] <EOL> menu_options = [ ] <EOL> staged_count = <NUM_LIT:0> <EOL> unstaged_count = <NUM_LIT:0> <EOL> for entry in status_entries : <EOL> if entry . index_status != "<STR_LIT:?>" and entry . index_status != "<STR_LIT:U+0020>" : <EOL> staged_count += <NUM_LIT:1> <EOL> if entry . working_status in ( "<STR_LIT:M>" , "<STR_LIT:D>" , "<STR_LIT:?>" ) : <EOL> unstaged_count += <NUM_LIT:1> <EOL> filename = ( entry . path if not entry . index_status == "<STR_LIT:R>" <EOL> else entry . path + "<STR_LIT>" + entry . path_alt ) <EOL> menu_text = "<STR_LIT>" . format ( entry . working_status , filename ) <EOL> menu_options . append ( MenuOption ( True , menu_text , filename , entry . index_status == "<STR_LIT:?>" ) ) <EOL> if unstaged_count > <NUM_LIT:0> : <EOL> menu_options . append ( MenuOption ( True , ADD_ALL_UNSTAGED_FILES , None , None ) ) <EOL> menu_options . append ( MenuOption ( True , ADD_ALL_FILES , None , None ) ) <EOL> if staged_count > <NUM_LIT:0> : <EOL> menu_options . append ( MenuOption ( False , STAGED . format ( staged_count ) , None , None ) ) <EOL> menu_options . append ( MenuOption ( True , COMMIT , None , None ) ) <EOL> return menu_options </s>
