2010-07-08 11:15:26 +02:00
|
|
|
#include "outlinefactory.h"
|
2010-07-14 16:46:54 +02:00
|
|
|
#include <coreplugin/icore.h>
|
2010-07-08 11:15:26 +02:00
|
|
|
#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);
|
2010-07-13 14:15:54 +02:00
|
|
|
|
|
|
|
|
// set background to be white
|
|
|
|
|
label->setAutoFillBackground(true);
|
|
|
|
|
label->setBackgroundRole(QPalette::Base);
|
|
|
|
|
|
2010-07-08 11:15:26 +02:00
|
|
|
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()));
|
|
|
|
|
|
2010-07-14 16:46:54 +02:00
|
|
|
m_filterButton = new QToolButton;
|
|
|
|
|
m_filterButton->setIcon(QIcon(":/core/images/filtericon.png"));
|
|
|
|
|
m_filterButton->setToolTip(tr("Filter tree"));
|
|
|
|
|
m_filterButton->setPopupMode(QToolButton::InstantPopup);
|
|
|
|
|
m_filterMenu = new QMenu(m_filterButton);
|
|
|
|
|
m_filterButton->setMenu(m_filterMenu);
|
|
|
|
|
connect(m_filterMenu, SIGNAL(aboutToShow()), this, SLOT(updateFilterMenu()));
|
|
|
|
|
|
2010-07-08 11:15:26 +02:00
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-14 16:46:54 +02:00
|
|
|
QToolButton *OutlineWidgetStack::filterButton()
|
|
|
|
|
{
|
|
|
|
|
return m_filterButton;
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-08 11:15:26 +02:00
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-14 16:46:54 +02:00
|
|
|
void OutlineWidgetStack::updateFilterMenu()
|
|
|
|
|
{
|
|
|
|
|
m_filterMenu->clear();
|
|
|
|
|
if (IOutlineWidget *outlineWidget = qobject_cast<IOutlineWidget*>(currentWidget())) {
|
|
|
|
|
foreach (QAction *filterAction, outlineWidget->filterMenuActions()) {
|
|
|
|
|
m_filterMenu->addAction(filterAction);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-08 11:15:26 +02:00
|
|
|
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());
|
2010-07-14 16:46:54 +02:00
|
|
|
n.dockToolBarWidgets.append(placeHolder->filterButton());
|
2010-07-08 11:15:26 +02:00
|
|
|
return n;
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-16 08:18:56 +02:00
|
|
|
void OutlineFactory::saveSettings(int position, QWidget *widget)
|
|
|
|
|
{
|
|
|
|
|
OutlineWidgetStack *widgetStack = qobject_cast<OutlineWidgetStack *>(widget);
|
|
|
|
|
Q_ASSERT(widgetStack);
|
|
|
|
|
QSettings *settings = Core::ICore::instance()->settings();
|
|
|
|
|
settings->setValue("Outline."+QString::number(position)+".SyncWithEditor",
|
|
|
|
|
widgetStack->toggleSyncButton()->isEnabled());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void OutlineFactory::restoreSettings(int position, QWidget *widget)
|
|
|
|
|
{
|
|
|
|
|
OutlineWidgetStack *widgetStack = qobject_cast<OutlineWidgetStack *>(widget);
|
|
|
|
|
Q_ASSERT(widgetStack);
|
|
|
|
|
QSettings *settings = Core::ICore::instance()->settings();
|
|
|
|
|
widgetStack->toggleSyncButton()->setChecked(
|
|
|
|
|
settings->value("Outline."+QString::number(position)+".SyncWithEditor", true).toBool());
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-08 11:15:26 +02:00
|
|
|
} // namespace Internal
|
|
|
|
|
} // namespace TextEditor
|