From b88dd1478ce46b5fb881007bb7a8247e18b13763 Mon Sep 17 00:00:00 2001 From: royqh1979 Date: Fri, 17 Sep 2021 07:44:03 +0800 Subject: [PATCH] work save: new project --- RedPandaIDE/editor.cpp | 26 +++++++++++++++++--------- RedPandaIDE/mainwindow.cpp | 6 ++++-- RedPandaIDE/project.cpp | 4 ++-- 3 files changed, 23 insertions(+), 13 deletions(-) diff --git a/RedPandaIDE/editor.cpp b/RedPandaIDE/editor.cpp index 8e091a7f..84a421f7 100644 --- a/RedPandaIDE/editor.cpp +++ b/RedPandaIDE/editor.cpp @@ -150,11 +150,13 @@ Editor::~Editor() { } void Editor::loadFile(const QString& filename) { - if (!filename.isEmpty()) { - mFilename = filename; + if (filename.isEmpty()) { + QFile file(mFilename); + this->lines()->LoadFromFile(file,mEncodingOption,mFileEncoding); + } else { + QFile file(filename); + this->lines()->LoadFromFile(file,mEncodingOption,mFileEncoding); } - QFile file(mFilename); - this->lines()->LoadFromFile(file,mEncodingOption,mFileEncoding); //this->setModified(false); updateCaption(); pMainWindow->updateForEncodingInfo(); @@ -174,6 +176,7 @@ void Editor::loadFile(const QString& filename) { checkSyntaxInBack(); } } + mLastIdCharPressed = 0; } void Editor::saveFile(const QString &filename) { @@ -192,7 +195,7 @@ void Editor::convertToEncoding(const QByteArray &encoding) } bool Editor::save(bool force, bool doReparse) { - if (this->mIsNew) { + if (this->mIsNew && !force) { return saveAs(); } QFileInfo info(mFilename); @@ -232,12 +235,17 @@ bool Editor::saveAs(){ selectedFileFilter = pSystemConsts->defaultCPPFileFilter(); else selectedFileFilter = pSystemConsts->defaultCFileFilter(); - QString newName = QFileDialog::getSaveFileName(pMainWindow, - tr("Save As"), QString(), pSystemConsts->defaultFileFilters().join(";;"), - &selectedFileFilter); - if (newName.isEmpty()) { + QFileDialog dialog(this,tr("Save As"),extractFilePath(mFilename), + pSystemConsts->defaultFileFilters().join(";;")); + dialog.selectNameFilter(selectedFileFilter); + dialog.selectFile(mFilename); + dialog.setFileMode(QFileDialog::AnyFile); + dialog.setOption(QFileDialog::DontConfirmOverwrite,false); + + if (!dialog.exec()) { return false; } + QString newName = dialog.selectedFiles()[0]; pMainWindow->fileSystemWatcher()->removePath(mFilename); if (pSettings->codeCompletion().enabled() && mParser) mParser->invalidateFile(mFilename); diff --git a/RedPandaIDE/mainwindow.cpp b/RedPandaIDE/mainwindow.cpp index 25deed30..0e78646e 100644 --- a/RedPandaIDE/mainwindow.cpp +++ b/RedPandaIDE/mainwindow.cpp @@ -2930,8 +2930,6 @@ void MainWindow::on_actionNew_Project_triggered() return; } } - openCloseLeftPanel(true); - ui->tabInfos->setCornerWidget(ui->tabProject); // if cbDefault.Checked then // devData.DefCpp := rbCpp.Checked; @@ -2960,6 +2958,10 @@ void MainWindow::on_actionNew_Project_triggered() QMessageBox::Ok); } mProject->saveAll(); + ui->projectView->setModel(mProject->model()); + openCloseLeftPanel(true); + ui->tabProject->setVisible(true); + ui->tabInfos->setCurrentWidget(ui->tabProject); } } diff --git a/RedPandaIDE/project.cpp b/RedPandaIDE/project.cpp index d8423cf6..6109f823 100644 --- a/RedPandaIDE/project.cpp +++ b/RedPandaIDE/project.cpp @@ -604,13 +604,13 @@ bool Project::assignTemplate(const std::shared_ptr aTemplate) PProjectUnit unit; if (aTemplate->options().useGPP) { s = templateUnit->CppText; - unit = newUnit(mNode,templateUnit->CppName); + unit = newUnit(mNode, templateUnit->CppName); } else { s = templateUnit->CText; unit = newUnit(mNode,templateUnit->CName); } Editor * editor = pMainWindow->editorList()->newEditor( - unit->fileName(), + QDir(directory()).absoluteFilePath(unit->fileName()), unit->encoding(), true, true);