Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

55 lines
2.1 KiB

  1. //===== Copyright � 1996-2005, Valve Corporation, All rights reserved. ======//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //===========================================================================//
  7. #ifndef BASEAUTOCOMPLETEFILELIST_H
  8. #define BASEAUTOCOMPLETEFILELIST_H
  9. #ifdef _WIN32
  10. #pragma once
  11. #endif
  12. #include "tier1/convar.h"
  13. //-----------------------------------------------------------------------------
  14. // Purpose: Simple helper class for doing autocompletion of all files in a specific directory by extension
  15. //-----------------------------------------------------------------------------
  16. class CBaseAutoCompleteFileList
  17. {
  18. public:
  19. CBaseAutoCompleteFileList( const char *cmdname, const char *subdir, const char *extension )
  20. {
  21. m_pszCommandName = cmdname;
  22. m_pszSubDir = subdir;
  23. m_pszExtension = extension;
  24. }
  25. int AutoCompletionFunc( const char *partial, char commands[ COMMAND_COMPLETION_MAXITEMS ][ COMMAND_COMPLETION_ITEM_LENGTH ] );
  26. private:
  27. const char *m_pszCommandName;
  28. const char *m_pszSubDir;
  29. const char *m_pszExtension;
  30. };
  31. #define DECLARE_AUTOCOMPLETION_FUNCTION( command, subdirectory, extension ) \
  32. static int g_##command##_CompletionFunc( const char *partial, \
  33. char commands[ COMMAND_COMPLETION_MAXITEMS ][ COMMAND_COMPLETION_ITEM_LENGTH ] ) \
  34. { \
  35. static CBaseAutoCompleteFileList command##Complete( #command, subdirectory, #extension ); \
  36. return command##Complete.AutoCompletionFunc( partial, commands ); \
  37. }
  38. #define AUTOCOMPLETION_FUNCTION( command ) \
  39. g_##command##_CompletionFunc
  40. //-----------------------------------------------------------------------------
  41. // Purpose: Utility to quicky generate a simple console command with file name autocompletion
  42. //-----------------------------------------------------------------------------
  43. #define CON_COMMAND_AUTOCOMPLETEFILE( name, func, description, subdirectory, extension ) \
  44. DECLARE_AUTOCOMPLETION_FUNCTION( name, subdirectory, extension ) \
  45. static ConCommand name##_command( #name, func, description, 0, AUTOCOMPLETION_FUNCTION( name ) );
  46. #endif // BASEAUTOCOMPLETEFILELIST_H