UIFinderWindow.h 3.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. //
  2. // Copyright (c) 2014-2017, THUNDERBEAST GAMES LLC All rights reserved
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to deal
  6. // in the Software without restriction, including without limitation the rights
  7. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. // copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  20. // THE SOFTWARE.
  21. //
  22. #pragma once
  23. #include <TurboBadger/tb_atomic_widgets.h>
  24. #include "UIWindow.h"
  25. namespace Atomic
  26. {
  27. class UIPromptWindow;
  28. class UIFinderWindow : public UIWindow
  29. {
  30. ATOMIC_OBJECT(UIFinderWindow, UIWindow)
  31. public:
  32. UIFinderWindow(Context* context, UIWidget* target, const String& id, bool createWidget = true);
  33. virtual ~UIFinderWindow();
  34. void FindFile(const String& title, const String& preset, int dimmer=0, int width=0, int height=0);
  35. void FindPath(const String& title, const String& preset, int dimmer=0, int width=0, int height=0);
  36. protected:
  37. void HandleCreateBookmark(StringHash eventType, VariantMap& eventData); /// event handler for bookmark creation
  38. void HandleCreateFolder(StringHash eventType, VariantMap& eventData); /// event handler for folder creation
  39. virtual bool OnEvent(const tb::TBWidgetEvent &ev); /// general event handler
  40. UIWidget* GetWindowWidget(); /// get internal widgets
  41. UIWidget* GetPathWidget();
  42. UIWidget* GetResultWidget();
  43. UIWidget* GetBookmarksWidget();
  44. UIWidget* GetFilesWidget();
  45. private:
  46. void PresetCurrentPath( const String& preset ); /// location where the finder starts
  47. void SetCurrentPath( const String& string ); /// set the current path value
  48. void ComposePath (const String& string ); /// using the list, jam things together, we'll either get another path or a file.
  49. void CreateBookmarks(); /// create the list of bookmarks, per platform
  50. void GoFolderUp(); /// go up one folder
  51. void UpdateUiPath (); /// move current path to widget
  52. void UpdateUiResult (); /// move result path to widget
  53. void UpdateUiList(); /// move folder contents into list
  54. void CreateFolder( const String& string ); /// utility to add a folder in current path
  55. void CreateBookmark ( const String& bkname, const String& bkpath ); /// utility to add a bookmark from the current path
  56. void DeleteBookmark ( int bkindex ); /// removes a bookmark based upon its index in the bookmark list
  57. void LoadBookmarks(); /// load user created bookmarks from file
  58. void SaveBookmarks(); /// save user created bookmarks to file
  59. int finderMode_; /// finder mode, 0 = find file, 1 = find folder
  60. String currentPath_; /// current path for the finder
  61. String resultPath_; /// result file for finder
  62. Vector <String> bookmarks_; /// array of names of bookmarks
  63. Vector <String> bookmarkPaths_; /// array of bookmark paths
  64. WeakPtr<UIPromptWindow> newBookmarkPtr_; /// pointer for bookmark prompt window
  65. WeakPtr<UIPromptWindow> newFolderPtr_; /// pointer for new folder prompt window
  66. int bookmarksDirty_; /// flag to track if the bookmark array has changed
  67. };
  68. }