gcsx_scripteditor.cpp 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /* GCSx
  2. ** SCRIPTEDITOR.CPP
  3. **
  4. ** Script editing window
  5. */
  6. /*****************************************************************************
  7. ** Copyright (C) 2003-2006 Janson
  8. **
  9. ** This program is free software; you can redistribute it and/or modify
  10. ** it under the terms of the GNU General Public License as published by
  11. ** the Free Software Foundation; either version 2 of the License, or
  12. ** (at your option) any later version.
  13. **
  14. ** This program is distributed in the hope that it will be useful,
  15. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. ** GNU General Public License for more details.
  18. **
  19. ** You should have received a copy of the GNU General Public License
  20. ** along with this program; if not, write to the Free Software
  21. ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
  22. *****************************************************************************/
  23. #include "all.h"
  24. ScriptEditor::ScriptEditor(list<string>* scriptData, ScriptEdit* myScript) throw_File : EditBox(scriptData, FONT_MONO) { start_func
  25. wordwrap = myScript->getType() == Script::SCRIPT_NOTE ? 1 : 0;
  26. autoIndent = myScript->getType() == Script::SCRIPT_NOTE ? 0 : 1;
  27. script = myScript;
  28. script->markLock();
  29. }
  30. ScriptEditor::~ScriptEditor() { start_func
  31. if (script) script->markUnlock();
  32. }
  33. void ScriptEditor::contentModifiedPre(EditBox::ContentChangeType type, int firstRow, int numRows) { start_func
  34. if (script) {
  35. assert((type == EDITBOX_MODIFY_LINE) || (type == EDITBOX_INSERT_LINES) || (type == EDITBOX_REMOVE_LINES) || (type == EDITBOX_MODIFY_DONE));
  36. ScriptEdit::ContentChangeType newType = ScriptEdit::SCRIPT_MODIFY_DONE;
  37. if (type == EDITBOX_MODIFY_LINE) newType = ScriptEdit::SCRIPT_MODIFY_LINE;
  38. else if (type == EDITBOX_INSERT_LINES) newType = ScriptEdit::SCRIPT_INSERT_LINES;
  39. else if (type == EDITBOX_REMOVE_LINES) newType = ScriptEdit::SCRIPT_REMOVE_LINES;
  40. script->codeModifiedPre(newType, firstRow, numRows, this, myFrame);
  41. }
  42. }
  43. void ScriptEditor::contentModifiedPost(EditBox::ContentChangeType type, int firstRow, int numRows) { start_func
  44. if (script) {
  45. assert((type == EDITBOX_MODIFY_LINE) || (type == EDITBOX_INSERT_LINES) || (type == EDITBOX_REMOVE_LINES) || (type == EDITBOX_MODIFY_DONE));
  46. ScriptEdit::ContentChangeType newType = ScriptEdit::SCRIPT_MODIFY_DONE;
  47. if (type == EDITBOX_MODIFY_LINE) newType = ScriptEdit::SCRIPT_MODIFY_LINE;
  48. else if (type == EDITBOX_INSERT_LINES) newType = ScriptEdit::SCRIPT_INSERT_LINES;
  49. else if (type == EDITBOX_REMOVE_LINES) newType = ScriptEdit::SCRIPT_REMOVE_LINES;
  50. script->codeModifiedPost(newType, firstRow, numRows, this, this);
  51. }
  52. }
  53. void ScriptEditor::updateTitlebar() { start_func
  54. if ((myFrame) && (script)) {
  55. myFrame->setTitle(formatString("%s : %s", script->getWorld()->getTitle().c_str(), script->getName().c_str()));
  56. }
  57. }
  58. int ScriptEditor::event(int hasFocus, const SDL_Event* event) { start_func
  59. ObjChange* obj;
  60. switch (event->type) {
  61. case SDL_COMMAND:
  62. if (script->getWorldEdit()->commandEvent(event->user.code)) return 1;
  63. break;
  64. case SDL_OBJECTCHANGE:
  65. obj = (ObjChange*)event->user.data1;
  66. if ((event->user.code & OBJ_SCRIPT) && (obj->obj == script)) {
  67. if (event->user.code & OBJMOD_DELETE) {
  68. script = NULL;
  69. closeWindow();
  70. }
  71. if (event->user.code & OBJMOD_NAME) {
  72. updateTitlebar();
  73. }
  74. if (event->user.code & OBJMOD_LINE) {
  75. contentModify(obj->info1, obj->info2);
  76. }
  77. if (event->user.code & OBJMOD_INSERT) {
  78. contentInsert(obj->info1, obj->info2);
  79. }
  80. if (event->user.code & OBJMOD_REMOVE) {
  81. contentDelete(obj->info1, obj->info2);
  82. }
  83. }
  84. if ((event->user.code & OBJ_WORLD) && (obj->obj == script->getWorld())) {
  85. if (event->user.code & OBJMOD_DELETE) {
  86. script = NULL;
  87. closeWindow();
  88. }
  89. if (event->user.code & OBJMOD_NAME) {
  90. updateTitlebar();
  91. }
  92. }
  93. return 1;
  94. }
  95. return EditBox::event(hasFocus, event);
  96. }
  97. Window::CommandSupport ScriptEditor::supportsCommand(int code) const { start_func
  98. Window::CommandSupport worldCmd = script->getWorldEdit()->supportsCommand(code);
  99. if (worldCmd != Window::COMMAND_HIDE) return worldCmd;
  100. return EditBox::supportsCommand(code);
  101. }