OSDN Git Service

QmlDesigner.desigModeWidget: add navigator to toolbar
authorThomas Hartmann <Thomas.Hartmann@nokia.com>
Mon, 20 Jun 2011 14:33:10 +0000 (16:33 +0200)
committerThomas Hartmann <Thomas.Hartmann@nokia.com>
Mon, 20 Jun 2011 14:35:38 +0000 (16:35 +0200)
Now we have a navigation history in the DesignMode.
The check (m_textEditor && editor) is there to keep the history clean.

Change-Id: I26bbefe45b51c53379bfecbe1cdc02a64df76012d
Reviewed-on: http://codereview.qt.nokia.com/519
Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com>
Reviewed-by: Thomas Hartmann <Thomas.Hartmann@nokia.com>
src/plugins/qmldesigner/designmodewidget.cpp
src/plugins/qmldesigner/designmodewidget.h

index ded3e62..e5011c7 100644 (file)
@@ -185,13 +185,16 @@ void DocumentWarningWidget::goToError()
 DesignModeWidget::DesignModeWidget(QWidget *parent) :
     QWidget(parent),
     m_syncWithTextEdit(false),
+    m_textEditor(0),
     m_mainSplitter(0),
     m_leftSideBar(0),
     m_rightSideBar(0),
     m_isDisabled(false),
     m_showSidebars(true),
     m_initStatus(NotInitialized),
-    m_warningWidget(0)
+    m_warningWidget(0),
+    m_navigatorHistoryCounter(-1),
+    m_keepNavigatorHistory(false)
 {
     m_undoAction = new QAction(tr("&Undo"), this);
     connect(m_undoAction, SIGNAL(triggered()), this, SLOT(undo()));
@@ -267,6 +270,9 @@ void DesignModeWidget::toggleSidebars()
 
 void DesignModeWidget::showEditor(Core::IEditor *editor)
 {
+    if (m_textEditor && editor)
+        if (m_textEditor->file()->fileName() == editor->file()->fileName())
+            return;
     //
     // Prevent recursive calls to function by explicitly managing initialization status
     // (QApplication::processEvents is called explicitly at a number of places)
@@ -289,6 +295,9 @@ void DesignModeWidget::showEditor(Core::IEditor *editor)
         textEditor = qobject_cast<TextEditor::ITextEditor*>(editor);
         if (textEditor)
             m_fakeToolBar->addEditor(textEditor);
+        if (!m_keepNavigatorHistory)
+            addNavigatorHistoryEntry(fileName);
+        setupNavigatorHistory();
     }
 
     if (debug)
@@ -723,9 +732,12 @@ void DesignModeWidget::setup()
 
     m_fakeToolBar->setToolbarCreationFlags(Core::EditorToolBar::FlagsStandalone);
     //m_fakeToolBar->addEditor(textEditor()); ### what does this mean?
-    m_fakeToolBar->setNavigationVisible(false);
+    m_fakeToolBar->setNavigationVisible(true);
 
     connect(m_fakeToolBar, SIGNAL(closeClicked()), this, SLOT(closeCurrentEditor()));
+    connect(m_fakeToolBar, SIGNAL(goForwardClicked()), this, SLOT(onGoForwardClicked()));
+    connect(m_fakeToolBar, SIGNAL(goBackClicked()), this, SLOT(onGoBackClicked()));
+    setupNavigatorHistory();
 
     // right area:
     QWidget *centerWidget = new QWidget;
@@ -808,6 +820,30 @@ void DesignModeWidget::qmlPuppetCrashed()
     disable(errorList);
 }
 
+void DesignModeWidget::onGoBackClicked()
+{
+    if (m_navigatorHistoryCounter > 0) {
+        --m_navigatorHistoryCounter;
+        m_keepNavigatorHistory = true;
+
+        Core::EditorManager::instance()->openEditor(m_navigatorHistory.at(m_navigatorHistoryCounter));
+
+        m_keepNavigatorHistory = false;
+    }
+}
+
+void DesignModeWidget::onGoForwardClicked()
+{
+    if (m_navigatorHistoryCounter < (m_navigatorHistory.size() - 1)) {
+        ++m_navigatorHistoryCounter;
+        m_keepNavigatorHistory = true;
+
+        Core::EditorManager::instance()->openEditor(m_navigatorHistory.at(m_navigatorHistoryCounter));
+
+        m_keepNavigatorHistory = false;
+    }
+}
+
 void DesignModeWidget::resizeEvent(QResizeEvent *event)
 {
     if (m_warningWidget)
@@ -842,6 +878,24 @@ ModelNode DesignModeWidget::nodeForPosition(int cursorPos) const
     return bestNode;
 }
 
+void DesignModeWidget::setupNavigatorHistory()
+{
+    const bool canGoBack = m_navigatorHistoryCounter > 0;
+    const bool canGoForward = m_navigatorHistoryCounter < (m_navigatorHistory.size() - 1);
+    m_fakeToolBar->setCanGoBack(canGoBack);
+    m_fakeToolBar->setCanGoForward(canGoForward);
+}
+
+void DesignModeWidget::addNavigatorHistoryEntry(const QString &fileName)
+{
+    if (m_navigatorHistoryCounter > 0)
+        m_navigatorHistory.insert(m_navigatorHistoryCounter + 1, fileName);
+    else
+        m_navigatorHistory.append(fileName);
+
+    ++m_navigatorHistoryCounter;
+}
+
 
 QString DesignModeWidget::contextHelpId() const
 {
index e0b0aec..1be2fa2 100644 (file)
@@ -157,6 +157,9 @@ private slots:
     void deleteSidebarWidgets();
     void qmlPuppetCrashed();
 
+    void onGoBackClicked();
+    void onGoForwardClicked();
+
 protected:
     void resizeEvent(QResizeEvent *event);
 
@@ -194,6 +197,8 @@ private:
     void setup();
     bool isInNodeDefinition(int nodeOffset, int nodeLength, int cursorPos) const;
     QmlDesigner::ModelNode nodeForPosition(int cursorPos) const;
+    void setupNavigatorHistory();
+    void addNavigatorHistoryEntry(const QString &fileName);
 
     TextEditor::ITextEditor *m_textEditor;
 
@@ -211,6 +216,9 @@ private:
     InitializeStatus m_initStatus;
 
     DocumentWarningWidget *m_warningWidget;
+    QStringList m_navigatorHistory;
+    int m_navigatorHistoryCounter;
+    bool m_keepNavigatorHistory;
 };
 
 } // namespace Internal