Commit a945f8b5 authored by Friedemann Kleint's avatar Friedemann Kleint
Browse files

ProjectManager: Make Open Project dialog open in default folder

Move open project dialog handling into ProjectExplorer and make it
use its list of project file patterns. Same in Checkout wizards.

Task-number: QTCREATORBUG-1759
Reviewed-by: dt
parent eaf8d269
...@@ -677,7 +677,7 @@ QString FileManager::getSaveAsFileName(IFile *file) ...@@ -677,7 +677,7 @@ QString FileManager::getSaveAsFileName(IFile *file)
} }
/*! /*!
\fn QString FileManager::getOpenFileNames(const QStringList &filters, QString *selectedFilter) const \fn QString FileManager::getOpenFileNames(const QStringList &filters, const QString &path, QString *selectedFilter) const
Asks the user for a set of file names to be opened. Asks the user for a set of file names to be opened.
*/ */
......
...@@ -1292,18 +1292,6 @@ QPrinter *MainWindow::printer() const ...@@ -1292,18 +1292,6 @@ QPrinter *MainWindow::printer() const
return m_printer; return m_printer;
} }
void MainWindow::openProject()
{
// ### We need a way to access the mimedatabase and differentiate
// between project types and other files. This is currently not possible
const QString filters = "All Files (*);;Projects(*.pro *.qmlproject)";
QString selectedFilters = "Projects(*.pro *.qmlproject)";
QStringList files =
Core::ICore::instance()->fileManager()->getOpenFileNames(
filters, tr("Open Project"), &selectedFilters);
openFiles(files);
}
void MainWindow::setFullScreen(bool on) void MainWindow::setFullScreen(bool on)
{ {
if (bool(windowState() & Qt::WindowFullScreen) == on) if (bool(windowState() & Qt::WindowFullScreen) == on)
......
...@@ -128,7 +128,6 @@ signals: ...@@ -128,7 +128,6 @@ signals:
void windowActivated(); void windowActivated();
public slots: public slots:
void openProject();
void newFile(); void newFile();
void openFileWith(); void openFileWith();
void exit(); void exit();
......
...@@ -1006,13 +1006,18 @@ bool ProjectExplorerPlugin::openProject(const QString &fileName) ...@@ -1006,13 +1006,18 @@ bool ProjectExplorerPlugin::openProject(const QString &fileName)
return false; return false;
} }
static inline QList<IProjectManager*> allProjectManagers()
{
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
return pm->getObjects<IProjectManager>();
}
QList<Project *> ProjectExplorerPlugin::openProjects(const QStringList &fileNames) QList<Project *> ProjectExplorerPlugin::openProjects(const QStringList &fileNames)
{ {
if (debug) if (debug)
qDebug() << "ProjectExplorerPlugin - opening projects " << fileNames; qDebug() << "ProjectExplorerPlugin - opening projects " << fileNames;
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance(); const QList<IProjectManager*> projectManagers = allProjectManagers();
QList<IProjectManager*> projectManagers = pm->getObjects<IProjectManager>();
QList<Project*> openedPro; QList<Project*> openedPro;
foreach (const QString &fileName, fileNames) { foreach (const QString &fileName, fileNames) {
...@@ -2157,4 +2162,28 @@ Internal::ProjectExplorerSettings ProjectExplorerPlugin::projectExplorerSettings ...@@ -2157,4 +2162,28 @@ Internal::ProjectExplorerSettings ProjectExplorerPlugin::projectExplorerSettings
return d->m_projectExplorerSettings; return d->m_projectExplorerSettings;
} }
QStringList ProjectExplorerPlugin::projectFilePatterns()
{
QStringList patterns;
const Core::MimeDatabase *mdb = Core::ICore::instance()->mimeDatabase();
foreach(const IProjectManager *pm, allProjectManagers())
if (const Core::MimeType mt = mdb->findByType(pm->mimeType()))
foreach(const QRegExp &re, mt.globPatterns())
patterns += re.pattern();
return patterns;
}
void ProjectExplorerPlugin::openOpenProjectDialog()
{
Core::FileManager *fileMananger = Core::ICore::instance()->fileManager();
const QString projectPatterns = ProjectExplorerPlugin::projectFilePatterns().join(QString(QLatin1Char(' ')));
QString projectFilesFilter = tr("Projects (%1)").arg(projectPatterns);
const QString allFilesFilter = tr("All Files (*)");
const QString filters = allFilesFilter + QLatin1String(";;") + projectFilesFilter;
const QString path = fileMananger->useProjectsDirectory() ? fileMananger->projectsDirectory() : QString();
const QStringList files = fileMananger->getOpenFileNames(filters, path, &projectFilesFilter);
if (!files.isEmpty())
Core::ICore::instance()->openFiles(files);
}
Q_EXPORT_PLUGIN(ProjectExplorerPlugin) Q_EXPORT_PLUGIN(ProjectExplorerPlugin)
...@@ -107,6 +107,8 @@ public: ...@@ -107,6 +107,8 @@ public:
void startRunControl(RunControl *runControl, const QString &mode); void startRunControl(RunControl *runControl, const QString &mode);
static QStringList projectFilePatterns();
signals: signals:
void aboutToShowContextMenu(ProjectExplorer::Project *project, void aboutToShowContextMenu(ProjectExplorer::Project *project,
ProjectExplorer::Node *node); ProjectExplorer::Node *node);
...@@ -123,6 +125,7 @@ signals: ...@@ -123,6 +125,7 @@ signals:
public slots: public slots:
void setStartupProject(ProjectExplorer::Project *project = 0); void setStartupProject(ProjectExplorer::Project *project = 0);
void openOpenProjectDialog();
private slots: private slots:
void buildStateChanged(ProjectExplorer::Project * pro); void buildStateChanged(ProjectExplorer::Project * pro);
......
...@@ -28,6 +28,7 @@ ...@@ -28,6 +28,7 @@
**************************************************************************/ **************************************************************************/
#include "projectwelcomepagewidget.h" #include "projectwelcomepagewidget.h"
#include "projectexplorer.h"
#include "ui_projectwelcomepagewidget.h" #include "ui_projectwelcomepagewidget.h"
#include <coreplugin/coreconstants.h> #include <coreplugin/coreconstants.h>
...@@ -92,7 +93,8 @@ ProjectWelcomePageWidget::ProjectWelcomePageWidget(QWidget *parent) : ...@@ -92,7 +93,8 @@ ProjectWelcomePageWidget::ProjectWelcomePageWidget(QWidget *parent) :
connect(ui->projTreeWidget, SIGNAL(activated(QString)), SLOT(slotProjectClicked(QString))); connect(ui->projTreeWidget, SIGNAL(activated(QString)), SLOT(slotProjectClicked(QString)));
connect(ui->createNewProjectButton, SIGNAL(clicked()), SLOT(slotCreateNewProject())); connect(ui->createNewProjectButton, SIGNAL(clicked()), SLOT(slotCreateNewProject()));
connect(ui->openProjectButton, SIGNAL(clicked()), connect(ui->openProjectButton, SIGNAL(clicked()),
Core::ICore::instance()->mainWindow(), SLOT(openProject())); ProjectExplorer::ProjectExplorerPlugin::instance(),
SLOT(openOpenProjectDialog()));
connect(ui->manageSessionsButton, SIGNAL(clicked()), SIGNAL(manageSessions())); connect(ui->manageSessionsButton, SIGNAL(clicked()), SIGNAL(manageSessions()));
ui->createNewProjectButton->setIcon( ui->createNewProjectButton->setIcon(
......
...@@ -34,6 +34,7 @@ ...@@ -34,6 +34,7 @@
#include <coreplugin/helpmanager.h> #include <coreplugin/helpmanager.h>
#include <coreplugin/coreconstants.h> #include <coreplugin/coreconstants.h>
#include <coreplugin/mainwindow.h> #include <coreplugin/mainwindow.h>
#include <projectexplorer/projectexplorer.h>
#include <utils/pathchooser.h> #include <utils/pathchooser.h>
...@@ -92,7 +93,9 @@ GettingStartedWelcomePageWidget::GettingStartedWelcomePageWidget(QWidget *parent ...@@ -92,7 +93,9 @@ GettingStartedWelcomePageWidget::GettingStartedWelcomePageWidget(QWidget *parent
connect(ui->nextTipBtn, SIGNAL(clicked()), this, SLOT(slotNextTip())); connect(ui->nextTipBtn, SIGNAL(clicked()), this, SLOT(slotNextTip()));
connect(ui->prevTipBtn, SIGNAL(clicked()), this, SLOT(slotPrevTip())); connect(ui->prevTipBtn, SIGNAL(clicked()), this, SLOT(slotPrevTip()));
connect(ui->openProjectButton, SIGNAL(clicked()), Core::ICore::instance()->mainWindow(), SLOT(openProject())); connect(ui->openProjectButton, SIGNAL(clicked()),
ProjectExplorer::ProjectExplorerPlugin::instance(),
SLOT(openOpenProjectDialog()));
connect(ui->createNewProjectButton, SIGNAL(clicked()), this, SLOT(slotCreateNewProject())); connect(ui->createNewProjectButton, SIGNAL(clicked()), this, SLOT(slotCreateNewProject()));
ui->createNewProjectButton->setIcon( ui->createNewProjectButton->setIcon(
......
...@@ -128,9 +128,7 @@ static inline QString msgNoProjectFiles(const QDir &dir, const QStringList &patt ...@@ -128,9 +128,7 @@ static inline QString msgNoProjectFiles(const QDir &dir, const QStringList &patt
// Try to find the project files in a project directory with some smartness // Try to find the project files in a project directory with some smartness
static QFileInfoList findProjectFiles(const QDir &projectDir, QString *errorMessage) static QFileInfoList findProjectFiles(const QDir &projectDir, QString *errorMessage)
{ {
// Hardcoded: Find *.pro/Cmakefiles const QStringList projectFilePatterns = ProjectExplorer::ProjectExplorerPlugin::projectFilePatterns();
QStringList projectFilePatterns;
projectFilePatterns << QLatin1String("*.pro") << QLatin1String("CMakeLists.txt");
// Project directory // Project directory
QFileInfoList projectFiles = projectDir.entryInfoList(projectFilePatterns, QDir::Files|QDir::NoDotAndDotDot|QDir::Readable); QFileInfoList projectFiles = projectDir.entryInfoList(projectFilePatterns, QDir::Files|QDir::NoDotAndDotDot|QDir::Readable);
if (!projectFiles.empty()) if (!projectFiles.empty())
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment