| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157 |
- /**
- * 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/File/File.js");
- include("scripts/File/Save/Save.js");
- include("scripts/Widgets/ViewportWidget/ViewportWidget.js");
- include("scripts/File/AutoSave/AutoSave.js");
- include("scripts/Reset/Reset.js");
- /**
- * \class NewFile
- * \brief Creates a new document.
- * \ingroup ecma_file
- */
- function NewProject(guiAction) {
- File.call(this, guiAction);
- }
- NewProject.prototype = new File();
- NewProject.includeBasePath = includeBasePath;
- /**
- * \param isOpen True if new is called from a file open function.
- */
- NewProject.prototype.beginEvent = function() {
- var appWin = EAction.getMainWindow();
-
- var dialog = WidgetFactory.createDialog(NewProject.includeBasePath, "NewProjectDialog.ui");
- var label1 = dialog.findChild("Text1");
- var label2 = dialog.findChild("Text2");
- var fileBtn = dialog.findChild("fileBtn");
- // 选择文件夹
- fileBtn.clicked.connect(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();
- label2.setText(selectDir[0]);
- });
- // 1、首先检查路径是否存在,如果不存在提示修改路径
- // 2、检查文件夹下是否已经存在项目名称的文件夹,如果存在提示修改名称
- // 3、验证通过后,创建文件夹,关闭对话框,进入项目主界面。
- var buttonBox = dialog.findChild("ButtonBox");
- buttonBox.clicked.connect(function(button) {
- var standardButton = buttonBox.standardButton(button);
- switch (standardButton) {
- // cancel:
- case QDialogButtonBox.Cancel:
- dialog.reject();
- break;
- // save:
- case QDialogButtonBox.Save:
- var dirTxt = label2.text;
- var pjText = label1.text;
- // EAction.handleUserMessage(label1.text);
- if(dirTxt == ""){
- QMessageBox.critical(appWin,qsTr("错误"),qsTr("请选择或输入工程路径!"));
- break;
- }else if(pjText == ""){
- QMessageBox.critical(appWin,qsTr("错误"),qsTr("请输入工程名称!"));
- break;
- }
- var dir = new QDir(dirTxt);
- if(!dir.exists()){
- QMessageBox.critical(appWin,qsTr("错误"),qsTr("工程路径找不到,请选择或输入正确的路径!"));
- break;
- }
- var pjPath = dirTxt + "/" + pjText;
- var path = new QDir(pjPath);
- if(path.exists())
- {
- QMessageBox.critical(appWin,qsTr("错误"),qsTr(pjText + "工程已存在,请重新输入工程名称!"));
- break;
- }
-
- var ismkdir = dir.mkdir(pjText);
- if(!ismkdir)
- {
- EAction.handleUserMessage("Create project fail");
- }
- else
- {
- EAction.handleUserMessage("Create project success");
- // 拷贝参数配置文件
- var srcFilePath = NewProject.includeBasePath + "/para.ini";
- var dstFilePath = pjPath + "/para.ini";
- QFile.copy(srcFilePath, dstFilePath);
- var buttons = makeQMessageBoxStandardButtons(QMessageBox.Yes, QMessageBox.No);
- var ret = QMessageBox.warning(null,
- qsTr("提示"),
- qsTr("\"%1\" 工程创建成功. \n "+
- "是否加载新的工程?").arg(pjText), buttons);
-
- if (ret===QMessageBox.Yes) {
- RSettings.setValue("OpenProject/Current", pjPath);
- }
- }
- if (dialog.exec()) {
- }
- else {
- }
- destr(dialog);
- break;
- }
- });
- if (dialog.exec()) {
- }
- else {
- }
- destr(dialog);
- EAction.activateMainWindow();
- };
- // 弹出选择文件夹对话框
- NewProject.prototype.selectDir = 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();
- EAction.handleUserMessage("Starting to load file: " + selectDir[0]);
- return selectDir[0];
- };
|