work save: new project

This commit is contained in:
royqh1979 2021-09-17 07:44:03 +08:00
parent f8be0d62c7
commit b88dd1478c
3 changed files with 23 additions and 13 deletions

View File

@ -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);

View File

@ -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);
}
}

View File

@ -604,13 +604,13 @@ bool Project::assignTemplate(const std::shared_ptr<ProjectTemplate> 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);