PolycodeEditor.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. /*
  2. Copyright (C) 2012 by Ivan Safrin
  3. Permission is hereby granted, free of charge, to any person obtaining a copy
  4. of this software and associated documentation files (the "Software"), to deal
  5. in the Software without restriction, including without limitation the rights
  6. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  7. copies of the Software, and to permit persons to whom the Software is
  8. furnished to do so, subject to the following conditions:
  9. The above copyright notice and this permission notice shall be included in
  10. all copies or substantial portions of the Software.
  11. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  12. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  13. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  14. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  15. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  16. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  17. THE SOFTWARE.
  18. */
  19. #pragma once
  20. #include "Polycode.h"
  21. #include "OSBasics.h"
  22. #include "PolyUIElement.h"
  23. #include "PolycodeProject.h"
  24. #include "PolycodeClipboard.h"
  25. #define MAX_EDITOR_UNDO_ACTIONS 40
  26. using namespace Polycode;
  27. class PolycodeEditorActionData {
  28. public:
  29. PolycodeEditorActionData(){}
  30. virtual ~PolycodeEditorActionData() {}
  31. };
  32. class PolycodeEditorAction {
  33. public:
  34. PolycodeEditorAction(){}
  35. ~PolycodeEditorAction() {}
  36. void deleteData() {
  37. delete beforeData;
  38. delete afterData;
  39. }
  40. String actionName;
  41. PolycodeEditorActionData *beforeData;
  42. PolycodeEditorActionData *afterData;
  43. };
  44. class PolycodeEditor : public UIElement, public ClipboardProvider {
  45. public:
  46. PolycodeEditor(bool _isReadOnly);
  47. virtual ~PolycodeEditor();
  48. virtual bool openFile(OSFileEntry filePath){ this->filePath = filePath.fullPath; return true;}
  49. virtual void Resize(int x, int y);
  50. virtual void handleEvent(Event *event);
  51. virtual void Activate() {};
  52. virtual void saveFile(){};
  53. void didAction(String actionName, PolycodeEditorActionData *beforeData, PolycodeEditorActionData *afterData, bool setFileChanged = true);
  54. virtual void doAction(String actionName, PolycodeEditorActionData *data) {}
  55. virtual String Copy(void **data) { return ""; }
  56. virtual void Paste(void *data, String clipboardType) {}
  57. virtual void handleDroppedFile(OSFileEntry file, Number x, Number y) {};
  58. void setFilePath(String newPath);
  59. String getFilePath() { return filePath; }
  60. bool isReadOnly() { return _isReadOnly; }
  61. String getEditorType() { return editorType; }
  62. bool hasChanges() { return _hasChanges;}
  63. void setHasChanges(bool newVal);
  64. PolycodeProject *parentProject;
  65. protected:
  66. bool _hasChanges;
  67. String filePath;
  68. bool _isReadOnly;
  69. Vector2 editorSize;
  70. String editorType;
  71. std::vector<PolycodeEditorAction> editorActions;
  72. int currentUndoPosition;
  73. };
  74. class PolycodeEditorFactory {
  75. public:
  76. PolycodeEditorFactory();
  77. virtual ~PolycodeEditorFactory();
  78. virtual PolycodeEditor *createEditor() = 0;
  79. bool canHandleExtension(String extension);
  80. protected:
  81. std::vector<std::string> extensions;
  82. };