Team Fortress 2 Source Code as on 22/4/2020
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.

72 lines
2.5 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //
  7. //=============================================================================//
  8. #include "dme_controls/AttributeFilePickerPanel.h"
  9. #include "filesystem.h"
  10. #include "vgui_controls/Button.h"
  11. #include "vgui_controls/FileOpenDialog.h"
  12. #include "dme_controls/AttributeTextEntry.h"
  13. #include "vgui/IInput.h"
  14. // memdbgon must be the last include file in a .cpp file!!!
  15. #include "tier0/memdbgon.h"
  16. using namespace vgui;
  17. //-----------------------------------------------------------------------------
  18. // Various file picker types
  19. //-----------------------------------------------------------------------------
  20. IMPLEMENT_ATTRIBUTE_FILE_PICKER( CAttributeTgaFilePickerPanel, "Choose TGA file", "TGA", "tga" );
  21. IMPLEMENT_ATTRIBUTE_FILE_PICKER( CAttributeDmeFilePickerPanel, "Choose DmE .xml file", "DmE XML", "xml" );
  22. IMPLEMENT_ATTRIBUTE_FILE_PICKER( CAttributeAviFilePickerPanel, "Choose AVI file", "AVI", "avi" );
  23. IMPLEMENT_ATTRIBUTE_FILE_PICKER( CAttributeShtFilePickerPanel, "Choose Sheet file", "SHT", "sht" );
  24. IMPLEMENT_ATTRIBUTE_FILE_PICKER( CAttributeRawFilePickerPanel, "Choose RAW file", "RAW", "raw" );
  25. //-----------------------------------------------------------------------------
  26. // Constructor
  27. //-----------------------------------------------------------------------------
  28. CAttributeFilePickerPanel::CAttributeFilePickerPanel( vgui::Panel *parent, const AttributeWidgetInfo_t &info ) :
  29. BaseClass( parent, info )
  30. {
  31. }
  32. CAttributeFilePickerPanel::~CAttributeFilePickerPanel()
  33. {
  34. }
  35. //-----------------------------------------------------------------------------
  36. // Shows the picker dialog
  37. //-----------------------------------------------------------------------------
  38. void CAttributeFilePickerPanel::ShowPickerDialog()
  39. {
  40. FileOpenDialog *pFileOpenDialog = new FileOpenDialog( this, "Choose file", true );
  41. SetupFileOpenDialog( pFileOpenDialog );
  42. pFileOpenDialog->AddActionSignalTarget( this );
  43. pFileOpenDialog->SetDeleteSelfOnClose( true );
  44. pFileOpenDialog->DoModal( true );
  45. input()->SetAppModalSurface( pFileOpenDialog->GetVPanel() );
  46. }
  47. void CAttributeFilePickerPanel::OnFileSelected( char const *fullpath )
  48. {
  49. if ( !fullpath || !fullpath[ 0 ] )
  50. return;
  51. char relativepath[ 512 ];
  52. g_pFullFileSystem->FullPathToRelativePath( fullpath, relativepath, sizeof( relativepath ) );
  53. // Apply to text panel
  54. m_pData->SetText( relativepath );
  55. SetDirty(true);
  56. if ( IsAutoApply() )
  57. {
  58. Apply();
  59. }
  60. }