diff options
author | Kai Koehne <kai.koehne@nokia.com> | 2010-07-16 11:04:20 +0200 |
---|---|---|
committer | Kai Koehne <kai.koehne@nokia.com> | 2010-07-16 14:10:02 +0200 |
commit | 97ca483d33bd6d37e6ac7738f662baf6715fb320 (patch) | |
tree | 938c119d1d95fbbfca1b76f18322e1bff060573b /src/plugins/texteditor | |
parent | ff5506f3b95bd64036d45aa4a206d31d57c8aab9 (diff) |
QmlJSOutline: Store the filter settings when switching files
Diffstat (limited to 'src/plugins/texteditor')
-rw-r--r-- | src/plugins/texteditor/ioutlinewidget.h | 3 | ||||
-rw-r--r-- | src/plugins/texteditor/outlinefactory.cpp | 42 | ||||
-rw-r--r-- | src/plugins/texteditor/outlinefactory.h | 4 |
3 files changed, 42 insertions, 7 deletions
diff --git a/src/plugins/texteditor/ioutlinewidget.h b/src/plugins/texteditor/ioutlinewidget.h index 1ac85f8074..d2d3403de6 100644 --- a/src/plugins/texteditor/ioutlinewidget.h +++ b/src/plugins/texteditor/ioutlinewidget.h @@ -18,6 +18,9 @@ public: virtual QList<QAction*> filterMenuActions() const = 0; virtual void setCursorSynchronization(bool syncWithCursor) = 0; + + virtual void restoreSettings(int position) { Q_UNUSED(position); } + virtual void saveSettings(int position) { Q_UNUSED(position); } }; class TEXTEDITOR_EXPORT IOutlineWidgetFactory : public QObject { diff --git a/src/plugins/texteditor/outlinefactory.cpp b/src/plugins/texteditor/outlinefactory.cpp index b80599ef34..374b53f2e9 100644 --- a/src/plugins/texteditor/outlinefactory.cpp +++ b/src/plugins/texteditor/outlinefactory.cpp @@ -14,7 +14,8 @@ namespace Internal { OutlineWidgetStack::OutlineWidgetStack(OutlineFactory *factory) : QStackedWidget(), m_factory(factory), - m_syncWithEditor(true) + m_syncWithEditor(true), + m_position(-1) { QLabel *label = new QLabel(tr("No outline available"), this); label->setAlignment(Qt::AlignCenter); @@ -60,6 +61,33 @@ QToolButton *OutlineWidgetStack::filterButton() return m_filterButton; } +void OutlineWidgetStack::restoreSettings(int position) +{ + m_position = position; // save it so that we can save/restore in updateCurrentEditor + + QSettings *settings = Core::ICore::instance()->settings(); + const bool toggleSync = settings->value("Outline."+ QString::number(position) + ".SyncWithEditor", + true).toBool(); + toggleSyncButton()->setChecked(toggleSync); + + if (IOutlineWidget *outlineWidget = qobject_cast<IOutlineWidget*>(currentWidget())) { + outlineWidget->restoreSettings(position); + } +} + +void OutlineWidgetStack::saveSettings(int position) +{ + Q_ASSERT(position == m_position); + + QSettings *settings = Core::ICore::instance()->settings(); + settings->setValue("Outline."+QString::number(position)+".SyncWithEditor", + toggleSyncButton()->isEnabled()); + + if (IOutlineWidget *outlineWidget = qobject_cast<IOutlineWidget*>(currentWidget())) { + outlineWidget->saveSettings(position); + } +} + bool OutlineWidgetStack::isCursorSynchronized() const { return m_syncWithEditor; @@ -98,10 +126,14 @@ void OutlineWidgetStack::updateCurrentEditor(Core::IEditor *editor) if (newWidget != currentWidget()) { // delete old widget if (IOutlineWidget *outlineWidget = qobject_cast<IOutlineWidget*>(currentWidget())) { + if (m_position > -1) + outlineWidget->saveSettings(m_position); removeWidget(outlineWidget); delete outlineWidget; } if (newWidget) { + if (m_position > -1) + newWidget->restoreSettings(m_position); newWidget->setCursorSynchronization(m_syncWithEditor); addWidget(newWidget); setCurrentWidget(newWidget); @@ -153,18 +185,14 @@ 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()); + widgetStack->saveSettings(position); } 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()); + widgetStack->restoreSettings(position); } } // namespace Internal diff --git a/src/plugins/texteditor/outlinefactory.h b/src/plugins/texteditor/outlinefactory.h index 8c5fe1b5c0..3614b93299 100644 --- a/src/plugins/texteditor/outlinefactory.h +++ b/src/plugins/texteditor/outlinefactory.h @@ -25,6 +25,9 @@ public: QToolButton *toggleSyncButton(); QToolButton *filterButton(); + void saveSettings(int position); + void restoreSettings(int position); + private: bool isCursorSynchronized() const; QWidget *dummyWidget() const; @@ -41,6 +44,7 @@ private: QToolButton *m_filterButton; QMenu *m_filterMenu; bool m_syncWithEditor; + int m_position; }; class OutlineFactory : public Core::INavigationWidgetFactory |