EclEditorControl.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /*##############################################################################
  2. # Copyright (C) 2011 HPCC Systems.
  3. #
  4. # All rights reserved. This program is free software: you can redistribute it and/or modify
  5. # it under the terms of the GNU Affero General Public License as
  6. # published by the Free Software Foundation, either version 3 of the
  7. # License, or (at your option) any later version.
  8. #
  9. # This program is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. # GNU Affero General Public License for more details.
  13. #
  14. # You should have received a copy of the GNU Affero General Public License
  15. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. ############################################################################## */
  17. define([
  18. "dojo/_base/declare"
  19. ], function(declare) {
  20. return declare(null, {
  21. domId : "",
  22. editor : null,
  23. markers : [],
  24. highlightLines : [],
  25. // The constructor
  26. constructor : function(args) {
  27. declare.safeMixin(this, args);
  28. this.editor = CodeMirror.fromTextArea(document.getElementById(this.domId), {
  29. tabMode : "indent",
  30. matchBrackets : true,
  31. gutter : true,
  32. lineNumbers : true
  33. });
  34. },
  35. clearErrors : function(errWarnings) {
  36. for (var i = 0; i < this.markers.length; ++i) {
  37. this.editor.clearMarker(this.markers[i]);
  38. }
  39. this.markers = [];
  40. },
  41. setErrors : function(errWarnings) {
  42. for (var i = 0; i < errWarnings.length; ++i) {
  43. this.markers.push(this.editor.setMarker(parseInt(
  44. errWarnings[i].LineNo, 10) - 1, "",
  45. errWarnings[i].Severity + "Line"));
  46. }
  47. },
  48. setCursor : function(line, col) {
  49. this.editor.setCursor(line - 1, col - 1);
  50. this.editor.focus();
  51. },
  52. clearHighlightLines : function() {
  53. for (var i = 0; i < this.highlightLines.length; ++i) {
  54. this.editor.setLineClass(this.highlightLines[i], null, null);
  55. }
  56. },
  57. highlightLine : function(line) {
  58. this.highlightLines.push(this.editor.setLineClass(line - 1, "highlightline"));
  59. },
  60. setText : function(ecl) {
  61. this.editor.setValue(ecl);
  62. },
  63. getText : function() {
  64. return this.editor.getValue();
  65. }
  66. });
  67. });