| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140 |
- /**
- * Copyright (c) 2011-2018 by Andrew Mustun. All rights reserved.
- *
- * This file is part of the QCAD project.
- *
- * QCAD is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * QCAD is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with QCAD.
- */
- include("scripts/library.js");
- include("scripts/File/File.js");
- include("scripts/EAction.js")
- /**
- * \class NewFile
- * \brief Creates a new document.
- * \ingroup ecma_file
- */
- function OpenProject(guiAction) {
- File.call(this, guiAction);
- }
- OpenProject.prototype = new File();
- OpenProject.includeBasePath = includeBasePath;
- /**
- * \param isOpen True if new is called from a file open function.
- */
- OpenProject.prototype.beginEvent = function() {
- var appWin = EAction.getMainWindow();
- var fileDialog = new QFileDialog(appWin);
- fileDialog.fileMode = QFileDialog.Directory;
- if (!fileDialog.exec()) {
- destr(fileDialog);
- EAction.activateMainWindow();
- return;
- }
- var selectDir = fileDialog.selectedFiles();
- var projectPath = selectDir[0];
- // 所选工程为xxx
- // EAction.handleUserMessage("select project is: " + projectPath);
- QMessageBox.information(appWin, qsTr("提示"), qsTr("选择的工程为:" + projectPath));
- RSettings.setValue("OpenProject/Current", projectPath);
- RSettings.setValue("OpenDisplayFile/PMFile", "");
- RSettings.setValue("OpenDisplayFile/ZDMFile", "");
- // 拷贝参数配置文件
- var srcFilePath = OpenProject.includeBasePath + "/para.ini";
- var dstFilePath = projectPath + "/para.ini";
- var paraFile = new QFile(dstFilePath);
- if(!paraFile.exists()){
- QFile.copy(srcFilePath, dstFilePath);
- }
- var di1 = getAssignDocumentInterface(1);
- var document1 = getAssignDocument(1);
- var ids = document1.queryAllEntities();
- var op = new RDeleteObjectsOperation();
- for (i=0; i<ids.length; i++) {
- var id = ids[i];
- op.deleteObject(document1.queryEntity(id));
- }
- di1.applyOperation(op);
- di1.clearPreview();
- di1.repaintViews();
- var di0 = getAssignDocumentInterface(0);
- var document0 = getAssignDocument(0);
- var ids0 = document0.queryAllEntities();
- var op0 = new RDeleteObjectsOperation();
- for (i=0; i<ids0.length; i++) {
- var id = ids0[i];
- op0.deleteObject(document0.queryEntity(id));
- }
- di0.applyOperation(op0);
- di0.clearPreview();
- di0.repaintViews();
- return ;
- var appWin = EAction.getMainWindow();
- var dialog = WidgetFactory.createDialog(OpenProject.includeBasePath, "OpenProjectDialog.ui");
- var listWidget = dialog.findChild("listWidget");
- var label = dialog.findChild("label");
- var pjDir = OpenProject.includeBasePath + "/../../../project";
- EAction.handleUserMessage(pjDir);
- var paraFile = new QDir(pjDir);
- if(!paraFile.exists())
- {
- QMessageBox.critical(appWin,qsTr("错误"),qsTr("文件夹找不到"));
- return;
- }
- //--2 获取当前路径下所有的文件夹名字
- var filterFlags = makeQDirFilters(QDir.Dirs | QDir.NoDotAndDotDot);
- var sortFlags = makeQDirSortFlags(QDir.NoSort);
- var names = paraFile.entryList(filterFlags, sortFlags);
- for(var i = 0; i < names.length; i++){
- listWidget.addItem(names[i]);
- }
- listWidget.itemClicked.connect(function(item) {
- label.text = "所选工程为:" + item.text();
- });
- var buttonBox = dialog.findChild("ButtonBox");
- buttonBox.clicked.connect(function(button) {
- var standardButton = buttonBox.standardButton(button);
- switch (standardButton) {
- // cancel:
- case QDialogButtonBox.Cancel:
- dialog.reject();
- break;
- // ok:
- case QDialogButtonBox.Ok:
- // 配置文件中设置工程名称
- // EAction.handleUserMessage(label.text.substring(label.text.indexOf(":")+1));
- RSettings.setValue("OpenProject/Current", label.text.substring(label.text.indexOf(":")+1));
- destr(dialog);
- break;
- }
- });
- if (!dialog.exec()) {
- destr(dialog);
- }
- EAction.activateMainWindow();
- };
|