refactor: remove ProjectUnit's mEditor field
This commit is contained in:
parent
947374b907
commit
090cccc033
|
@ -356,9 +356,10 @@ void ProjectCompiler::writeMakeObjFilesRules(QFile &file)
|
||||||
if (mProject->options().addCharset) {
|
if (mProject->options().addCharset) {
|
||||||
QByteArray defaultSystemEncoding = pCharsetInfoManager->getDefaultSystemEncoding();
|
QByteArray defaultSystemEncoding = pCharsetInfoManager->getDefaultSystemEncoding();
|
||||||
if (unit->encoding() == ENCODING_AUTO_DETECT) {
|
if (unit->encoding() == ENCODING_AUTO_DETECT) {
|
||||||
if (unit->editor() && unit->editor()->fileEncoding()!=ENCODING_ASCII)
|
Editor* editor = mProject->unitEditor(unit);
|
||||||
|
if (editor && editor->fileEncoding()!=ENCODING_ASCII)
|
||||||
encodingStr = QString(" -finput-charset=%1 -fexec-charset=%2")
|
encodingStr = QString(" -finput-charset=%1 -fexec-charset=%2")
|
||||||
.arg(QString(unit->editor()->fileEncoding()),
|
.arg(QString(editor->fileEncoding()),
|
||||||
QString(defaultSystemEncoding));
|
QString(defaultSystemEncoding));
|
||||||
} else if (unit->encoding()==ENCODING_SYSTEM_DEFAULT) {
|
} else if (unit->encoding()==ENCODING_SYSTEM_DEFAULT) {
|
||||||
encodingStr = QString(" -finput-charset=%1 -fexec-charset=%2")
|
encodingStr = QString(" -finput-charset=%1 -fexec-charset=%2")
|
||||||
|
|
|
@ -321,11 +321,15 @@ bool Editor::saveAs(const QString &name, bool fromProject){
|
||||||
QDir::setCurrent(extractFileDir(newName));
|
QDir::setCurrent(extractFileDir(newName));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (pMainWindow->editorList()->getOpenedEditorByFilename(newName)) {
|
||||||
|
QMessageBox::critical(pMainWindow,tr("Error"),
|
||||||
|
tr("File %1 already openned!").arg(newName));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
// Update project information
|
// Update project information
|
||||||
if (mInProject && pMainWindow->project() && !fromProject) {
|
if (mInProject && pMainWindow->project() && !fromProject) {
|
||||||
int unitIndex = pMainWindow->project()->indexInUnits(mFilename);
|
int unitIndex = pMainWindow->project()->indexInUnits(newName);
|
||||||
if (unitIndex>=0) {
|
if (unitIndex<0) {
|
||||||
pMainWindow->project()->units()[unitIndex]->setEditor(nullptr);
|
|
||||||
mInProject = false;
|
mInProject = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1146,7 +1146,9 @@ void MainWindow::openProject(const QString &filename, bool openFiles)
|
||||||
auto action = finally([this]{
|
auto action = finally([this]{
|
||||||
mClassBrowserModel.endUpdate();
|
mClassBrowserModel.endUpdate();
|
||||||
});
|
});
|
||||||
mProject = std::make_shared<Project>(filename,DEV_INTERNAL_OPEN);
|
mProject = std::make_shared<Project>(filename,DEV_INTERNAL_OPEN,
|
||||||
|
mEditorList,
|
||||||
|
&mFileSystemWatcher);
|
||||||
updateProjectView();
|
updateProjectView();
|
||||||
pSettings->history().removeProject(filename);
|
pSettings->history().removeProject(filename);
|
||||||
|
|
||||||
|
@ -5485,7 +5487,9 @@ void MainWindow::on_actionNew_Project_triggered()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create an empty project
|
// Create an empty project
|
||||||
mProject = std::make_shared<Project>(s,dialog.getProjectName());
|
mProject = std::make_shared<Project>(s,dialog.getProjectName(),
|
||||||
|
mEditorList,
|
||||||
|
&mFileSystemWatcher);
|
||||||
if (!mProject->assignTemplate(dialog.getTemplate(),dialog.isCppProject())) {
|
if (!mProject->assignTemplate(dialog.getTemplate(),dialog.isCppProject())) {
|
||||||
mProject = nullptr;
|
mProject = nullptr;
|
||||||
QMessageBox::critical(this,
|
QMessageBox::critical(this,
|
||||||
|
|
|
@ -16,7 +16,6 @@
|
||||||
*/
|
*/
|
||||||
#include "project.h"
|
#include "project.h"
|
||||||
#include "editor.h"
|
#include "editor.h"
|
||||||
#include "mainwindow.h"
|
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
#include "systemconsts.h"
|
#include "systemconsts.h"
|
||||||
#include "editorlist.h"
|
#include "editorlist.h"
|
||||||
|
@ -27,26 +26,33 @@
|
||||||
#include "systemconsts.h"
|
#include "systemconsts.h"
|
||||||
#include "iconsmanager.h"
|
#include "iconsmanager.h"
|
||||||
|
|
||||||
|
#include <QFileSystemWatcher>
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
#include <QFileDialog>
|
#include <QFileDialog>
|
||||||
#include <QFileInfo>
|
#include <QFileInfo>
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
#include <QTextCodec>
|
#include <QTextCodec>
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
|
#include <QDirIterator>
|
||||||
#include "customfileiconprovider.h"
|
#include "customfileiconprovider.h"
|
||||||
#include <QMimeData>
|
#include <QMimeData>
|
||||||
#include "settings.h"
|
#include "settings.h"
|
||||||
#include "vcs/gitrepository.h"
|
#include "vcs/gitrepository.h"
|
||||||
|
|
||||||
Project::Project(const QString &filename, const QString &name, QObject *parent) :
|
Project::Project(const QString &filename, const QString &name,
|
||||||
|
EditorList* editorList,
|
||||||
|
QFileSystemWatcher* fileSystemWatcher,
|
||||||
|
QObject *parent) :
|
||||||
QObject(parent),
|
QObject(parent),
|
||||||
mModel(this)
|
mModel(this),
|
||||||
|
mEditorList(editorList),
|
||||||
|
mFileSystemWatcher(fileSystemWatcher)
|
||||||
{
|
{
|
||||||
mFilename = QFileInfo(filename).absoluteFilePath();
|
mFilename = QFileInfo(filename).absoluteFilePath();
|
||||||
mParser = std::make_shared<CppParser>();
|
mParser = std::make_shared<CppParser>();
|
||||||
mParser->setOnGetFileStream(
|
mParser->setOnGetFileStream(
|
||||||
std::bind(
|
std::bind(
|
||||||
&EditorList::getContentFromOpenedEditor,pMainWindow->editorList(),
|
&EditorList::getContentFromOpenedEditor,mEditorList,
|
||||||
std::placeholders::_1, std::placeholders::_2));
|
std::placeholders::_1, std::placeholders::_2));
|
||||||
if (name == DEV_INTERNAL_OPEN) {
|
if (name == DEV_INTERNAL_OPEN) {
|
||||||
open();
|
open();
|
||||||
|
@ -64,14 +70,14 @@ Project::Project(const QString &filename, const QString &name, QObject *parent)
|
||||||
|
|
||||||
Project::~Project()
|
Project::~Project()
|
||||||
{
|
{
|
||||||
pMainWindow->editorList()->beginUpdate();
|
mEditorList->beginUpdate();
|
||||||
foreach (const PProjectUnit& unit, mUnits) {
|
foreach (const PProjectUnit& unit, mUnits) {
|
||||||
if (unit->editor()) {
|
Editor * editor = unitEditor(unit);
|
||||||
pMainWindow->editorList()->forceCloseEditor(unit->editor());
|
if (editor) {
|
||||||
unit->setEditor(nullptr);
|
mEditorList->forceCloseEditor(editor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pMainWindow->editorList()->endUpdate();
|
mEditorList->endUpdate();
|
||||||
}
|
}
|
||||||
|
|
||||||
QString Project::directory() const
|
QString Project::directory() const
|
||||||
|
@ -155,7 +161,7 @@ void Project::open()
|
||||||
dir.absoluteFilePath(
|
dir.absoluteFilePath(
|
||||||
fromByteArray(ini.GetValue(groupName,"FileName",""))));
|
fromByteArray(ini.GetValue(groupName,"FileName",""))));
|
||||||
if (!QFileInfo(newUnit->fileName()).exists()) {
|
if (!QFileInfo(newUnit->fileName()).exists()) {
|
||||||
QMessageBox::critical(pMainWindow,
|
QMessageBox::critical(nullptr,
|
||||||
tr("File Not Found"),
|
tr("File Not Found"),
|
||||||
tr("Project file '%1' can't be found!")
|
tr("Project file '%1' can't be found!")
|
||||||
.arg(newUnit->fileName()),
|
.arg(newUnit->fileName()),
|
||||||
|
@ -179,7 +185,6 @@ void Project::open()
|
||||||
if (QTextCodec::codecForName(newUnit->encoding())==nullptr) {
|
if (QTextCodec::codecForName(newUnit->encoding())==nullptr) {
|
||||||
newUnit->setEncoding(ENCODING_AUTO_DETECT);
|
newUnit->setEncoding(ENCODING_AUTO_DETECT);
|
||||||
}
|
}
|
||||||
newUnit->setEditor(nullptr);
|
|
||||||
newUnit->setNew(false);
|
newUnit->setNew(false);
|
||||||
newUnit->setParent(this);
|
newUnit->setParent(this);
|
||||||
newUnit->setNode(makeNewFileNode(extractFileName(newUnit->fileName()), false, folderNodeFromName(newUnit->folder())));
|
newUnit->setNode(makeNewFileNode(extractFileName(newUnit->fileName()), false, folderNodeFromName(newUnit->folder())));
|
||||||
|
@ -268,7 +273,6 @@ PProjectUnit Project::newUnit(PProjectModelNode parentNode, const QString& custo
|
||||||
// Set all properties
|
// Set all properties
|
||||||
newUnit->setFileName(s);
|
newUnit->setFileName(s);
|
||||||
newUnit->setNew(true);
|
newUnit->setNew(true);
|
||||||
newUnit->setEditor(nullptr);
|
|
||||||
newUnit->setFolder(getFolderPath(parentNode));
|
newUnit->setFolder(getFolderPath(parentNode));
|
||||||
newUnit->setNode(makeNewFileNode(extractFileName(newUnit->fileName()),
|
newUnit->setNode(makeNewFileNode(extractFileName(newUnit->fileName()),
|
||||||
false, parentNode));
|
false, parentNode));
|
||||||
|
@ -293,9 +297,8 @@ Editor *Project::openUnit(int index)
|
||||||
PProjectUnit unit = mUnits[index];
|
PProjectUnit unit = mUnits[index];
|
||||||
|
|
||||||
if (!unit->fileName().isEmpty()) {
|
if (!unit->fileName().isEmpty()) {
|
||||||
QDir dir(directory());
|
QString fullPath = unitFullPath(unit);
|
||||||
QString fullPath = dir.absoluteFilePath(unit->fileName());
|
Editor * editor = mEditorList->getOpenedEditorByFilename(fullPath);
|
||||||
Editor * editor = pMainWindow->editorList()->getOpenedEditorByFilename(fullPath);
|
|
||||||
if (editor) {//already opened in the editors
|
if (editor) {//already opened in the editors
|
||||||
editor->setInProject(true);
|
editor->setInProject(true);
|
||||||
editor->activate();
|
editor->activate();
|
||||||
|
@ -303,9 +306,8 @@ Editor *Project::openUnit(int index)
|
||||||
}
|
}
|
||||||
QByteArray encoding;
|
QByteArray encoding;
|
||||||
encoding = unit->encoding();
|
encoding = unit->encoding();
|
||||||
editor = pMainWindow->editorList()->newEditor(fullPath, encoding, true, unit->isNew());
|
editor = mEditorList->newEditor(fullPath, encoding, true, unit->isNew());
|
||||||
editor->setInProject(true);
|
editor->setInProject(true);
|
||||||
unit->setEditor(editor);
|
|
||||||
//unit->setEncoding(encoding);
|
//unit->setEncoding(encoding);
|
||||||
editor->activate();
|
editor->activate();
|
||||||
loadUnitLayout(editor,index);
|
loadUnitLayout(editor,index);
|
||||||
|
@ -314,6 +316,28 @@ Editor *Project::openUnit(int index)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString Project::unitFullPath(const PProjectUnit &unit) const
|
||||||
|
{
|
||||||
|
QDir dir(directory());
|
||||||
|
return dir.absoluteFilePath(unit->fileName());
|
||||||
|
}
|
||||||
|
|
||||||
|
QString Project::unitFullPath(const ProjectUnit *unit) const
|
||||||
|
{
|
||||||
|
QDir dir(directory());
|
||||||
|
return dir.absoluteFilePath(unit->fileName());
|
||||||
|
}
|
||||||
|
|
||||||
|
Editor *Project::unitEditor(const PProjectUnit &unit) const
|
||||||
|
{
|
||||||
|
return mEditorList->getOpenedEditorByFilename(unitFullPath(unit));
|
||||||
|
}
|
||||||
|
|
||||||
|
Editor *Project::unitEditor(const ProjectUnit *unit) const
|
||||||
|
{
|
||||||
|
return mEditorList->getOpenedEditorByFilename(unitFullPath(unit));
|
||||||
|
}
|
||||||
|
|
||||||
void Project::rebuildNodes()
|
void Project::rebuildNodes()
|
||||||
{
|
{
|
||||||
mModel.beginUpdate();
|
mModel.beginUpdate();
|
||||||
|
@ -378,10 +402,12 @@ bool Project::removeUnit(int index, bool doClose , bool removeFile)
|
||||||
// qDebug()<<unit->fileName();
|
// qDebug()<<unit->fileName();
|
||||||
// qDebug()<<(qint64)unit->editor();
|
// qDebug()<<(qint64)unit->editor();
|
||||||
// Attempt to close it
|
// Attempt to close it
|
||||||
if (doClose && (unit->editor())) {
|
if (doClose) {
|
||||||
unit->editor()->setInProject(false);
|
Editor* editor = unitEditor(unit);
|
||||||
if (!pMainWindow->editorList()->closeEditor(unit->editor()))
|
if (editor) {
|
||||||
return false;
|
editor->setInProject(false);
|
||||||
|
mEditorList->closeEditor(editor);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (removeFile) {
|
if (removeFile) {
|
||||||
|
@ -450,8 +476,8 @@ void Project::saveLayout()
|
||||||
SimpleIni layIni;
|
SimpleIni layIni;
|
||||||
QStringList sl;
|
QStringList sl;
|
||||||
// Write list of open project files
|
// Write list of open project files
|
||||||
for (int i=0;i<pMainWindow->editorList()->pageCount();i++) {
|
for (int i=0;i<mEditorList->pageCount();i++) {
|
||||||
Editor* e= (*(pMainWindow->editorList()))[i];
|
Editor* e= (*mEditorList)[i];
|
||||||
if (e && e->inProject())
|
if (e && e->inProject())
|
||||||
sl.append(QString("%1").arg(indexInUnits(e)));
|
sl.append(QString("%1").arg(indexInUnits(e)));
|
||||||
}
|
}
|
||||||
|
@ -459,14 +485,14 @@ void Project::saveLayout()
|
||||||
|
|
||||||
Editor *e, *e2;
|
Editor *e, *e2;
|
||||||
// Remember what files were visible
|
// Remember what files were visible
|
||||||
pMainWindow->editorList()->getVisibleEditors(e, e2);
|
mEditorList->getVisibleEditors(e, e2);
|
||||||
if (e)
|
if (e)
|
||||||
layIni.SetLongValue("Editors","Focused", indexInUnits(e));
|
layIni.SetLongValue("Editors","Focused", indexInUnits(e));
|
||||||
// save editor info
|
// save editor info
|
||||||
for (int i=0;i<mUnits.count();i++) {
|
for (int i=0;i<mUnits.count();i++) {
|
||||||
QByteArray groupName = QString("Editor_%1").arg(i).toUtf8();
|
QByteArray groupName = QString("Editor_%1").arg(i).toUtf8();
|
||||||
PProjectUnit unit = mUnits[i];
|
PProjectUnit unit = mUnits[i];
|
||||||
Editor* editor = unit->editor();
|
Editor* editor = unitEditor(unit);
|
||||||
if (editor) {
|
if (editor) {
|
||||||
layIni.SetLongValue(groupName,"CursorCol", editor->caretX());
|
layIni.SetLongValue(groupName,"CursorCol", editor->caretX());
|
||||||
layIni.SetLongValue(groupName,"CursorRow", editor->caretY());
|
layIni.SetLongValue(groupName,"CursorRow", editor->caretY());
|
||||||
|
@ -496,9 +522,10 @@ void Project::saveUnitAs(int i, const QString &sFileName, bool syncEditor)
|
||||||
if (fileExists(unit->fileName())) {
|
if (fileExists(unit->fileName())) {
|
||||||
unit->setNew(false);
|
unit->setNew(false);
|
||||||
}
|
}
|
||||||
if (unit->editor() && syncEditor) {
|
Editor * editor=unitEditor(unit);
|
||||||
|
if (editor && syncEditor) {
|
||||||
//prevent recurse
|
//prevent recurse
|
||||||
unit->editor()->saveAs(sFileName,true);
|
editor->saveAs(sFileName,true);
|
||||||
}
|
}
|
||||||
unit->setNew(false);
|
unit->setNew(false);
|
||||||
unit->setFileName(sFileName);
|
unit->setFileName(sFileName);
|
||||||
|
@ -548,7 +575,7 @@ bool Project::saveUnits()
|
||||||
if (unit->modified() && fileExists(unit->fileName())
|
if (unit->modified() && fileExists(unit->fileName())
|
||||||
&& isReadOnly(unit->fileName())) {
|
&& isReadOnly(unit->fileName())) {
|
||||||
// file is read-only
|
// file is read-only
|
||||||
QMessageBox::critical(pMainWindow,
|
QMessageBox::critical(nullptr,
|
||||||
tr("Can't save file"),
|
tr("Can't save file"),
|
||||||
tr("Can't save file '%1'").arg(unit->fileName()),
|
tr("Can't save file '%1'").arg(unit->fileName()),
|
||||||
QMessageBox::Ok
|
QMessageBox::Ok
|
||||||
|
@ -618,11 +645,10 @@ void Project::associateEditorToUnit(Editor *editor, PProjectUnit unit)
|
||||||
if (!unit)
|
if (!unit)
|
||||||
return;
|
return;
|
||||||
if (editor) {
|
if (editor) {
|
||||||
unit->setEditor(editor);
|
|
||||||
unit->setEncoding(editor->encodingOption());
|
unit->setEncoding(editor->encodingOption());
|
||||||
editor->setInProject(true);
|
editor->setInProject(true);
|
||||||
} else {
|
} else {
|
||||||
unit->setEditor(nullptr);
|
editor->setInProject(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -730,8 +756,8 @@ bool Project::assignTemplate(const std::shared_ptr<ProjectTemplate> aTemplate, b
|
||||||
unit = newUnit(mRootNode,templateUnit->CName);
|
unit = newUnit(mRootNode,templateUnit->CName);
|
||||||
}
|
}
|
||||||
|
|
||||||
Editor * editor = pMainWindow->editorList()->newEditor(
|
Editor * editor = mEditorList->newEditor(
|
||||||
QDir(directory()).absoluteFilePath(unit->fileName()),
|
unitFullPath(unit),
|
||||||
unit->encoding(),
|
unit->encoding(),
|
||||||
true,
|
true,
|
||||||
true);
|
true);
|
||||||
|
@ -741,7 +767,7 @@ bool Project::assignTemplate(const std::shared_ptr<ProjectTemplate> aTemplate, b
|
||||||
try {
|
try {
|
||||||
editor->loadFile(s2);
|
editor->loadFile(s2);
|
||||||
} catch(FileError& e) {
|
} catch(FileError& e) {
|
||||||
QMessageBox::critical(pMainWindow,
|
QMessageBox::critical(nullptr,
|
||||||
tr("Error Load File"),
|
tr("Error Load File"),
|
||||||
e.reason());
|
e.reason());
|
||||||
}
|
}
|
||||||
|
@ -749,7 +775,6 @@ bool Project::assignTemplate(const std::shared_ptr<ProjectTemplate> aTemplate, b
|
||||||
s.replace("#13#10","\r\n");
|
s.replace("#13#10","\r\n");
|
||||||
editor->insertString(s,false);
|
editor->insertString(s,false);
|
||||||
}
|
}
|
||||||
unit->setEditor(editor);
|
|
||||||
editor->save(true,false);
|
editor->save(true,false);
|
||||||
editor->activate();
|
editor->activate();
|
||||||
}
|
}
|
||||||
|
@ -853,7 +878,7 @@ PProjectUnit Project::addUnit(const QString &inFileName, PProjectModelNode paren
|
||||||
PProjectUnit newUnit;
|
PProjectUnit newUnit;
|
||||||
// Don't add if it already exists
|
// Don't add if it already exists
|
||||||
if (fileAlreadyExists(inFileName)) {
|
if (fileAlreadyExists(inFileName)) {
|
||||||
QMessageBox::critical(pMainWindow,
|
QMessageBox::critical(nullptr,
|
||||||
tr("File Exists"),
|
tr("File Exists"),
|
||||||
tr("File '%1' is already in the project"),
|
tr("File '%1' is already in the project"),
|
||||||
QMessageBox::Ok);
|
QMessageBox::Ok);
|
||||||
|
@ -864,13 +889,11 @@ PProjectUnit Project::addUnit(const QString &inFileName, PProjectModelNode paren
|
||||||
// Set all properties
|
// Set all properties
|
||||||
newUnit->setFileName(QDir(directory()).filePath(inFileName));
|
newUnit->setFileName(QDir(directory()).filePath(inFileName));
|
||||||
newUnit->setNew(false);
|
newUnit->setNew(false);
|
||||||
Editor * e= pMainWindow->editorList()->getOpenedEditorByFilename(newUnit->fileName());
|
Editor * e= unitEditor(newUnit);
|
||||||
if (e) {
|
if (e) {
|
||||||
newUnit->setEditor(e);
|
|
||||||
newUnit->setEncoding(e->encodingOption());
|
newUnit->setEncoding(e->encodingOption());
|
||||||
e->setInProject(true);
|
e->setInProject(true);
|
||||||
} else {
|
} else {
|
||||||
newUnit->setEditor(nullptr);
|
|
||||||
newUnit->setEncoding(ENCODING_AUTO_DETECT);
|
newUnit->setEncoding(ENCODING_AUTO_DETECT);
|
||||||
}
|
}
|
||||||
newUnit->setFolder(getFolderPath(parentNode));
|
newUnit->setFolder(getFolderPath(parentNode));
|
||||||
|
@ -1228,7 +1251,7 @@ void Project::checkProjectFileForUpdate(SimpleIni &ini)
|
||||||
|
|
||||||
if (cnvt)
|
if (cnvt)
|
||||||
QMessageBox::information(
|
QMessageBox::information(
|
||||||
pMainWindow,
|
nullptr,
|
||||||
tr("Project Updated"),
|
tr("Project Updated"),
|
||||||
tr("Your project was succesfully updated to a newer file format!")
|
tr("Your project was succesfully updated to a newer file format!")
|
||||||
+"<br />"
|
+"<br />"
|
||||||
|
@ -1240,11 +1263,11 @@ void Project::checkProjectFileForUpdate(SimpleIni &ini)
|
||||||
void Project::closeUnit(int index)
|
void Project::closeUnit(int index)
|
||||||
{
|
{
|
||||||
PProjectUnit unit = mUnits[index];
|
PProjectUnit unit = mUnits[index];
|
||||||
if (unit->editor()) {
|
Editor * editor =unitEditor(unit);
|
||||||
saveUnitLayout(unit->editor(),index);
|
if (editor) {
|
||||||
unit->editor()->setInProject(false);
|
saveUnitLayout(editor,index);
|
||||||
pMainWindow->editorList()->forceCloseEditor(unit->editor());
|
editor->setInProject(false);
|
||||||
unit->setEditor(nullptr);
|
mEditorList->forceCloseEditor(editor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1432,8 +1455,9 @@ void Project::loadLayout()
|
||||||
openUnit(currIdx);
|
openUnit(currIdx);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (topLeft>=0 && topLeft<mUnits.count() && mUnits[topLeft]->editor()) {
|
if (topLeft>=0 && topLeft<mUnits.count()) {
|
||||||
mUnits[topLeft]->editor()->activate();
|
Editor * editor = unitEditor(mUnits[topLeft]);
|
||||||
|
editor->activate();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1450,7 +1474,7 @@ void Project::loadOptions(SimpleIni& ini)
|
||||||
if (mOptions.version > 0) { // ver > 0 is at least a v5 project
|
if (mOptions.version > 0) { // ver > 0 is at least a v5 project
|
||||||
if (mOptions.version < 2) {
|
if (mOptions.version < 2) {
|
||||||
mOptions.version = 2;
|
mOptions.version = 2;
|
||||||
QMessageBox::information(pMainWindow,
|
QMessageBox::information(nullptr,
|
||||||
tr("Settings need update"),
|
tr("Settings need update"),
|
||||||
tr("The compiler settings format of Red Panda C++ has changed.")
|
tr("The compiler settings format of Red Panda C++ has changed.")
|
||||||
+"<BR /><BR />"
|
+"<BR /><BR />"
|
||||||
|
@ -1490,7 +1514,7 @@ void Project::loadOptions(SimpleIni& ini)
|
||||||
if (mOptions.compilerSet >= pSettings->compilerSets().size()
|
if (mOptions.compilerSet >= pSettings->compilerSets().size()
|
||||||
|| mOptions.compilerSet < 0) { // TODO: change from indices to names
|
|| mOptions.compilerSet < 0) { // TODO: change from indices to names
|
||||||
QMessageBox::critical(
|
QMessageBox::critical(
|
||||||
pMainWindow,
|
nullptr,
|
||||||
tr("Compiler not found"),
|
tr("Compiler not found"),
|
||||||
tr("The compiler set you have selected for this project, no longer exists.")
|
tr("The compiler set you have selected for this project, no longer exists.")
|
||||||
+"<BR />"
|
+"<BR />"
|
||||||
|
@ -1655,6 +1679,16 @@ void Project::updateCompilerSetType()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QFileSystemWatcher *Project::fileSystemWatcher() const
|
||||||
|
{
|
||||||
|
return mFileSystemWatcher;
|
||||||
|
}
|
||||||
|
|
||||||
|
EditorList *Project::editorList() const
|
||||||
|
{
|
||||||
|
return mEditorList;
|
||||||
|
}
|
||||||
|
|
||||||
const QList<PProjectUnit> &Project::units() const
|
const QList<PProjectUnit> &Project::units() const
|
||||||
{
|
{
|
||||||
return mUnits;
|
return mUnits;
|
||||||
|
@ -1709,7 +1743,6 @@ const QString &Project::filename() const
|
||||||
|
|
||||||
ProjectUnit::ProjectUnit(Project* parent)
|
ProjectUnit::ProjectUnit(Project* parent)
|
||||||
{
|
{
|
||||||
mEditor = nullptr;
|
|
||||||
mNode = nullptr;
|
mNode = nullptr;
|
||||||
mParent = parent;
|
mParent = parent;
|
||||||
}
|
}
|
||||||
|
@ -1724,16 +1757,6 @@ void ProjectUnit::setParent(Project* newParent)
|
||||||
mParent = newParent;
|
mParent = newParent;
|
||||||
}
|
}
|
||||||
|
|
||||||
Editor *ProjectUnit::editor() const
|
|
||||||
{
|
|
||||||
return mEditor;
|
|
||||||
}
|
|
||||||
|
|
||||||
void ProjectUnit::setEditor(Editor *newEditor)
|
|
||||||
{
|
|
||||||
mEditor = newEditor;
|
|
||||||
}
|
|
||||||
|
|
||||||
const QString &ProjectUnit::fileName() const
|
const QString &ProjectUnit::fileName() const
|
||||||
{
|
{
|
||||||
return mFileName;
|
return mFileName;
|
||||||
|
@ -1842,8 +1865,9 @@ const QByteArray &ProjectUnit::encoding() const
|
||||||
void ProjectUnit::setEncoding(const QByteArray &newEncoding)
|
void ProjectUnit::setEncoding(const QByteArray &newEncoding)
|
||||||
{
|
{
|
||||||
if (mEncoding != newEncoding) {
|
if (mEncoding != newEncoding) {
|
||||||
if (mEditor) {
|
Editor * editor=mParent->unitEditor(this);
|
||||||
mEditor->setEncodingOption(newEncoding);
|
if (editor) {
|
||||||
|
editor->setEncodingOption(newEncoding);
|
||||||
}
|
}
|
||||||
mEncoding = newEncoding;
|
mEncoding = newEncoding;
|
||||||
}
|
}
|
||||||
|
@ -1851,8 +1875,9 @@ void ProjectUnit::setEncoding(const QByteArray &newEncoding)
|
||||||
|
|
||||||
bool ProjectUnit::modified() const
|
bool ProjectUnit::modified() const
|
||||||
{
|
{
|
||||||
if (mEditor) {
|
Editor * editor=mParent->unitEditor(this);
|
||||||
return mEditor->modified();
|
if (editor) {
|
||||||
|
return editor->modified();
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -1860,9 +1885,10 @@ bool ProjectUnit::modified() const
|
||||||
|
|
||||||
void ProjectUnit::setModified(bool value)
|
void ProjectUnit::setModified(bool value)
|
||||||
{
|
{
|
||||||
|
Editor * editor=mParent->unitEditor(this);
|
||||||
// Mark the change in the coupled editor
|
// Mark the change in the coupled editor
|
||||||
if (mEditor) {
|
if (editor) {
|
||||||
return mEditor->setModified(value);
|
return editor->setModified(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
// If modified is set to true, mark project as modified too
|
// If modified is set to true, mark project as modified too
|
||||||
|
@ -1873,17 +1899,18 @@ void ProjectUnit::setModified(bool value)
|
||||||
|
|
||||||
bool ProjectUnit::save()
|
bool ProjectUnit::save()
|
||||||
{
|
{
|
||||||
bool previous=pMainWindow->fileSystemWatcher()->blockSignals(true);
|
bool previous=mParent->fileSystemWatcher()->blockSignals(true);
|
||||||
auto action = finally([&previous](){
|
auto action = finally([&previous,this](){
|
||||||
pMainWindow->fileSystemWatcher()->blockSignals(previous);
|
mParent->fileSystemWatcher()->blockSignals(previous);
|
||||||
});
|
});
|
||||||
bool result=true;
|
bool result=true;
|
||||||
if (!mEditor && !fileExists(mFileName)) {
|
Editor * editor=mParent->unitEditor(this);
|
||||||
|
if (!editor && !fileExists(mFileName)) {
|
||||||
// file is neither open, nor saved
|
// file is neither open, nor saved
|
||||||
QStringList temp;
|
QStringList temp;
|
||||||
stringsToFile(temp,mFileName);
|
stringsToFile(temp,mFileName);
|
||||||
} else if (mEditor && mEditor->modified()) {
|
} else if (editor && editor->modified()) {
|
||||||
result = mEditor->save();
|
result = editor->save();
|
||||||
}
|
}
|
||||||
if (mNode) {
|
if (mNode) {
|
||||||
mNode->text = extractFileName(mFileName);
|
mNode->text = extractFileName(mFileName);
|
||||||
|
@ -2083,16 +2110,16 @@ bool ProjectModel::setData(const QModelIndex &index, const QVariant &value, int
|
||||||
// Only continue if the user says so...
|
// Only continue if the user says so...
|
||||||
if (fileExists(newName) && newName.compare(oldName, PATH_SENSITIVITY)!=0) {
|
if (fileExists(newName) && newName.compare(oldName, PATH_SENSITIVITY)!=0) {
|
||||||
// don't remove when changing case for example
|
// don't remove when changing case for example
|
||||||
if (QMessageBox::question(pMainWindow,
|
if (QMessageBox::question(nullptr,
|
||||||
tr("File exists"),
|
tr("File exists"),
|
||||||
tr("File '%1' already exists. Delete it now?")
|
tr("File '%1' already exists. Delete it now?")
|
||||||
.arg(newName),
|
.arg(newName),
|
||||||
QMessageBox::Yes | QMessageBox::No,
|
QMessageBox::Yes | QMessageBox::No,
|
||||||
QMessageBox::No) == QMessageBox::Yes) {
|
QMessageBox::No) == QMessageBox::Yes) {
|
||||||
// Close the target file...
|
// Close the target file...
|
||||||
Editor * e= pMainWindow->editorList()->getOpenedEditorByFilename(newName);
|
Editor * e=mProject->editorList()->getOpenedEditorByFilename(newName);
|
||||||
if (e)
|
if (e)
|
||||||
pMainWindow->editorList()->closeEditor(e);
|
mProject->editorList()->closeEditor(e);
|
||||||
|
|
||||||
// Remove it from the current project...
|
// Remove it from the current project...
|
||||||
int projindex = mProject->indexInUnits(newName);
|
int projindex = mProject->indexInUnits(newName);
|
||||||
|
@ -2102,7 +2129,7 @@ bool ProjectModel::setData(const QModelIndex &index, const QVariant &value, int
|
||||||
|
|
||||||
// All references to the file are removed. Delete the file from disk
|
// All references to the file are removed. Delete the file from disk
|
||||||
if (!QFile::remove(newName)) {
|
if (!QFile::remove(newName)) {
|
||||||
QMessageBox::critical(pMainWindow,
|
QMessageBox::critical(nullptr,
|
||||||
tr("Remove failed"),
|
tr("Remove failed"),
|
||||||
tr("Failed to remove file '%1'")
|
tr("Failed to remove file '%1'")
|
||||||
.arg(newName),
|
.arg(newName),
|
||||||
|
@ -2117,10 +2144,10 @@ bool ProjectModel::setData(const QModelIndex &index, const QVariant &value, int
|
||||||
// change name in project file first (no actual file renaming on disk)
|
// change name in project file first (no actual file renaming on disk)
|
||||||
//save old file, if it is openned;
|
//save old file, if it is openned;
|
||||||
// remove old file from monitor list
|
// remove old file from monitor list
|
||||||
pMainWindow->fileSystemWatcher()->removePath(oldName);
|
mProject->fileSystemWatcher()->removePath(oldName);
|
||||||
|
|
||||||
if (!QFile::rename(oldName,newName)) {
|
if (!QFile::rename(oldName,newName)) {
|
||||||
QMessageBox::critical(pMainWindow,
|
QMessageBox::critical(nullptr,
|
||||||
tr("Rename failed"),
|
tr("Rename failed"),
|
||||||
tr("Failed to rename file '%1' to '%2'")
|
tr("Failed to rename file '%1' to '%2'")
|
||||||
.arg(oldName,newName),
|
.arg(oldName,newName),
|
||||||
|
@ -2130,7 +2157,7 @@ bool ProjectModel::setData(const QModelIndex &index, const QVariant &value, int
|
||||||
mProject->saveUnitAs(idx,newName);
|
mProject->saveUnitAs(idx,newName);
|
||||||
|
|
||||||
// Add new filename to file minitor
|
// Add new filename to file minitor
|
||||||
pMainWindow->fileSystemWatcher()->addPath(newName);
|
mProject->fileSystemWatcher()->addPath(newName);
|
||||||
|
|
||||||
//suffix changed
|
//suffix changed
|
||||||
if (mProject && mProject->modelType() == ProjectModelType::FileSystem
|
if (mProject && mProject->modelType() == ProjectModelType::FileSystem
|
||||||
|
|
|
@ -26,6 +26,8 @@
|
||||||
class Project;
|
class Project;
|
||||||
class Editor;
|
class Editor;
|
||||||
class CppParser;
|
class CppParser;
|
||||||
|
class EditorList;
|
||||||
|
class QFileSystemWatcher;
|
||||||
|
|
||||||
|
|
||||||
enum ProjectSpecialFolderNode {
|
enum ProjectSpecialFolderNode {
|
||||||
|
@ -54,8 +56,6 @@ public:
|
||||||
explicit ProjectUnit(Project* parent);
|
explicit ProjectUnit(Project* parent);
|
||||||
Project* parent() const;
|
Project* parent() const;
|
||||||
void setParent(Project* newParent);
|
void setParent(Project* newParent);
|
||||||
Editor *editor() const;
|
|
||||||
void setEditor(Editor *newEditor);
|
|
||||||
const QString &fileName() const;
|
const QString &fileName() const;
|
||||||
void setFileName(QString newFileName);
|
void setFileName(QString newFileName);
|
||||||
bool isNew() const;
|
bool isNew() const;
|
||||||
|
@ -85,7 +85,6 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Project* mParent;
|
Project* mParent;
|
||||||
Editor* mEditor;
|
|
||||||
QString mFileName;
|
QString mFileName;
|
||||||
bool mNew;
|
bool mNew;
|
||||||
QString mFolder;
|
QString mFolder;
|
||||||
|
@ -154,7 +153,10 @@ class Project : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
explicit Project(const QString& filename, const QString& name,QObject *parent = nullptr);
|
explicit Project(const QString& filename, const QString& name,
|
||||||
|
EditorList* editorList,
|
||||||
|
QFileSystemWatcher* fileSystemWatcher,
|
||||||
|
QObject *parent = nullptr);
|
||||||
~Project();
|
~Project();
|
||||||
QString directory() const;
|
QString directory() const;
|
||||||
QString executable() const;
|
QString executable() const;
|
||||||
|
@ -181,6 +183,15 @@ public:
|
||||||
PProjectUnit newUnit(PProjectModelNode parentNode,
|
PProjectUnit newUnit(PProjectModelNode parentNode,
|
||||||
const QString& customFileName="");
|
const QString& customFileName="");
|
||||||
Editor* openUnit(int index);
|
Editor* openUnit(int index);
|
||||||
|
QString unitFullPath(const PProjectUnit& unit) const;
|
||||||
|
QString unitFullPath(const ProjectUnit* unit) const;
|
||||||
|
Editor* unitEditor(const PProjectUnit& unit) const;
|
||||||
|
Editor* unitEditor(const ProjectUnit* unit) const;
|
||||||
|
Editor* unitEditor(int index) const {
|
||||||
|
if (index<0 || index>=mUnits.count())
|
||||||
|
return nullptr;
|
||||||
|
return unitEditor(mUnits[index]);
|
||||||
|
}
|
||||||
PProjectModelNode pointerToNode(ProjectModelNode * p, PProjectModelNode parent=PProjectModelNode());
|
PProjectModelNode pointerToNode(ProjectModelNode * p, PProjectModelNode parent=PProjectModelNode());
|
||||||
void rebuildNodes();
|
void rebuildNodes();
|
||||||
bool removeUnit(int index, bool doClose, bool removeFile = false);
|
bool removeUnit(int index, bool doClose, bool removeFile = false);
|
||||||
|
@ -220,6 +231,10 @@ public:
|
||||||
ProjectModelType modelType() const;
|
ProjectModelType modelType() const;
|
||||||
void setModelType(ProjectModelType type);
|
void setModelType(ProjectModelType type);
|
||||||
|
|
||||||
|
EditorList *editorList() const;
|
||||||
|
|
||||||
|
QFileSystemWatcher *fileSystemWatcher() const;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void nodesChanged();
|
void nodesChanged();
|
||||||
void modifyChanged(bool value);
|
void modifyChanged(bool value);
|
||||||
|
@ -256,6 +271,8 @@ private:
|
||||||
QHash<ProjectSpecialFolderNode, PProjectModelNode> mSpecialNodes;
|
QHash<ProjectSpecialFolderNode, PProjectModelNode> mSpecialNodes;
|
||||||
QHash<QString, PProjectModelNode> mFileSystemFolderNodes;
|
QHash<QString, PProjectModelNode> mFileSystemFolderNodes;
|
||||||
ProjectModel mModel;
|
ProjectModel mModel;
|
||||||
|
EditorList *mEditorList;
|
||||||
|
QFileSystemWatcher* mFileSystemWatcher;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // PROJECT_H
|
#endif // PROJECT_H
|
||||||
|
|
|
@ -362,7 +362,7 @@ void SearchDialog::on_btnExecute_clicked()
|
||||||
SearchFileScope::wholeProject
|
SearchFileScope::wholeProject
|
||||||
);
|
);
|
||||||
for (int i=0;i<pMainWindow->project()->units().count();i++) {
|
for (int i=0;i<pMainWindow->project()->units().count();i++) {
|
||||||
Editor * e = pMainWindow->project()->units()[i]->editor();
|
Editor * e = pMainWindow->project()->unitEditor(i);
|
||||||
QString curFilename = pMainWindow->project()->units()[i]->fileName();
|
QString curFilename = pMainWindow->project()->units()[i]->fileName();
|
||||||
if (e) {
|
if (e) {
|
||||||
fileSearched++;
|
fileSearched++;
|
||||||
|
|
Loading…
Reference in New Issue