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.

193 lines
5.7 KiB

  1. //===== Copyright � 1996-2005, 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, by default deletes itself on close
  19. //-----------------------------------------------------------------------------
  20. enum FileOpenDialogType_t
  21. {
  22. FOD_SAVE = 0,
  23. FOD_OPEN,
  24. FOD_SELECT_DIRECTORY,
  25. };
  26. struct FileData_t
  27. {
  28. CUtlString m_FileAttributes;
  29. CUtlString m_CreationTime;
  30. int64 m_nCreationTime;
  31. CUtlString m_LastAccessTime;
  32. CUtlString m_LastWriteTime;
  33. int64 m_nLastWriteTime;
  34. int64 m_nFileSize;
  35. CUtlString m_FileName;
  36. CUtlString m_FullPath;
  37. wchar_t m_FileType[ 80 ];
  38. bool m_bDirectory;
  39. void PrepareKV( KeyValues *kv );
  40. };
  41. class FileOpenDialog : public vgui::Frame
  42. {
  43. DECLARE_CLASS_SIMPLE( FileOpenDialog, Frame );
  44. public:
  45. // NOTE: Backward compat constructor
  46. FileOpenDialog( Panel *parent, const char *title, bool bOpenFile, KeyValues *pContextKeyValues = 0 );
  47. // The context keyvalues are added to all messages sent by this dialog if they are specified
  48. FileOpenDialog( Panel *parent, const char *title, FileOpenDialogType_t type, KeyValues *pContextKeyValues = 0 );
  49. ~FileOpenDialog();
  50. // Set the directory the file search starts in
  51. void SetStartDirectory(const char *dir);
  52. // Sets the start directory context (and resets the start directory in the process)
  53. // NOTE: If you specify a startdir context, then if you've already opened
  54. // a file with that same start dir context before, it will start in the
  55. // same directory it ended up in.
  56. void SetStartDirectoryContext( const char *pContext, const char *pDefaultDir );
  57. // Add filters for the drop down combo box
  58. // The filter info, if specified, gets sent back to the app in the FileSelected message
  59. void AddFilter( const char *filter, const char *filterName, bool bActive, const char *pFilterInfo = NULL );
  60. // Activate the dialog
  61. // NOTE: The argument is there for backward compat
  62. void DoModal( bool bUnused = false );
  63. // Get the directory this is currently in
  64. void GetCurrentDirectory( char *buf, int bufSize );
  65. // Get the last selected file name
  66. void GetSelectedFileName( char *buf, int bufSize );
  67. /*
  68. messages sent:
  69. "FileSelected"
  70. "fullpath" // specifies the fullpath of the file
  71. "filterinfo" // Returns the filter info associated with the active filter
  72. "FileSelectionCancelled"
  73. */
  74. static bool FileNameWildCardMatch( char const *pchFileName, char const *pchPattern );
  75. protected:
  76. virtual void OnCommand( const char *command );
  77. virtual void ApplySchemeSettings(IScheme *pScheme);
  78. virtual void OnClose();
  79. virtual void OnKeyCodeTyped(KeyCode code);
  80. // handles the open button being pressed
  81. // checks on what has changed and acts accordingly
  82. MESSAGE_FUNC( OnOpen, "OnOpen" );
  83. MESSAGE_FUNC( OnSelectFolder, "SelectFolder" );
  84. MESSAGE_FUNC( OnFolderUp, "OnFolderUp" );
  85. MESSAGE_FUNC( OnNewFolder, "OnNewFolder" );
  86. MESSAGE_FUNC( OnOpenInExplorer, "OpenInExplorer" );
  87. MESSAGE_FUNC( PopulateFileList, "PopulateFileList" );
  88. MESSAGE_FUNC( PopulateDriveList, "PopulateDriveList" );
  89. MESSAGE_FUNC( PopulateFileNameSearchHistory, "PopulateFileNameSearchHistory" );
  90. // moves the directory structure up
  91. virtual void MoveUpFolder();
  92. // validates that the current path is valid
  93. virtual void ValidatePath();
  94. // handles an item in the list being selected
  95. MESSAGE_FUNC( OnItemSelected, "ItemSelected" );
  96. MESSAGE_FUNC( OnListItemSelected, "ListItemSelected" )
  97. {
  98. OnItemSelected();
  99. }
  100. // changes directories in response to selecting drives from the combo box
  101. MESSAGE_FUNC_PARAMS( OnTextChanged, "TextChanged", kv );
  102. MESSAGE_FUNC( OnInputCanceled, "InputCanceled" );
  103. MESSAGE_FUNC_PARAMS( OnInputCompleted, "InputCompleted", data );
  104. MESSAGE_FUNC( OnMatchStringSelected, "OnMatchStringSelected" );
  105. private:
  106. // Necessary because we have 2 constructors
  107. void Init( const char *title, KeyValues *pContextKeyValues );
  108. // Does the specified extension match something in the filter list?
  109. bool ExtensionMatchesFilter( const char *pExt );
  110. // Choose the first non *.* filter in the filter list
  111. void ChooseExtension( char *pExt, int nBufLen );
  112. // Saves the file to the start dir context
  113. void SaveFileToStartDirContext( const char *pFullPath );
  114. // Posts a file selected message
  115. void PostFileSelectedMessage( const char *pFileName );
  116. // Creates a new folder
  117. void NewFolder( char const *folderName );
  118. void BuildFileList();
  119. void FilterFileList();
  120. bool PassesFilter( FileData_t *fd );
  121. int CountSubstringMatches();
  122. void AddSearchHistoryString( char const *str );
  123. vgui::ComboBox *m_pFullPathEdit;
  124. vgui::ListPanel *m_pFileList;
  125. vgui::ComboBox *m_pFileNameCombo;
  126. vgui::ComboBox *m_pFileTypeCombo;
  127. vgui::Button *m_pOpenButton;
  128. vgui::Button *m_pCancelButton;
  129. vgui::Button *m_pFolderUpButton;
  130. vgui::Button *m_pNewFolderButton;
  131. vgui::Button *m_pOpenInExplorerButton;
  132. vgui::Label *m_pFileTypeLabel;
  133. KeyValues *m_pContextKeyValues;
  134. char m_szLastPath[1024];
  135. unsigned short m_nStartDirContext;
  136. FileOpenDialogType_t m_DialogType;
  137. bool m_bFileSelected : 1;
  138. VPANEL m_SaveModal;
  139. vgui::DHANDLE< vgui::InputDialog > m_hInputDialog;
  140. CUtlVector< FileData_t > m_Files;
  141. CUtlVector< FileData_t * > m_Filtered;
  142. CUtlVector< CUtlString > m_SearchHistory;
  143. CUtlString m_CurrentSubstringFilter;
  144. };
  145. } // namespace vgui
  146. #endif // FILEOPENDIALOG_H