summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKai Koehne <kai.koehne@nokia.com>2010-07-08 11:15:26 +0200
committerKai Koehne <kai.koehne@nokia.com>2010-07-08 14:02:51 +0200
commit5439ce976eaa160a41c295dee8971509bed8425d (patch)
tree9aee7b3fd247cb7d90f60fce2845f9b31b5380d4
parentebe388ee926773ff603d7360c31ebd3eec3509c5 (diff)
downloadqt-creator-5439ce976eaa160a41c295dee8971509bed8425d.tar.gz
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
-rw-r--r--src/plugins/texteditor/ioutlinewidget.h31
-rw-r--r--src/plugins/texteditor/outlinefactory.cpp123
-rw-r--r--src/plugins/texteditor/outlinefactory.h63
-rw-r--r--src/plugins/texteditor/texteditor.pro7
-rw-r--r--src/plugins/texteditor/texteditorplugin.cpp11
-rw-r--r--src/plugins/texteditor/texteditorplugin.h2
6 files changed, 234 insertions, 3 deletions
diff --git a/src/plugins/texteditor/ioutlinewidget.h b/src/plugins/texteditor/ioutlinewidget.h
new file mode 100644
index 0000000000..1242b85356
--- /dev/null
+++ b/src/plugins/texteditor/ioutlinewidget.h
@@ -0,0 +1,31 @@
+#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
diff --git a/src/plugins/texteditor/outlinefactory.cpp b/src/plugins/texteditor/outlinefactory.cpp
new file mode 100644
index 0000000000..421c31f440
--- /dev/null
+++ b/src/plugins/texteditor/outlinefactory.cpp
@@ -0,0 +1,123 @@
+#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
diff --git a/src/plugins/texteditor/outlinefactory.h b/src/plugins/texteditor/outlinefactory.h
new file mode 100644
index 0000000000..c3b7b440c1
--- /dev/null
+++ b/src/plugins/texteditor/outlinefactory.h
@@ -0,0 +1,63 @@
+#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
diff --git a/src/plugins/texteditor/texteditor.pro b/src/plugins/texteditor/texteditor.pro
index 65bc255c93..931f561490 100644
--- a/src/plugins/texteditor/texteditor.pro
+++ b/src/plugins/texteditor/texteditor.pro
@@ -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 \
diff --git a/src/plugins/texteditor/texteditorplugin.cpp b/src/plugins/texteditor/texteditorplugin.cpp
index 633bde6f0d..e314ae3de3 100644
--- a/src/plugins/texteditor/texteditorplugin.cpp
+++ b/src/plugins/texteditor/texteditorplugin.cpp
@@ -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)
diff --git a/src/plugins/texteditor/texteditorplugin.h b/src/plugins/texteditor/texteditorplugin.h
index 93f8870e1f..cb57ab2df5 100644
--- a/src/plugins/texteditor/texteditorplugin.h
+++ b/src/plugins/texteditor/texteditorplugin.h
@@ -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