Window.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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. /**
  20. * \defgroup ecma_window Window Tools
  21. * \ingroup ecma_scripts
  22. *
  23. * \brief This module contains ECMAScript implementations of various
  24. * window tools.
  25. */
  26. include("scripts/EAction.js");
  27. function MenuData(d) {
  28. this.data = d;
  29. }
  30. MenuData.prototype.triggered = function() {
  31. var mdiArea = EAction.getMdiArea();
  32. this.data.show();
  33. mdiArea.setActiveSubWindow(this.data);
  34. };
  35. /**
  36. * \class Window
  37. * \brief Base class for all window tools.
  38. * \ingroup ecma_window
  39. */
  40. function Window(guiAction) {
  41. EAction.call(this, guiAction);
  42. }
  43. Window.prototype = new EAction();
  44. Window.includeBasePath = includeBasePath;
  45. Window.getMenu = function() {
  46. var i, action;
  47. var menu = EAction.getMenu(Window.getTitle(), "WindowMenu", function(menu) {
  48. menu.aboutToShow.connect(function() {
  49. var mdiArea = EAction.getMdiArea();
  50. var windows = mdiArea.subWindowList();
  51. var actions = menu.actions();
  52. for (i = 0; i < actions.length; ++i) {
  53. action = actions[i];
  54. if (action.objectName === "MdiChild") {
  55. menu.removeAction(action);
  56. }
  57. }
  58. var separator = new RGuiAction("", menu);
  59. separator.setSeparator(true);
  60. separator.objectName = "MdiChild";
  61. separator.addToMenu(menu);
  62. // for (i = 0; i < windows.length; ++i) {
  63. // var window = windows[i];
  64. // var file = window.getDocument().getFileName();
  65. // var modified = window.getDocument().isModified();
  66. // var text = new QFileInfo(file).fileName();
  67. // if (text === "") {
  68. // text = stripDirtyFlag(window.windowTitle);
  69. // }
  70. // if (modified) {
  71. // text += " *";
  72. // }
  73. // text = text.replace(/&/g, "&&");
  74. // action = menu.addAction(text);
  75. // action.checkable = true;
  76. // var winId;
  77. // var activeWinId;
  78. // if (RSettings.getQtVersion() >= 0x060000) {
  79. // winId = window.getAddress();
  80. // activeWinId = mdiArea.activeSubWindow().getAddress();
  81. // }
  82. // else {
  83. // winId = window.getObjectId();
  84. // activeWinId = mdiArea.activeSubWindow().getObjectId();
  85. // }
  86. // if (!isNull(mdiArea.activeSubWindow()) && winId === activeWinId) {
  87. // action.checked = true;
  88. // } else {
  89. // action.checked = false;
  90. // }
  91. // action.objectName = "MdiChild";
  92. // var menuData = new MenuData(windows[i]);
  93. // action.triggered.connect(menuData, menuData.triggered);
  94. // }
  95. });
  96. });
  97. menu.setProperty("scriptFile", Window.includeBasePath + "/Window.js");
  98. return menu;
  99. };
  100. Window.getToolBar = function() {
  101. var tb = EAction.getToolBar(Window.getTitle(), "WindowToolBar");
  102. tb.visible = false;
  103. return tb;
  104. };
  105. Window.getTitle = function() {
  106. return qsTr("窗口");
  107. // return qsTr("&Window");
  108. };
  109. Window.prototype.getTitle = function() {
  110. return Window.getTitle();
  111. };
  112. Window.init = function() {
  113. Window.getMenu();
  114. Window.getToolBar();
  115. // make sure there's an action:
  116. // var appWin = EAction.getMainWindow();
  117. // var action = new RGuiAction(qsTr("Window Tools"), appWin);
  118. // action.setScriptFile(Window.includeBasePath + "/Window.js");
  119. // action.setWidgetNames([]);
  120. };