From: Ivailo Monev Date: Fri, 14 Jul 2023 06:15:39 +0000 (+0300) Subject: dolphin: redo add and remove actions conditions X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=907cd347d053588bb873fb4abef49023efa9d054;p=kde%2Fkde-workspace.git dolphin: redo add and remove actions conditions Signed-off-by: Ivailo Monev --- diff --git a/dolphin/plugins/git/fileviewgitplugin.cpp b/dolphin/plugins/git/fileviewgitplugin.cpp index babd8788..0378b556 100644 --- a/dolphin/plugins/git/fileviewgitplugin.cpp +++ b/dolphin/plugins/git/fileviewgitplugin.cpp @@ -194,6 +194,8 @@ QList FileViewGitPlugin::actions(const KFileItemList &items) const return result; } bool hasdir = false; + bool shouldadd = false; + bool shouldremove = false; foreach (const KFileItem &item, items) { if (item.isDir()) { kDebug() << "Items include directory" << item; @@ -202,6 +204,22 @@ QList FileViewGitPlugin::actions(const KFileItemList &items) const hasdir = true; break; } else { + const QByteArray gitfile = getGitFile(item, m_directory); + unsigned int gitstatusflags = 0; + const int gitresult = git_status_file(&gitstatusflags, m_gitrepo, gitfile.constData()); + if (gitresult != GIT_OK) { + kWarning() << "Could not get status" << gitfile << FileViewGitPlugin::getGitError(); + gitstatusflags = 0; + } + if (gitstatusflags & GIT_STATUS_INDEX_NEW || gitstatusflags & GIT_STATUS_CONFLICTED + || gitstatusflags == GIT_STATUS_CURRENT) { + shouldremove = true; + } + // NOTE: git_index_add_bypath() force-adds ignored files + if (gitstatusflags & GIT_STATUS_WT_NEW || gitstatusflags & GIT_STATUS_INDEX_DELETED + || gitstatusflags & GIT_STATUS_IGNORED) { + shouldadd = true; + } m_actionitems.append(item); } } @@ -211,8 +229,12 @@ QList FileViewGitPlugin::actions(const KFileItemList &items) const result.append(m_commitaction); } } else { - result.append(m_addaction); - result.append(m_removeaction); + if (shouldadd) { + result.append(m_addaction); + } + if (shouldremove) { + result.append(m_removeaction); + } } return result; } diff --git a/dolphin/plugins/git/gitcommitdialog.cpp b/dolphin/plugins/git/gitcommitdialog.cpp index b34729b8..f01dff74 100644 --- a/dolphin/plugins/git/gitcommitdialog.cpp +++ b/dolphin/plugins/git/gitcommitdialog.cpp @@ -87,7 +87,7 @@ void GitCommitDialog::setupWidgets(const QStringList &changedfiles, const QStrin { m_changedfiles->setText(changedfiles.join(QLatin1String("\n"))); if (m_diffdocument) { - // by not re-setting the text the cursor position and selection is preserved + // by not re-setting the text the cursor position and selection are preserved if (m_diffdocument->text() != diff) { // NOTE: can't set the text in read-only mode m_diffdocument->setReadWrite(true);