From kde-commits Fri Oct 31 23:09:49 2008 From: David Nolden Date: Fri, 31 Oct 2008 23:09:49 +0000 To: kde-commits Subject: KDE/kdevplatform/plugins/contextbrowser Message-Id: <1225494589.217303.16014.nullmailer () svn ! kde ! org> X-MARC-Message: https://marc.info/?l=kde-commits&m=122549459907523 SVN commit 878339 by zwabel: Better tracking of the context-history. Whenever any kind of jump is performed, be it from navigation, from quickopen, or whathever, then a history-entry is inserted for the start- and for the end-position of the jump. This makes the history actually useful and reliable, because it always brings you to your last position in the other document. This is especially useful in the "browsing" mode, since it brings the convenience of web-browsing. M +1 -0 browsemanager.cpp M +2 -7 contextbrowser.cpp M +2 -0 contextbrowser.h M +32 -3 contextbrowserview.cpp M +9 -2 contextbrowserview.h --- trunk/KDE/kdevplatform/plugins/contextbrowser/browsemanager.cpp #878338:878339 @@ -180,6 +180,7 @@ } if(jumpTo.first.isValid() && jumpTo.second.isValid()) { if(mouseEvent->button() == Qt::LeftButton && mouseEvent->type() == QEvent::MouseButtonPress) { + view->setCursorPosition(textCursor); ICore::self()->documentController()->openDocument(jumpTo.first, jumpTo.second.textCursor()); event->accept(); return true; --- trunk/KDE/kdevplatform/plugins/contextbrowser/contextbrowser.cpp #878338:878339 @@ -111,12 +111,12 @@ connect( m_updateTimer, SIGNAL( timeout() ), this, SLOT( updateViews() ) ); KAction* previousContext = actions->addAction("previous_context"); - previousContext->setText( i18n("&Previous Context") ); + previousContext->setText( i18n("&Previous Visited Context") ); previousContext->setShortcut( Qt::META | Qt::Key_Left ); connect(previousContext, SIGNAL(triggered(bool)), this, SIGNAL(previousContextShortcut())); KAction* nextContext = actions->addAction("next_context"); - nextContext->setText( i18n("&Next Context") ); + nextContext->setText( i18n("&Next Visited Context") ); nextContext->setShortcut( Qt::META | Qt::Key_Right ); connect(nextContext, SIGNAL(triggered(bool)), this, SIGNAL(nextContextShortcut())); @@ -395,9 +395,6 @@ } } -namespace -{ - DUContext* contextAt(const SimpleCursor& position, TopDUContext* topContext) { DUContext* ctx = topContext->findContextAt(position); @@ -406,8 +403,6 @@ return ctx; } -} // end anonymous namespace - void ContextBrowserPlugin::updateBrowserWidgetFor(View* view) { bool mouseHighlight = --- trunk/KDE/kdevplatform/plugins/contextbrowser/contextbrowser.h #878338:878339 @@ -134,6 +134,8 @@ ContextBrowserViewFactory* m_viewFactory; }; +DUContext* contextAt(const SimpleCursor& position, TopDUContext* topContext); + #endif // CONTEXTBROWSERPLUGIN_H // kate: space-indent on; indent-width 2; tab-width 4; replace-tabs on; auto-insert-doxygen on --- trunk/KDE/kdevplatform/plugins/contextbrowser/contextbrowserview.cpp #878338:878339 @@ -47,6 +47,7 @@ #include #include "browsemanager.h" #include +#include const int maxHistoryLength = 30; @@ -67,6 +68,8 @@ ContextController::ContextController(ContextBrowserView* view) : m_nextHistoryIndex(0), m_view(view) { m_browseManager = new BrowseManager(this); + connect(ICore::self()->documentController(), SIGNAL(documentJumpPerformed(KDevelop::IDocument*, KTextEditor::Cursor, KDevelop::IDocument*, KTextEditor::Cursor)), this, SLOT(documentJumpPerformed(KDevelop::IDocument*, KTextEditor::Cursor, KDevelop::IDocument*, KTextEditor::Cursor))); + m_previousButton = new QToolButton(); m_previousButton->setPopupMode(QToolButton::MenuButtonPopup); m_previousButton->setIcon(KIcon("go-previous")); @@ -97,6 +100,31 @@ connect(m_currentContextBox, SIGNAL(activated(int)), this, SLOT(comboItemActivated(int))); } +///Duchain must be locked +DUContext* getContextAt(KUrl url, KTextEditor::Cursor cursor) { + TopDUContext* topContext = DUChainUtils::standardContextForUrl(url); + if (!topContext) return 0; + return contextAt(SimpleCursor(cursor), topContext); +} + +void ContextController::documentJumpPerformed( KDevelop::IDocument* newDocument, KTextEditor::Cursor newCursor, KDevelop::IDocument* previousDocument, KTextEditor::Cursor previousCursor) { + if(newCursor.isValid() && previousCursor.isValid()) { + + KUrl oldIgnore = m_ignoreJump; + m_ignoreJump = KUrl(); + if(newDocument->url() == oldIgnore) + return; + + DUChainReadLocker lock(DUChain::lock()); + + if(previousDocument && previousCursor.isValid()) + updateHistory(getContextAt(previousDocument->url(), previousCursor), SimpleCursor(previousCursor), true); + + if(newDocument && newCursor.isValid()) + updateHistory(getContextAt(newDocument->url(), newCursor), SimpleCursor(newCursor), true); + } +} + ContextBrowserView* ContextController::view() const { return m_view; } @@ -155,7 +183,8 @@ Q_ASSERT_X(historyIndex < m_history.size(), "openDocument", "history index out of range"); DocumentCursor c = m_history[historyIndex].computePosition(); if (c.isValid() && !c.document().str().isEmpty()) { - ICore::self()->documentController()->openDocument(KUrl(c.document().str()), c); + m_ignoreJump = KUrl(c.document().str()); + ICore::self()->documentController()->openDocument(m_ignoreJump, c); KDevelop::DUChainReadLocker lock( KDevelop::DUChain::lock() ); updateDeclarationListBox(m_history[historyIndex].context.data()); @@ -320,10 +349,10 @@ currentContextBox()->setCurrentIndex(m_listDeclarations.indexOf(context->owner())); } -void ContextController::updateHistory(KDevelop::DUContext* context, const KDevelop::SimpleCursor& position) +void ContextController::updateHistory(KDevelop::DUContext* context, const KDevelop::SimpleCursor& position, bool force) { if (context == 0) return; - if(!context->owner()) + if(!context->owner() && !force) return; //Only add history-entries for contexts that have owners, which in practice should be functions and classes //This keeps the history cleaner --- trunk/KDE/kdevplatform/plugins/contextbrowser/contextbrowserview.h #878338:878339 @@ -39,6 +39,10 @@ class ContextController; // declared below class DeclarationController; // declared below +namespace KDevelop { +class IDocument; +} + class ContextBrowserView : public QWidget { Q_OBJECT public: @@ -84,9 +88,10 @@ ContextController(ContextBrowserView*); virtual ~ContextController(); - //duchain must be locked + ///duchain must be locked + ///@param force When this is true, the history-entry is added, no matter whether the context is "interesting" or not void updateHistory(KDevelop::DUContext* context, const - KDevelop::SimpleCursor& cursorPosition); + KDevelop::SimpleCursor& cursorPosition, bool force = false); QWidget* createWidget(KDevelop::DUContext* context); QToolButton* previousButton() const; @@ -119,6 +124,7 @@ void actionTriggered(); private Q_SLOTS: void comboItemActivated(int index); + void documentJumpPerformed( KDevelop::IDocument* newDocument, KTextEditor::Cursor newCursor, KDevelop::IDocument* previousDocument, KTextEditor::Cursor previousCursor); private: void updateDeclarationListBox(KDevelop::DUContext* context); bool isPreviousEntry(KDevelop::DUContext*, const KDevelop::SimpleCursor& cursor); @@ -141,6 +147,7 @@ QList m_listDeclarations; KDevelop::IndexedString m_listUrl; BrowseManager* m_browseManager; + KUrl m_ignoreJump; }; // Handles Declaration related operations for ContextBrowserView