[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: KDE/kdelibs
From: David Nolden <david.nolden.kde () art-master ! de>
Date: 2010-12-10 16:54:02
Message-ID: 20101210165402.6C90EAC8A6 () svn ! kde ! org
[Download RAW message or body]
SVN commit 1205271 by zwabel:
- Allow completion models to specify that there items should be hidden if "better" models have items with \
the same name
- Use this to filter out items from the kate word-completion model, if there is a more sophisticated \
model with the same item This makes working with kate word-completion and other completion-models at the \
same time much more pleasant
M +6 -0 interfaces/ktexteditor/codecompletionmodelcontrollerinterface.cpp
M +14 -0 interfaces/ktexteditor/codecompletionmodelcontrollerinterface.h
M +69 -2 kate/completion/katecompletionmodel.cpp
M +3 -0 kate/completion/katecompletionmodel.h
M +8 -1 kate/completion/katewordcompletion.cpp
M +4 -2 kate/completion/katewordcompletion.h
--- trunk/KDE/kdelibs/interfaces/ktexteditor/codecompletionmodelcontrollerinterface.cpp #1205270:1205271
@@ -203,5 +203,11 @@
}
//END V3
+//BEGIN V4
+bool CodeCompletionModelControllerInterface4::shouldHideItemsWithEqualNames() const
+{
+ return false;
+}
+//END V4
}
--- trunk/KDE/kdelibs/interfaces/ktexteditor/codecompletionmodelcontrollerinterface.h #1205270:1205271
@@ -337,10 +337,24 @@
};
//END V3
+//BEGIN V4
+///Extension of CodeCompletionModelControllerInterface3
+class KTEXTEDITOR_EXPORT_DEPRECATED CodeCompletionModelControllerInterface4 : public \
CodeCompletionModelControllerInterface3 { + public:
+ /**
+ * When multiple completion models are used at the same time, it may happen that multiple models add \
items with the same + * name to the list. This option allows to hide items from this completion model \
when another model with higher priority + * contains items with the same name.
+ * \return Whether items of this completion model should be hidden if another completion model has \
items with the same name + */
+ virtual bool shouldHideItemsWithEqualNames() const;
+};
+//END V4
}
Q_DECLARE_INTERFACE(KTextEditor::CodeCompletionModelControllerInterface, \
"org.kde.KTextEditor.CodeCompletionModelControllerInterface") \
Q_DECLARE_INTERFACE(KTextEditor::CodeCompletionModelControllerInterface2, \
"org.kde.KTextEditor.CodeCompletionModelControllerInterface2") \
Q_DECLARE_INTERFACE(KTextEditor::CodeCompletionModelControllerInterface3, \
"org.kde.KTextEditor.CodeCompletionModelControllerInterface3") \
+Q_DECLARE_INTERFACE(KTextEditor::CodeCompletionModelControllerInterface4, \
"org.kde.KTextEditor.CodeCompletionModelControllerInterface4") #endif // \
KDELIBS_KTEXTEDITOR_CODECOMPLETIONMODELCONTROLLERINTERFACE_H
--- trunk/KDE/kdelibs/kate/completion/katecompletionmodel.cpp #1205270:1205271
@@ -596,6 +596,8 @@
foreach (Group* g, m_emptyGroups)
hideOrShowGroup(g);
+ makeGroupItemsUnique();
+
updateBestMatches();
reset();
@@ -948,9 +950,8 @@
if(g != m_argumentHints)
needsReset |= changeCompletions(g, changeType);
}
-
+ }
updateBestMatches();
- }
kDebug()<<"needsReset"<<needsReset;
if(needsReset)
@@ -1947,6 +1948,72 @@
}
}
+void KateCompletionModel::makeGroupItemsUnique(bool onlyFiltered)
+{
+ struct FilterItems {
+ FilterItems(KateCompletionModel& model, const QVector<KTextEditor::CodeCompletionModel*>& \
needShadowing) : m_model(model), m_needShadowing(needShadowing) { + }
+
+ QHash<QString, CodeCompletionModel*> had;
+ KateCompletionModel& m_model;
+ const QVector< KTextEditor::CodeCompletionModel* > m_needShadowing;
+
+ void filter(QList<Item>& items)
+ {
+ QList<Item> temp;
+ foreach(const Item& item, items)
+ {
+ QHash<QString, CodeCompletionModel*>::const_iterator it = had.find(item.name());
+ if(it != had.end() && *it != item.sourceRow().first && \
m_needShadowing.contains(item.sourceRow().first)) + continue;
+ had.insert(item.name(), item.sourceRow().first);
+ temp.push_back(item);
+ }
+ items = temp;
+ }
+
+ void filter(Group* group, bool onlyFiltered)
+ {
+ if(group->prefilter.size() == group->filtered.size())
+ {
+ // Filter only once
+ filter(group->filtered);
+ if(!onlyFiltered)
+ group->prefilter = group->filtered;
+ }else{
+ // Must filter twice
+ filter(group->filtered);
+ if(!onlyFiltered)
+ filter(group->prefilter);
+ }
+
+ if(group->filtered.isEmpty())
+ m_model.hideOrShowGroup(group);
+
+ }
+ };
+
+ QVector<KTextEditor::CodeCompletionModel*> needShadowing;
+
+ foreach(KTextEditor::CodeCompletionModel* model, m_completionModels)
+ {
+ KTextEditor::CodeCompletionModelControllerInterface4* v4 = \
dynamic_cast<KTextEditor::CodeCompletionModelControllerInterface4*>(model); + if(v4 && \
v4->shouldHideItemsWithEqualNames()) + needShadowing.push_back(model);
+ }
+
+ if(needShadowing.isEmpty())
+ return;
+
+ FilterItems filter(*this, needShadowing);
+
+ filter.filter(m_ungrouped, onlyFiltered);
+
+ foreach(Group* group, m_rowTable)
+ filter.filter(group, onlyFiltered);
+}
+
+
//Updates the best-matches group
void KateCompletionModel::updateBestMatches() {
int maxMatches = 300; //We cannot do too many operations here, because they are all executed whenever \
a character is added. Would be nice if we could split the operations up somewhat using a \
timer.
--- trunk/KDE/kdelibs/kate/completion/katecompletionmodel.h #1205270:1205271
@@ -199,6 +199,9 @@
//Updates the best-matches group
void updateBestMatches();
+ //Makes sure that the ungrouped group contains each item only once
+ //Must only be called right after the group was created
+ void makeGroupItemsUnique(bool onlyFiltered = false);
private:
--- trunk/KDE/kdelibs/kate/completion/katewordcompletion.cpp #1205270:1205271
@@ -170,7 +170,7 @@
if (currentCompletion.length()<v->config()->wordCompletionMinimalWordLength()) return true;
}
- return CodeCompletionModelControllerInterface3::shouldAbortCompletion(view,range,currentCompletion);
+ return CodeCompletionModelControllerInterface4::shouldAbortCompletion(view,range,currentCompletion);
}
@@ -243,6 +243,13 @@
return HideListIfAutomaticInvocation;
}
+bool KateWordCompletionModel::shouldHideItemsWithEqualNames() const
+{
+ // We don't want word-completion items if the same items
+ // are available through more sophisticated completion models
+ return true;
+}
+
//END KateWordCompletionModel
--- trunk/KDE/kdelibs/kate/completion/katewordcompletion.h #1205270:1205271
@@ -37,10 +37,10 @@
#include <kdebug.h>
-class KateWordCompletionModel : public KTextEditor::CodeCompletionModel, public \
KTextEditor::CodeCompletionModelControllerInterface3 +class KateWordCompletionModel : public \
KTextEditor::CodeCompletionModel, public KTextEditor::CodeCompletionModelControllerInterface4 {
Q_OBJECT
- Q_INTERFACES(KTextEditor::CodeCompletionModelControllerInterface3)
+ Q_INTERFACES(KTextEditor::CodeCompletionModelControllerInterface4)
public:
KateWordCompletionModel( QObject *parent );
~KateWordCompletionModel();
@@ -73,6 +73,8 @@
virtual QModelIndex parent(const QModelIndex& index) const;
virtual MatchReaction matchingItem(const QModelIndex& matched);
+ virtual bool shouldHideItemsWithEqualNames() const;
+
const QStringList allMatches( KTextEditor::View *view, const KTextEditor::Range &range ) const;
private:
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic