disconnect(m_model, &KFileItemModel::itemsInserted,
this, &VersionControlObserver::delayedDirectoryVerification);
disconnect(m_model, &KFileItemModel::itemsChanged,
- this, &VersionControlObserver::delayedDirectoryVerification);
+ this, &VersionControlObserver::slotItemsChanged);
}
m_model = model;
connect(m_model, &KFileItemModel::itemsInserted,
this, &VersionControlObserver::delayedDirectoryVerification);
connect(m_model, &KFileItemModel::itemsChanged,
- this, &VersionControlObserver::delayedDirectoryVerification);
+ this, &VersionControlObserver::slotItemsChanged);
}
}
}
}
- if (!m_model || hasNullItems || !isVersioned()) {
+ if (!m_model || hasNullItems) {
return {};
}
- return m_plugin->actions(items);
+ if (isVersionControlled()) {
+ return m_plugin->versionControlActions(items);
+ } else {
+ QList<QAction*> actions;
+ for (const auto &plugin : qAsConst(m_plugins)) {
+ actions << plugin.first->outOfVersionControlActions(items);
+ }
+ return actions;
+ }
}
void VersionControlObserver::delayedDirectoryVerification()
m_dirVerificationTimer->start();
}
+void VersionControlObserver::slotItemsChanged(const KItemRangeList& itemRanges, const QSet<QByteArray>& roles)
+{
+ Q_UNUSED(itemRanges)
+
+ // Because "version" role is emitted by VCS plugin (ourselfs) we don't need to
+ // analyze it and update directory item states information. So lets check if
+ // there is only "version".
+ if ( !(roles.count() == 1 && roles.contains("version")) ) {
+ delayedDirectoryVerification();
+ }
+}
+
void VersionControlObserver::verifyDirectory()
{
if (!m_model) {
if (enabledPlugins.contains((*it)->name())) {
KVersionControlPlugin* plugin = (*it)->createInstance<KVersionControlPlugin>(this);
if (plugin) {
- m_plugins.append(plugin);
+ m_plugins.append( qMakePair(plugin, plugin->fileName()) );
}
}
}
// Verify whether the current directory contains revision information
// like .svn, .git, ...
- foreach (KVersionControlPlugin* plugin, m_plugins) {
- const QString fileName = directory.path() + '/' + plugin->fileName();
+ for (const auto &it : qAsConst(m_plugins)) {
+ const QString fileName = directory.path() + '/' + it.second;
if (QFile::exists(fileName)) {
// The score of this plugin is 0 (best), so we can just return this plugin,
// instead of going through the plugin scoring procedure, we can't find a better one ;)
- return plugin;
+ return it.first;
}
// Version control systems like Git provide the version information
QUrl upUrl = KIO::upUrl(dirUrl);
int upUrlCounter = 1;
while ((upUrlCounter < bestScore) && (upUrl != dirUrl)) {
- const QString fileName = dirUrl.path() + '/' + plugin->fileName();
+ const QString fileName = dirUrl.path() + '/' + it.second;
if (QFile::exists(fileName)) {
if (upUrlCounter < bestScore) {
- bestPlugin = plugin;
+ bestPlugin = it.first;
bestScore = upUrlCounter;
}
break;
return bestPlugin;
}
-bool VersionControlObserver::isVersioned() const
+bool VersionControlObserver::isVersionControlled() const
{
return m_versionedDirectory && m_plugin;
}