Commit 5439ce97 authored by Kai Koehne's avatar Kai Koehne
Browse files

Add new Outline sidebar pane

Adds a generic Outline pane to the sidebar. The CppEditor & QmlJSEditor
plugins will implement the IOutlineWidget/IOutlineWidgetFactory interface to
provide views specific to C++/Qml/JS documents.

Reviewed-by: con
parent ebe388ee
#ifndef IOUTLINEWIDGET_H
#define IOUTLINEWIDGET_H
#include <texteditor/texteditor_global.h>
#include <QtGui/QWidget>
namespace Core {
class IEditor;
}
namespace TextEditor {
class TEXTEDITOR_EXPORT IOutlineWidget : public QWidget
{
Q_OBJECT
public:
IOutlineWidget(QWidget *parent = 0) : QWidget(parent) {}
virtual void setCursorSynchronization(bool syncWithCursor) = 0;
};
class TEXTEDITOR_EXPORT IOutlineWidgetFactory : public QObject {
Q_OBJECT
public:
virtual bool supportsEditor(Core::IEditor *editor) const = 0;
virtual IOutlineWidget *createWidget(Core::IEditor *editor) = 0;
};
} // namespace TextEditor
#endif // IOUTLINEWIDGET_H
#include "outlinefactory.h"
#include <coreplugin/editormanager/editormanager.h>
#include <coreplugin/editormanager/ieditor.h>
#include <QVBoxLayout>
#include <QDebug>
#include <QToolButton>
#include <QLabel>
#include <QStackedWidget>
namespace TextEditor {
namespace Internal {
OutlineWidgetStack::OutlineWidgetStack(OutlineFactory *factory) :
QStackedWidget(),
m_factory(factory),
m_syncWithEditor(true)
{
QLabel *label = new QLabel(tr("No outline available"), this);
label->setAlignment(Qt::AlignCenter);
addWidget(label);
m_toggleSync = new QToolButton;
m_toggleSync->setIcon(QIcon(":/core/images/linkicon.png"));
m_toggleSync->setCheckable(true);
m_toggleSync->setChecked(true);
m_toggleSync->setToolTip(tr("Synchronize with Editor"));
connect(m_toggleSync, SIGNAL(clicked(bool)), this, SLOT(toggleCursorSynchronization()));
Core::EditorManager *editorManager = Core::EditorManager::instance();
connect(editorManager, SIGNAL(currentEditorChanged(Core::IEditor*)),
this, SLOT(updateCurrentEditor(Core::IEditor*)));
updateCurrentEditor(editorManager->currentEditor());
}
OutlineWidgetStack::~OutlineWidgetStack()
{
}
QToolButton *OutlineWidgetStack::toggleSyncButton()
{
return m_toggleSync;
}
bool OutlineWidgetStack::isCursorSynchronized() const
{
return m_syncWithEditor;
}
void OutlineWidgetStack::toggleCursorSynchronization()
{
m_syncWithEditor = !m_syncWithEditor;
if (IOutlineWidget *outlineWidget = qobject_cast<IOutlineWidget*>(currentWidget()))
outlineWidget->setCursorSynchronization(m_syncWithEditor);
}
void OutlineWidgetStack::updateCurrentEditor(Core::IEditor *editor)
{
IOutlineWidget *newWidget = 0;
if (editor) {
foreach (IOutlineWidgetFactory *widgetFactory, m_factory->widgetFactories()) {
if (widgetFactory->supportsEditor(editor)) {
newWidget = widgetFactory->createWidget(editor);
break;
}
}
}
if (newWidget != currentWidget()) {
// delete old widget
if (IOutlineWidget *outlineWidget = qobject_cast<IOutlineWidget*>(currentWidget())) {
removeWidget(outlineWidget);
delete outlineWidget;
}
if (newWidget) {
newWidget->setCursorSynchronization(m_syncWithEditor);
addWidget(newWidget);
setCurrentWidget(newWidget);
}
}
}
OutlineFactory::OutlineFactory() :
Core::INavigationWidgetFactory()
{
}
QList<IOutlineWidgetFactory*> OutlineFactory::widgetFactories() const
{
return m_factories;
}
void OutlineFactory::setWidgetFactories(QList<IOutlineWidgetFactory*> factories)
{
m_factories = factories;
}
QString OutlineFactory::displayName() const
{
return tr("Outline");
}
QString OutlineFactory::id() const
{
return QLatin1String("Outline");
}
QKeySequence OutlineFactory::activationSequence() const
{
return QKeySequence();
}
Core::NavigationView OutlineFactory::createWidget()
{
Core::NavigationView n;
OutlineWidgetStack *placeHolder = new OutlineWidgetStack(this);
n.widget = placeHolder;
n.dockToolBarWidgets.append(placeHolder->toggleSyncButton());
return n;
}
} // namespace Internal
} // namespace TextEditor
#ifndef OUTLINE_H
#define OUTLINE_H
#include <texteditor/ioutlinewidget.h>
#include <coreplugin/inavigationwidgetfactory.h>
#include <QtGui/QStackedWidget>
namespace Core {
class IEditor;
}
namespace TextEditor {
namespace Internal {
class OutlineFactory;
class OutlineWidgetStack : public QStackedWidget
{
Q_OBJECT
public:
OutlineWidgetStack(OutlineFactory *factory);
~OutlineWidgetStack();
QToolButton *toggleSyncButton();
private:
bool isCursorSynchronized() const;
QWidget *dummyWidget() const;
private slots:
void toggleCursorSynchronization();
void updateCurrentEditor(Core::IEditor *editor);
private:
QStackedWidget *m_widgetStack;
OutlineFactory *m_factory;
QToolButton *m_toggleSync;
bool m_syncWithEditor;
};
class OutlineFactory : public Core::INavigationWidgetFactory
{
Q_OBJECT
public:
OutlineFactory();
QList<IOutlineWidgetFactory*> widgetFactories() const;
void setWidgetFactories(QList<IOutlineWidgetFactory*> factories);
// from INavigationWidgetFactory
virtual QString displayName() const;
virtual QString id() const;
virtual QKeySequence activationSequence() const;
virtual Core::NavigationView createWidget();
private:
QList<IOutlineWidgetFactory*> m_factories;
};
} // namespace Internal
} // namespace TextEditor
#endif // OUTLINE_H
......@@ -60,7 +60,8 @@ SOURCES += texteditorplugin.cpp \
generichighlighter/highlightdefinitionmetadata.cpp \
generichighlighter/definitiondownloader.cpp \
refactoringchanges.cpp \
refactoroverlay.cpp
refactoroverlay.cpp \
outlinefactory.cpp
HEADERS += texteditorplugin.h \
textfilewizard.h \
......@@ -123,7 +124,9 @@ HEADERS += texteditorplugin.h \
generichighlighter/highlightdefinitionmetadata.h \
generichighlighter/definitiondownloader.h \
refactoringchanges.h \
refactoroverlay.h
refactoroverlay.h \
outlinefactory.h \
ioutlinewidget.h
FORMS += behaviorsettingspage.ui \
displaysettingspage.ui \
......
......@@ -40,6 +40,7 @@
#include "plaintexteditor.h"
#include "storagesettings.h"
#include "manager.h"
#include "outlinefactory.h"
#include <coreplugin/icore.h>
#include <coreplugin/coreconstants.h>
......@@ -144,6 +145,9 @@ bool TextEditorPlugin::initialize(const QStringList &arguments, QString *errorMe
connect(Core::ICore::instance(), SIGNAL(coreOpened()),
Manager::instance(), SLOT(registerMimeTypes()));
m_outlineFactory = new OutlineFactory;
addAutoReleasedObject(m_outlineFactory);
return true;
}
......@@ -151,7 +155,11 @@ void TextEditorPlugin::extensionsInitialized()
{
m_editorFactory->actionHandler()->initializeActions();
m_searchResultWindow = ExtensionSystem::PluginManager::instance()->getObject<Find::SearchResultWindow>();
ExtensionSystem::PluginManager *pluginManager = ExtensionSystem::PluginManager::instance();
m_searchResultWindow = pluginManager->getObject<Find::SearchResultWindow>();
m_outlineFactory->setWidgetFactories(pluginManager->getObjects<TextEditor::IOutlineWidgetFactory>());
connect(m_settings, SIGNAL(fontSettingsChanged(TextEditor::FontSettings)),
this, SLOT(updateSearchResultsFont(TextEditor::FontSettings)));
......@@ -162,6 +170,7 @@ void TextEditorPlugin::extensionsInitialized()
ExtensionSystem::PluginManager::instance()->getObject<Find::SearchResultWindow>()));
addAutoReleasedObject(new FindInCurrentFile(
ExtensionSystem::PluginManager::instance()->getObject<Find::SearchResultWindow>()));
}
void TextEditorPlugin::initializeEditor(PlainTextEditor *editor)
......
......@@ -47,6 +47,7 @@ namespace Internal {
class LineNumberFilter;
class PlainTextEditorFactory;
class OutlineFactory;
class TextEditorPlugin : public ExtensionSystem::IPlugin
{
......@@ -79,6 +80,7 @@ private:
PlainTextEditorFactory *m_editorFactory;
LineNumberFilter *m_lineNumberFilter;
Find::SearchResultWindow *m_searchResultWindow;
OutlineFactory *m_outlineFactory;
};
} // namespace Internal
......
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