OpenProject.js 4.5 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. 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. var projectPath = selectDir[0];
  46. // 所选工程为xxx
  47. // EAction.handleUserMessage("select project is: " + projectPath);
  48. QMessageBox.information(appWin, qsTr("提示"), qsTr("选择的工程为:" + projectPath));
  49. RSettings.setValue("OpenProject/Current", projectPath);
  50. RSettings.setValue("OpenDisplayFile/PMFile", "");
  51. RSettings.setValue("OpenDisplayFile/ZDMFile", "");
  52. // 拷贝参数配置文件
  53. var srcFilePath = OpenProject.includeBasePath + "/para.ini";
  54. var dstFilePath = projectPath + "/para.ini";
  55. var paraFile = new QFile(dstFilePath);
  56. if(!paraFile.exists()){
  57. QFile.copy(srcFilePath, dstFilePath);
  58. }
  59. var di1 = getAssignDocumentInterface(1);
  60. var document1 = getAssignDocument(1);
  61. var ids = document1.queryAllEntities();
  62. var op = new RDeleteObjectsOperation();
  63. for (i=0; i<ids.length; i++) {
  64. var id = ids[i];
  65. op.deleteObject(document1.queryEntity(id));
  66. }
  67. di1.applyOperation(op);
  68. di1.clearPreview();
  69. di1.repaintViews();
  70. var di0 = getAssignDocumentInterface(0);
  71. var document0 = getAssignDocument(0);
  72. var ids0 = document0.queryAllEntities();
  73. var op0 = new RDeleteObjectsOperation();
  74. for (i=0; i<ids0.length; i++) {
  75. var id = ids0[i];
  76. op0.deleteObject(document0.queryEntity(id));
  77. }
  78. di0.applyOperation(op0);
  79. di0.clearPreview();
  80. di0.repaintViews();
  81. return ;
  82. var appWin = EAction.getMainWindow();
  83. var dialog = WidgetFactory.createDialog(OpenProject.includeBasePath, "OpenProjectDialog.ui");
  84. var listWidget = dialog.findChild("listWidget");
  85. var label = dialog.findChild("label");
  86. var pjDir = OpenProject.includeBasePath + "/../../../project";
  87. EAction.handleUserMessage(pjDir);
  88. var paraFile = new QDir(pjDir);
  89. if(!paraFile.exists())
  90. {
  91. QMessageBox.critical(appWin,qsTr("错误"),qsTr("文件夹找不到"));
  92. return;
  93. }
  94. //--2 获取当前路径下所有的文件夹名字
  95. var filterFlags = makeQDirFilters(QDir.Dirs | QDir.NoDotAndDotDot);
  96. var sortFlags = makeQDirSortFlags(QDir.NoSort);
  97. var names = paraFile.entryList(filterFlags, sortFlags);
  98. for(var i = 0; i < names.length; i++){
  99. listWidget.addItem(names[i]);
  100. }
  101. listWidget.itemClicked.connect(function(item) {
  102. label.text = "所选工程为:" + item.text();
  103. });
  104. var buttonBox = dialog.findChild("ButtonBox");
  105. buttonBox.clicked.connect(function(button) {
  106. var standardButton = buttonBox.standardButton(button);
  107. switch (standardButton) {
  108. // cancel:
  109. case QDialogButtonBox.Cancel:
  110. dialog.reject();
  111. break;
  112. // ok:
  113. case QDialogButtonBox.Ok:
  114. // 配置文件中设置工程名称
  115. // EAction.handleUserMessage(label.text.substring(label.text.indexOf(":")+1));
  116. RSettings.setValue("OpenProject/Current", label.text.substring(label.text.indexOf(":")+1));
  117. destr(dialog);
  118. break;
  119. }
  120. });
  121. if (!dialog.exec()) {
  122. destr(dialog);
  123. }
  124. EAction.activateMainWindow();
  125. };