File indexing completed on 2024-04-28 04:36:29
0001 /* 0002 SPDX-FileCopyrightText: 2007 Andreas Pakulat <apaku@gmx.de> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #include "idocument.h" 0008 0009 #include "icore.h" 0010 #include "idocumentcontroller.h" 0011 0012 namespace KDevelop { 0013 0014 class IDocumentPrivate 0015 { 0016 public: 0017 inline explicit IDocumentPrivate(KDevelop::ICore *core) 0018 : m_core(core), scriptWrapper(nullptr) 0019 {} 0020 0021 KDevelop::ICore* m_core; 0022 QObject *scriptWrapper; 0023 QString m_prettyName; 0024 0025 /* Internal access to the wrapper script object */ 0026 static inline QObject *&getWrapper(IDocument *doc) 0027 { 0028 return doc->d_func()->scriptWrapper; 0029 } 0030 }; 0031 0032 /* This allows the scripting backend to register the scripting 0033 wrapper. Not beautiful, but makes sure it doesn't expand to much code. 0034 */ 0035 QObject *&getWrapper(IDocument *doc) 0036 { 0037 return IDocumentPrivate::getWrapper(doc); 0038 } 0039 0040 IDocument::IDocument( KDevelop::ICore* core ) 0041 : d_ptr(new IDocumentPrivate(core)) 0042 { 0043 } 0044 0045 IDocument::~IDocument() 0046 { 0047 Q_D(IDocument); 0048 0049 delete d->scriptWrapper; 0050 } 0051 0052 KDevelop::ICore* IDocument::core() 0053 { 0054 Q_D(IDocument); 0055 0056 return d->m_core; 0057 } 0058 0059 void IDocument::notifySaved() 0060 { 0061 emit core()->documentController()->documentSaved(this); 0062 } 0063 0064 void IDocument::notifyStateChanged() 0065 { 0066 emit core()->documentController()->documentStateChanged(this); 0067 } 0068 0069 void IDocument::notifyActivated() 0070 { 0071 // DocumentController::cleanup() closes open documents one by one on shutdown. When the active document is closed, 0072 // another still-open document is activated and this function is called. Emitting the documentActivated signal then 0073 // results in useless work, such as UI updates and parsing activated documents with higher priority. It also causes 0074 // undesirable side effects, for example, a wrong ProjectTreeView row is selected, then saved and restored on next 0075 // KDevelop start. Don't emit the signal while shutting down to speed up shutdown and prevent bugs. cleanup() closes 0076 // documents without checking whether they should be saved (Discard mode), so temporary UI inconsistencies caused by 0077 // skipped signals should be brief and harmless. 0078 if (!core()->shuttingDown()) { 0079 emit core()->documentController()->documentActivated(this); 0080 } 0081 } 0082 0083 void IDocument::notifyContentChanged() 0084 { 0085 emit core()->documentController()->documentContentChanged(this); 0086 } 0087 0088 void IDocument::notifyTextDocumentCreated() 0089 { 0090 emit core()->documentController()->textDocumentCreated(this); 0091 } 0092 0093 KTextEditor::Range IDocument::textSelection() const 0094 { 0095 return KTextEditor::Range::invalid(); 0096 } 0097 0098 QString IDocument::textLine() const 0099 { 0100 return QString(); 0101 } 0102 0103 QString IDocument::textWord() const 0104 { 0105 return QString(); 0106 } 0107 0108 QString IDocument::prettyName() const 0109 { 0110 Q_D(const IDocument); 0111 0112 return d->m_prettyName; 0113 } 0114 0115 void IDocument::setPrettyName(const QString& name) 0116 { 0117 Q_D(IDocument); 0118 0119 d->m_prettyName = name; 0120 } 0121 0122 void IDocument::notifyUrlChanged(const QUrl& previousUrl) 0123 { 0124 emit core()->documentController()->documentUrlChanged(this, previousUrl); 0125 } 0126 0127 void IDocument::notifyLoaded() 0128 { 0129 emit core()->documentController()->documentLoadedPrepare(this); 0130 emit core()->documentController()->documentLoaded(this); 0131 } 0132 0133 KTextEditor::View* IDocument::activeTextView() const 0134 { 0135 return nullptr; 0136 } 0137 0138 QString KDevelop::IDocument::text(const KTextEditor::Range& range) const 0139 { 0140 Q_UNUSED(range); 0141 return {}; 0142 } 0143 0144 } 0145