File indexing completed on 2024-05-12 04:38:06
0001 /* 0002 SPDX-FileCopyrightText: 2010 David Nolden <david.nolden.kdevelop@art-master.de> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #include "persistentmovingrangeprivate.h" 0008 #include <interfaces/icore.h> 0009 #include <interfaces/ilanguagecontroller.h> 0010 #include <backgroundparser/backgroundparser.h> 0011 0012 #include <KTextEditor/MovingInterface> 0013 #include <KTextEditor/Document> 0014 0015 void KDevelop::PersistentMovingRangePrivate::connectTracker() 0016 { 0017 Q_ASSERT(m_tracker == nullptr); 0018 Q_ASSERT(m_movingRange == nullptr); 0019 0020 m_tracker = ICore::self()->languageController()->backgroundParser()->trackerForUrl(m_document); 0021 0022 if (m_tracker) { 0023 // Create a moving range 0024 m_movingRange = m_tracker->documentMovingInterface()->newMovingRange(m_range); 0025 if (m_shouldExpand) 0026 m_movingRange->setInsertBehaviors( 0027 KTextEditor::MovingRange::ExpandLeft | KTextEditor::MovingRange::ExpandRight); 0028 // can't use new connect syntax here, MovingInterface is not a QObject 0029 connect(m_tracker->document(), SIGNAL(aboutToDeleteMovingInterfaceContent(KTextEditor::Document*)), this, 0030 SLOT(aboutToDeleteMovingInterfaceContent())); 0031 connect(m_tracker->document(), SIGNAL(aboutToInvalidateMovingInterfaceContent(KTextEditor::Document*)), this, 0032 SLOT(aboutToInvalidateMovingInterfaceContent())); 0033 m_movingRange->setAttribute(m_attribte); 0034 m_movingRange->setZDepth(m_zDepth); 0035 } 0036 } 0037 0038 void KDevelop::PersistentMovingRangePrivate::aboutToInvalidateMovingInterfaceContent() 0039 { 0040 if (m_movingRange) { 0041 m_valid = false; /// @todo More precise tracking: Why is the document being invalidated? Try 0042 /// keeping the range alive. DocumentChangeTracker to the rescue. 0043 delete m_movingRange; 0044 m_movingRange = nullptr; 0045 m_range = KTextEditor::Range::invalid(); 0046 } 0047 } 0048 0049 void KDevelop::PersistentMovingRangePrivate::aboutToDeleteMovingInterfaceContent() 0050 { 0051 // The whole document is being closed. Map the range back to the last saved revision, and use that. 0052 updateRangeFromMoving(); 0053 if (m_tracker && m_tracker->diskRevision()) { 0054 if (m_movingRange) 0055 m_range = m_tracker->diskRevision()->transformFromCurrentRevision(m_range).castToSimpleRange(); 0056 } else { 0057 m_valid = false; 0058 m_range = KTextEditor::Range::invalid(); 0059 } 0060 0061 // No need to disconnect, as the document is being deleted. Simply set the references to zero. 0062 delete m_movingRange; 0063 m_movingRange = nullptr; 0064 m_tracker.clear(); 0065 } 0066 0067 #include "moc_persistentmovingrangeprivate.cpp"