From 412165fcfbbd27d679a7400ebdef75ff3a9d6aa7 Mon Sep 17 00:00:00 2001 From: isanae <14251494+isanae@users.noreply.github.com> Date: Wed, 22 Jan 2020 03:29:40 -0500 Subject: show file counts when there are discrepancies --- src/envshell.cpp | 32 ++++++++++++++++++++++++++++++++ src/envshell.h | 4 ++++ src/filetree.cpp | 16 +++++++++++++++- 3 files changed, 51 insertions(+), 1 deletion(-) diff --git a/src/envshell.cpp b/src/envshell.cpp index e01bb804..33ec0624 100644 --- a/src/envshell.cpp +++ b/src/envshell.cpp @@ -185,6 +185,11 @@ void ShellMenu::addFile(QFileInfo fi) m_files.emplace_back(std::move(fi)); } +int ShellMenu::fileCount() const +{ + return static_cast(m_files.size()); +} + void ShellMenu::exec(const QPoint& pos) { HMENU menu = getMenu(); @@ -529,6 +534,11 @@ ShellMenuCollection::ShellMenuCollection(QMainWindow* mw) { } +void ShellMenuCollection::addDetails(QString s) +{ + m_details.emplace_back(std::move(s)); +} + void ShellMenuCollection::add(QString name, ShellMenu m) { m_menus.push_back({name, std::move(m)}); @@ -547,6 +557,28 @@ void ShellMenuCollection::exec(const QPoint& pos) return; } + if (!m_details.empty()) { + for (auto&& d : m_details) { + const auto s = d.toStdWString(); + const auto r = AppendMenuW(menu, MF_STRING|MF_DISABLED, 0, s.c_str()); + + if (!r) { + const auto e = GetLastError(); + log::error( + "AppendMenuW failed for details '{}', {}", + d, formatSystemMessage(e)); + } + } + + const auto r = AppendMenuW(menu, MF_SEPARATOR, 0, nullptr); + if (!r) { + const auto e = GetLastError(); + log::error( + "AppendMenuW failed for separator, {}", + formatSystemMessage(e)); + } + } + for (auto&& m : m_menus) { auto hmenu = m.menu.getMenu(); if (!hmenu) { diff --git a/src/envshell.h b/src/envshell.h index 52125a5c..f9245a37 100644 --- a/src/envshell.h +++ b/src/envshell.h @@ -20,6 +20,7 @@ public: ShellMenu& operator=(ShellMenu&&) = default; void addFile(QFileInfo fi); + int fileCount() const; void exec(const QPoint& pos); HMENU getMenu(); @@ -57,7 +58,9 @@ class ShellMenuCollection public: ShellMenuCollection(QMainWindow* mw); + void addDetails(QString s); void add(QString name, ShellMenu m); + void exec(const QPoint& pos); private: @@ -68,6 +71,7 @@ private: }; QMainWindow* m_mw; + std::vector m_details; std::vector m_menus; MenuInfo* m_active; diff --git a/src/filetree.cpp b/src/filetree.cpp index 4e3db1f7..a826ed9a 100644 --- a/src/filetree.cpp +++ b/src/filetree.cpp @@ -487,6 +487,7 @@ void FileTree::showShellMenu(QPoint pos) // menus by origin std::map menus; + int totalFiles = 0; for (auto&& index : m_tree->selectionModel()->selectedRows()) { auto* item = m_model->itemFromIndex(index); @@ -500,6 +501,7 @@ void FileTree::showShellMenu(QPoint pos) } itor->second.addFile(item->realPath()); + ++totalFiles; if (item->isConflicted()) { const auto file = m_core.directoryStructure()->searchFile( @@ -549,6 +551,7 @@ void FileTree::showShellMenu(QPoint pos) menu.exec(m_tree->viewport()->mapToGlobal(pos)); } else { env::ShellMenuCollection mc(mw); + bool hasDiscrepancies = false; for (auto&& m : menus) { const auto* origin = m_core.directoryStructure()->findOriginByID(m.first); @@ -557,7 +560,18 @@ void FileTree::showShellMenu(QPoint pos) continue; } - mc.add(QString::fromStdWString(origin->getName()), std::move(m.second)); + QString caption = QString::fromStdWString(origin->getName()); + if (m.second.fileCount() < totalFiles) { + const auto d = m.second.fileCount(); + caption += " " + tr("(only has %1 file(s))").arg(d); + hasDiscrepancies = true; + } + + mc.add(caption, std::move(m.second)); + } + + if (hasDiscrepancies) { + mc.addDetails(tr("%1 file(s) selected").arg(totalFiles)); } mc.exec(m_tree->viewport()->mapToGlobal(pos)); -- cgit v1.3.1