forked from qt-creator/qt-creator
ProjectExplorer: Use FilePath for Recent projects
Change-Id: Ifaf893358d4fbe20696b39b795434cb51a3e29d4 Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
@@ -470,7 +470,7 @@ public:
|
|||||||
QPair<bool, QString> buildSettingsEnabledForSession();
|
QPair<bool, QString> buildSettingsEnabledForSession();
|
||||||
QPair<bool, QString> buildSettingsEnabled(const Project *pro);
|
QPair<bool, QString> buildSettingsEnabled(const Project *pro);
|
||||||
|
|
||||||
void addToRecentProjects(const QString &fileName, const QString &displayName);
|
void addToRecentProjects(const FilePath &filePath, const QString &displayName);
|
||||||
void startRunControl(RunControl *runControl);
|
void startRunControl(RunControl *runControl);
|
||||||
void showOutputPaneForRunControl(RunControl *runControl);
|
void showOutputPaneForRunControl(RunControl *runControl);
|
||||||
|
|
||||||
@@ -515,8 +515,8 @@ public:
|
|||||||
|
|
||||||
void updateRecentProjectMenu();
|
void updateRecentProjectMenu();
|
||||||
void clearRecentProjects();
|
void clearRecentProjects();
|
||||||
void openRecentProject(const QString &fileName);
|
void openRecentProject(const FilePath &filePath);
|
||||||
void removeFromRecentProjects(const QString &fileName, const QString &displayName);
|
void removeFromRecentProjects(const FilePath &filePath);
|
||||||
void updateUnloadProjectMenu();
|
void updateUnloadProjectMenu();
|
||||||
using EnvironmentGetter = std::function<Utils::optional<Environment>(const Project *project)>;
|
using EnvironmentGetter = std::function<Utils::optional<Environment>(const Project *project)>;
|
||||||
void openTerminalHere(const EnvironmentGetter &env);
|
void openTerminalHere(const EnvironmentGetter &env);
|
||||||
@@ -627,7 +627,7 @@ public:
|
|||||||
RecentProjectsEntries m_recentProjects; // pair of filename, displayname
|
RecentProjectsEntries m_recentProjects; // pair of filename, displayname
|
||||||
static const int m_maxRecentProjects = 25;
|
static const int m_maxRecentProjects = 25;
|
||||||
|
|
||||||
QString m_lastOpenDirectory;
|
FilePath m_lastOpenDirectory;
|
||||||
QPointer<RunConfiguration> m_defaultRunConfiguration;
|
QPointer<RunConfiguration> m_defaultRunConfiguration;
|
||||||
QPointer<RunConfiguration> m_delayedRunConfiguration;
|
QPointer<RunConfiguration> m_delayedRunConfiguration;
|
||||||
QString m_projectFilterString;
|
QString m_projectFilterString;
|
||||||
@@ -1677,7 +1677,7 @@ bool ProjectExplorerPlugin::initialize(const QStringList &arguments, QString *er
|
|||||||
.toStringList();
|
.toStringList();
|
||||||
if (fileNames.size() == displayNames.size()) {
|
if (fileNames.size() == displayNames.size()) {
|
||||||
for (int i = 0; i < fileNames.size(); ++i) {
|
for (int i = 0; i < fileNames.size(); ++i) {
|
||||||
dd->m_recentProjects.append(qMakePair(fileNames.at(i), displayNames.at(i)));
|
dd->m_recentProjects.append({FilePath::fromUserInput(fileNames.at(i)), displayNames.at(i)});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2129,18 +2129,18 @@ bool ProjectExplorerPlugin::initialize(const QStringList &arguments, QString *er
|
|||||||
|
|
||||||
void ProjectExplorerPluginPrivate::loadAction()
|
void ProjectExplorerPluginPrivate::loadAction()
|
||||||
{
|
{
|
||||||
QString dir = dd->m_lastOpenDirectory;
|
FilePath dir = dd->m_lastOpenDirectory;
|
||||||
|
|
||||||
// for your special convenience, we preselect a pro file if it is
|
// for your special convenience, we preselect a pro file if it is
|
||||||
// the current file
|
// the current file
|
||||||
if (const IDocument *document = EditorManager::currentDocument()) {
|
if (const IDocument *document = EditorManager::currentDocument()) {
|
||||||
const QString fn = document->filePath().toString();
|
const FilePath fn = document->filePath();
|
||||||
const bool isProject = dd->m_profileMimeTypes.contains(document->mimeType());
|
const bool isProject = dd->m_profileMimeTypes.contains(document->mimeType());
|
||||||
dir = isProject ? fn : QFileInfo(fn).absolutePath();
|
dir = isProject ? fn : fn.absolutePath();
|
||||||
}
|
}
|
||||||
|
|
||||||
FilePath filePath = Utils::FileUtils::getOpenFilePath(nullptr,
|
FilePath filePath = Utils::FileUtils::getOpenFilePath(ICore::dialogParent(),
|
||||||
tr("Load Project"), FilePath::fromString(dir),
|
tr("Load Project"), dir,
|
||||||
dd->m_projectFilterString);
|
dd->m_projectFilterString);
|
||||||
if (filePath.isEmpty())
|
if (filePath.isEmpty())
|
||||||
return;
|
return;
|
||||||
@@ -2199,7 +2199,7 @@ void ProjectExplorerPlugin::unloadProject(Project *project)
|
|||||||
if (projectExplorerSettings().closeSourceFilesWithProject && !dd->closeAllFilesInProject(project))
|
if (projectExplorerSettings().closeSourceFilesWithProject && !dd->closeAllFilesInProject(project))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
dd->addToRecentProjects(project->projectFilePath().toString(), project->displayName());
|
dd->addToRecentProjects(project->projectFilePath(), project->displayName());
|
||||||
|
|
||||||
SessionManager::removeProject(project);
|
SessionManager::removeProject(project);
|
||||||
dd->updateActions();
|
dd->updateActions();
|
||||||
@@ -2420,7 +2420,7 @@ void ProjectExplorerPluginPrivate::savePersistentSettings()
|
|||||||
RecentProjectsEntries::const_iterator it, end;
|
RecentProjectsEntries::const_iterator it, end;
|
||||||
end = dd->m_recentProjects.constEnd();
|
end = dd->m_recentProjects.constEnd();
|
||||||
for (it = dd->m_recentProjects.constBegin(); it != end; ++it) {
|
for (it = dd->m_recentProjects.constBegin(); it != end; ++it) {
|
||||||
fileNames << (*it).first;
|
fileNames << (*it).first.toUserOutput();
|
||||||
displayNames << (*it).second;
|
displayNames << (*it).second;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2483,9 +2483,9 @@ void ProjectExplorerPluginPrivate::savePersistentSettings()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ProjectExplorerPlugin::openProjectWelcomePage(const QString &fileName)
|
void ProjectExplorerPlugin::openProjectWelcomePage(const FilePath &filePath)
|
||||||
{
|
{
|
||||||
OpenProjectResult result = openProject(FilePath::fromUserInput(fileName));
|
OpenProjectResult result = openProject(filePath);
|
||||||
if (!result)
|
if (!result)
|
||||||
showOpenProjectError(result);
|
showOpenProjectError(result);
|
||||||
}
|
}
|
||||||
@@ -2496,7 +2496,7 @@ ProjectExplorerPlugin::OpenProjectResult ProjectExplorerPlugin::openProject(cons
|
|||||||
Project *project = result.project();
|
Project *project = result.project();
|
||||||
if (!project)
|
if (!project)
|
||||||
return result;
|
return result;
|
||||||
dd->addToRecentProjects(filePath.toString(), project->displayName());
|
dd->addToRecentProjects(filePath, project->displayName());
|
||||||
SessionManager::setStartupProject(project);
|
SessionManager::setStartupProject(project);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@@ -2853,7 +2853,7 @@ void ProjectExplorerPluginPrivate::buildQueueFinished(bool success)
|
|||||||
RecentProjectsEntries ProjectExplorerPluginPrivate::recentProjects() const
|
RecentProjectsEntries ProjectExplorerPluginPrivate::recentProjects() const
|
||||||
{
|
{
|
||||||
return Utils::filtered(dd->m_recentProjects, [](const RecentProjectsEntry &p) {
|
return Utils::filtered(dd->m_recentProjects, [](const RecentProjectsEntry &p) {
|
||||||
return QFileInfo(p.first).isFile();
|
return p.first.isFile();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3290,7 +3290,7 @@ void ProjectExplorerPluginPrivate::projectRemoved(Project *pro)
|
|||||||
|
|
||||||
void ProjectExplorerPluginPrivate::projectDisplayNameChanged(Project *pro)
|
void ProjectExplorerPluginPrivate::projectDisplayNameChanged(Project *pro)
|
||||||
{
|
{
|
||||||
addToRecentProjects(pro->projectFilePath().toString(), pro->displayName());
|
addToRecentProjects(pro->projectFilePath(), pro->displayName());
|
||||||
updateActions();
|
updateActions();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3425,24 +3425,22 @@ void ProjectExplorerPluginPrivate::doUpdateRunActions()
|
|||||||
emit m_instance->runActionsUpdated();
|
emit m_instance->runActionsUpdated();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ProjectExplorerPluginPrivate::addToRecentProjects(const QString &fileName, const QString &displayName)
|
void ProjectExplorerPluginPrivate::addToRecentProjects(const FilePath &filePath, const QString &displayName)
|
||||||
{
|
{
|
||||||
if (fileName.isEmpty())
|
if (filePath.isEmpty())
|
||||||
return;
|
return;
|
||||||
QString prettyFileName(QDir::toNativeSeparators(fileName));
|
|
||||||
|
|
||||||
RecentProjectsEntries::iterator it;
|
RecentProjectsEntries::iterator it;
|
||||||
for (it = m_recentProjects.begin(); it != m_recentProjects.end();)
|
for (it = m_recentProjects.begin(); it != m_recentProjects.end();)
|
||||||
if ((*it).first == prettyFileName)
|
if ((*it).first == filePath)
|
||||||
it = m_recentProjects.erase(it);
|
it = m_recentProjects.erase(it);
|
||||||
else
|
else
|
||||||
++it;
|
++it;
|
||||||
|
|
||||||
if (m_recentProjects.count() > m_maxRecentProjects)
|
if (m_recentProjects.count() > m_maxRecentProjects)
|
||||||
m_recentProjects.removeLast();
|
m_recentProjects.removeLast();
|
||||||
m_recentProjects.prepend(qMakePair(prettyFileName, displayName));
|
m_recentProjects.prepend(qMakePair(filePath, displayName));
|
||||||
QFileInfo fi(prettyFileName);
|
m_lastOpenDirectory = filePath.absolutePath();
|
||||||
m_lastOpenDirectory = fi.absolutePath();
|
|
||||||
emit m_instance->recentProjectsChanged();
|
emit m_instance->recentProjectsChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3460,7 +3458,6 @@ void ProjectExplorerPluginPrivate::updateUnloadProjectMenu()
|
|||||||
|
|
||||||
void ProjectExplorerPluginPrivate::updateRecentProjectMenu()
|
void ProjectExplorerPluginPrivate::updateRecentProjectMenu()
|
||||||
{
|
{
|
||||||
using StringPairListConstIterator = RecentProjectsEntries::const_iterator;
|
|
||||||
ActionContainer *aci = ActionManager::actionContainer(Constants::M_RECENTPROJECTS);
|
ActionContainer *aci = ActionManager::actionContainer(Constants::M_RECENTPROJECTS);
|
||||||
QMenu *menu = aci->menu();
|
QMenu *menu = aci->menu();
|
||||||
menu->clear();
|
menu->clear();
|
||||||
@@ -3468,18 +3465,18 @@ void ProjectExplorerPluginPrivate::updateRecentProjectMenu()
|
|||||||
int acceleratorKey = 1;
|
int acceleratorKey = 1;
|
||||||
const RecentProjectsEntries projects = recentProjects();
|
const RecentProjectsEntries projects = recentProjects();
|
||||||
//projects (ignore sessions, they used to be in this list)
|
//projects (ignore sessions, they used to be in this list)
|
||||||
const StringPairListConstIterator end = projects.constEnd();
|
for (const RecentProjectsEntry &item : projects) {
|
||||||
for (StringPairListConstIterator it = projects.constBegin(); it != end; ++it, ++acceleratorKey) {
|
const FilePath &filePath = item.first;
|
||||||
const QString fileName = it->first;
|
if (filePath.endsWith(QLatin1String(".qws")))
|
||||||
if (fileName.endsWith(QLatin1String(".qws")))
|
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
const QString actionText = ActionManager::withNumberAccelerator(
|
const QString actionText = ActionManager::withNumberAccelerator(
|
||||||
Utils::withTildeHomePath(fileName), acceleratorKey);
|
Utils::withTildeHomePath(filePath.toUserOutput()), acceleratorKey);
|
||||||
QAction *action = menu->addAction(actionText);
|
QAction *action = menu->addAction(actionText);
|
||||||
connect(action, &QAction::triggered, this, [this, fileName] {
|
connect(action, &QAction::triggered, this, [this, filePath] {
|
||||||
openRecentProject(fileName);
|
openRecentProject(filePath);
|
||||||
});
|
});
|
||||||
|
++acceleratorKey;
|
||||||
}
|
}
|
||||||
const bool hasRecentProjects = !projects.empty();
|
const bool hasRecentProjects = !projects.empty();
|
||||||
menu->setEnabled(hasRecentProjects);
|
menu->setEnabled(hasRecentProjects);
|
||||||
@@ -3501,21 +3498,22 @@ void ProjectExplorerPluginPrivate::clearRecentProjects()
|
|||||||
updateWelcomePage();
|
updateWelcomePage();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ProjectExplorerPluginPrivate::openRecentProject(const QString &fileName)
|
void ProjectExplorerPluginPrivate::openRecentProject(const FilePath &filePath)
|
||||||
{
|
{
|
||||||
if (!fileName.isEmpty()) {
|
if (!filePath.isEmpty()) {
|
||||||
ProjectExplorerPlugin::OpenProjectResult result
|
ProjectExplorerPlugin::OpenProjectResult result
|
||||||
= ProjectExplorerPlugin::openProject(FilePath::fromUserInput(fileName));
|
= ProjectExplorerPlugin::openProject(filePath);
|
||||||
if (!result)
|
if (!result)
|
||||||
ProjectExplorerPlugin::showOpenProjectError(result);
|
ProjectExplorerPlugin::showOpenProjectError(result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ProjectExplorerPluginPrivate::removeFromRecentProjects(const QString &fileName,
|
void ProjectExplorerPluginPrivate::removeFromRecentProjects(const FilePath &filePath)
|
||||||
const QString &displayName)
|
|
||||||
{
|
{
|
||||||
QTC_ASSERT(!fileName.isEmpty() && !displayName.isEmpty(), return);
|
QTC_ASSERT(!filePath.isEmpty(), return);
|
||||||
QTC_CHECK(m_recentProjects.removeOne(RecentProjectsEntry(fileName, displayName)));
|
QTC_CHECK(Utils::eraseOne(m_recentProjects, [filePath](const RecentProjectsEntry &entry) {
|
||||||
|
return entry.first == filePath;
|
||||||
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
void ProjectExplorerPluginPrivate::invalidateProject(Project *project)
|
void ProjectExplorerPluginPrivate::invalidateProject(Project *project)
|
||||||
@@ -4349,10 +4347,9 @@ void ProjectExplorerPlugin::clearRecentProjects()
|
|||||||
dd->clearRecentProjects();
|
dd->clearRecentProjects();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ProjectExplorerPlugin::removeFromRecentProjects(const QString &fileName,
|
void ProjectExplorerPlugin::removeFromRecentProjects(const FilePath &filePath)
|
||||||
const QString &displayName)
|
|
||||||
{
|
{
|
||||||
dd->removeFromRecentProjects(fileName, displayName);
|
dd->removeFromRecentProjects(filePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ProjectExplorerPlugin::updateRunActions()
|
void ProjectExplorerPlugin::updateRunActions()
|
||||||
|
|||||||
@@ -40,7 +40,6 @@ class QThreadPool;
|
|||||||
QT_END_NAMESPACE
|
QT_END_NAMESPACE
|
||||||
|
|
||||||
namespace Core {
|
namespace Core {
|
||||||
class IMode;
|
|
||||||
class OutputWindow;
|
class OutputWindow;
|
||||||
} // Core
|
} // Core
|
||||||
|
|
||||||
@@ -64,7 +63,7 @@ class MiniProjectTargetSelector;
|
|||||||
class ProjectExplorerSettings;
|
class ProjectExplorerSettings;
|
||||||
}
|
}
|
||||||
|
|
||||||
using RecentProjectsEntry = QPair<QString, QString>;
|
using RecentProjectsEntry = QPair<Utils::FilePath, QString>;
|
||||||
using RecentProjectsEntries = QList<RecentProjectsEntry>;
|
using RecentProjectsEntries = QList<RecentProjectsEntry>;
|
||||||
|
|
||||||
class PROJECTEXPLORER_EXPORT ProjectExplorerPlugin : public ExtensionSystem::IPlugin
|
class PROJECTEXPLORER_EXPORT ProjectExplorerPlugin : public ExtensionSystem::IPlugin
|
||||||
@@ -122,7 +121,7 @@ public:
|
|||||||
static OpenProjectResult openProject(const Utils::FilePath &filePath);
|
static OpenProjectResult openProject(const Utils::FilePath &filePath);
|
||||||
static OpenProjectResult openProjects(const Utils::FilePaths &filePaths);
|
static OpenProjectResult openProjects(const Utils::FilePaths &filePaths);
|
||||||
static void showOpenProjectError(const OpenProjectResult &result);
|
static void showOpenProjectError(const OpenProjectResult &result);
|
||||||
static void openProjectWelcomePage(const QString &fileName);
|
static void openProjectWelcomePage(const Utils::FilePath &filePath);
|
||||||
static void unloadProject(Project *project);
|
static void unloadProject(Project *project);
|
||||||
|
|
||||||
static bool saveModifiedFiles();
|
static bool saveModifiedFiles();
|
||||||
@@ -187,7 +186,7 @@ public:
|
|||||||
|
|
||||||
static void activateProjectPanel(Utils::Id panelId);
|
static void activateProjectPanel(Utils::Id panelId);
|
||||||
static void clearRecentProjects();
|
static void clearRecentProjects();
|
||||||
static void removeFromRecentProjects(const QString &fileName, const QString &displayName);
|
static void removeFromRecentProjects(const Utils::FilePath &filePath);
|
||||||
|
|
||||||
static void updateRunActions();
|
static void updateRunActions();
|
||||||
|
|
||||||
|
|||||||
@@ -42,6 +42,7 @@
|
|||||||
#include <utils/icon.h>
|
#include <utils/icon.h>
|
||||||
#include <utils/qtcassert.h>
|
#include <utils/qtcassert.h>
|
||||||
#include <utils/stringutils.h>
|
#include <utils/stringutils.h>
|
||||||
|
#include <utils/qtcassert.h>
|
||||||
#include <utils/theme/theme.h>
|
#include <utils/theme/theme.h>
|
||||||
|
|
||||||
#include <QAbstractItemDelegate>
|
#include <QAbstractItemDelegate>
|
||||||
@@ -92,9 +93,9 @@ QVariant ProjectModel::data(const QModelIndex &index, int role) const
|
|||||||
return data.second;
|
return data.second;
|
||||||
case Qt::ToolTipRole:
|
case Qt::ToolTipRole:
|
||||||
case FilePathRole:
|
case FilePathRole:
|
||||||
return data.first;
|
return data.first.toVariant();
|
||||||
case PrettyFilePathRole:
|
case PrettyFilePathRole:
|
||||||
return Utils::withTildeHomePath(data.first);
|
return Utils::withTildeHomePath(data.first.toUserOutput()); // FIXME: FilePath::displayName() ?
|
||||||
case ShortcutRole: {
|
case ShortcutRole: {
|
||||||
const Id projectBase = PROJECT_BASE_ID;
|
const Id projectBase = PROJECT_BASE_ID;
|
||||||
if (Command *cmd = ActionManager::command(projectBase.withSuffix(index.row() + 1)))
|
if (Command *cmd = ActionManager::command(projectBase.withSuffix(index.row() + 1)))
|
||||||
@@ -162,9 +163,9 @@ void ProjectWelcomePage::openSessionAt(int index)
|
|||||||
void ProjectWelcomePage::openProjectAt(int index)
|
void ProjectWelcomePage::openProjectAt(int index)
|
||||||
{
|
{
|
||||||
QTC_ASSERT(m_projectModel, return);
|
QTC_ASSERT(m_projectModel, return);
|
||||||
const QString projectFile = m_projectModel->data(m_projectModel->index(index, 0),
|
const QVariant projectFile = m_projectModel->data(m_projectModel->index(index, 0),
|
||||||
ProjectModel::FilePathRole).toString();
|
ProjectModel::FilePathRole);
|
||||||
ProjectExplorerPlugin::openProjectWelcomePage(projectFile);
|
ProjectExplorerPlugin::openProjectWelcomePage(FilePath::fromVariant(projectFile));
|
||||||
}
|
}
|
||||||
|
|
||||||
void ProjectWelcomePage::createActions()
|
void ProjectWelcomePage::createActions()
|
||||||
@@ -529,8 +530,8 @@ public:
|
|||||||
const QMouseEvent *mouseEvent = static_cast<QMouseEvent *>(ev);
|
const QMouseEvent *mouseEvent = static_cast<QMouseEvent *>(ev);
|
||||||
const Qt::MouseButtons button = mouseEvent->button();
|
const Qt::MouseButtons button = mouseEvent->button();
|
||||||
if (button == Qt::LeftButton) {
|
if (button == Qt::LeftButton) {
|
||||||
const QString projectFile = idx.data(ProjectModel::FilePathRole).toString();
|
const QVariant projectFile = idx.data(ProjectModel::FilePathRole);
|
||||||
ProjectExplorerPlugin::openProjectWelcomePage(projectFile);
|
ProjectExplorerPlugin::openProjectWelcomePage(FilePath::fromVariant(projectFile));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (button == Qt::RightButton) {
|
if (button == Qt::RightButton) {
|
||||||
@@ -540,9 +541,8 @@ public:
|
|||||||
const auto projectModel = qobject_cast<ProjectModel *>(model);
|
const auto projectModel = qobject_cast<ProjectModel *>(model);
|
||||||
contextMenu.addAction(action);
|
contextMenu.addAction(action);
|
||||||
connect(action, &QAction::triggered, [idx, projectModel](){
|
connect(action, &QAction::triggered, [idx, projectModel](){
|
||||||
const QString projectFile = idx.data(ProjectModel::FilePathRole).toString();
|
const QVariant projectFile = idx.data(ProjectModel::FilePathRole);
|
||||||
const QString displayName = idx.data(Qt::DisplayRole).toString();
|
ProjectExplorerPlugin::removeFromRecentProjects(FilePath::fromVariant(projectFile));
|
||||||
ProjectExplorerPlugin::removeFromRecentProjects(projectFile, displayName);
|
|
||||||
projectModel->resetProjects();
|
projectModel->resetProjects();
|
||||||
});
|
});
|
||||||
contextMenu.addSeparator();
|
contextMenu.addSeparator();
|
||||||
|
|||||||
@@ -29,6 +29,8 @@
|
|||||||
|
|
||||||
#include <coreplugin/iwelcomepage.h>
|
#include <coreplugin/iwelcomepage.h>
|
||||||
|
|
||||||
|
#include <utils/filepath.h>
|
||||||
|
|
||||||
#include <QAbstractListModel>
|
#include <QAbstractListModel>
|
||||||
|
|
||||||
namespace ProjectExplorer {
|
namespace ProjectExplorer {
|
||||||
@@ -74,7 +76,7 @@ public slots:
|
|||||||
void openProject();
|
void openProject();
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void requestProject(const QString &project);
|
void requestProject(const Utils::FilePath &project);
|
||||||
void manageSessions();
|
void manageSessions();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|||||||
@@ -47,6 +47,7 @@
|
|||||||
#include <texteditor/texteditor.h>
|
#include <texteditor/texteditor.h>
|
||||||
|
|
||||||
#include <utils/algorithm.h>
|
#include <utils/algorithm.h>
|
||||||
|
#include <utils/qtcassert.h>
|
||||||
#include <utils/stylehelper.h>
|
#include <utils/stylehelper.h>
|
||||||
#include <utils/qtcassert.h>
|
#include <utils/qtcassert.h>
|
||||||
|
|
||||||
|
|||||||
@@ -80,6 +80,9 @@
|
|||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
|
using namespace ProjectExplorer;
|
||||||
|
using namespace Utils;
|
||||||
|
|
||||||
namespace StudioWelcome {
|
namespace StudioWelcome {
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
|
|
||||||
@@ -231,8 +234,8 @@ public:
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
m_blockOpenRecent = true;
|
m_blockOpenRecent = true;
|
||||||
const QString projectFile = data(index(row, 0), ProjectModel::FilePathRole).toString();
|
const FilePath projectFile = FilePath::fromVariant(data(index(row, 0), ProjectModel::FilePathRole));
|
||||||
if (QFileInfo::exists(projectFile))
|
if (projectFile.exists())
|
||||||
ProjectExplorer::ProjectExplorerPlugin::openProjectWelcomePage(projectFile);
|
ProjectExplorer::ProjectExplorerPlugin::openProjectWelcomePage(projectFile);
|
||||||
|
|
||||||
resetProjects();
|
resetProjects();
|
||||||
@@ -260,7 +263,7 @@ public:
|
|||||||
if (!explicitQmlproject.isEmpty())
|
if (!explicitQmlproject.isEmpty())
|
||||||
projectFile = exampleFolder + explicitQmlproject;
|
projectFile = exampleFolder + explicitQmlproject;
|
||||||
|
|
||||||
ProjectExplorer::ProjectExplorerPlugin::openProjectWelcomePage(projectFile);
|
ProjectExplorer::ProjectExplorerPlugin::openProjectWelcomePage(FilePath::fromString(projectFile));
|
||||||
|
|
||||||
const QString qmlFile = QFileInfo(projectFile).dir().absolutePath() + "/" + formFile;
|
const QString qmlFile = QFileInfo(projectFile).dir().absolutePath() + "/" + formFile;
|
||||||
|
|
||||||
@@ -283,7 +286,7 @@ public:
|
|||||||
Q_UNUSED(completeBaseName)
|
Q_UNUSED(completeBaseName)
|
||||||
const Utils::FilePath projectFile = Core::ICore::resourcePath("examples")
|
const Utils::FilePath projectFile = Core::ICore::resourcePath("examples")
|
||||||
/ example / example + ".qmlproject";
|
/ example / example + ".qmlproject";
|
||||||
ProjectExplorer::ProjectExplorerPlugin::openProjectWelcomePage(projectFile.toString());
|
ProjectExplorer::ProjectExplorerPlugin::openProjectWelcomePage(projectFile);
|
||||||
const Utils::FilePath qmlFile = Core::ICore::resourcePath("examples")
|
const Utils::FilePath qmlFile = Core::ICore::resourcePath("examples")
|
||||||
/ example / formFile;
|
/ example / formFile;
|
||||||
|
|
||||||
@@ -328,10 +331,10 @@ int ProjectModel::rowCount(const QModelIndex &) const
|
|||||||
return ProjectExplorer::ProjectExplorerPlugin::recentProjects().count();
|
return ProjectExplorer::ProjectExplorerPlugin::recentProjects().count();
|
||||||
}
|
}
|
||||||
|
|
||||||
QString getQDSVersion(const QString &projectFilePath)
|
static QString getQDSVersion(const FilePath &projectFilePath)
|
||||||
{
|
{
|
||||||
const QString qdsVersion = QmlProjectManager::ProjectFileContentTools::qdsVersion(
|
const QString qdsVersion = QmlProjectManager::ProjectFileContentTools::qdsVersion(
|
||||||
Utils::FilePath::fromString(projectFilePath));
|
projectFilePath);
|
||||||
|
|
||||||
return ProjectModel::tr("Created with Qt Design Studio version: %1").arg(qdsVersion);
|
return ProjectModel::tr("Created with Qt Design Studio version: %1").arg(qdsVersion);
|
||||||
}
|
}
|
||||||
@@ -347,11 +350,11 @@ static QString fromCamelCase(const QString &s) {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
static QString resolutionFromConstants(const QString &projectFilePath)
|
static QString resolutionFromConstants(const FilePath &projectFilePath)
|
||||||
{
|
{
|
||||||
QmlProjectManager::ProjectFileContentTools::Resolution res =
|
QmlProjectManager::ProjectFileContentTools::Resolution res =
|
||||||
QmlProjectManager::ProjectFileContentTools::resolutionFromConstants(
|
QmlProjectManager::ProjectFileContentTools::resolutionFromConstants(
|
||||||
Utils::FilePath::fromString(projectFilePath));
|
projectFilePath);
|
||||||
|
|
||||||
if (res.width > 0 && res.height > 0)
|
if (res.width > 0 && res.height > 0)
|
||||||
return ProjectModel::tr("Resolution: %1x%2").arg(res.width).arg(res.height);
|
return ProjectModel::tr("Resolution: %1x%2").arg(res.width).arg(res.height);
|
||||||
@@ -359,25 +362,25 @@ static QString resolutionFromConstants(const QString &projectFilePath)
|
|||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
static QString description(const QString &projectFilePath)
|
static QString description(const FilePath &projectFilePath)
|
||||||
{
|
{
|
||||||
|
|
||||||
const QString created = ProjectModel::tr("Created: %1").arg(
|
const QString created = ProjectModel::tr("Created: %1").arg(
|
||||||
QFileInfo(projectFilePath).fileTime(QFileDevice::FileBirthTime).toString());
|
projectFilePath.toFileInfo().fileTime(QFileDevice::FileBirthTime).toString());
|
||||||
const QString lastEdited = ProjectModel::tr("Last Edited: %1").arg(
|
const QString lastEdited = ProjectModel::tr("Last Edited: %1").arg(
|
||||||
QFileInfo(projectFilePath).fileTime(QFileDevice::FileModificationTime).toString());
|
projectFilePath.toFileInfo().fileTime(QFileDevice::FileModificationTime).toString());
|
||||||
|
|
||||||
return fromCamelCase(QFileInfo(projectFilePath).baseName()) + "\n\n" + created + "\n" + lastEdited
|
return fromCamelCase(projectFilePath.baseName()) + "\n\n" + created + "\n" + lastEdited
|
||||||
+ "\n" + resolutionFromConstants(projectFilePath)
|
+ "\n" + resolutionFromConstants(projectFilePath)
|
||||||
+ "\n" + getQDSVersion(projectFilePath);
|
+ "\n" + getQDSVersion(projectFilePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
static QString tags(const QString &projectFilePath)
|
static QString tags(const FilePath &projectFilePath)
|
||||||
{
|
{
|
||||||
QStringList ret;
|
QStringList ret;
|
||||||
const QString defaultReturn = "content/App.qml";
|
const QString defaultReturn = "content/App.qml";
|
||||||
Utils::FileReader reader;
|
Utils::FileReader reader;
|
||||||
if (!reader.fetch(Utils::FilePath::fromString(projectFilePath)))
|
if (!reader.fetch(projectFilePath))
|
||||||
return defaultReturn;
|
return defaultReturn;
|
||||||
|
|
||||||
const QByteArray data = reader.data();
|
const QByteArray data = reader.data();
|
||||||
@@ -403,13 +406,13 @@ QVariant ProjectModel::data(const QModelIndex &index, int role) const
|
|||||||
return data.second;
|
return data.second;
|
||||||
break;
|
break;
|
||||||
case FilePathRole:
|
case FilePathRole:
|
||||||
return data.first;
|
return data.first.toVariant();
|
||||||
case PrettyFilePathRole:
|
case PrettyFilePathRole:
|
||||||
return Utils::withTildeHomePath(QFileInfo(data.first).dir().absolutePath());
|
return Utils::withTildeHomePath(data.first.absolutePath().toUserOutput());
|
||||||
case PreviewUrl:
|
case PreviewUrl:
|
||||||
return QVariant(QStringLiteral("image://project_preview/") +
|
return QVariant(QStringLiteral("image://project_preview/") +
|
||||||
QmlProjectManager::ProjectFileContentTools::appQmlFile(
|
QmlProjectManager::ProjectFileContentTools::appQmlFile(
|
||||||
Utils::FilePath::fromString(data.first)));
|
data.first));
|
||||||
case TagData:
|
case TagData:
|
||||||
return tags(data.first);
|
return tags(data.first);
|
||||||
case Description:
|
case Description:
|
||||||
|
|||||||
Reference in New Issue
Block a user