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