fix: If a project is auto openned when start, close app will cause dead lock.

This commit is contained in:
Roy Qu 2022-01-13 17:15:57 +08:00
parent 0875d15d67
commit 82bbd7a846
3 changed files with 37 additions and 16 deletions

View File

@ -975,9 +975,11 @@ void MainWindow::openFile(const QString &filename, QTabWidget* page)
} }
try { try {
pSettings->history().removeFile(filename); pSettings->history().removeFile(filename);
bool inProject = (mProject && mProject->isProjectUnit(filename));
editor = mEditorList->newEditor(filename,ENCODING_AUTO_DETECT, editor = mEditorList->newEditor(filename,ENCODING_AUTO_DETECT,
inProject, false, page); false, false, page);
if (mProject) {
mProject->associateEditor(editor);
}
editor->activate(); editor->activate();
this->updateForEncodingInfo(); this->updateForEncodingInfo();
} catch (FileError e) { } catch (FileError e) {
@ -1041,13 +1043,7 @@ void MainWindow::openProject(const QString &filename, bool openFiles)
for (int i=0;i<mProject->units().count();i++) { for (int i=0;i<mProject->units().count();i++) {
PProjectUnit unit = mProject->units()[i]; PProjectUnit unit = mProject->units()[i];
Editor* e = mEditorList->getOpenedEditorByFilename(unit->fileName()); Editor* e = mEditorList->getOpenedEditorByFilename(unit->fileName());
if (e) { mProject->associateEditorToUnit(e,unit);
unit->setEditor(e);
unit->setEncoding(e->encodingOption());
e->setInProject(true);
} else {
unit->setEditor(nullptr);
}
} }
Editor * e = mEditorList->getEditor(); Editor * e = mEditorList->getEditor();
@ -2005,10 +2001,12 @@ void MainWindow::loadLastOpens()
page = mEditorList->leftPageWidget(); page = mEditorList->leftPageWidget();
else else
page = mEditorList->rightPageWidget(); page = mEditorList->rightPageWidget();
bool inProject = (mProject && mProject->isProjectUnit(editorFilename)); Editor * editor = mEditorList->newEditor(editorFilename,ENCODING_AUTO_DETECT,false,false,page);
Editor * editor = mEditorList->newEditor(editorFilename,ENCODING_AUTO_DETECT,inProject,false,page);
if (!editor) if (!editor)
continue; continue;
if (mProject) {
mProject->associateEditor(editor);
}
BufferCoord pos; BufferCoord pos;
pos.Char = lastOpenIni.GetLongValue(sectionName,"CursorCol", 1); pos.Char = lastOpenIni.GetLongValue(sectionName,"CursorCol", 1);
pos.Line = lastOpenIni.GetLongValue(sectionName,"CursorRow", 1); pos.Line = lastOpenIni.GetLongValue(sectionName,"CursorRow", 1);

View File

@ -564,13 +564,34 @@ bool Project::saveUnits()
return true; 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) 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) void Project::setCompilerOption(const QString &optionString, char value)

View File

@ -184,7 +184,9 @@ public:
void saveUnitAs(int i, const QString& sFileName, bool syncEditor = true); // save single [UnitX] void saveUnitAs(int i, const QString& sFileName, bool syncEditor = true); // save single [UnitX]
void saveUnitLayout(Editor* e, int index); // save single [UnitX] cursor positions void saveUnitLayout(Editor* e, int index); // save single [UnitX] cursor positions
bool saveUnits(); 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 setCompilerOption(const QString& optionString, char value);
void sortUnitsByPriority(); void sortUnitsByPriority();
void sortUnitsByAlpha(); void sortUnitsByAlpha();