From 1f4e1e0ffe77aa9bd912bcfce6891180c800c7d4 Mon Sep 17 00:00:00 2001 From: Kimmo Varis Date: Wed, 24 Aug 2011 22:41:48 +0300 Subject: [PATCH] GUI: Check the project after creation. Earlier the GUI (project) went into some weird state after creating a new project. The project could not be checked in any discoverable way. This commit fixes the above bug by automatically checking the new project after the project dialog is closed. I think this is what most users expect to happen. --- gui/mainwindow.cpp | 15 ++++++++++++--- gui/mainwindow.h | 6 ++++++ gui/project.cpp | 10 ++++++++++ gui/project.h | 13 +++++++++++++ 4 files changed, 41 insertions(+), 3 deletions(-) diff --git a/gui/mainwindow.cpp b/gui/mainwindow.cpp index 57dc37998..a6e6a4f73 100644 --- a/gui/mainwindow.cpp +++ b/gui/mainwindow.cpp @@ -856,8 +856,16 @@ void MainWindow::LoadProjectFile(const QString &filePath) mUI.mActionEditProjectFile->setEnabled(true); delete mProject; mProject = new Project(filePath, this); - mProject->Open(); - const QString rootpath = mProject->GetProjectFile()->GetRootPath(); + CheckProject(mProject); +} + +void MainWindow::CheckProject(Project *project) +{ + if (!project->IsOpen()) + project->Open(); + + QFileInfo inf(project->Filename()); + const QString rootpath = project->GetProjectFile()->GetRootPath(); // If the root path is not given or is not "current dir", use project // file's location directory as root path @@ -866,7 +874,7 @@ void MainWindow::LoadProjectFile(const QString &filePath) else mCurrentDirectory = rootpath; - QStringList paths = mProject->GetProjectFile()->GetCheckPaths(); + QStringList paths = project->GetProjectFile()->GetCheckPaths(); // If paths not given then check the root path (which may be the project // file's location, see above). This is to keep the compatibility with @@ -911,6 +919,7 @@ void MainWindow::NewProjectFile() mProject->Edit(); } AddProjectMRU(filepath); + CheckProject(mProject); } void MainWindow::CloseProjectFile() diff --git a/gui/mainwindow.h b/gui/mainwindow.h index 8ea309e84..9abbdb450 100644 --- a/gui/mainwindow.h +++ b/gui/mainwindow.h @@ -169,6 +169,12 @@ public slots: */ void Save(); + /** + * @brief Check the project. + * @param project Pointer to the project to check. + */ + void CheckProject(Project *project); + /** * @brief Slot to create new project file.. * diff --git a/gui/project.cpp b/gui/project.cpp index 856255117..eaa56b7f3 100644 --- a/gui/project.cpp +++ b/gui/project.cpp @@ -47,11 +47,21 @@ Project::~Project() delete mPFile; } +QString Project::Filename() const +{ + return mFilename; +} + void Project::SetFilename(const QString &filename) { mFilename = filename; } +bool Project::IsOpen() const +{ + return mPFile != NULL; +} + bool Project::Open() { mPFile = new ProjectFile(mFilename, this); diff --git a/gui/project.h b/gui/project.h index 5d0945164..2d235e314 100644 --- a/gui/project.h +++ b/gui/project.h @@ -41,12 +41,25 @@ public: Project(const QString &filename, QWidget *parent = 0); ~Project(); + /** + * @brief Return the filename of the project. + * @return Project's filename. + */ + QString Filename() const; + /** * @brief Set filename for the project file. * @param filename Filename. */ void SetFilename(const QString &filename); + /** + * @brief Is the project open? + * The project is considered to be open if it has an opened project file. + * @return true if the project is open, false otherwise. + */ + bool IsOpen() const; + /** * @brief Open existing project file. */