diff --git a/RedPandaIDE/mainwindow.cpp b/RedPandaIDE/mainwindow.cpp index cae2e734..52ef3850 100644 --- a/RedPandaIDE/mainwindow.cpp +++ b/RedPandaIDE/mainwindow.cpp @@ -975,9 +975,11 @@ void MainWindow::openFile(const QString &filename, QTabWidget* page) } try { pSettings->history().removeFile(filename); - bool inProject = (mProject && mProject->isProjectUnit(filename)); editor = mEditorList->newEditor(filename,ENCODING_AUTO_DETECT, - inProject, false, page); + false, false, page); + if (mProject) { + mProject->associateEditor(editor); + } editor->activate(); this->updateForEncodingInfo(); } catch (FileError e) { @@ -1041,13 +1043,7 @@ void MainWindow::openProject(const QString &filename, bool openFiles) for (int i=0;iunits().count();i++) { PProjectUnit unit = mProject->units()[i]; Editor* e = mEditorList->getOpenedEditorByFilename(unit->fileName()); - if (e) { - unit->setEditor(e); - unit->setEncoding(e->encodingOption()); - e->setInProject(true); - } else { - unit->setEditor(nullptr); - } + mProject->associateEditorToUnit(e,unit); } Editor * e = mEditorList->getEditor(); @@ -2005,10 +2001,12 @@ void MainWindow::loadLastOpens() page = mEditorList->leftPageWidget(); else page = mEditorList->rightPageWidget(); - bool inProject = (mProject && mProject->isProjectUnit(editorFilename)); - Editor * editor = mEditorList->newEditor(editorFilename,ENCODING_AUTO_DETECT,inProject,false,page); + Editor * editor = mEditorList->newEditor(editorFilename,ENCODING_AUTO_DETECT,false,false,page); if (!editor) continue; + if (mProject) { + mProject->associateEditor(editor); + } BufferCoord pos; pos.Char = lastOpenIni.GetLongValue(sectionName,"CursorCol", 1); pos.Line = lastOpenIni.GetLongValue(sectionName,"CursorRow", 1); diff --git a/RedPandaIDE/project.cpp b/RedPandaIDE/project.cpp index d2cd6b8e..f4e42865 100644 --- a/RedPandaIDE/project.cpp +++ b/RedPandaIDE/project.cpp @@ -564,13 +564,34 @@ bool Project::saveUnits() return true; } -bool Project::isProjectUnit(const QString &filename) +PProjectUnit Project::findUnitByFilename(const QString &filename) { - foreach(const PProjectUnit& unit, mUnits) { + foreach(PProjectUnit unit, mUnits) { if (QString::compare(unit->fileName(),filename, PATH_SENSITIVITY)==0) - return true; + return unit; + } + return PProjectUnit(); +} + +void Project::associateEditor(Editor *editor) +{ + if (!editor) + return; + PProjectUnit unit = findUnitByFilename(editor->filename()); + associateEditorToUnit(editor,unit); +} + +void Project::associateEditorToUnit(Editor *editor, PProjectUnit unit) +{ + if (!unit) + return; + if (editor) { + unit->setEditor(editor); + unit->setEncoding(editor->encodingOption()); + editor->setInProject(true); + } else { + unit->setEditor(nullptr); } - return false; } void Project::setCompilerOption(const QString &optionString, char value) diff --git a/RedPandaIDE/project.h b/RedPandaIDE/project.h index 6ade7f3c..c1536f89 100644 --- a/RedPandaIDE/project.h +++ b/RedPandaIDE/project.h @@ -184,7 +184,9 @@ public: void saveUnitAs(int i, const QString& sFileName, bool syncEditor = true); // save single [UnitX] void saveUnitLayout(Editor* e, int index); // save single [UnitX] cursor positions bool saveUnits(); - bool isProjectUnit(const QString& filename); + PProjectUnit findUnitByFilename(const QString& filename); + void associateEditor(Editor* editor); + void associateEditorToUnit(Editor* editor, PProjectUnit unit); void setCompilerOption(const QString& optionString, char value); void sortUnitsByPriority(); void sortUnitsByAlpha();