forked from qt-creator/qt-creator
Added "Open with" menu to FolderNavigationWidget.
This commit is contained in:
@@ -284,6 +284,14 @@ void FolderNavigationWidget::contextMenuEvent(QContextMenuEvent *ev)
|
|||||||
actionExplorer->setEnabled(hasCurrentItem);
|
actionExplorer->setEnabled(hasCurrentItem);
|
||||||
QAction *actionTerminal = menu.addAction(msgTerminalAction());
|
QAction *actionTerminal = menu.addAction(msgTerminalAction());
|
||||||
actionTerminal->setEnabled(hasCurrentItem);
|
actionTerminal->setEnabled(hasCurrentItem);
|
||||||
|
|
||||||
|
// open with...
|
||||||
|
if (!m_fileSystemModel->isDir(current)) {
|
||||||
|
QMenu *openWith = menu.addMenu(tr("Open with"));
|
||||||
|
ProjectExplorerPlugin::populateOpenWithMenu(openWith,
|
||||||
|
m_fileSystemModel->filePath(current));
|
||||||
|
}
|
||||||
|
|
||||||
// Open file dialog to choose a path starting from current
|
// Open file dialog to choose a path starting from current
|
||||||
QAction *actionChooseFolder = menu.addAction(tr("Choose folder..."));
|
QAction *actionChooseFolder = menu.addAction(tr("Choose folder..."));
|
||||||
// Sync checkable action
|
// Sync checkable action
|
||||||
@@ -319,6 +327,8 @@ void FolderNavigationWidget::contextMenuEvent(QContextMenuEvent *ev)
|
|||||||
showInGraphicalShell(this, m_fileSystemModel->filePath(current));
|
showInGraphicalShell(this, m_fileSystemModel->filePath(current));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
ProjectExplorerPlugin::openEditorFromAction(action,
|
||||||
|
m_fileSystemModel->filePath(current));
|
||||||
}
|
}
|
||||||
|
|
||||||
QString FolderNavigationWidget::msgGraphicalShellAction()
|
QString FolderNavigationWidget::msgGraphicalShellAction()
|
||||||
|
|||||||
@@ -2025,15 +2025,14 @@ void ProjectExplorerPlugin::runConfigurationMenuTriggered(QAction *action)
|
|||||||
setStartupProject(runConfiguration->project());
|
setStartupProject(runConfiguration->project());
|
||||||
}
|
}
|
||||||
|
|
||||||
void ProjectExplorerPlugin::populateOpenWithMenu()
|
void ProjectExplorerPlugin::populateOpenWithMenu(QMenu *menu, const QString &fileName)
|
||||||
{
|
{
|
||||||
typedef QList<Core::IEditorFactory*> EditorFactoryList;
|
typedef QList<Core::IEditorFactory*> EditorFactoryList;
|
||||||
typedef QList<Core::IExternalEditor*> ExternalEditorList;
|
typedef QList<Core::IExternalEditor*> ExternalEditorList;
|
||||||
|
|
||||||
d->m_openWithMenu->clear();
|
menu->clear();
|
||||||
|
|
||||||
bool anyMatches = false;
|
bool anyMatches = false;
|
||||||
const QString fileName = currentNode()->path();
|
|
||||||
|
|
||||||
Core::ICore *core = Core::ICore::instance();
|
Core::ICore *core = Core::ICore::instance();
|
||||||
if (const Core::MimeType mt = core->mimeDatabase()->findByFile(QFileInfo(fileName))) {
|
if (const Core::MimeType mt = core->mimeDatabase()->findByFile(QFileInfo(fileName))) {
|
||||||
@@ -2046,7 +2045,7 @@ void ProjectExplorerPlugin::populateOpenWithMenu()
|
|||||||
foreach (Core::IEditorFactory *editorFactory, factories) {
|
foreach (Core::IEditorFactory *editorFactory, factories) {
|
||||||
// Add action to open with this very editor factory
|
// Add action to open with this very editor factory
|
||||||
QString const actionTitle = editorFactory->displayName();
|
QString const actionTitle = editorFactory->displayName();
|
||||||
QAction * const action = d->m_openWithMenu->addAction(actionTitle);
|
QAction * const action = menu->addAction(actionTitle);
|
||||||
action->setData(qVariantFromValue(editorFactory));
|
action->setData(qVariantFromValue(editorFactory));
|
||||||
// File already open in an editor -> only enable that entry since
|
// File already open in an editor -> only enable that entry since
|
||||||
// we currently do not support opening a file in two editors at once
|
// we currently do not support opening a file in two editors at once
|
||||||
@@ -2062,31 +2061,40 @@ void ProjectExplorerPlugin::populateOpenWithMenu()
|
|||||||
} // for editor factories
|
} // for editor factories
|
||||||
// Add all suitable external editors
|
// Add all suitable external editors
|
||||||
foreach (Core::IExternalEditor *externalEditor, externalEditors) {
|
foreach (Core::IExternalEditor *externalEditor, externalEditors) {
|
||||||
QAction * const action = d->m_openWithMenu->addAction(externalEditor->displayName());
|
QAction * const action = menu->addAction(externalEditor->displayName());
|
||||||
action->setData(qVariantFromValue(externalEditor));
|
action->setData(qVariantFromValue(externalEditor));
|
||||||
}
|
}
|
||||||
} // matches
|
} // matches
|
||||||
}
|
}
|
||||||
d->m_openWithMenu->setEnabled(anyMatches);
|
menu->setEnabled(anyMatches);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ProjectExplorerPlugin::populateOpenWithMenu()
|
||||||
|
{
|
||||||
|
populateOpenWithMenu(d->m_openWithMenu, currentNode()->path());
|
||||||
}
|
}
|
||||||
|
|
||||||
void ProjectExplorerPlugin::openWithMenuTriggered(QAction *action)
|
void ProjectExplorerPlugin::openWithMenuTriggered(QAction *action)
|
||||||
{
|
{
|
||||||
if (!action) {
|
if (!action)
|
||||||
qWarning() << "ProjectExplorerPlugin::openWithMenuTriggered no action, can't happen.";
|
qWarning() << "ProjectExplorerPlugin::openWithMenuTriggered no action, can't happen.";
|
||||||
return;
|
else
|
||||||
}
|
openEditorFromAction(action, currentNode()->path());
|
||||||
|
}
|
||||||
|
|
||||||
|
void ProjectExplorerPlugin::openEditorFromAction(QAction *action, const QString &fileName)
|
||||||
|
{
|
||||||
Core::EditorManager *em = Core::EditorManager::instance();
|
Core::EditorManager *em = Core::EditorManager::instance();
|
||||||
const QVariant data = action->data();
|
const QVariant data = action->data();
|
||||||
if (qVariantCanConvert<Core::IEditorFactory *>(data)) {
|
if (qVariantCanConvert<Core::IEditorFactory *>(data)) {
|
||||||
Core::IEditorFactory *factory = qVariantValue<Core::IEditorFactory *>(data);
|
Core::IEditorFactory *factory = qVariantValue<Core::IEditorFactory *>(data);
|
||||||
em->openEditor(currentNode()->path(), factory->id());
|
em->openEditor(fileName, factory->id());
|
||||||
em->ensureEditorManagerVisible();
|
em->ensureEditorManagerVisible();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (qVariantCanConvert<Core::IExternalEditor *>(data)) {
|
if (qVariantCanConvert<Core::IExternalEditor *>(data)) {
|
||||||
Core::IExternalEditor *externalEditor = qVariantValue<Core::IExternalEditor *>(data);
|
Core::IExternalEditor *externalEditor = qVariantValue<Core::IExternalEditor *>(data);
|
||||||
em->openExternalEditor(currentNode()->path(), externalEditor->id());
|
em->openExternalEditor(fileName, externalEditor->id());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -41,6 +41,7 @@ QT_BEGIN_NAMESPACE
|
|||||||
class QPoint;
|
class QPoint;
|
||||||
class QAction;
|
class QAction;
|
||||||
class QComboBox;
|
class QComboBox;
|
||||||
|
class QMenu;
|
||||||
QT_END_NAMESPACE
|
QT_END_NAMESPACE
|
||||||
|
|
||||||
namespace Core {
|
namespace Core {
|
||||||
@@ -122,6 +123,8 @@ public:
|
|||||||
bool saveModifiedFiles();
|
bool saveModifiedFiles();
|
||||||
|
|
||||||
void showContextMenu(const QPoint &globalPos, Node *node);
|
void showContextMenu(const QPoint &globalPos, Node *node);
|
||||||
|
static void populateOpenWithMenu(QMenu *menu, const QString &fileName);
|
||||||
|
static void openEditorFromAction(QAction *action, const QString &fileName);
|
||||||
|
|
||||||
//PluginInterface
|
//PluginInterface
|
||||||
bool initialize(const QStringList &arguments, QString *error_message);
|
bool initialize(const QStringList &arguments, QString *error_message);
|
||||||
|
|||||||
Reference in New Issue
Block a user