Commit 7643b2cc authored by Eike Ziller's avatar Eike Ziller

File System pane: Add item for opening project file as project

The default "open" action was changed (in
3c988e5a) to open project files in the
editor, so add an explicit action for opening them as a project.

Change-Id: I34ac1e25e249bafeea6659b0f40130d43454bbef
Reviewed-by: default avatarAndré Hartmann <aha_1980@gmx.de>
parent 5d5d0497
......@@ -324,19 +324,26 @@ void FolderNavigationWidget::contextMenuEvent(QContextMenuEvent *ev)
const bool hasCurrentItem = current.isValid();
QAction *actionOpenFile = nullptr;
QAction *actionOpenProjects = nullptr;
QAction *actionOpenAsProject = nullptr;
const Utils::FileName filePath = hasCurrentItem ? Utils::FileName::fromString(
m_fileSystemModel->filePath(current))
: Utils::FileName();
if (hasCurrentItem) {
const QString fileName = m_fileSystemModel->fileName(current);
if (m_fileSystemModel->isDir(current))
if (m_fileSystemModel->isDir(current)) {
actionOpenProjects = menu.addAction(tr("Open Project in \"%1\"").arg(fileName));
else
} else {
actionOpenFile = menu.addAction(tr("Open \"%1\"").arg(fileName));
if (ProjectExplorerPlugin::isProjectFile(Utils::FileName::fromString(fileName)))
actionOpenAsProject = menu.addAction(tr("Open Project \"%1\"").arg(fileName));
}
}
// we need dummy DocumentModel::Entry with absolute file path in it
// to get EditorManager::addNativeDirAndOpenWithActions() working
Core::DocumentModel::Entry fakeEntry;
Core::IDocument document;
document.setFilePath(Utils::FileName::fromString(m_fileSystemModel->filePath(current)));
document.setFilePath(filePath);
fakeEntry.document = &document;
Core::EditorManager::addNativeDirAndOpenWithActions(&menu, &fakeEntry);
......@@ -347,6 +354,8 @@ void FolderNavigationWidget::contextMenuEvent(QContextMenuEvent *ev)
ev->accept();
if (action == actionOpenFile)
openItem(current);
else if (action == actionOpenAsProject)
ProjectExplorerPlugin::openProject(filePath.toString());
else if (action == actionOpenProjects)
openProjectsInDirectory(current);
}
......
......@@ -3534,6 +3534,16 @@ QStringList ProjectExplorerPlugin::projectFilePatterns()
return patterns;
}
bool ProjectExplorerPlugin::isProjectFile(const Utils::FileName &filePath)
{
Utils::MimeType mt = Utils::mimeTypeForFile(filePath.toString());
for (const QString &mime : dd->m_projectCreators.keys()) {
if (mt.inherits(mime))
return true;
}
return false;
}
void ProjectExplorerPlugin::openOpenProjectDialog()
{
const QString path = DocumentManager::useProjectsDirectory()
......
......@@ -43,7 +43,10 @@ class IMode;
class Id;
} // namespace Core
namespace Utils { class ProcessHandle; }
namespace Utils {
class ProcessHandle;
class FileName;
}
namespace ProjectExplorer {
class RunControl;
......@@ -132,6 +135,7 @@ public:
// internal public for FlatModel
static void renameFile(Node *node, const QString &newFilePath);
static QStringList projectFilePatterns();
static bool isProjectFile(const Utils::FileName &filePath);
static QList<QPair<QString, QString> > recentProjects();
static bool canRunStartupProject(Core::Id runMode, QString *whyNot = nullptr);
......
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