Esc.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. /**
  2. * Copyright (c) 2011-2018 by Andrew Mustun. All rights reserved.
  3. *
  4. * This file is part of the QCAD project.
  5. *
  6. * QCAD is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * QCAD is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with QCAD.
  18. */
  19. include("scripts/Edit/Edit.js");
  20. function Esc(guiAction) {
  21. Edit.call(this, guiAction);
  22. }
  23. Esc.prototype = new Edit();
  24. Esc.prototype.beginEvent = function() {
  25. Edit.prototype.beginEvent.call(this);
  26. var returnFocus = false;
  27. var appWin = EAction.getMainWindow();
  28. var w = QApplication.focusWidget();
  29. // focus in RMathLineEdit (e.g. in options toolbar)
  30. // return focus to graphics view:
  31. if (isOfType(w, RMathLineEdit) || isOfType(w, QSpinBox)) {
  32. if (w.ignoreEscape===true) {
  33. // ignore escape and use standard action for escape
  34. // this is for some actions to make sure esc triggers step back
  35. // and not move focus to graphics view
  36. // the ignoreEscape property can be set in the UI file
  37. }
  38. else {
  39. returnFocus = true;
  40. }
  41. }
  42. // special case: erase command line text:
  43. var commandLineEdit = objectFromPath("MainWindow::CommandLine::CommandEdit");
  44. if (!isNull(commandLineEdit)) {
  45. if (commandLineEdit.focus) {
  46. if (commandLineEdit.text!=="") {
  47. commandLineEdit.text = "";
  48. this.terminate();
  49. return;
  50. }
  51. else {
  52. returnFocus = true;
  53. }
  54. }
  55. }
  56. // special case: erase script shell text:
  57. var ecmaScriptShellEdit = objectFromPath("MainWindow::EcmaScriptShell::CommandEdit");
  58. if (!isNull(ecmaScriptShellEdit)) {
  59. if (ecmaScriptShellEdit.focus) {
  60. if (ecmaScriptShellEdit.text!=="") {
  61. ecmaScriptShellEdit.text = "";
  62. this.terminate();
  63. return;
  64. }
  65. else {
  66. // give script shell a chance to cancel open brackets
  67. ecmaScriptShellEdit.escape();
  68. if (ecmaScriptShellEdit.property("OpenBrackets")>0) {
  69. ecmaScriptShellEdit.setProperty("OpenBrackets", 0);
  70. }
  71. else {
  72. returnFocus = true;
  73. }
  74. }
  75. }
  76. }
  77. // special case: erase tool matrix filter text:
  78. var filterEdit = objectFromPath("MainWindow::ToolMatrixDock::FilterEdit");
  79. if (!isNull(filterEdit)) {
  80. if (filterEdit.focus) {
  81. if (filterEdit.text!=="") {
  82. filterEdit.text = "";
  83. this.terminate();
  84. return;
  85. }
  86. else {
  87. returnFocus = true;
  88. }
  89. }
  90. }
  91. // return focus to graphics view or application window:
  92. if (returnFocus) {
  93. var view = this.getGraphicsView();
  94. if (!isNull(view) && isFunction(view.getQWidget)) {
  95. var viewQt = view.getQWidget();
  96. if (!isNull(viewQt)) {
  97. viewQt.setFocus(Qt.OtherFocusReason);
  98. this.terminate();
  99. return;
  100. }
  101. }
  102. else {
  103. appWin.setFocus(Qt.OtherFocusReason);
  104. this.terminate();
  105. return;
  106. }
  107. }
  108. // send escape event to current action:
  109. var base = this.getOverrideBase();
  110. if (!isNull(base)) {
  111. base.escapeEvent();
  112. }
  113. // clear key log of recorded keystrokes:
  114. appWin.clearKeyLog();
  115. this.terminate();
  116. };