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.

160 lines
4.9 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: Declaration of FileOpenDialog class, a generic open/save as file dialog
  4. //
  5. // $NoKeywords: $
  6. //===========================================================================//
  7. #ifndef FILEOPENDIALOG_H
  8. #define FILEOPENDIALOG_H
  9. #ifdef _WIN32
  10. #pragma once
  11. #endif
  12. #include "vgui_controls/Frame.h"
  13. namespace vgui
  14. {
  15. class FileCompletionEdit; // local
  16. class InputDialog;
  17. //-----------------------------------------------------------------------------
  18. // Purpose: generic open/save as file dialog
  19. //-----------------------------------------------------------------------------
  20. enum FileOpenDialogType_t
  21. {
  22. FOD_SAVE = 0,
  23. FOD_OPEN,
  24. FOD_SELECT_DIRECTORY,
  25. };
  26. class FileOpenDialog : public vgui::Frame
  27. {
  28. DECLARE_CLASS_SIMPLE( FileOpenDialog, Frame );
  29. public:
  30. // NOTE: Backward compat constructor
  31. FileOpenDialog( Panel *parent, const char *title, bool bOpenFile, KeyValues *pContextKeyValues = 0 );
  32. // The context keyvalues are added to all messages sent by this dialog if they are specified
  33. FileOpenDialog( Panel *parent, const char *title, FileOpenDialogType_t type, KeyValues *pContextKeyValues = 0 );
  34. ~FileOpenDialog();
  35. // Set the directory the file search starts in
  36. void SetStartDirectory(const char *dir);
  37. // Sets the start directory context (and resets the start directory in the process)
  38. // NOTE: If you specify a startdir context, then if you've already opened
  39. // a file with that same start dir context before, it will start in the
  40. // same directory it ended up in.
  41. void SetStartDirectoryContext( const char *pContext, const char *pDefaultDir );
  42. // Add filters for the drop down combo box
  43. // The filter info, if specified, gets sent back to the app in the FileSelected message
  44. void AddFilter( const char *filter, const char *filterName, bool bActive, const char *pFilterInfo = NULL );
  45. // Activate the dialog
  46. // NOTE: The argument is there for backward compat
  47. void DoModal( bool bUnused = false );
  48. // Get the directory this is currently in
  49. void GetCurrentDirectory( char *buf, int bufSize );
  50. // Get the last selected file name
  51. void GetSelectedFileName( char *buf, int bufSize );
  52. /*
  53. messages sent:
  54. "FileSelected"
  55. "fullpath" // specifies the fullpath of the file
  56. "filterinfo" // Returns the filter info associated with the active filter
  57. "FileSelectionCancelled"
  58. */
  59. protected:
  60. virtual void OnCommand( const char *command );
  61. virtual void ApplySchemeSettings(IScheme *pScheme);
  62. virtual void OnClose();
  63. virtual void OnKeyCodeTyped(KeyCode code);
  64. // handles the open button being pressed
  65. // checks on what has changed and acts accordingly
  66. MESSAGE_FUNC( OnOpen, "OnOpen" );
  67. MESSAGE_FUNC( OnSelectFolder, "SelectFolder" );
  68. MESSAGE_FUNC( OnFolderUp, "OnFolderUp" );
  69. MESSAGE_FUNC( OnNewFolder, "OnNewFolder" );
  70. MESSAGE_FUNC( OnOpenInExplorer, "OpenInExplorer" );
  71. MESSAGE_FUNC( PopulateFileList, "PopulateFileList" );
  72. MESSAGE_FUNC( PopulateDriveList, "PopulateDriveList" );
  73. MESSAGE_FUNC( PopulateFileNameCompletion, "PopulateFileNameCompletion" );
  74. // moves the directory structure up
  75. virtual void MoveUpFolder();
  76. // validates that the current path is valid
  77. virtual void ValidatePath();
  78. // handles an item in the list being selected
  79. MESSAGE_FUNC( OnItemSelected, "ItemSelected" );
  80. MESSAGE_FUNC( OnListItemSelected, "ListItemSelected" )
  81. {
  82. OnItemSelected();
  83. }
  84. // changes directories in response to selecting drives from the combo box
  85. MESSAGE_FUNC_PARAMS( OnTextChanged, "TextChanged", kv );
  86. MESSAGE_FUNC( OnInputCanceled, "InputCanceled" );
  87. MESSAGE_FUNC_PARAMS( OnInputCompleted, "InputCompleted", data );
  88. private:
  89. // Necessary because we have 2 constructors
  90. void Init( const char *title, KeyValues *pContextKeyValues );
  91. // Does the specified extension match something in the filter list?
  92. bool ExtensionMatchesFilter( const char *pExt );
  93. // Choose the first non *.* filter in the filter list
  94. void ChooseExtension( char *pExt, int nBufLen );
  95. // Saves the file to the start dir context
  96. void SaveFileToStartDirContext( const char *pFullPath );
  97. // Posts a file selected message
  98. void PostFileSelectedMessage( const char *pFileName );
  99. // Creates a new folder
  100. void NewFolder( char const *folderName );
  101. vgui::ComboBox *m_pFullPathEdit;
  102. vgui::ListPanel *m_pFileList;
  103. FileCompletionEdit *m_pFileNameEdit;
  104. vgui::ComboBox *m_pFileTypeCombo;
  105. vgui::Button *m_pOpenButton;
  106. vgui::Button *m_pCancelButton;
  107. vgui::Button *m_pFolderUpButton;
  108. vgui::Button *m_pNewFolderButton;
  109. vgui::Button *m_pOpenInExplorerButton;
  110. vgui::ImagePanel *m_pFolderIcon;
  111. vgui::Label *m_pFileTypeLabel;
  112. KeyValues *m_pContextKeyValues;
  113. char m_szLastPath[1024];
  114. unsigned short m_nStartDirContext;
  115. FileOpenDialogType_t m_DialogType;
  116. bool m_bFileSelected : 1;
  117. VPANEL m_SaveModal;
  118. vgui::DHANDLE< vgui::InputDialog > m_hInputDialog;
  119. };
  120. } // namespace vgui
  121. #endif // FILEOPENDIALOG_H