Commit c95f079f authored by dt's avatar dt
Browse files

Fixes: Recent Projectsd list all cmake projects as CMakeLists.txt

Required a few changes to pass on the displayName everywhere.

Task-number: 250402
parent 16be88e9
......@@ -233,10 +233,13 @@ void WelcomeMode::updateWelcomePage(const WelcomePageData &welcomePageData)
{
QString projects;
QTextStream str(&projects);
foreach (const QString &s, welcomePageData.projectList) {
const QFileInfo fi(s);
str << "<li><p><a href=\"gh-project:" << s << "\" title=\""
<< fi.absolutePath() << "\">" << fi.fileName() << "</a></p></li>\n";
QList<QPair<QString, QString> >::const_iterator it, end;
end = welcomePageData.projectList.constEnd();
for( it = welcomePageData.projectList.constBegin(); it != end; ++it) {
const QFileInfo fi((*it).first);
str << "<li><p><a href=\"gh-project:" << (*it).first << "\" title=\""
<< fi.absolutePath() << "\">" << (*it).second << "</a></p></li>\n";
}
projectHtml.replace(QLatin1String("<!-- RECENT PROJECTS LIST -->"), projects);
}
......
......@@ -33,6 +33,7 @@
#include <coreplugin/imode.h>
#include <QtCore/QObject>
#include <QtCore/QPair>
QT_BEGIN_NAMESPACE
class QWidget;
......@@ -59,7 +60,7 @@ public:
QString previousSession;
QString activeSession;
QStringList sessionList;
QStringList projectList;
QList<QPair<QString, QString> > projectList; // pair of filename, displayname
};
void updateWelcomePage(const WelcomePageData &welcomePageData);
......
......@@ -602,16 +602,34 @@ bool ProjectExplorerPlugin::initialize(const QStringList &arguments, QString *er
addAutoReleasedObject(new ProjectTreeWidgetFactory);
addAutoReleasedObject(new FolderNavigationWidgetFactory);
QStringList oldRecentProjects;
if (QSettings *s = core->settings())
m_recentProjects = s->value("ProjectExplorer/RecentProjects/Files", QStringList()).toStringList();
for (QStringList::iterator it = m_recentProjects.begin(); it != m_recentProjects.end(); ) {
oldRecentProjects = s->value("ProjectExplorer/RecentProjects/Files", QStringList()).toStringList();
for (QStringList::iterator it = oldRecentProjects.begin(); it != oldRecentProjects.end(); ) {
if (QFileInfo(*it).isFile()) {
++it;
} else {
it = m_recentProjects.erase(it);
it = oldRecentProjects.erase(it);
}
}
foreach(const QString &s, oldRecentProjects) {
m_recentProjects.append(qMakePair(s, QFileInfo(s).fileName()));
}
// TODO restore recentProjects
if (QSettings *s = core->settings()) {
const QStringList fileNames = s->value("ProjectExplorer/RecentProjects/FileNames").toStringList();
const QStringList displayNames = s->value("ProjectExplorer/RecentProjects/DisplayNames").toStringList();
if (fileNames.size() == displayNames.size()) {
for (int i = 0; i < fileNames.size(); ++i) {
m_recentProjects.append(qMakePair(fileNames.at(i), displayNames.at(i)));
}
}
}
connect(m_sessionManagerAction, SIGNAL(triggered()), this, SLOT(showSessionManager()));
connect(m_newAction, SIGNAL(triggered()), this, SLOT(newProject()));
#if 0
......@@ -726,7 +744,7 @@ void ProjectExplorerPlugin::unloadProject()
if (!success)
return;
addToRecentProjects(fi->fileName());
addToRecentProjects(fi->fileName(), m_currentProject->name());
m_session->removeProject(m_currentProject);
updateActions();
}
......@@ -822,7 +840,19 @@ void ProjectExplorerPlugin::savePersistentSettings()
QSettings *s = Core::ICore::instance()->settings();
if (s) {
s->setValue("ProjectExplorer/StartupSession", m_session->file()->fileName());
s->setValue("ProjectExplorer/RecentProjects/Files", m_recentProjects);
s->remove("ProjectExplorer/RecentProjects/Files");
QStringList fileNames;
QStringList displayNames;
QList<QPair<QString, QString> >::const_iterator it, end;
end = m_recentProjects.constEnd();
for (it = m_recentProjects.constBegin(); it != end; ++it) {
fileNames << (*it).first;
displayNames << (*it).second;
}
s->setValue("ProjectExplorer/RecentProjects/FileNames", fileNames);
s->setValue("ProjectExplorer/RecentProjects/DisplayNames", displayNames);
}
}
......@@ -831,14 +861,15 @@ bool ProjectExplorerPlugin::openProject(const QString &fileName)
if (debug)
qDebug() << "ProjectExplorerPlugin::openProject";
if (openProjects(QStringList() << fileName)) {
addToRecentProjects(fileName);
QList<Project *> list = openProjects(QStringList() << fileName);
if (!list.isEmpty()) {
addToRecentProjects(fileName, list.first()->name());
return true;
}
return false;
}
bool ProjectExplorerPlugin::openProjects(const QStringList &fileNames)
QList<Project *> ProjectExplorerPlugin::openProjects(const QStringList &fileNames)
{
if (debug)
qDebug() << "ProjectExplorerPlugin - opening projects " << fileNames;
......@@ -866,7 +897,7 @@ bool ProjectExplorerPlugin::openProjects(const QStringList &fileNames)
if (debug)
qDebug() << "ProjectExplorerPlugin - Could not open any projects!";
QApplication::restoreOverrideCursor();
return false;
return QList<Project *>();
}
foreach (Project *pro, openedPro) {
......@@ -886,7 +917,7 @@ bool ProjectExplorerPlugin::openProjects(const QStringList &fileNames)
Core::ModeManager::instance()->activateMode(Core::Constants::MODE_EDIT);
QApplication::restoreOverrideCursor();
return true;
return openedPro;
}
Project *ProjectExplorerPlugin::currentProject() const
......@@ -1477,7 +1508,7 @@ void ProjectExplorerPlugin::cancelBuild()
m_buildManager->cancel();
}
void ProjectExplorerPlugin::addToRecentProjects(const QString &fileName)
void ProjectExplorerPlugin::addToRecentProjects(const QString &fileName, const QString &displayName)
{
if (debug)
qDebug() << "ProjectExplorerPlugin::addToRecentProjects(" << fileName << ")";
......@@ -1485,10 +1516,17 @@ void ProjectExplorerPlugin::addToRecentProjects(const QString &fileName)
if (fileName.isEmpty())
return;
QString prettyFileName(QDir::toNativeSeparators(fileName));
m_recentProjects.removeAll(prettyFileName);
QList<QPair<QString, QString> >::iterator it;
for(it = m_recentProjects.begin(); it != m_recentProjects.end();)
if ((*it).first == prettyFileName)
it = m_recentProjects.erase(it);
else
++it;
if (m_recentProjects.count() > m_maxRecentProjects)
m_recentProjects.removeLast();
m_recentProjects.prepend(prettyFileName);
m_recentProjects.prepend(qMakePair(prettyFileName, displayName));
QFileInfo fi(prettyFileName);
m_lastOpenDirectory = fi.absolutePath();
}
......@@ -1506,11 +1544,15 @@ void ProjectExplorerPlugin::updateRecentProjectMenu()
menu->setEnabled(!m_recentProjects.isEmpty());
//projects (ignore sessions, they used to be in this list)
foreach (const QString &s, m_recentProjects) {
if (s.endsWith(".qws"))
QList<QPair<QString, QString> >::const_iterator it, end;
end = m_recentProjects.constEnd();
for (it = m_recentProjects.constBegin(); it != end; ++it) {
const QPair<QString, QString> &s = *it;
if (s.first.endsWith(".qws"))
continue;
QAction *action = menu->addAction(s);
action->setData(s);
QAction *action = menu->addAction(s.second);
action->setData(s.first);
connect(action, SIGNAL(triggered()), this, SLOT(openRecentProject()));
}
}
......
......@@ -85,7 +85,7 @@ public:
static ProjectExplorerPlugin *instance();
bool openProject(const QString &fileName);
bool openProjects(const QStringList &fileNames);
QList<Project *> openProjects(const QStringList &fileNames);
SessionManager *session() const;
......@@ -192,7 +192,7 @@ private:
IRunConfigurationRunner *findRunner(QSharedPointer<RunConfiguration> config, const QString &mode);
void updateActions();
void addToRecentProjects(const QString &fileName);
void addToRecentProjects(const QString &fileName, const QString &displayName);
void updateWelcomePage(Core::Internal::WelcomeMode *welcomeMode);
Internal::ProjectFileFactory *findProjectFileFactory(const QString &filename) const;
......@@ -251,7 +251,7 @@ private:
QStringList m_profileMimeTypes;
Internal::OutputPane *m_outputPane;
QStringList m_recentProjects;
QList<QPair<QString, QString> > m_recentProjects; // pair of filename, displayname
static const int m_maxRecentProjects = 7;
QString m_lastOpenDirectory;
......
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