OpenProject.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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/library.js");
  20. include("scripts/File/File.js");
  21. include("scripts/EAction.js")
  22. /**
  23. * \class NewFile
  24. * \brief Creates a new document.
  25. * \ingroup ecma_file
  26. */
  27. function OpenProject(guiAction) {
  28. File.call(this, guiAction);
  29. }
  30. OpenProject.prototype = new File();
  31. OpenProject.includeBasePath = includeBasePath;
  32. /**
  33. * \param isOpen True if new is called from a file open function.
  34. */
  35. OpenProject.prototype.beginEvent = function() {
  36. var appWin = EAction.getMainWindow();
  37. var fileDialog = new QFileDialog(appWin);
  38. fileDialog.fileMode = QFileDialog.Directory;
  39. if (!fileDialog.exec()) {
  40. destr(fileDialog);
  41. EAction.activateMainWindow();
  42. return;
  43. }
  44. var selectDir = fileDialog.selectedFiles();
  45. // 所选工程为xxx
  46. // EAction.handleUserMessage("select project is: " + selectDir[0]);
  47. QMessageBox.information(
  48. appWin,
  49. qsTr("提示"),
  50. qsTr("选择的工程为:" + selectDir[0])
  51. );
  52. RSettings.setValue("OpenProject/Current", selectDir[0]);
  53. RSettings.setValue("OpenDisplayFile/PMFile", "");
  54. RSettings.setValue("OpenDisplayFile/ZDMFile", "");
  55. var di1 = getAssignDocumentInterface(1);
  56. var document1 = getAssignDocument(1);
  57. var ids = document1.queryAllEntities();
  58. var op = new RDeleteObjectsOperation();
  59. for (i=0; i<ids.length; i++) {
  60. var id = ids[i];
  61. op.deleteObject(document1.queryEntity(id));
  62. }
  63. di1.applyOperation(op);
  64. di1.clearPreview();
  65. di1.repaintViews();
  66. var di0 = getAssignDocumentInterface(0);
  67. var document0 = getAssignDocument(0);
  68. var ids0 = document0.queryAllEntities();
  69. var op0 = new RDeleteObjectsOperation();
  70. for (i=0; i<ids0.length; i++) {
  71. var id = ids0[i];
  72. op0.deleteObject(document0.queryEntity(id));
  73. }
  74. di0.applyOperation(op0);
  75. di0.clearPreview();
  76. di0.repaintViews();
  77. return ;
  78. var appWin = EAction.getMainWindow();
  79. var dialog = WidgetFactory.createDialog(OpenProject.includeBasePath, "OpenProjectDialog.ui");
  80. var listWidget = dialog.findChild("listWidget");
  81. var label = dialog.findChild("label");
  82. var pjDir = OpenProject.includeBasePath + "/../../../project";
  83. EAction.handleUserMessage(pjDir);
  84. var dir = new QDir(pjDir);
  85. if(!dir.exists())
  86. {
  87. QMessageBox.critical(appWin,qsTr("错误"),qsTr("文件夹找不到"));
  88. return;
  89. }
  90. //--2 获取当前路径下所有的文件夹名字
  91. var filterFlags = makeQDirFilters(QDir.Dirs | QDir.NoDotAndDotDot);
  92. var sortFlags = makeQDirSortFlags(QDir.NoSort);
  93. var names = dir.entryList(filterFlags, sortFlags);
  94. for(var i = 0; i < names.length; i++){
  95. listWidget.addItem(names[i]);
  96. }
  97. listWidget.itemClicked.connect(function(item) {
  98. label.text = "所选工程为:" + item.text();
  99. });
  100. var buttonBox = dialog.findChild("ButtonBox");
  101. buttonBox.clicked.connect(function(button) {
  102. var standardButton = buttonBox.standardButton(button);
  103. switch (standardButton) {
  104. // cancel:
  105. case QDialogButtonBox.Cancel:
  106. dialog.reject();
  107. break;
  108. // ok:
  109. case QDialogButtonBox.Ok:
  110. // 配置文件中设置工程名称
  111. // EAction.handleUserMessage(label.text.substring(label.text.indexOf(":")+1));
  112. RSettings.setValue("OpenProject/Current", label.text.substring(label.text.indexOf(":")+1));
  113. destr(dialog);
  114. break;
  115. }
  116. });
  117. if (!dialog.exec()) {
  118. destr(dialog);
  119. }
  120. EAction.activateMainWindow();
  121. };