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.

88 lines
2.3 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #include "DemoPage.h"
  8. #include <VGUI/IVGui.h>
  9. #include <vgui_controls/Controls.h>
  10. #include <Keyvalues.h>
  11. #include <vgui_controls/FileOpenDialog.h>
  12. using namespace vgui;
  13. class FileOpenDemo: public DemoPage
  14. {
  15. public:
  16. FileOpenDemo(Panel *parent, const char *name);
  17. ~FileOpenDemo();
  18. void SetVisible(bool status);
  19. private:
  20. void OnFileSelected(const char *fullpath);
  21. DHANDLE<FileOpenDialog> m_hFileDialog;
  22. DECLARE_PANELMAP();
  23. };
  24. //-----------------------------------------------------------------------------
  25. // Purpose: Constructor
  26. //-----------------------------------------------------------------------------
  27. FileOpenDemo::FileOpenDemo(Panel *parent, const char *name) : DemoPage(parent, name)
  28. {
  29. }
  30. //-----------------------------------------------------------------------------
  31. // Purpose: Destructor
  32. //-----------------------------------------------------------------------------
  33. FileOpenDemo::~FileOpenDemo()
  34. {
  35. }
  36. //-----------------------------------------------------------------------------
  37. // Purpose: When we make this this demo page visible we make the dialog visible.
  38. //-----------------------------------------------------------------------------
  39. void FileOpenDemo::SetVisible(bool status)
  40. {
  41. if (status)
  42. {
  43. if (!m_hFileDialog.Get())
  44. {
  45. // Pop up the dialog
  46. FileOpenDialog *pFileDialog = new FileOpenDialog (NULL, "Find the TestFile", true);
  47. m_hFileDialog = pFileDialog;
  48. m_hFileDialog->AddActionSignalTarget(this);
  49. }
  50. m_hFileDialog->DoModal(false);
  51. }
  52. }
  53. //-----------------------------------------------------------------------------
  54. // Purpose: When a file is selected print out its full path in the debugger
  55. //-----------------------------------------------------------------------------
  56. void FileOpenDemo::OnFileSelected(const char *fullpath)
  57. {
  58. ivgui()->DPrintf("File selected\n");
  59. ivgui()->DPrintf(fullpath);
  60. ivgui()->DPrintf("\n");
  61. }
  62. MessageMapItem_t FileOpenDemo::m_MessageMap[] =
  63. {
  64. MAP_MESSAGE_CONSTCHARPTR(FileOpenDemo, "FileSelected", OnFileSelected, "fullpath"),
  65. };
  66. IMPLEMENT_PANELMAP(FileOpenDemo, DemoPage);
  67. Panel* FileOpenDemo_Create(Panel *parent)
  68. {
  69. return new FileOpenDemo(parent, "FileOpenDialogDemo");
  70. }