EclEditorControl.js 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /*##############################################################################
  2. # HPCC SYSTEMS software Copyright (C) 2012 HPCC Systems.
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. ############################################################################## */
  16. define([
  17. "dojo/_base/declare"
  18. ], function (declare) {
  19. return declare(null, {
  20. domId: "",
  21. editor: null,
  22. markers: [],
  23. highlightLines: [],
  24. // The constructor
  25. constructor: function (args) {
  26. declare.safeMixin(this, args);
  27. this.editor = CodeMirror.fromTextArea(document.getElementById(this.domId), {
  28. tabMode: "indent",
  29. matchBrackets: true,
  30. gutter: true,
  31. lineNumbers: true
  32. });
  33. },
  34. clearErrors: function (errWarnings) {
  35. for (var i = 0; i < this.markers.length; ++i) {
  36. this.editor.clearMarker(this.markers[i]);
  37. }
  38. this.markers = [];
  39. },
  40. setErrors: function (errWarnings) {
  41. for (var i = 0; i < errWarnings.length; ++i) {
  42. this.markers.push(this.editor.setMarker(parseInt(
  43. errWarnings[i].LineNo, 10) - 1, "",
  44. errWarnings[i].Severity + "Line"));
  45. }
  46. },
  47. setCursor: function (line, col) {
  48. this.editor.setCursor(line - 1, col - 1);
  49. this.editor.focus();
  50. },
  51. clearHighlightLines: function () {
  52. for (var i = 0; i < this.highlightLines.length; ++i) {
  53. this.editor.setLineClass(this.highlightLines[i], null, null);
  54. }
  55. },
  56. highlightLine: function (line) {
  57. this.highlightLines.push(this.editor.setLineClass(line - 1, "highlightline"));
  58. },
  59. setText: function (ecl) {
  60. this.editor.setValue(ecl);
  61. },
  62. getText: function () {
  63. return this.editor.getValue();
  64. }
  65. });
  66. });